Skip to content

Loading…

Don't append EXT if already present in libfile #39

Closed
wants to merge 2 commits into from

2 participants

@raphaelr

Fix for issue #38. This patch checks whether EXT is already present in libfile, if not, append EXT, otherwise do nothing. Additionally, I've added a test for this issue.

I've tested this patch both on Windows and Debian Squeeze - the unit tests behave the same on both systems.

@TooTallNate

Thanks @raphaelr, I had to adjust the test case a bit, but I applied your fix in 384867f. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 1 deletion.
  1. +5 −1 lib/library.js
  2. +9 −0 test/library.js
View
6 lib/library.js
@@ -7,8 +7,12 @@ var ffi = require('./ffi')
* ForeignFunction.
*/
function Library (libfile, funcs) {
+ if(libfile && libfile.indexOf(EXT) === -1) {
+ libfile += EXT
+ }
+
var lib = {}
- , dl = new ffi.DynamicLibrary(libfile ? libfile + EXT : null, RTLD_NOW)
+ , dl = new ffi.DynamicLibrary(libfile || null, RTLD_NOW)
if (funcs) {
Object.keys(funcs).forEach(function (func) {
View
9 test/library.js
@@ -34,6 +34,15 @@ describe('Library', function () {
expect(libm.ceil(1.1)).to.equal(2)
})
+ it('should accept a lib name with file extension', function() {
+ var lib = process.platform == 'win32' ? 'msvcrt.dll' : 'libm.so'
+ expect(function() {
+ var libm = new Library(lib, {
+ 'ceil': [ 'double', ['double'] ]
+ })
+ }).to.not.throwError()
+ })
+
it('should throw when an invalid function name is used', function () {
expect(function () {
new Library(null, {
Something went wrong with that request. Please try again.