Can't figure out segfault
Daniel Murphy
yebblies at nospamgmail.com
Wed Mar 2 01:29:21 PST 2011
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.
More information about the Digitalmars-d-learn
mailing list