New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-ffi

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-ffi - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

2

example/factorial/factorial.js

@@ -14,2 +14,2 @@ var FFI = require("../../lib/ffi");

console.log("Your output: " + output);
console.log("Your output: " + output);

@@ -36,3 +36,3 @@ var FFI = require("node-ffi"),

var obj = {};
for (var i = 0; i < cols; i++) {

@@ -43,6 +43,6 @@ var colName = colv.getPointer().getCString();

}
util.log("Row: " + JSON.stringify(obj));
rowCount++;
return 0;

@@ -49,0 +49,0 @@ });

@@ -11,13 +11,13 @@ var FFI = require("./ffi");

var args = [];
for (var i = 0, len = types.length; i < len; i++) {
args.push(FFI.derefValuePtr(types[i], pptr.getPointer(true)));
}
var methodResult = func.apply(this, args);
if (retType != "void")
retval["put" + FFI.TYPE_TO_POINTER_METHOD_MAP[retType]](methodResult);
retval["put" + FFI.TYPE_TO_POINTER_METHOD_MAP[retType]](methodResult);
});
this._pointer = this._info.pointer;

@@ -24,0 +24,0 @@ };

@@ -7,12 +7,12 @@ var FFI = require("./ffi")

this._types = types;
if (!FFI.isValidReturnType(this._returnType)) {
throw new Error("Invalid Return Type");
}
this._argtypesptr = new FFI.Pointer(types.length * FFI.Bindings.FFI_TYPE_SIZE);
this._rtypeptr = FFI.ffiTypeFor(this._returnType);
var tptr = this._argtypesptr.seek(0);
for (var i = 0, len = types.length; i < len; i++) {

@@ -28,4 +28,4 @@ var typeName = types[i];

}
this._cifptr = FFI.Bindings.prepCif(types.length, this._rtypeptr, this._argtypesptr);
this._cifptr = FFI.Bindings.prepCif(types.length, this._rtypeptr, this._argtypesptr);
};

@@ -32,0 +32,0 @@

@@ -29,3 +29,3 @@ var FFI = require("./ffi"),

var match;
if (match = err.match(/^(([^ \t()])+\.so([^ \t:()])*):([ \t])*invalid ELF header$/)) {

@@ -38,3 +38,3 @@ var content = fs.readFileSync(match[1], "ascii");

}
throw new Error("Dynamic Linking Error: " + err);

@@ -41,0 +41,0 @@ }

@@ -24,2 +24,2 @@ // Implementation of errno. This is a #define :/. On Linux, it's a global variable with the symbol

}
};
};

@@ -10,6 +10,6 @@ var util = require("util");

} catch (e) {
throw new Error("Cannot find compiled bindings!");
throw e;
}}
FFI.VERSION = "0.4.1";
FFI.VERSION = "0.4.2";

@@ -87,3 +87,3 @@ FFI.TYPE_TO_POINTER_METHOD_MAP = {

}
if (type == "void") {

@@ -127,7 +127,7 @@ return null;

var dptr = ptr.getPointer();
if (dptr.isNull()) {
return null;
}
return getf.call(dptr);

@@ -134,0 +134,0 @@ }

@@ -62,3 +62,3 @@ var FFI = require("./ffi"),

var self = this;
// cache these for a bit quicker calls

@@ -71,8 +71,8 @@ var stlen = this._types.length;

var nullptr = FFI.Pointer.NULL;
var caller = new FFI.Bindings.ForeignCaller(
this._cif.getPointer(),
this._cif.getPointer(),
this._fptr,
this._arglistPtr,
this._resultPtr,
this._arglistPtr,
this._resultPtr,
async

@@ -79,0 +79,0 @@ );

@@ -9,14 +9,14 @@ var FFI = require("./ffi");

);
for (var k in funcs) {
var fptr = dl.get(k);
if (fptr.isNull()) throw new Error("DynamicLibrary returned NULL function pointer.");
var resultType = funcs[k][0],
paramTypes = funcs[k][1],
fopts = funcs[k][2];
this[k] = FFI.ForeignFunction.build(fptr, resultType, paramTypes, fopts ? fopts.async : undefined);
}
};
var FFI = require("./ffi");
// Pointer represents data stored in
// Pointer represents data stored in
var Pointer = module.exports = FFI.Bindings.Pointer;

@@ -10,3 +10,3 @@

friend.__attached = [];
friend.__attached.push(this);

@@ -26,5 +26,5 @@ };

