Shared library string safety?
evilrat
evilrat666 at gmail.com
Mon Jan 13 23:23:51 PST 2014
On Tuesday, 14 January 2014 at 06:48:48 UTC, Mineko wrote:
> Sorry for the double post, I should be more specific.
> .dup worked, I don't know how to have the GC proxy for shared
> libs though.
the reason string.dup worked is due to GC on app side, right
after the moment your lib receive the original string it is may
be marked by GC for collection, so you need to save a copy on lib
side. but using the proxies it should work without copying.
for windows here is the topic about this http://dlang.org/dll.html
for *nix platforms it should be the same.
in short(pseudocode):
==========================
app.d
extern(C) void* gc_getProxy();
void main()
{
loadlib();
initLib( gc_getProxy() );
... do something ...
libFinalize();
}
------------------
lib.d
extern (C)
{
void gc_setProxy(void* p);
void gc_clrProxy();
}
export void initLib(void* gc)
{
gc_setProxy(gc);
}
export void libFinalize()
{
gc_clrProxy();
}
==========================
as i said i don't know about current status of shared libs, but
there was some progress on linux and Windows, and unfortunatelly
not OS X...
More information about the Digitalmars-d-learn
mailing list