digitalmars.D - help -- Segmentation fault: std.c.setjmp - setjmp.d
-
some where.com
(87/87)
Apr 30 2004
I'm try to create std.c.setjmp from
(on Linux, gcc 3.3.1) - Walter (9/78) Apr 30 2004 sj.d ---------------------
- some where.com (23/24) Apr 30 2004 What do you mean?
- Walter (4/29) Apr 30 2004 C's setjmp() takes a pointer to a struct, not the struct itself. Just as...
- Walter (6/48) Apr 30 2004 Forgot to mention, you'll also need to fix your declaration of setjmp() ...
- some where.com (22/30) Apr 30 2004 I also have *thought* that setjmp() should take a pointer. And the call...
- Walter (13/45) May 02 2004 You're falling victim to the C rule of implicitly converting arrays to
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) ; } --------------------------------------------------------------------------- begin 0644 setjmp.d M;6]D=6QE('-T9"YC+G-E=&IM<#L*"F5X=&5R;B`H0RD "GL*"F%L:6%S(&EN M="!?7VIM<%]B=69;-ET["F%L:6%S(&EN="!?7W-I9U]A=&]M:6-?=#L*"G-T M<G5C="!?7W-I9W-E=%]T"B` >PH ("` =6EN="!?7W9A;%LH,3`R-"`O(" X M("H =6EN="YS:7IE;V8I*5T["B` ?0H*<W1R=6-T(%]?:FUP7V)U9E]T86<* M("![" H ("` 7U]J;7!?8G5F(%]?:FUP8G5F.PH ("` :6YT(%]?;6%S:U]W M87-?<V%V960["B` ("!?7W-I9W-E=%]T(%]?<V%V961?;6%S:SL*("!]" IA M;&EA<R!?7VIM<%]B=69?=&%G(&IM<%]B=68[" IE>'1E<FX :6YT('-E=&IM M<"`H:FUP7V)U9B!?7V5N=BD .PH*97AT97)N(&EN="!?7W-I9W-E=&IM<"`) M*%]?:FUP7V)U9E]T86< 7U]E;G8L(&EN="!?7W-A=F5M87-K*2`[" IE>'1E M<FX :6YT(%]S971J;7` "2A?7VIM<%]B=69?=&%G(%]?96YV*2`[" IE>'1E M<FX =F]I9"!L;VYG:FUP(`DH7U]J;7!?8G5F7W1A9R!?7V5N=BP :6YT(%]? M=F%L*2`[" IE>'1E<FX =F]I9"!?;&]N9VIM<"`)*%]?:FUP7V)U9E]T86< M7U]E;G8L(&EN="!?7W9A;"D .PH*86QI87, 7U]J;7!?8G5F7W1A9R!S:6=J M;7!?8G5F.PIE>'1E<FX =F]I9"!S:6=L;VYG:FUP(`DH<VEG:FUP7V)U9B!? 67V5N=BP :6YT(%]?=F%L*2`[" I]"F=L ` end
Apr 30 2004
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 linksj:[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) ; } ---------------------------------------------------------------------------
Apr 30 2004
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.
Apr 30 2004
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...typesTry &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(__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.
Apr 30 2004
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 asyouwould in C. <some where.com> wrote in message news:c6tu09$2t7e$1 digitaldaemon.com...In article <c6tsrh$2r2d$1 digitaldaemon.com>, Walter says...typesTry &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(__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.
Apr 30 2004
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 asyouwould in C.
Apr 30 2004
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 thecallingfunction should hold the actual struct. But ... (Digital Mars CompilerVersion8.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 yourexplanation?Thanks. In article <c6uk14$ts0$1 digitaldaemon.com>, Walter says...inForgot to mention, you'll also need to fix your declaration of setjmp()messagesetjmp.d to take a pointer to the struct. Otherwise, you'll get theasyou 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. Justyouwould in C.
May 02 2004