var ptr = new Pointer((typeDef == "string") ? value.length + 1 : FFI.sizeOf(typeDef));
Pointer.putDispatchTable[typeDef].apply(ptr, [value]);
if (typeDef == "string") {

@@ -45,3 +45,3 @@ // we have to actually build an "in-between" pointer for strings

var mapped = FFI.TYPE_TO_POINTER_METHOD_MAP[typeDef];
if (mapped) {

@@ -56,3 +56,3 @@ // it's hard mapped

signed = (typeDef != "byte" && typeDef != "size_t" && typeDef.substr(0, 1) != "u");
if (sz) {

@@ -75,3 +75,3 @@ // XXX: This is kind of a shitty way to detect unsigned/signed

FFI.TYPE_TO_POINTER_METHOD_MAP[typeName] = suffix;
Pointer.prototype["put" + method] = Pointer.prototype["put" + suffix];

@@ -86,5 +86,5 @@ Pointer.prototype["get" + method] = Pointer.prototype["get" + suffix];

for (var type in FFI.TYPE_TO_POINTER_METHOD_MAP) {
Pointer.putDispatchTable[type] =
Pointer.putDispatchTable[type] =
Pointer.prototype["put" + FFI.TYPE_TO_POINTER_METHOD_MAP[type]];
Pointer.getDispatchTable[type] =
Pointer.getDispatchTable[type] =
Pointer.prototype["get" + FFI.TYPE_TO_POINTER_METHOD_MAP[type]];

@@ -91,0 +91,0 @@ }

@@ -27,3 +27,3 @@ var FFI = require("./ffi");

var fptr = ptr.seek(info.offset);
if (FFI.isStructType(info.type)) {

@@ -37,7 +37,7 @@ return new info.type(fptr);

}
function write(ptr, name, val) {
var info = struct.struct[name];
var fptr = ptr.seek(info.offset);
if (FFI.isStructType(info.type)) {

@@ -55,3 +55,3 @@ new info.type(fptr, val);

}
// TODO: Allow serialize/deserialize to accept struct instances?

@@ -63,3 +63,3 @@ function serialize(ptr, data) {

}
// TODO: Not used?

@@ -76,3 +76,3 @@ function deserialize(ptr) {

}
// Read the fields list and apply all the fields to the struct

@@ -113,3 +113,3 @@ if (fields) {

}
var constructor = function(arg, data) {

@@ -121,3 +121,3 @@ this.__isStructInstance__ = true;

this.__pointer = arg;
if (data) {

@@ -129,3 +129,3 @@ serialize(this.__pointer, data);

this.__pointer = new FFI.Pointer(struct.size);
if (arg) {

@@ -135,3 +135,3 @@ serialize(this.__pointer, arg);

}
this.__wrappedPointer__ = this.__pointer;

@@ -170,3 +170,3 @@

var fieldName = struct.members[i];
(function(field) {

@@ -182,3 +182,3 @@ constructor.prototype.__defineGetter__(fieldName, function () {

}
constructor.__isStructType__ = true;

@@ -185,0 +185,0 @@ constructor.__structInfo__ = struct;

{
"name": "node-ffi",
"version": "0.4.1",
"version": "0.4.2",
"author": "Rick Branson",

@@ -22,5 +22,4 @@ "contributors": [

"bugs": {
"mail": "",
"web": "http://github.com/rbranson/node-ffi/issues"
"url": "http://github.com/rbranson/node-ffi/issues"
}
}

@@ -8,18 +8,20 @@ # node-ffi

node-ffi is a Node.js addon for loading and calling dynamic libraries using pure JavaScript. It can be used to create bindings to native libraries without writing any C++ code.
node-ffi is a Node.js addon for loading and calling dynamic libraries using pure JavaScript. It can be used to create bindings to native libraries without writing any C++ code.
It also simplifies the augmentation of node.js with C code as it takes care of handling the translation of types across JavaScript and C, which can add reams of boilerplate code to your otherwise simple C. See the `example/factorial` for an example of this use case.
WARNING: node-ffi assumes you know what you're doing. You can pretty easily create situations where you will segfault the interpreter and unless you've got C debugger skills, you probably won't know what's going on.
**WARNING**: node-ffi assumes you know what you're doing. You can pretty easily create situations where you will segfault the interpreter and unless you've got C debugger skills, you probably won't know what's going on.
# EXAMPLE
var FFI = require("node-ffi");
``` js
var FFI = require("node-ffi");
var libm = new FFI.Library("libm", { "ceil": [ "double", [ "double" ] ] });
libm.ceil(1.5); // 2
var libm = new FFI.Library("libm", { "ceil": [ "double", [ "double" ] ] });
libm.ceil(1.5); // 2
// You can also access just functions in the current process by passing a null
var current = new FFI.Library(null, { "atoi": [ "int32", [ "string" ] ] });
current.atoi("1234"); // 1234
// You can also access just functions in the current process by passing a null
var current = new FFI.Library(null, { "atoi": [ "int32", [ "string" ] ] });
current.atoi("1234"); // 1234
```

@@ -29,16 +31,20 @@ # REQUIREMENTS

* Linux, OS X, or Solaris.
* The current version is tested to run on node.js 0.4 (specifically, 0.4.7)
* The current version is tested to run on node.js 0.4 (specifically, 0.4.12)
* libffi installed -- with development headers (comes with OS X and most Linux distros)
# NPM INSTALL
$ npm install node-ffi
``` bash
$ npm install node-ffi
```
# SOURCE INSTALL
$ git clone git://github.com/rbranson/node-ffi.git
$ cd node-ffi
$ node-waf configure build
$ node test.js
$ node-waf install
``` bash
$ git clone git://github.com/rbranson/node-ffi.git
$ cd node-ffi
$ node-waf configure build
$ node test.js
$ node-waf install
```

@@ -53,4 +59,4 @@ # TYPES

uint32 Unsigned 32-bit Integer
int64 Signed 64-bit Integer
uint64 Unsigned 64-bit Integer
int64 Signed 64-bit Integer
uint64 Unsigned 64-bit Integer
float Single Precision Floating Point Number (float)

@@ -67,9 +73,9 @@ double Double Precision Floating Point Number (double)

short short
ushort unsigned short
int int
uint unsigned int
long long
ulong unsigned long
longlong long long
ulonglong unsigned long long
ushort unsigned short
int int
uint unsigned int
long long
ulong unsigned long
longlong long
ulonglong unsigned long long
size_t platform-dependent, usually pointer size

@@ -79,3 +85,3 @@

Internally, V8 stores integers that will fit into a 32-bit space in a 32-bit integer, and those that fall outside of this get put into double-precision floating point numbers. This is problematic because FP numbers are imprecise. To get around this, the methods in node-ffi that deal with 64-bit integers return strings and can accept strings as parameters.
Internally, V8 stores integers that will fit into a 32-bit space in a 32-bit integer, and those that fall outside of this get put into double-precision floating point numbers. This is problematic because FP numbers are imprecise. To get around this, the methods in node-ffi that deal with 64-bit integers return strings and can accept strings as parameters.

@@ -82,0 +88,0 @@ # Call Overhead

@@ -6,3 +6,3 @@ var FFI = require("../lib/ffi"),

granularity = granularity || 1000;
var iterations = 0,

@@ -17,6 +17,6 @@ start = Date.now();

};
var duration = Date.now() - start,
persec = (iterations / (Date.now() - start)) * 1000;
util.log("Executed " + what + " " + iterations + " times in " + duration + "ms " + "(" + persec + "/sec)");

@@ -23,0 +23,0 @@ }

@@ -229,3 +229,3 @@ var util = require("util");

assert.throws(function() {
ptr.putSizeT(-1);
ptr.putSizeT(-1);
});

@@ -514,5 +514,5 @@

assert.ok(ceil instanceof Function);
assert.equal(2, ceil(1.5));
libm.close();

@@ -586,3 +586,3 @@

libm.ceil(1.5).on("success", function(res) {
libm.ceil(1.5).on("success", function(res) {
libmCeilAsyncCallExecuted = true;

@@ -609,8 +609,8 @@ assert.equal(2, res);

]);
var lib = new FFI.Library(null, { "gettimeofday": [ "int", [ "pointer", "pointer"] ] });
var tv = new timeval();
lib.gettimeofday(tv.ref(), null);
assert.equal(tv.tv_sec, Math.floor(Date.now() / 1000));

@@ -625,3 +625,3 @@ })();

]);
var ParentStructType = FFI.Struct([

@@ -631,3 +631,3 @@ [ChildStructType, "childA"],

]);
var ps = new ParentStructType({

@@ -637,3 +637,3 @@ "childA": { "a": 100, "b": 200 },

});
assert.equal(100, ps.childA.a);

@@ -640,0 +640,0 @@ assert.equal(200, ps.childA.b);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc