Thread overview
Can't pass [] to extern function object method
Nov 16, 2020
frame
Nov 16, 2020
Jack
Nov 16, 2020
frame
Nov 18, 2020
frame
Nov 19, 2020
Bastiaan Veelo
Nov 19, 2020
frame
November 16, 2020
I have a DLL in D-code which returns an object and want to pass a struct S[] to a member function of that object. The first element is passed correctly, the rest is just garbage. In fact the next item is just a single byte with value 0x11 following some 0x00.

It doesn't matter if I'm using S[], S[]* or S* with .ptr. The length of the array is correct but the data isn't except the first item.

Is this a trap because of extern function? How can I access the next item? Increasing the pointer is equivalent with S[1].
November 16, 2020
On Monday, 16 November 2020 at 21:31:44 UTC, frame wrote:
> I have a DLL in D-code which returns an object and want to pass a struct S[] to a member function of that object. The first element is passed correctly, the rest is just garbage. In fact the next item is just a single byte with value 0x11 following some 0x00.
>
> It doesn't matter if I'm using S[], S[]* or S* with .ptr. The length of the array is correct but the data isn't except the first item.
>
> Is this a trap because of extern function? How can I access the next item? Increasing the pointer is equivalent with S[1].

What is the function prototype like and how are you declaring that struct?
November 16, 2020
On Monday, 16 November 2020 at 21:58:44 UTC, Jack wrote:

> What is the function prototype like and how are you declaring that struct?

The struct is very simple, it contains:

struct S {
    SysTime a;
    ulong b;
    double c;
    ubyte[] d;
    string e;
}

And I tried:

bool foo(S[] params);     // passing a S[]
bool foo(S[]* params);    // passing a &S[]
bool foo(S* params);      // passing a S.ptr

November 18, 2020
On Monday, 16 November 2020 at 22:22:42 UTC, frame wrote:
> On Monday, 16 November 2020 at 21:58:44 UTC, Jack wrote:
>
>> What is the function prototype like and how are you declaring that struct?
>
> The struct is very simple, it contains:

I found the "bug". It was caused by a debug {} statement within a struct method. I assume that the debug symbol is just incompatible called from the DLL context.


November 19, 2020
On Wednesday, 18 November 2020 at 10:50:12 UTC, frame wrote:
> I found the "bug". It was caused by a debug {} statement within a struct method. I assume that the debug symbol is just incompatible called from the DLL context.

Were the DLL and main program built in different modes (debug/release)? Then this problem is understandable. Otherwise I find this surprising, and probably worth a bug report?

— Bastiaan.
November 19, 2020
On Thursday, 19 November 2020 at 07:46:20 UTC, Bastiaan Veelo wrote:
> On Wednesday, 18 November 2020 at 10:50:12 UTC, frame wrote:
>> I found the "bug". It was caused by a debug {} statement within a struct method. I assume that the debug symbol is just incompatible called from the DLL context.
>
> Were the DLL and main program built in different modes (debug/release)? Then this problem is understandable. Otherwise I find this surprising, and probably worth a bug report?
>
> — Bastiaan.

No, but the DLL was compiled with -debug flag which enables an additional member that the main program cannot see. I think that is the explaination. In fact the flag was not set on the main program.