Thank you very much for the fast response. You are right about overwriting a local variable. However, when I use the code you suggest, I still do not know how to access the four header values within the coffeescript code.
I will continue investigating this. Cheers, Gilles On Tuesday, March 18, 2014 8:25:27 AM UTC+1, Fedor Indutny wrote: > > Hello! > > Try following code: > > https://gist.github.com/indutny/bc2b05d3f75f6dd81e77 > > I may be missing some nuances regarding FFI signature, but the main > thing is that you are overwriting local variable in a C function, not > writing a value to the pointer which it contains. Changing it to > `char**` and doing `*out = header` should make it work. > > Cheers, > Fedor. > > On Tue, Mar 18, 2014 at 11:21 AM, <[email protected] <javascript:>> > wrote: > > Hi, > > > > I have been using node ffi for various libraries but today I am facing > an > > unexpected difficulty. Here is a simple C function that takes as > parameter a > > pointer and allocates memory for that pointer. > > > > int write_headers(char *header) > > { > > header = calloc(1024, 1); > > header[0] = 0x66; > > header[1] = 0x4C; > > header[2] = 0x61; > > header[3] = 0x43; > > > > return 4; > > } > > > > > > In node, I am using the following coffeescript code to call the > > write_headers function: > > > > ref = require 'ref' > > ffi = require 'ffi' > > > > API = { > > 'write_headers': ['int', ['pointer']] > > } > > test = ffi.Library './libtest.so', API > > > > header = ref.NULL_POINTER > > > > res = test.write_headers header.ref() > > > > > > I tried various options but never succeeded to get the correct value of > > header after the call of the write_headers function in order to get the > 4 > > values of the header. > > > > I would appreciate any help on this. > > > > Thank you,GIlles > > > > -- > > -- > > 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]<javascript:> > > To unsubscribe from this group, send email to > > [email protected] <javascript:> > > 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] <javascript:>. > > For more options, visit https://groups.google.com/d/optout. > -- -- 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/d/optout.
