Closed Bug 518130 Opened 11 years ago Closed 10 years ago

[jsctypes] provide platform-independent way to open a library


(Core :: js-ctypes, defect)

Not set





(Reporter: dwitte, Unassigned)



(Keywords: dev-doc-complete, Whiteboard: fixed by bug 577589)

Currently, you need to specify the full library name to, which means you need to pass on linux, libfoo.dylib on mac, and foo.dll on windows. We should abstract this logic into open() itself, perhaps with a flag to enable this behavior (ctypes.SEARCH), to make things easier in the common case.

pyctypes has something like this, which also hunts around your search path for the library in an appropriate way on each platform:
Product: Other Applications → Core

That blurb seems to indicate you can already do open("user32") and get the correct library.

dolske: Did you find that open("libnss3.dylib") didn't seem to work either, so you had to pass in the full path? Might be a separate bug from this one though.
Blocks: 513798
Keywords: dev-doc-needed
Hmm. Maybe just define the system-specific extension in ctypes (eg ctypes.LIBEXT == ".dll" on Win32, == ".so" on Unix)? Thus,"mylib" + ctypes.LIBEXT);

I'm not sure hiding the extension entirely makes sense... You wouldn't want open("user32") to try opening "" on linux, and there are cases where you might want to open a specific library version, eg "". Doesn't seem like there's much gain from hiding the extension.

I would like to see the ability to use some of the non-filename flags from dlopen/dlsym, though... eg RTLD_NOLOAD with dlopen, RTLD_DEFAULT with dlsym. My usecase with WeaveCrypto is that I want to load NSS, but only the image already loaded into the process. Determining which that is can be tricky, specifically on Linux.

Thus, I'd either want something like:

  for each(var file in ["path1/", "path2/", ...]) {
    var lib =, RTLD_NOLOAD);
    if (lib) break;


  var lib ="RTLD_DEFAULT");
  var myfunc = lib.declare("myfunc", ...);

There might be some things to consider with wanting to load a symbol Foo from library Bar, where the actual library/symbol is being influenced by LD_PRELOAD, LD_LIBARY_PATH, or the way the app was linked with -R... And maybe that's the one you want, and maybe it isn't. :-o
Why not use PR_GetLibraryName ?
I fixed bug 577589 (because I didn't look hard enough for this bug), which lets you do:
var name = ctypes.libraryName("foo");
and get back foo.dll / / libfoo.dylib depending on platform.

Is that enough for this bug?
Closed: 10 years ago
Depends on: 577589
Resolution: --- → FIXED
Whiteboard: fixed by bug 577589
Yup! :)
You need to log in before you can comment on or make changes to this bug.