Thread overview
Memory Management issuse interfacing to C
Apr 13, 2004
C
Apr 13, 2004
C
Apr 14, 2004
J Anderson
Apr 14, 2004
Russ Lewis
Apr 14, 2004
C
April 13, 2004
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.

April 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 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.

April 14, 2004
C wrote:

> Oops this should be the bar.d

C 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/
April 14, 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.

April 14, 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 value 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 == 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.
>



-- 
D Newsgroup.