Created attachment 1571
D and C code files along with makefile
Trying to call D code from C is resulting in segfault.
Comment #1 by puneet — 2016-01-04T13:28:13Z
(In reply to Puneet Goel from comment #0)
> Created attachment 1571 [details]
> D and C code files along with makefile
>
> Trying to call D code from C is resulting in segfault.
Kindly see the attachment to look at the code that segfaults.
Comment #2 by ag0aep6g — 2016-01-04T21:15:01Z
Reduced the test case a little:
main.c:
----
extern void initialize();
int main(int argc, char*argv[]) {
initialize();
return 0;
}
----
foo.d:
----
extern(C) void initialize() {
import core.runtime;
Runtime.initialize;
int x;
auto dg = {x = 2;};
Runtime.terminate();
}
----
Compiling and running:
----
$ gcc -c main.c
$ dmd foo.d main.o
$ ./foo
Segmentation fault (core dumped)
----
Comment #3 by ag0aep6g — 2016-01-04T21:19:25Z
I think the problem is that the memory for the closure is allocated as soon as the initialize function is entered, i.e. before the call to Runtime.initialize.
Comment #4 by razvan.nitu1305 — 2022-10-28T09:12:37Z
I cannot reproduce this example. Compiling the reduced test case and running it now leads to graceful program exit.