Skip to content

Conversation

@nathanvoglsam
Copy link

Hello!

I've got a PR here for adding a new 'JS_FreeCStringRT' function that (if I understand the code correctly) should function the same as the existing 'JS_FreeCString' but takes a JSRuntime instead of a JSContext. It looks like the c-string being returned is just actually a JSString value with the string data trailing off the end of the allocation. I can't see any obvious reason why it needs to be tied to a JSContext.

My motivation for this feature follows on from my question in this discussion. My Rust bindings rely on a single, thread local JSRuntime for each thread. Nothing can get sent to other threads so I get a reasonably safe API without lifetime soup. The c-strings were the odd one left, still needing a reference to the JSContext they were created from so I could clean them up with RAII. With this change that can go away.

If this is API internals you don't want to commit to I understand, as this is a whole new API, but thought I'd forward this for discussion.

Seems to work in my Rust code but I haven't tested very thoroughly.

Copy link
Contributor

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

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

Seems unobjectionable to me but, since it's not being used anywhere in quickjs itself, can you add a regression test to api-test.c?

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.

2 participants