D - Memory Management issuse interfacing to C
- C (17/17) Apr 13 2004 Hi all,
- C (7/21) Apr 13 2004 to
- J Anderson (6/7) Apr 13 2004 C and I figured it out.
- Russ Lewis (7/7) Apr 13 2004 I also noticed that main() checks bt == null, but then assumes that it's...
- C (28/35) Apr 14 2004 Yes your , it was simplied for the example
Hi all, Im trying to create a linked-list struct in C, and retuning a pointer to= = it in D, but everytime I try to access the data it faults in D , though = in = C it works as expected. Also trying to pass BackTrace* as a parameter to FillStruct and using D = to = allocate a BackTrace struct fails with same error. Files attached, am I missing something obvious ? dmc -c foo.c dmd bar.d foo.obj bar.exe Thanks, Charlie -- = D Newsgroup.
Apr 13 2004
Oops this should be the bar.d On Tue, 13 Apr 2004 17:03:20 -0700, C <dont respond.com> wrote:Hi all, Im trying to create a linked-list struct in C, and retuning a pointer =toit in D, but everytime I try to access the data it faults in D , thoug=h =in C it works as expected. Also trying to pass BackTrace* as a parameter to FillStruct and using =D =to allocate a BackTrace struct fails with same error. Files attached, am I missing something obvious ? dmc -c foo.c dmd bar.d foo.obj bar.exe Thanks, Charlie-- = D Newsgroup.
Apr 13 2004
C wrote:Oops this should be the bar.dC and I figured it out. Simply replace %s with %.*s. D seems to be converting the c array to a d array when its passed into printf. -- -Anderson: http://badmama.com.au/~anderson/
Apr 13 2004
I also noticed that main() checks bt == null, but then assumes that it's not null. If you think that bt might be null, then you MUST NOT check bt.curr, since any attempt to read the value of this will result in null pointer dereferenece. Return from main() when you detect null, or put the while() inside an else... of the if statement, or just include a bt != null test in the while.
Apr 13 2004
Yes your , it was simplied for the example I was also having trouble because in my D import file i used struct tagBackTraceItem { char fileName[MAX_PATH+1]; char symName[4096]; int lineNumber; BackTraceItem * next; }; And in my actual header file I was using typedef struct tagBackTraceItem{ char symName[4096]; char fileName[MAX_PATH +1]; int lineNumber; struct tagBackTraceItem* next; } BackTraceItem; The order of the fields are not the same, I was getting the symName valu= e = stored in the D fileName variable. Thanks, Charlie On Tue, 13 Apr 2004 23:03:21 -0700, Russ Lewis = <spamhole-2001-07-16 deming-os.org> wrote:I also noticed that main() checks bt =3D=3D null, but then assumes tha=t it's =not null. If you think that bt might be null, then you MUST NOT check bt.curr, =since any attempt to read the value of this will result in null pointe=r =dereferenece. Return from main() when you detect null, or put the =while() inside an else... of the if statement, or just include a bt !=3D==null test in the while.-- = D Newsgroup.
Apr 14 2004