Sitelet https://github.com/node-ffi/node-ffi/pull/306
Skip to content

Allow to pass DynamicLibrary to Library func - #306

Open
kolya-ay wants to merge 1 commit into
node-ffi:masterfrom
kolya-ay:master
Open

kolya-ay wants to merge 1 commit into
node-ffi:masterfrom
kolya-ay:master

Conversation

@kolya-ay

Copy link
Copy Markdown

Extend Library API to support DynamicLibrary as first parameter. This might be useful for manual dlopen flags setting and nonstandard lib names.

Address #137

Comment thread lib/library.js
if (libfile && libfile.indexOf(EXT) === -1) {
debug('appending library extension to library name', EXT)
libfile += EXT
if (!(dl instanceof DynamicLibrary)) {

@TooTallNate TooTallNate Jun 22, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do if ('string' === typeof dl || null === dl) instead. I'm paranoid about instanceof and try to avoid it when possible.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason? instanceof is logically correct, no?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO instanceof is an anti-pattern in dynamically typed languages like JavaScript. Consider a DynamicLibrary instance from another "env" (i.e. another copy of node-ffi in the node_modules structure), or another module that implements the DynamicLibrary interface but using a different backend (perhaps libuv's dl functions). Basically the "if it looks like a duck, and quacks like a duck" benefits of dynamic langs are lost with instanceof.

@TooTallNate

Copy link
Copy Markdown
Member

I'm 👍 for this, but needs a test case or two before merging.

@xogeny

xogeny commented Dec 14, 2016

Copy link
Copy Markdown

I have another use case for this. That is closing the DynamicLibrary instance. If I could create the Library from my own existing instance of DynamicLibrary, then I have the ability to also retain a reference to the DynamicLibrary and I can, therefore, close it when I need to.

This is a significant issue for me right now because I'm dropping DLLs into temporary directories but I can never clean up "the mess" because Windows won't let me remove DLLs if they are in use by any process.

Any news on merging this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants