[erlang-questions] Sharing resource types between NIFs
Mon Feb 17 17:54:59 CET 2014
Windows IIRC, especially, can allocate memory so only certain DLL's
can access it, I don't recall the details, or if this is the default
or not. I think they call it "apartment model"? It's been a looooong
time since I've been deep in on windows so I could be pretty far off
On Mon, Feb 17, 2014 at 6:19 AM, Loïc Hoguin <essen@REDACTED> wrote:
> On 02/17/2014 02:56 PM, Sverker Eriksson wrote:
>> Having dependences between NIF modules (or drivers) on the native code
>> level is not supported.
>> How symbols are resolved (or not) between dynamic libraries is OS
>> dependent (Windows).
>> The runtime system can not keep track of such dependencies. For example,
>> if module B makes a native call to a function in module A and module A
>> has been unloaded...VM crash (or worse).
>> I suggest you merge your dependent NIF code into one module. You can
>> still have different modules on Erlang level and have them call a
>> backend NIF module.
> Thanks, that's exactly what I ended up doing.
>> That being said... ... the scenario you describe should work in current
>> implementation. enif_get_resource() does not care where it is called from.
> Well it didn't work. :-)
>> /Sverker, Erlang/OTP
>> On 02/15/2014 11:22 PM, Loïc Hoguin wrote:
>>> I have been looking into this and after looking into the source it
>>> doesn't seem possible, but I might as well ask just in case.
>>> Say I am writing bindings for a big library. That library is cut into
>>> various components, and I would like to do similar on the Erlang side.
>>> Components are more or less dependent. Let's just say that component B
>>> uses component A. You can't do anything in B without A. They are both
>>> NIF resources pointing to things used by the library.
>>> Now if I try to create a NIF module for A and a NIF module for B, I
>>> need to access the resource type of A from the B NIF. I tried simply
>>> exporting a function from the A .so and use it from the B .so, the
>>> function returns the resource type as expected, however using it to
>>> retrieve the resource fails.
>>> Trying to do the same from A of course works. It's just trying to use
>>> the resource type of A from B that fails.
>>> I'm assuming this isn't possible?
> Loïc Hoguin
> erlang-questions mailing list
"Genius might be described as a supreme capacity for getting its possessors
into trouble of all kinds."
-- Samuel Butler
More information about the erlang-questions