Thread overview |
---|
April 30, 2004 help -- Segmentation fault: std.c.setjmp - setjmp.d | ||||
---|---|---|---|---|
| ||||
Attachments: | I'm try to create std.c.setjmp from <setjmp.h> (on Linux, gcc 3.3.1) The following simple program seg faults: [d] dmd -g sj.d gcc sj.o -o sj -g -lphobos -lpthread -lm [d] ./sj Segmentation fault ------------------------------------------------ sj.d --------------------- import std.c.setjmp; jmp_buf env; void main() { if(setjmp(env)) { printf("0\n"); } else { printf("1\n"); } } --------------------------------------------------------------------------- Can anybody tell me why? thanks! Also, if I change "env" to be a local var inside "main()", I cannot link sj: [d] dmd -g sj.d gcc sj.o -o sj -g -lphobos -lpthread -lm sj.o(.gnu.linkonce.t_Dmain+0x8): In function `_Dmain': : undefined reference to `_init_3std1c6setjmp13__jmp_buf_tag' collect2: ld returned 1 exit status --- errorlevel 256 ------------------------------------------------ sj.d --------------------- import std.c.setjmp; void main() { jmp_buf env; if(setjmp(env)) { printf("0\n"); } else { printf("1\n"); } } --------------------------------------------------------------------------- So what's the problem with linking? Thanks. The generated setjmp.d is here (also attached): ---------------------------------------------------------- setjmp.d ------- odule std.c.setjmp; extern (C) { alias int __jmp_buf[6]; alias int __sig_atomic_t; struct __sigset_t { uint __val[(1024 / (8 * uint.sizeof))]; } struct __jmp_buf_tag { __jmp_buf __jmpbuf; int __mask_was_saved; __sigset_t __saved_mask; } alias __jmp_buf_tag jmp_buf; extern int setjmp (jmp_buf __env) ; extern int __sigsetjmp (__jmp_buf_tag __env, int __savemask) ; extern int _setjmp (__jmp_buf_tag __env) ; extern void longjmp (__jmp_buf_tag __env, int __val) ; extern void _longjmp (__jmp_buf_tag __env, int __val) ; alias __jmp_buf_tag sigjmp_buf; extern void siglongjmp (sigjmp_buf __env, int __val) ; } --------------------------------------------------------------------------- |
April 30, 2004 Re: help -- Segmentation fault: std.c.setjmp - setjmp.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to some | Try &jmp_buf. <some@where.com> wrote in message news:c6t0e4$1bc8$1@digitaldaemon.com... > I'm try to create std.c.setjmp from <setjmp.h> (on Linux, gcc 3.3.1) > > The following simple program seg faults: > > [d] dmd -g sj.d > gcc sj.o -o sj -g -lphobos -lpthread -lm > [d] ./sj > Segmentation fault > ------------------------------------------------ sj.d --------------------- > import std.c.setjmp; > > jmp_buf env; > > void main() > { > if(setjmp(env)) { > printf("0\n"); > } > else { > printf("1\n"); > } > } > -------------------------------------------------------------------------- - > > Can anybody tell me why? thanks! > > Also, if I change "env" to be a local var inside "main()", I cannot link sj: > > [d] dmd -g sj.d > gcc sj.o -o sj -g -lphobos -lpthread -lm > sj.o(.gnu.linkonce.t_Dmain+0x8): In function `_Dmain': > : undefined reference to `_init_3std1c6setjmp13__jmp_buf_tag' > collect2: ld returned 1 exit status > --- errorlevel 256 > ------------------------------------------------ sj.d --------------------- > import std.c.setjmp; > > void main() > { > jmp_buf env; > > if(setjmp(env)) { > printf("0\n"); > } > else { > printf("1\n"); > } > } > -------------------------------------------------------------------------- - > > So what's the problem with linking? > > Thanks. > > The generated setjmp.d is here (also attached): > ---------------------------------------------------------- setjmp.d ------- > odule std.c.setjmp; > > extern (C) > { > > alias int __jmp_buf[6]; > alias int __sig_atomic_t; > > struct __sigset_t > { > uint __val[(1024 / (8 * uint.sizeof))]; > } > > struct __jmp_buf_tag > { > > __jmp_buf __jmpbuf; > int __mask_was_saved; > __sigset_t __saved_mask; > } > > alias __jmp_buf_tag jmp_buf; > > extern int setjmp (jmp_buf __env) ; > > extern int __sigsetjmp (__jmp_buf_tag __env, int __savemask) ; > > extern int _setjmp (__jmp_buf_tag __env) ; > > extern void longjmp (__jmp_buf_tag __env, int __val) ; > > extern void _longjmp (__jmp_buf_tag __env, int __val) ; > > alias __jmp_buf_tag sigjmp_buf; > extern void siglongjmp (sigjmp_buf __env, int __val) ; > > } > -------------------------------------------------------------------------- - > > > > |
April 30, 2004 Re: help -- Segmentation fault: std.c.setjmp - setjmp.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | In article <c6tsrh$2r2d$1@digitaldaemon.com>, Walter says... > >Try &jmp_buf. What do you mean? I tried to put "&" before/after "jmp_buf", the file is not compiling: [d] dmd sj.d sj.d(3): no identifier for declarator sj.d(3): semicolon expected, not '&' sj.d(3): Declaration expected, not '&' If I try to put "&" before "env", it says: [d] dmd sj.d sj.d(6): function setjmp (__jmp_buf_tag __env) does not match argument types (__jmp_buf_tag *) [d] cat sj.d ------------------------------------------------------------------ import std.c.setjmp; jmp_buf env; void main() { if(setjmp(&env)) { printf("0\n"); } else { printf("1\n"); } } ------------------------------------------------------------------ This is a very tiny example, can you be more verbose in your response? Thanks. |
April 30, 2004 Re: help -- Segmentation fault: std.c.setjmp - setjmp.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to some | C's setjmp() takes a pointer to a struct, not the struct itself. Just as you would in C. <some@where.com> wrote in message news:c6tu09$2t7e$1@digitaldaemon.com... > In article <c6tsrh$2r2d$1@digitaldaemon.com>, Walter says... > > > >Try &jmp_buf. > > What do you mean? > > I tried to put "&" before/after "jmp_buf", the file is not compiling: > > [d] dmd sj.d > sj.d(3): no identifier for declarator > sj.d(3): semicolon expected, not '&' > sj.d(3): Declaration expected, not '&' > > If I try to put "&" before "env", it says: > > [d] dmd sj.d > sj.d(6): function setjmp (__jmp_buf_tag __env) does not match argument types > (__jmp_buf_tag *) > > > [d] cat sj.d > ------------------------------------------------------------------ > import std.c.setjmp; > > jmp_buf env; > void main() > { > if(setjmp(&env)) { printf("0\n"); } > else { printf("1\n"); } > } > ------------------------------------------------------------------ > > This is a very tiny example, can you be more verbose in your response? > > Thanks. > > > |
April 30, 2004 Re: help -- Segmentation fault: std.c.setjmp - setjmp.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Forgot to mention, you'll also need to fix your declaration of setjmp() in setjmp.d to take a pointer to the struct. Otherwise, you'll get the message you did in the second example. "Walter" <newshound@digitalmars.com> wrote in message news:c6uja9$sqg$1@digitaldaemon.com... > C's setjmp() takes a pointer to a struct, not the struct itself. Just as you > would in C. > > <some@where.com> wrote in message news:c6tu09$2t7e$1@digitaldaemon.com... > > In article <c6tsrh$2r2d$1@digitaldaemon.com>, Walter says... > > > > > >Try &jmp_buf. > > > > What do you mean? > > > > I tried to put "&" before/after "jmp_buf", the file is not compiling: > > > > [d] dmd sj.d > > sj.d(3): no identifier for declarator > > sj.d(3): semicolon expected, not '&' > > sj.d(3): Declaration expected, not '&' > > > > If I try to put "&" before "env", it says: > > > > [d] dmd sj.d > > sj.d(6): function setjmp (__jmp_buf_tag __env) does not match argument > types > > (__jmp_buf_tag *) > > > > > > [d] cat sj.d > > ------------------------------------------------------------------ > > import std.c.setjmp; > > > > jmp_buf env; > > void main() > > { > > if(setjmp(&env)) { printf("0\n"); } > > else { printf("1\n"); } > > } > > ------------------------------------------------------------------ > > > > This is a very tiny example, can you be more verbose in your response? > > > > Thanks. > > > > > > > > |
April 30, 2004 Re: help -- Segmentation fault: std.c.setjmp - setjmp.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | I also have *thought* that setjmp() should take a pointer. And the calling function should hold the actual struct. But ... (Digital Mars Compiler Version 8.38n) c:\> dmc sj.c link sj,,,user32+kernel32/noi; c:\> sj.exe sizeof(jmp_buf) = 64 ----------------------------------------------------------------- sj.c ----- #include <setjmp.h> #include <stdio.h> int main() { printf("sizeof(jmp_buf) = %d\n", sizeof(jmp_buf)); return 0; } ----------------------------------------------------------------- sj.c ----- And on Linux: [d] ./sj sizeof(jmp_buf) = 156 I'm totally confused. Can you try my example? and what's your explanation? Thanks. In article <c6uk14$ts0$1@digitaldaemon.com>, Walter says... > >Forgot to mention, you'll also need to fix your declaration of setjmp() in setjmp.d to take a pointer to the struct. Otherwise, you'll get the message you did in the second example. > >"Walter" <newshound@digitalmars.com> wrote in message news:c6uja9$sqg$1@digitaldaemon.com... >> C's setjmp() takes a pointer to a struct, not the struct itself. Just as >you >> would in C. |
May 02, 2004 Re: help -- Segmentation fault: std.c.setjmp - setjmp.d | ||||
---|---|---|---|---|
| ||||
Posted in reply to some | You're falling victim to the C rule of implicitly converting arrays to pointers, *EXCEPT* if they are the argument to sizeof. Thus, setjmp(jmp_buf) passes a pointer to setjmp, but sizeof(jmp_buf) gives the size of the jmp_buf array, not the size of a pointer. <some@where.com> wrote in message news:c6ull3$104i$1@digitaldaemon.com... > I also have *thought* that setjmp() should take a pointer. And the calling > function should hold the actual struct. But ... (Digital Mars Compiler Version > 8.38n) > > c:\> dmc sj.c > link sj,,,user32+kernel32/noi; > > c:\> sj.exe > sizeof(jmp_buf) = 64 > > ----------------------------------------------------------------- sj.c ----- > #include <setjmp.h> > #include <stdio.h> > > int main() > { > printf("sizeof(jmp_buf) = %d\n", sizeof(jmp_buf)); > return 0; > } > ----------------------------------------------------------------- sj.c ----- > > And on Linux: > > [d] ./sj > sizeof(jmp_buf) = 156 > > I'm totally confused. Can you try my example? and what's your explanation? > > Thanks. > > > In article <c6uk14$ts0$1@digitaldaemon.com>, Walter says... > > > >Forgot to mention, you'll also need to fix your declaration of setjmp() in > >setjmp.d to take a pointer to the struct. Otherwise, you'll get the message > >you did in the second example. > > > >"Walter" <newshound@digitalmars.com> wrote in message news:c6uja9$sqg$1@digitaldaemon.com... > >> C's setjmp() takes a pointer to a struct, not the struct itself. Just as > >you > >> would in C. > > |
Copyright © 1999-2021 by the D Language Foundation