tjfontaine / node-addon-layer

A thin C API to create node binary addons with, inspired by JSAPI
38 stars 3 forks source link

Err unpacking function args to SHIM_TYPE_FUNCTION #3

Open notmatt opened 11 years ago

notmatt commented 11 years ago

Ran into a blatant lie in the following error message:

/root/hackathon/ndb/dump.js:4
ndb.runcmd_async(handle, "::status", function(err, data) { console.log("in the
    ^
TypeError: Argument 2 not of type SHIM_TYPE_FUNCTION
    at Object.<anonymous> (/root/hackathon/ndb/dump.js:4:5)
    at Module._compile (module.js:456:26)

Where argument 2 is clearly a function.

The related code (which is not free of other issues) is:

shim_bool_t
runcmd_async(shim_ctx_t* ctx, shim_args_t* args)
{
    runcmd_baton_t* baton = malloc(sizeof(runcmd_baton_t));

    uint32_t handle;
    shim_val_t* command = malloc(sizeof(shim_val_t*));
    shim_val_t* callback = malloc(sizeof(shim_val_t*));

    if (!shim_unpack(ctx, args,
       SHIM_TYPE_UINT32, &handle,
       SHIM_TYPE_STRING, &command,
       SHIM_TYPE_FUNCTION, &callback,
       SHIM_TYPE_UNKNOWN))
        return FALSE;

    /* make these persistent, presumably? */
    baton->handle = shim_persistent_new(ctx, shim_integer_uint(ctx, handle));
    baton->command = shim_persistent_new(ctx, command);
    baton->callback = shim_persistent_new(ctx, callback);

    shim_queue_work((shim_work_cb)runcmd_work, (shim_after_work)runcmd_after, baton);
    return TRUE;
}

NB: building on SmartOS with node 0.10.17