GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||
GeezerVison is showing github.com — gh-89653: PEP 670: Convert PyUnicode_KIND() macro to function by vstinner · Pull Request #92705 · python/cpython Conversation
Member
In the limited C API version 3.12, PyUnicode_KIND() is now Update _decimal.c and stringlib/eq.h for PyUnicode_KIND().
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page.
erlend-aasland
approved these changes
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good to me
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsIn the limited C API version 3.12, PyUnicode_KIND() is now implemented as a static inline function. Keep the macro for the regular C API and for the limited C API version 3.11 and older to prevent introducing new compiler warnings. Update _decimal.c and stringlib/eq.h for PyUnicode_KIND().
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
erlend-aasland
approved these changes
methane
approved these changes
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
|
Perf hit would be measurable, but not end of the world. In 2018, I port MarkupSafe to PEP 393. I wrote logic in macro and 3 functions for each kind. In 2020, I port Genshi to Python 3.3+, but used UTF-8 instead of PEP 393 API. I think optimizing for PEP 393 won't pay for most cases. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
For I would not want to lose such advantage. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The _PyUnicodeWriter API should be as efficient as using the (kind, data) API. Overallocation can be enabled or disabled, and it's possible to request max character when the writer is initialized to avoid expensive conversions from UCS1 to UCS2 and then to UCS4. But it's usually hard to know in advance to know what will be the final maximum character. _PyUnicodeWriter also allows to change the buffer format at each write from UCS1, to UCS2 and then UCS4. In the early days of Python 3.3, most code only used UCS4 buffers (simple C array of Py_UCS4 characters allocated on the heap) and then downcasted to UCS1 or UCS2 when the final string was created. I'm not proposing to expose directly the _PyUnicodeWriter API. I'm thinking about proposing a public C API with the same idea: "append only" API and a "finish" function which returns a Python str object. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Would it be acceptable for the regex module to use the internal C API to access directly to the Python str internals: the (kind, data) API? Anyway, this idea is in the PEP area: use cases should be written down, and the performance of each use case should be measured. If possible, I would prefer to have no impact or minor overhead on CPython, but the main goal is to get "native speed" for other Python implementations, especially PyPy which uses UTF-8 internally. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Can we move this discussion to Discourse or a separate issue? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The future of the (kind, data) API is discussed at: https://discuss.python.org/t/un-deprecate-pyunicode-ready-for-future-unicode-improvement/15717 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.