jpf91

Member
  • Content count

    0
  • Joined

  • Last visited

Community Reputation

122 Neutral

About jpf91

  • Rank
    Newbie
  1. D Exceptions and C Callbacks

    I now tested what happens with exceptions in GLFW callbacks on linux to verify my claims and it also depends on the compiler:   DMD: program aborts GDC: exceptions propagate through C code   So with windows we now have 3 options: Exceptions might propagate The program may crash Exceptions might get ignored I guess I'd call that undefined behaviour ;-)
  2. D Exceptions and C Callbacks

    Nice article! Some comments:   in the D code example, log.writefln should be _log.writefln     This is a little misleading. According to TDPL scope guards and finally statements can be skipped for errors and there are probably some more differences between Exception and Error. Of course in your case it does make sense to catch Errors but it's probably much safer to print a log message and call abort() ASAP.   glfwSetWindowCloseCallback should only accept nothrow functions for some additional safety.     I assume you tested this on windows? Do exceptions really not propagate through language boundaries on windows? On linux D exceptions often can propagate through C code (this depends on the exact compiler settings) but of course it usually messes up the internal state of those C libraries.
  3. Binding D to C Part Five

    It would need lots of string manipulation / appending and I think that's known to be slow so it might indeed not be feasible yet.   I hope at some time CTFE will be backed by something like LLVM JIT and a proper GC. Actually in many cases in CTFE a region allocator could already help a lot regarding memory usage: enum int x = ctfeFun(); allocate everything in ctfeFun in a region, free region when x has been calculated. As ctfe functions can't have side effects that should be simple.   But there are probably more important issues right now than these performance optimizations.  
  4. Functional Me

    In that regard Germany is stuck in the stone age. Althought we don't have to pay any fees for college which is a big plus, I don't know of even one free online course. That's because of intellectual property crap, you can't even get the slides for a lecture if you don't attend it physically as it might contain copyrighted images. So what they usually do is password protect the slides and give out the password in the first lecture...   Kinda ironical how my experimental physics prof recommended watching Walter Lewins course (MIT).
  5. Binding D to C Part Five

    Here's a third solution: fooPtr = cast(typeof(fooPtr))getPtr(); and in bindFunc, "ref void* func" could be used instead of void**, that's a little nicer imho.   What would be really cool is if someone could come up with a compile-time only system which allows to write one binding and compile it to dynamic/static binding depending on a version statement:   //All done in ctfe string genCode() { Libarary lib = Library(); lib.addLib("linux", "libGL.so"); lib.addLib("linux", "libGL.so.1"); lib.useStaticVersion("DerelictGLStatic"); lib.aliasPrefix = "da_"; lib.setBindFunc(gl_Bind); //preferably pass by alias, not a string constant lib.addFunction(GLEnum, "glGetError"); lib.addFunction(void, "glGenVertexArrays", GLsizei, GLuint*); return lib.genCode(); } mixin(genCode());
  6. Binding D to C Part Four

    The only 'portable' way I know would be to write accessor functions in c, then add bindings to those. C: [CODE] int get_x(foo_t foo) { return foo.x; } [/CODE] D: [CODE] extern(C) int get_x(foo_t); struct foo_t { int flags; //to make sure the struct has the correct size int x() @property { return get_x(this); } int y() @property { ... } int z() @property { ... } } [/CODE]
  7. Binding D to C Part Three

    [CODE] alias int MyEnum; enum { ME_FOO, ME_BAR, ME_BAZ } [/CODE] One more problem with this is that it doesn't work with final switch. BTW: There's a better C<=>D type table on this page: [url="http://dlang.org/interfaceToC.html"]http://dlang.org/interfaceToC.html[/url] It's too bad we often have duplicate and outdated information on the D website.
  8. DerelictGLFW and a Word on Binding D to C

    Well, there really should be some way to do exactly this without the alias, but I can't make it work. BTW: It's not that surprising that it works: The D part is just a data field/variable, it doesn't have any calling convention. extern(C) only affects it's name mangling, nothing else. Just like extern(C) char* test; and char* test; are exactly the same except for name mangling. The underlying type can still be everything, even a C function.
  9. DerelictGLFW and a Word on Binding D to C

    The "--export-dynamic" flag was added when stack traces were implemented. IIRC without that flag stack traces only show function addresses, but no function names (Thinking about it: this seems like a hack to solve a huge bug. I guess all phobos code should actually be declared with 'export'). If I understood correctly, your issue is that the names of the derelict function pointers now clash with the original names. This is the way the function pointers are declared in derelict: [code] module test; extern(C) { int function(void* test) FT_Init_FreeType; }[/code] This means: I want a function pointer to a extern(C) function. But it also means: I want that function pointer to be extern(C) --> have C name mangling. The resulting symbol is the following: "00000000 B FT_Init_FreeType". The alternative is this: [code] module test; alias extern(C) int function(void* test) FTInitFunc; FTInitFunc FT_Init_FreeType;[/code] This doesn't declare the pointer itself as extern(C), the resulting symbol is: "00000000 B _D4test16FT_Init_FreeTypePUPvZi" . So it uses D name mangling and there shouldn't be clashes anymore. However, I can't find a way to declare this on one line / without an alias?