Varargs issue with LDC
Don Allen
donaldcallen at gmail.com
Wed Jan 31 17:16:51 UTC 2024
On Wednesday, 31 January 2024 at 16:19:17 UTC, Hipreme wrote:
> On Wednesday, 31 January 2024 at 15:25:44 UTC, Don Allen wrote:
>> As mentioned in previous posts, I've written a personal
>> finance manager in D (ported from the original C) that works
>> well when compiled with dmd.
>>
>> When compiled with ldc, however, it segfaults when I try to
>> perform an operation that involves a call to a varargs
>> function in gtk3. The segfault occurs in the
>> bowels of gtk3, but a backtrace in gdb shows that the last
>> thing that happened in my code was the call to the varargs
>> function that I refer to above. At this point I am assuming,
>> but do not know, that the issue is related to the varargs
>> nature of the called gtk function.
>>
>> This is disappointing. Has anyone experienced a similar issue
>> with ldc or knows of known varargs problems with ldc? I did
>> check the ldc github repository and did not find an open issue
>> that sounds similar to what I'm seeing.
>>
>> This problem occurred on an up-to-date Arch Linux system with
>> the latest release of ldc installed.
>>
>> /Don Allen
>
> Works well in DMD, crashes on LDC, arguments issue. Take a look
> if you're using the correct `extern(C)` and `extern(D)` in the
> right places. Depending on the compiler you're using, `extern`
> does more than name mangling, it also changes the order in
> which the argument are received.
The called gtk function has this prototype, which I believe is
correct:
````
extern (C) GtkListStore* gtk_list_store_new (gint n_columns, ...);
````
The call site looks like
````
writefln("debug: %d", NMktStore.num_cols);
store = gtk_list_store_new(NMktStore.num_cols,
g_type_string, // date
g_type_string, // num
g_type_string, // description
g_type_boolean, // r
g_type_string, // transaction guid
g_type_string, // value
g_type_string); // balance
````
The debugging writefln prints "debug: 7", which is correct.
>
> Also, on a related note: I don't know if you're doing it or
> not, but always mark vararg as `scope`. That means you can't
> save them anywhere, why? Because you really can't. varargs are
> stack allocated so it may also cause a segfault if you try to
> access them after the function exits its scope.
>
I'm not sure what you mean here. Maybe you can be more explicit
after seeing the extern and call above.
> Also, you should post this on Learn instead.
I thought of that, but wanted a wider audience for my question.
More information about the Digitalmars-d
mailing list