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

fix(value): handle transfer-full, in arguments properly #303

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

peat-psuwit
Copy link
Contributor

@peat-psuwit peat-psuwit commented Jun 18, 2021

This is done by making V8ToGIArgument() accept the transfer status and
react accordingly. I does not make the new argument optional; this
forces me into thinking about the appropriate value to put in for
various callsites of this function.

Closes #303

@peat-psuwit peat-psuwit changed the title Correctly handle transfer-full, in arguments fix(value): handle transfer-full, in arguments properly Jul 18, 2021
@peat-psuwit peat-psuwit marked this pull request as ready for review July 18, 2021 18:49
src/value.cc Show resolved Hide resolved
@peat-psuwit peat-psuwit force-pushed the transfer-fully-in branch 2 times, most recently from c63aedf to 35de0ce Compare August 29, 2021 19:04
src/value.cc Outdated Show resolved Hide resolved
tests/function_call.js Outdated Show resolved Hide resolved
@romgrk
Copy link
Owner

romgrk commented Sep 28, 2021

@peat-psuwit sorry for the delay, was traveling a bit this summer.

Overall this looks good, one thing though. For all the changes it makes, the PR only has a single test. Is it really the only case affected by these changes?

@peat-psuwit
Copy link
Contributor Author

For all the changes it makes, the PR only has a single test. Is it really the only case affected by these changes?

Well, the thing is that I can't find more APIs in GStreamer, GLib or GTK that would be affected by this. I would prefer to have at least an equivalent test but for GObject. I considered adding an introspectable library for testing, but I'm not sure if it can be done using node-gyp system

@romgrk
Copy link
Owner

romgrk commented Sep 29, 2021

Alright. There is #269 open to add libgimarshallingtest which does that kind of stuff, we can add more tests once the lib is used for testing. I'll merge as soon as you fix the last two nitpicks :]

@romgrk
Copy link
Owner

romgrk commented Oct 2, 2021

How is this one related to #302? Do you want to include the memory ownership thing here?

@peat-psuwit
Copy link
Contributor Author

It's a different problem. This one try to prevent use-after-free for transfer-full, in argument, while #302 concerns about memory leakage. Both are memory problems, but of different kinds...

This one can be merged without the fix for #302.

src/value.cc Outdated Show resolved Hide resolved
@romgrk
Copy link
Owner

romgrk commented Oct 2, 2021

Got it. You can fix the last comment up here and it's ready for merging.

src/value.cc Outdated Show resolved Hide resolved
This is done by making V8ToGIArgument() accept the transfer status and
react accordingly. I does not make the new argument optional; this
forces me into thinking about the appropriate value to put in for
various callsites of this function.

The make the test added in the previous commit passes.
@@ -652,6 +671,8 @@ bool V8ToGIArgument(GIBaseInfo *gi_info, GIArgument *arg, Local<Value> value) {
}
case GI_INFO_TYPE_INTERFACE:
arg->v_pointer = GObjectFromWrapper(value);
if (transfer == GI_TRANSFER_EVERYTHING)
g_object_ref(arg->v_pointer);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this one isn't going to leak anything? Is this case the one tested by the test down here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this one isn't going to leak anything?

I suppose no. The new reference should be taken by the callee, by the definition of TRANSFER_EVERYTHING. I don't see a failure case in this function.

Is this case the one tested by the test down here?

Similar, but of different type. The added test is for GBoxed [1], while this one is for GObject. That's why I said I want to test this.

[1] specifically GstMiniObject, but to node-gtk it's a boxed object.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new reference should be taken by the callee

But maybe here TRANSFER_EVERYTHING means to take ownership of the passed ref, no? Either way, I'd first try to find a failing case before adding a reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever the function's transfer say, we cannot transfer the JS wrapper to the C world. That means the JS wrapper will have to stay, and so does the wrapper's object reference. If we don't increase a reference here, the JS wrapper's reference will (metaphorically) be transferred to the function. And if such function un-reference this reference, it can leave the JS wrapper dangling.

Maybe you intend to leave the JS wrapper dangling after a call to transfer-full function. However, that doesn't work either. Every reference to this object in the JS world shares single JS wrapper, and thus have single GObject reference. If the JS wrapper becomes dangling, so does every refernce in the JS world.

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

Successfully merging this pull request may close these issues.

None yet

2 participants