digitalmars.D.learn - Dynamic bindings to global variables
- remi thebault (13/13) Aug 02 2015 Hello
- Mike Parker (4/16) Aug 02 2015 You have to declare it as a pointer, then retrieve the pointer in
- remi thebault (15/18) Aug 02 2015 and how would you make this source compatible with the static
- remi thebault (4/22) Aug 02 2015 I'll manage this through static @property-ies
Hello I wrote static bindings to a C library. I want to also offer a version(Dynamic) of the bindings. I follow and use derelict-util to get the address of function pointers. In the library I bind, there is also global variables. here's one example in the static bindings: extern __gshared wl_interface wl_display_interface; (wl_interface is a struct, not a pointer alias) How would one make dynamic binding of this? Is it possible to retrieve the address of the symbol and use std.conv.emplace? thank you
Aug 02 2015
On Sunday, 2 August 2015 at 15:31:48 UTC, remi thebault wrote:Hello I wrote static bindings to a C library. I want to also offer a version(Dynamic) of the bindings. I follow and use derelict-util to get the address of function pointers. In the library I bind, there is also global variables. here's one example in the static bindings: extern __gshared wl_interface wl_display_interface; (wl_interface is a struct, not a pointer alias) How would one make dynamic binding of this? Is it possible to retrieve the address of the symbol and use std.conv.emplace?You have to declare it as a pointer, then retrieve the pointer in the same way you do the function pointers, via the system loader (GetProcAddress/dlsym).
Aug 02 2015
On Sunday, 2 August 2015 at 15:38:34 UTC, Mike Parker wrote:You have to declare it as a pointer, then retrieve the pointer in the same way you do the function pointers, via the system loader (GetProcAddress/dlsym).and how would you make this source compatible with the static binding version? I guess it is not possible extern(C): version(Dynamic) { __gshared wl_interface *wl_display_interface; } else { extern __gshared wl_interface wl_display_interface; } // use case: some_func expects a pointer to wl_interface // the C version is using addressof operator, (as do the static D bindings) some_func(&wl_display_interface);
Aug 02 2015
On Sunday, 2 August 2015 at 16:20:29 UTC, remi thebault wrote:On Sunday, 2 August 2015 at 15:38:34 UTC, Mike Parker wrote:I'll manage this through static property-ies thanks for your help RĂ©miYou have to declare it as a pointer, then retrieve the pointer in the same way you do the function pointers, via the system loader (GetProcAddress/dlsym).and how would you make this source compatible with the static binding version? I guess it is not possible extern(C): version(Dynamic) { __gshared wl_interface *wl_display_interface; } else { extern __gshared wl_interface wl_display_interface; } // use case: some_func expects a pointer to wl_interface // the C version is using addressof operator, (as do the static D bindings) some_func(&wl_display_interface);
Aug 02 2015