Uh oh!
There was an error while loading. Please reload this page.
gh-119609, PEP 756: Add PyUnicode_Export() function - #123738
Conversation
Add PyUnicode_Export(), PyUnicode_GetBufferFormat() and PyUnicode_Import() functions to the limited C API.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
When you're done making the requested changes, leave the comment: |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
vstinner
commented
Sep 5, 2024
I have made the requested changes; please review again. |
Thanks for making the requested changes! @mdboom: please review the changes made to this pull request. |
vstinner
commented
Sep 5, 2024
picnixz
left a comment
There was a problem hiding this comment.
A final nitpick on my side (sorry but I only skimmed through the implementation since I don't have much energy now...).
A bit off-topic, but do we use the PRI* macros in the code base? I saw that you used the %i for formatting a uint32_t value, which usually works, but I wondered whether you prefer using the platform-dependent ones.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
vstinner
commented
Sep 5, 2024
A side effect of this change is to add the I had to implement |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
vstinner
commented
Sep 12, 2024
@serhiy-storchaka: I updated the PR to use _PyUnicode_EncodeUTF16() and _PyUnicode_EncodeUTF32(), and address your other comments. |
vstinner
commented
Sep 12, 2024
I had to remove the check "last character in a NUL character" in tests, since _PyUnicode_EncodeUTF16() and _PyUnicode_EncodeUTF32() don't write such last NUL character. |
encukou
commented
Sep 12, 2024
That's a security vulnerability waiting to happen. Since the internal buffers do have the terminating NUL, and in most cases we expose those, people will expect the NUL even if we'd explicitly document that it's not guaranteed. IMO, we need to add it. |
vstinner
commented
Sep 12, 2024
@serhiy-storchaka: Sorry, I reverted the "Use _PyUnicode_EncodeUTF16() and _PyUnicode_EncodeUTF32()" change to get back the NUL trailing character. |
vstinner
commented
Sep 12, 2024
I'm not sure if we should guarantee that the exported buffer ends with a NUL character. I'm not sure that all Python implementations will be able to provide such guarantee in an efficient way (without having to allocate a temporary buffer for that). |
encukou
commented
Sep 12, 2024
We should. As long as the API is used from C, exported strings should be NUL-terminated for safety. |
vstinner
commented
Sep 12, 2024
I suggest to continue this discussion at: capi-workgroup/decisions#33 (comment) |
Uh oh!
There was an error while loading. Please reload this page.
vstinner
commented
Nov 5, 2024
I withdrawn my PEP 756. |
Add PyUnicode_Export(), PyUnicode_GetBufferFormat() and PyUnicode_Import() functions to the limited C API.
📚 Documentation preview 📚: https://cpython-previews--123738.org.readthedocs.build/