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

Add a lock around parse, to prevent concurrent access to the underlying parse tree. #367

Merged
merged 2 commits into from
Apr 15, 2024

Conversation

migueldeicaza
Copy link
Contributor

The parse method in TreeSitterInternalLanguageMode is invoked directly by the
TextInputView.string.setter method, which can happen concurrently with the
calls to parse(_ text: NSString, completion: @escaping ((Bool) -> Void)) which happen to
queue things into a dedicated thread.

This causes a double-free of the underlying structures and assorted other crashes.

I caught this using the "address sanitizer" as I was trying to use my SwiftUI wrapper for
Runestone, which would trigger this event.

… parse and this parse happen at the same time
@simonbs
Copy link
Owner

simonbs commented Apr 6, 2024

Thanks a ton! I’ve been postponing fixing this for waaaay too long. It didn’t occur to me that that issue could be addressed this simply/elegantly 😄

Copy link
Contributor Author

@migueldeicaza migueldeicaza left a comment

Choose a reason for hiding this comment

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

Looks fine to me.

@simonbs simonbs merged commit 36d91bf into simonbs:main Apr 15, 2024
9 checks passed
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