[llvm-commits] [PATCH] Look up symbols in a specific library with DynamicLibrary

Jordy Rose jediknil at belkadan.com
Thu Aug 11 09:56:34 PDT 2011


On Aug 11, 2011, at 8:30, Argyrios Kyrtzidis wrote:

> Hmm, I still don't see why DynamicLibrary needs to do refcount and not just be a thin wrapper over the handle (constructor will be private and will be only callable by DynamicLibrary's getPermanentLibrary; copy constructor has no issue).
> Since the API states that the loading is permanent there's no need for refcounting.

The only way to acquire the handle is using dlopen, and that increments the internal refcount; with no destructor, it's never decremented. Unless we give up and make our own map. The code below shows the alternative of decrementing the refcount if we know it's greater than 1, but that's not particularly nice...

void *handle = dlopen(filename, [options]);
if (OpenedHandles.contains(handle))
 dlclose(handle);
else
 OpenHandles.insert(handle);
return DynamicLibrary(handle);

...but maybe it's the best alternative, bending but not breaking the contract.

Jordy





More information about the llvm-commits mailing list