D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4199 - D2 core.sys.posix.*: array parameters of C functions must be ref
Summary: D2 core.sys.posix.*: array parameters of C functions must be ref
Status: RESOLVED DUPLICATE of issue 3604
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: Sean Kelly
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-17 00:41 UTC by Shin Fujishiro
Modified: 2014-02-15 02:42 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Shin Fujishiro 2010-05-17 00:41:40 UTC
This program core dumps on FreeBSD (and it should on Linux):
--------------------
import core.sys.posix.setjmp;

void main()
{
    jmp_buf st = void;

    setjmp(st);
    assert(0); // trap; not reached due to the bug
}
--------------------

The C standard defines jmp_buf as an array.  In C and D1, the definition works since arrays (static arrays) are passed to functions by reference.  But in D2, static arrays are passed by value!  Hence the above program core dumps.

So, setjmp() and longjmp() must be declared as:
--------------------
int  setjmp(ref jmp_buf);
void longjmp(ref jmp_buf, int);
--------------------
Comment 1 Shin Fujishiro 2010-05-17 06:17:01 UTC
Hmm, the problem seems more generic.  More functions in core.sys.posix.* take array parameters, and these are not ref-ed.  A good example is pipe():
--------------------
import std.stdio;
import core.sys.posix.unistd; // int pipe(int[2]);
void main() {
    int[2] pp;
    pipe(pp);
    writeln("Hello, world."); // not reached!
}
--------------------

The pipe() must be declared like: int pipe(ref int[2]).
Comment 2 Steven Schveighoffer 2010-05-17 06:34:35 UTC

*** This issue has been marked as a duplicate of issue 3604 ***