www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can't figure out segfault

reply rm <xenomorph64 gmail.com> writes:
I put together bindings for DevIL in D to use on a school assignment.  The
bindings (attached) work fine on Windows, but cause a segfault on Linux when I
call ilInit.

this can be demonstrated by a little test program

"
import graphics.bindings.devil;

public void main(string[] args)
{
   ilInit();
}
"
compiled with "dmd -L-ldl test.d devil.d" where test.d is the above program
and devil.d is attached.

When run, this program segfaults, but if lines 112,113,165,166 of devil.d are
commented out, the program works fine, and I can't figure out what the problem
with those lines is.  The fact that this works on Windows confuses me even more.

Any help would be appreciated.
begin 644 devil.d
M;6]D=6QE(&=R87!H:6-S+F)I;F1I;F=S+F1E=FEL.PH*:6UP;W)T('-T9"YS
M=')I;F<[" IV97)S:6]N*%=I;F1O=W,I"GL*"6EM<&]R="!S=&0N8RYW:6YD
M;W=S+G=I;F1O=W,["GT*96QS92!V97)S:6]N*&QI;G5X*0I[" EI;7!O<G0 
M<W1D+F,N;&EN=7 N;&EN=7 ["GT*96QS90I[" ES=&%T:6, 87-S97)T*&9A
M;'-E*3L*?0H*<'5B;&EC(&EM;75T86)L92!U:6YT($E,7T-/3$]54E])3D1%
M6"` ("` /2`P>#$Y,#`["G!U8FQI8R!I;6UU=&%B;&4 =6EN="!)3%]#3TQ/
M4E])3D1%6"` ("` (#T ,' Q.3`P.PIP=6)L:6, :6UM=71A8FQE('5I;G0 
M24Q?04Q02$$)"0D (#T ,' Q.3`V.PIP=6)L:6, :6UM=71A8FQE('5I;G0 
M24Q?4D="("` ("` ("` ("` ("`](#!X,3DP-SL*<'5B;&EC(&EM;75T86)L
M92!U:6YT($E,7U)'0D$ ("` ("` ("` ("` /2`P>#$Y,# ["G!U8FQI8R!I
M;6UU=&%B;&4 =6EN="!)3%]"1U( ("` ("` ("` ("` (#T ,' X,$4P.PIP
M=6)L:6, :6UM=71A8FQE('5I;G0 24Q?0D=202` ("` ("` ("` ("`](#!X
M.#!%,3L*<'5B;&EC(&EM;75T86)L92!U:6YT($E,7TQ534E.04Y#12` ("` 
M("` /2`P>#$Y,#D["G!U8FQI8R!I;6UU=&%B;&4 =6EN="!)3%],54U)3D%.
M0T5?04Q02$$ (#T ,' Q.3!!.PH*<'5B;&EC(&EM;75T86)L92!U:6YT($E,
M7T)95$4 ("` ("` ("` (#T ,' Q-#`P.PIP=6)L:6, :6UM=71A8FQE('5I
M;G0 24Q?54Y324=.141?0EE412` /2`P>#$T,#$["G!U8FQI8R!I;6UU=&%B
M;&4 =6EN="!)3%]32$]25"` ("` ("` ("`](#!X,30P,CL*<'5B;&EC(&EM
M;75T86)L92!U:6YT($E,7U5.4TE'3D5$7U-(3U)4(#T ,' Q-#`S.PIP=6)L
M:6, :6UM=71A8FQE('5I;G0 24Q?24Y4("` ("` ("` ("` /2`P>#$T,#0[
M"G!U8FQI8R!I;6UU=&%B;&4 =6EN="!)3%]53E-)1TY%1%])3E0 ("`](#!X
M,30P-3L*<'5B;&EC(&EM;75T86)L92!U:6YT($E,7T9,3T%4("` ("` ("` 
M(#T ,' Q-#`V.PIP=6)L:6, :6UM=71A8FQE('5I;G0 24Q?1$]50DQ%("` 
M("` ("` /2`P>#$T,$$["G!U8FQI8R!I;6UU=&%B;&4 =6EN="!)3%](04Q&
M("` ("` ("` ("`](#!X,30P0CL*"B\O26UA9V4 5'EP97,*<'5B;&EC(&EM
M;75T86)L92!U:6YT($E,7U194$5?54Y+3D]73B`](#!X,#`P,#L*<'5B;&EC
M(&EM;75T86)L92!U:6YT($E,7T)-4"` ("` ("` ("`](#!X,#0R,#L ("\O
M(3P 36EC<F]S;V9T(%=I;F1O=W, 0FET;6%P("T +F)M<"!E>'1E;G-I;VX*
M<'5B;&EC(&EM;75T86)L92!U:6YT($E,7T-55"` ("` ("` ("`](#!X,#0R
M,3L ("\O(3P 1'(N($AA;&\ +2`N8W5T(&5X=&5N<VEO; IP=6)L:6, :6UM
M=71A8FQE('5I;G0 24Q?1$]/32` ("` ("` (#T ,' P-#(R.R` +R\A/"!$
M;V]-('=A;&QS("T ;F\ <W!E8VEF:6, 97AT96YS:6]N"G!U8FQI8R!I;6UU
M=&%B;&4 =6EN="!)3%]$3T]-7T9,050 ("` /2`P>#`T,C,[("`O+R$\($1O
M;TT 9FQA=', +2!N;R!S<&5C:69I8R!E>'1E;G-I;VX*<'5B;&EC(&EM;75T
M86)L92!U:6YT($E,7TE#3R` ("` ("` ("`](#!X,#0R-#L ("\O(3P 36EC
M<F]S;V9T(%=I;F1O=W, 26-O;G, 86YD($-U<G-O<G, +2`N:6-O(&%N9"`N
M8W5R(&5X=&5N<VEO;G,*<'5B;&EC(&EM;75T86)L92!U:6YT($E,7TI01R` 
M("` ("` ("`](#!X,#0R-3L ("\O(3P 2E!%1R`M("YJ<&<L("YJ<&4 86YD
M("YJ<&5G(&5X=&5N<VEO;G,*<'5B;&EC(&EM;75T86)L92!U:6YT($E,7TI&
M248 ("` ("` ("`](#!X,#0R-3L ("\O(3P*<'5B;&EC(&EM;75T86)L92!U
M:6YT($E,7TE,0DT ("` ("` ("`](#!X,#0R-CL ("\O(3P 06UI9V$ 249&
M("A&3U)-($E,0DTI("T +FEF9BP +FEL8FTL("YL8FT 97AT96YS:6]N<PIP
M=6)L:6, :6UM=71A8FQE('5I;G0 24Q?4$-$("` ("` ("` (#T ,' P-#(W
M.R` +R\A/"!+;V1A:R!0:&]T;T-$("T +G!C9"!E>'1E;G-I;VX*<'5B;&EC
M(&EM;75T86)L92!U:6YT($E,7U!#6"` ("` ("` ("`](#!X,#0R.#L ("\O
M(3P 6E-O9G0 4$-8("T +G!C>"!E>'1E;G-I;VX*<'5B;&EC(&EM;75T86)L
M92!U:6YT($E,7U!)0R` ("` ("` ("`](#!X,#0R.3L ("\O(3P 4$E#("T 
M+G!I8R!E>'1E;G-I;VX*<'5B;&EC(&EM;75T86)L92!U:6YT($E,7U!.1R` 
M("` ("` ("`](#!X,#0R03L ("\O(3P 4&]R=&%B;&4 3F5T=V]R:R!'<F%P
M:&EC<R`M("YP;F< 97AT96YS:6]N"G!U8FQI8R!I;6UU=&%B;&4 =6EN="!)
M3%]03DT ("` ("` ("` /2`P>#`T,D([("`O+R$\(%!O<G1A8FQE($%N>2!-
M87` +2`N<&)M+"`N<&=M+"`N<'!M(&%N9"`N<&YM(&5X=&5N<VEO;G,*<'5B
M;&EC(&EM;75T86)L92!U:6YT($E,7U-'22` ("` ("` ("`](#!X,#0R0SL 
M("\O(3P 4VEL:6-O;B!'<F%P:&EC<R`M("YS9VDL("YB=RP +G)G8B!A;F0 
M+G)G8F$ 97AT96YS:6]N<PIP=6)L:6, :6UM=71A8FQE('5I;G0 24Q?5$=!
M("` ("` ("` (#T ,' P-#)$.R` +R\A/"!4<G5E5FES:6]N(%1A<F=A($9I
M;&4 +2`N=&=A+"`N=F1A+"`N:6-B(&%N9"`N=G-T(&5X=&5N<VEO;G,*<'5B
M;&EC(&EM;75T86)L92!U:6YT($E,7U1)1B` ("` ("` ("`](#!X,#0R13L 
M("\O(3P 5&%G9V5D($EM86=E($9I;&4 1F]R;6%T("T +G1I9B!A;F0 +G1I
M9F8 97AT96YS:6]N<PIP=6)L:6, :6UM=71A8FQE('5I;G0 24Q?0TA%040 
M("` ("` (#T ,' P-#)&.R` +R\A/"!#+5-T>6QE($AE861E<B`M("YH(&5X
M=&5N<VEO; IP=6)L:6, :6UM=71A8FQE('5I;G0 24Q?4D%7("` ("` ("` 
M(#T ,' P-#,P.R` +R\A/"!287< 26UA9V4 1&%T82`M(&%N>2!E>'1E;G-I
M;VX*<'5B;&EC(&EM;75T86)L92!U:6YT($E,7TU$3"` ("` ("` ("`](#!X
M,#0S,3L ("\O(3P 2&%L9BU,:69E($UO9&5L(%1E>'1U<F4 +2`N;61L(&5X
M=&5N<VEO; IP=6)L:6, :6UM=71A8FQE('5I;G0 24Q?5T%,("` ("` ("` 
M(#T ,' P-#,R.R` +R\A/"!1=6%K92`R(%1E>'1U<F4 +2`N=V%L(&5X=&5N
M<VEO; IP=6)L:6, :6UM=71A8FQE('5I;G0 24Q?3$E&("` ("` ("` (#T 
M,' P-#,T.R` +R\A/"!(;VUE=V]R;&0 5&5X='5R92`M("YL:68 97AT96YS
M:6]N"G!U8FQI8R!I;6UU=&%B;&4 =6EN="!)3%]-3D< ("` ("` ("` /2`P
M>#`T,S4[("`O+R$\($UU;'1I<&QE+6EM86=E($YE='=O<FL 1W)A<&AI8W, 
M+2`N;6YG(&5X=&5N<VEO; IP=6)L:6, :6UM=71A8FQE('5I;G0 24Q?2DY'
M("` ("` ("` (#T ,' P-#,U.R` +R\A/"`*<'5B;&EC(&EM;75T86)L92!U
M:6YT($E,7T=)1B` ("` ("` ("`](#!X,#0S-CL ("\O(3P 1W)A<&AI8W, 
M26YT97)C:&%N9V4 1F]R;6%T("T +F=I9B!E>'1E;G-I;VX*<'5B;&EC(&EM
M;75T86)L92!U:6YT($E,7T1$4R` ("` ("` ("`](#!X,#0S-SL ("\O(3P 
M1&ER96-T1')A=R!3=7)F86-E("T +F1D<R!E>'1E;G-I;VX*<'5B;&EC(&EM
M;75T86)L92!U:6YT($E,7T1#6"` ("` ("` ("`](#!X,#0S.#L ("\O(3P 
M6E-O9G0 375L=&DM4$-8("T +F1C>"!E>'1E;G-I;VX*<'5B;&EC(&EM;75T
M86)L92!U:6YT($E,7U!31"` ("` ("` ("`](#!X,#0S.3L ("\O(3P 061O
M8F4 4&AO=&]3:&]P("T +G!S9"!E>'1E;G-I;VX*<'5B;&EC(&EM;75T86)L
M92!U:6YT($E,7T58248 ("` ("` ("`](#!X,#0S03L ("\O(3P "G!U8FQI
M8R!I;6UU=&%B;&4 =6EN="!)3%]04U` ("` ("` ("` /2`P>#`T,T([("`O
M+R$\(%!A:6YT4VAO<"!0<F\ +2`N<'-P(&5X=&5N<VEO; IP=6)L:6, :6UM
M=71A8FQE('5I;G0 24Q?4$E8("` ("` ("` (#T ,' P-#-#.R` +R\A/"!0
M25  +2`N<&EX(&5X=&5N<VEO; IP=6)L:6, :6UM=71A8FQE('5I;G0 24Q?
M4%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('5I;G0 24Q?5$585%5210D)/2`P>#`T-$8[("`O+R$\($UE
M9&EE=F%L($E).B!4;W1A;"!787( 5&5X='5R92`M("YT97AT=7)E(&5X=&5N
M<VEO; IP=6)L:6, :6UM=71A8FQE('5I;G0 24Q?1%!8"0D)/2`P>#`T-3`[
M("`O+R$\($1I9VET86P 4&EC='5R92!%>&-H86YG92`M("YD<'  97AT96YS
M:6]N"G!U8FQI8R!I;6UU=&%B;&4 =6EN="!)3%]55% )"0D](#!X,#0U,3L 
M("\O(3P 56YR96%L("AA;F0 56YR96%L(%1O=7)N86UE;G0I(%1E>'1U<F4 
M+2`N=71X(&5X=&5N<VEO; IP=6)L:6, :6UM=71A8FQE('5I;G0 24Q?35`S
M"0D)/2`P>#`T-3([("`O+R$\($U014<M,2!!=61I;R!,87EE<B`S("T +FUP
M,R!E>'1E;G-I;VX*"B\O($]R:6=I;B!$969I;FET:6]N<PIP=6)L:6, :6UM
M=71A8FQE('5I;G0 24Q?3U))1TE.7U-%5"` ("` ("` /2`P>#`V,#`["G!U
M8FQI8R!I;6UU=&%B;&4 =6EN="!)3%]/4DE'24Y?3$]715)?3$5&5"`](#!X
M,#8P,3L*<'5B;&EC(&EM;75T86)L92!U:6YT($E,7T]224=)3E]54%!%4E],
M1494(#T ,' P-C`R.PIP=6)L:6, :6UM=71A8FQE('5I;G0 24Q?3U))1TE.
M7TU/1$4 ("` ("` /2`P>#`V,#,[" HO+R!&:6QE(&1E9FEN:71I;VYS"G!U
M8FQI8R!I;6UU=&%B;&4 =6EN="!)3%]&24Q%7T]615)74DE410D](#!X,#8R
M,#L*<'5B;&EC(&EM;75T86)L92!U:6YT($E,7T9)3$5?34]$10D)/2`P>#`V
M,C$[" IP=6)L:6, :6UM=71A8FQE('5I;G0 24Q?24U!1T5?5TE$5$ )/2`P
M>#!$130["G!U8FQI8R!I;6UU=&%B;&4 =6EN="!)3%])34%'15](14E'2%0)
M/2`P>#!$134[" D)"0D)"0D)"0D ("` "G!U8FQI8R!E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&]3=')I;F=Z*")I;$QO
M861);6%G92(I*3L*"0EI;$-O<'E0:7AE;', /2!C87-T*'9O:60 9G5N8W1I
M;VXH=6EN="P =6EN="P =6EN="P =6EN="P =6EN="P =6EN="P =6EN="P 
M=6EN="P =F]I9"HI*61L<WEM*&1E=FEL3&EB2&%N9&QE+"!S=&0N<W1R:6YG
M+G1O4W1R:6YG>B B:6Q#;W!Y4&EX96QS(BDI.PH)?0H)96QS90H)>PH)"7-T
M871I8R!A<W-E<G0H9F%L<V4I.PH)?0I]" IP<FEV871E('-T871I8R!^=&AI
(<R I"GL*?0H`
`
end
Mar 01 2011
next sibling parent "Daniel Murphy" <yebblies nospamgmail.com> writes:
Assuming you've checked that dlopen isn't returning null, I can't find the 
source of the error in that code, sorry.

Unsolicited advice:

Is there any reason you're manually loading the dll rather than using an 
import library?

A couple of remarks about the rest of the code:

Generally in D the constants would all be:
enum uint IL_BLAH = BLAH;
rather than immutable.

You can specify attributes such as public and immutable in blocks

public immutable
{
   // lots of constants
}

Or if using enums, the following will have the same effect.

enum : uint
{
   constant1 = value,
   constant2 = value,
}


All of your function pointers are currently thread local, as are the static 
ctor/dtors.
To have them run once rather than once per thread, you should use 'shared 
static this()' and 'shared static ~this()' instead, and mark the function 
pointer variables as __gshared.

In all of the 'pointer = cast(function pointer)dlsym(...);' calls you're 
actually relying on a compiler bug, as you're assigning a 'extern(D) 
something function(args)' to a 'extern(System) something function(args)'.

For shorter, clearer and correct code you could instead use:
blah = cast(typeof(blah))dlsym(...);

You don't need to call std.string.toStringz on string literals, they're 
guaranteed to be null-terminated.

All the function signatures using immutable (void 
function(immutable(char)*), etc) are incorrect.  C or C++ function 
signatures should be using const instead (eg void function(const(char)*) ).

I really suggest using an import library if possible. 
Mar 02 2011
prev sibling parent Mike Wey <mike-wey example.com> writes:
On 03/02/2011 01:49 AM, rm wrote:
 I put together bindings for DevIL in D to use on a school assignment.  The
 bindings (attached) work fine on Windows, but cause a segfault on Linux when I
 call ilInit.

 this can be demonstrated by a little test program

 "
 import graphics.bindings.devil;

 public void main(string[] args)
 {
     ilInit();
 }
 "
 compiled with "dmd -L-ldl test.d devil.d" where test.d is the above program
 and devil.d is attached.

 When run, this program segfaults, but if lines 112,113,165,166 of devil.d are
 commented out, the program works fine, and I can't figure out what the problem
 with those lines is.  The fact that this works on Windows confuses me even
more.

 Any help would be appreciated.
On linux the linker is called with --export-dynamic by default and this tells the linker to export all the symbols pressent in your executable. So it is posible that dlsym is returning the address of the symbols in your execuable. Thunderbird is having some problems with your attachment so i'm not able to test, but renaming the functions should do the trick. -- Mike Wey
Mar 02 2011