Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mezoni opened this issue Apr 24, 2015 · 1 comment

Comments

@mezoni
Copy link

mezoni commented Apr 24, 2015

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);
@azenla
Copy link

azenla commented Apr 24, 2015

Ok. I'll do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants