This is my first day of trying to use node-ffi, and I'm going mad trying to get
it to work with a function that has this signature:
int makeData(char **data, unsigned int *length);
This function will return a pointer to some data and an unsigned int saying how
many bytes long the data is. The data might be text or binary.
How do I define this function in node-ffi? What kind of variables do I need to
declare and pass to it? And how do I get the data out in the end? I have spent
hours on this already, finding very little information on Google and only a
single example in the node-ffi repository (which doesn't cover this use case),
and sparse documentation.
What I have at the moment is:
var mylib = ffi.Library('/path/to/mylib', {
makeData: ['int', ['char **', 'uint *']],
});
var lengthpointer = ref.alloc('uint *');
var datapointer = ref.alloc('char *');
mylib.makeData(datapointer, lengthpointer);
var length = lengthpointer.deref();
var data = ref.reinterpret(datapointer.deref(), length);
The problem is that length is always NaN. If I set length to some integer
instead, then the reinterpreting of the buffer works and I get that amount of
data.
A surprise is that if I alloc() datapointer before lengthpointer instead of
after, deref()ing lengthpointer causes a segmentation fault. I really don't
understand why the order in which I declare some variables would have this
effect.
If I declare datapointer as alloc('char **') (to match the function's
signature) instead of 'char *' I also get a segmentation fault when deref()ing
lengthpointer.
This is on OS X 10.8.4 with node 0.10.12 and node-ffi 1.2.5.
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.