Having a strange issue with std.net.curl.HTTP as a struct dependency

NoBigDeal256 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jul 9 17:10:36 PDT 2017


I'm currently learning D and started working on one of my first 
projects which is an API wrapper. I'm currently having an issue 
with my program getting a InvalidMemoryOperationError upon 
exiting the process on Windows 7. On my Debian VM I get a 
segmentation fault.

I have tried to minimize the code as much as I possibly can while 
still reproducing the error. Here is the code:

import std.net.curl;

struct ThingA {

     HTTP http;

     this(HTTP http) {
         this.http = http;

         arrayOfThingBs();
     }

     ThingB[] arrayOfThingBs() {
         ThingB[] thingBs;

         thingBs ~= ThingB(this);

         return thingBs;
     }

}

struct ThingB {

     ThingA thingA;

     this(ThingA thingA) {
         this.thingA = thingA;
     }

}

void main() {
     auto http = HTTP();
     auto thingA = ThingA(http);
}


If I comment out the HTTP dependency like:

struct ThingA {

     //HTTP http;

     this(HTTP http) {
         //this.http = http;

         arrayOfThingBs();
     }

     ThingB[] arrayOfThingBs() {
         ThingB[] thingBs;

         thingBs ~= ThingB(this);

         return thingBs;
     }

}

The error goes away. The error also goes away if 
ThingA.arrayOfThingBs returns a single instance of ThingB instead 
of an array of ThingB. Removing ThingBs dependency on ThingA also 
gets rid of the error. I'm new to low level languages in general 
so maybe I'm doing something wrong, but this seems like really 
strange behavior.


More information about the Digitalmars-d-learn mailing list