node-addon-layer icon indicating copy to clipboard operation
node-addon-layer copied to clipboard

Is it an external or an integer?

Open notmatt opened this issue 10 years ago • 0 comments

With node v0.10.17, ran into a problem where an external being passed back to JS-land was represented there as a number, and when passed back to the addon layer could not easily be recognized as an external. E.g.,

> var ndb = require('bindings')('ndb');
undefined
> var handle = ndb.init('core.69564', '');
undefined
> handle
71161188
> ndb.runcmd(handle, "::status")
TypeError: Argument 0 not of type SHIM_TYPE_EXTERNAL
    at repl:1:6
    at REPLServer.self.eval (repl.js:110:21)

Related addon code is:

shim_bool_t
runcmd(shim_ctx_t* ctx, shim_args_t* args)
{
    uint32_t val;
    shim_val_t* h = malloc(sizeof(shim_val_t*));
    shim_val_t* c = malloc(sizeof(shim_val_t*));

    int bufsz = 65536;
    char *buf;
    int rval;

    shim_val_t* dresult;

    if(!shim_unpack(ctx, args,
       // SHIM_TYPE_UINT32, &val,
       SHIM_TYPE_EXTERNAL, &h,
       SHIM_TYPE_STRING, &c,
       SHIM_TYPE_UNKNOWN))
        return FALSE;

    /* external passed back from JS can't be unpacked as an external.
       v8 numbers unwrapped are shifted (apparently), so shift it back,
       an boom, we've hacked ourselves the address we need. */
    libmdb_t* mdbp = shim_external_valu(ctx, h);
    const char *command = shim_string_value(c);

notmatt avatar Nov 15 '13 00:11 notmatt