Skip to content

Arg::keepAlive can be ignored on exception #185

Description

@uvlad7

checkKeepAlive is called after invokeNativeFunction/invokeNativeMethod. So, imagine a native function that caches its argument and then throws an exception for some reason. In that case NativeFunction<>::call will handle the exception, but NativeFunction<>::operator() will fail to store the argument into keepAlive_.
It's not an issue for me, actually, but I think it's worth highlighting in the documentation or fixing it.

Activity

  1. cfis commented on Feb 19, 2024

    @cfis
    Collaborator

    If an exception is raised in invokeNativeFunction/invokeNativeMethod then there would be no result returned from either. So seems ok for return values marked as keepAlive since there is nothing to mark.

    As for args marked as keep alive, I am not sure what the right thing would be. The code could process those before invoking the function...but what if the function never got far enough to actually take ownership of the passed in arg? I guess better to call mark on it and be safe then not do it and possibly GC it on the Ruby side?

  2. uvlad7 commented on Feb 19, 2024

    @uvlad7
    Author

    I'm also not sure what to do with it, probably just highlight the pitfall in the docs is OK. Usually this has no effect.

  3. cfis commented on Feb 19, 2024

    @cfis
    Collaborator

    Another thing that crossed my mind is there no API removeKeepAlive. For example, if you remove an item from a collection. Have you ran into that issue?

  4. uvlad7 commented on Feb 22, 2024

    @uvlad7
    Author

    No, I never needed that. Actually, I used Arg::keepAlive only in constructor and have never ran into keepAlive on exception issue, too. I just noticed it can happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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