Skip to content

Commit 5566191

Browse files
committed
ffi, dynamic_library: export the dlfcn.h flags from the C layer
1 parent 76eb118 commit 5566191

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

lib/dynamic_library.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
var ForeignFunction = require('./foreign_function')
77
, assert = require('assert')
88
, debug = require('debug')('ffi:DynamicLibrary')
9-
, funcs = require('./bindings').StaticFunctions
9+
, bindings = require('./bindings')
10+
, funcs = bindings.StaticFunctions
1011
, ref = require('ref')
1112
, read = require('fs').readFileSync
1213

@@ -76,15 +77,15 @@ function DynamicLibrary (path, mode) {
7677
module.exports = DynamicLibrary
7778

7879
/**
79-
* See "dlfcn.h"
80+
* Set the exported flags from "dlfcn.h"
8081
*/
8182

82-
DynamicLibrary.FLAGS = {
83-
'RTLD_LAZY': 0x1
84-
, 'RTLD_NOW': 0x2
85-
, 'RTLD_LOCAL': 0x4
86-
, 'RTLD_GLOBAL': 0x8
87-
}
83+
DynamicLibrary.FLAGS = {};
84+
Object.keys(bindings).forEach(function (k) {
85+
if (!/^RTLD_/.test(k)) return;
86+
DynamicLibrary.FLAGS[k] = bindings[k];
87+
});
88+
8889

8990
/**
9091
* Close this library, returns the result of the dlclose() system function.

lib/ffi.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ var bindings = require('./bindings')
1717
, 'FFI_OK', 'FFI_BAD_TYPEDEF', 'FFI_BAD_ABI'
1818
, 'FFI_DEFAULT_ABI', 'FFI_FIRST_ABI', 'FFI_LAST_ABI', 'FFI_SYSV', 'FFI_UNIX64'
1919
, 'FFI_WIN64', 'FFI_VFP', 'FFI_STDCALL', 'FFI_THISCALL', 'FFI_FASTCALL'
20-
, 'FFI_MS_CDECL'].forEach(function (prop) {
20+
, 'RTLD_LAZY', 'RTLD_NOW', 'RTLD_LOCAL', 'RTLD_GLOBAL', 'RTLD_NOLOAD'
21+
, 'RTLD_NODELETE', 'RTLD_FIRST', 'RTLD_NEXT', 'RTLD_DEFAULT', 'RTLD_SELF'
22+
, 'RTLD_MAIN_ONLY', 'FFI_MS_CDECL'].forEach(function (prop) {
2123
if (!bindings.hasOwnProperty(prop)) {
2224
return debug('skipping exporting of non-existant property', prop)
2325
}

0 commit comments

Comments
 (0)