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

caleb/fix/stringdata #417

Merged
merged 12 commits into from
Aug 28, 2024
Merged

caleb/fix/stringdata #417

merged 12 commits into from
Aug 28, 2024

Conversation

zollqir
Copy link
Collaborator

@zollqir zollqir commented Aug 26, 2024

In pursuit of fixing #340, this PR fixes some issues with string object reference counts. We now decrement strings (as well as lists and objects) even if their refcount = 1, which we were not doing before due to potential crashes during python's finalization, but now we just check if python is finalizing and if so skip all the refcount managing.
This also more intelligently manages the reference counts of string objects depended upon by JSExternalStrings, which will now have exactly the same lifetime as the JSExternalString (unless some other thing is keeping it alive, of course) without leaking memory.
Finally, it adds a GC callback that re-points all of the JSStringProxy data pointers to their associated data, since they may have moved during a GC.

@zollqir zollqir requested a review from Xmader August 26, 2024 15:36
@zollqir zollqir self-assigned this Aug 26, 2024
}

JS::AutoCheckCannotGC nogc;
for (const JSStringProxy *jsStringProxy: jsStringProxies) { // char buffers may have moved, so we need to re-point our JSStringProxies
Copy link
Member

Choose a reason for hiding this comment

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

In symmetry to this, would a Python str object move its char buffers, and how to notify the JS land?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you know if python string objects move their buffers? As far as I'm aware they never move

Xmader
Xmader previously approved these changes Aug 27, 2024
Copy link
Member

@Xmader Xmader left a comment

Choose a reason for hiding this comment

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

Other than the above comments, the pull request looks good to me.
Good code!

@Xmader Xmader merged commit a0b3602 into main Aug 28, 2024
22 of 34 checks passed
@Xmader Xmader deleted the caleb/fix/stringdata branch August 28, 2024 15:25
@wesgarland
Copy link
Collaborator

Between JS_SetGCCallback and JS::AddGCNurseryCollectionCallback(), we should cover all cases where a JS String can be moved. (per jonco from moz, he hacks on the GC)

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.

4 participants