Skip to content

If the binary callback (as and any other binary data) used not immediately it is required to keep it alive all time that it used #6

@mezoni

Description

@mezoni
static void bindKey(key, Function handler) {
    LibReadline.init();

    var functionType = getBinaryType("rl_command_func_t");

    var callback = new BinaryCallback(functionType, (args) {
      if (handler is ReadlineCommandRegularFunction) {
        return handler(args[0], args[1]);
      } else {
        return handler();
      }
    });

    checkSysCallResult(invoke("readline::rl_bind_key", [key is String ? key.codeUnitAt(0) : key, callback.functionCode]));
  }

After the last use (in checkSysCallResult) of the binary data (BinaryCallback) it will be freed by the garbage collector at the first opportunity.
Binary function code also would be invalid (deallocated).

I do not know how the "readline" works but if you want create a "long life" binary callback you should return it back and store it in a safe place.

Local variables not a good place.
If it used only in the function body then you can use method keepAlive()

var data = allocData();
someFunc(data);
// above we not use data directly
// but some code may use data in physical memory
// Without this data would be freed
// Keep it alive
keepAlive(data);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions