bpo-31484: Cache single-character strings outside of the Latin1 range.#3600
bpo-31484: Cache single-character strings outside of the Latin1 range.#3600serhiy-storchaka wants to merge 2 commits into
Conversation
| /* Single character Unicode objects can be shared when using this | ||
| constructor. */ | ||
| if (size == 1) { | ||
| return unicode_char((Py_UCS4)*u); |
There was a problem hiding this comment.
def test_issue17223(self):
# this used to crash
if sizeof_wchar == 4:
# U+FFFFFFFF is an invalid code point in Unicode 6.0
invalid_str = b'\xff\xff\xff\xff'
else:
# PyUnicode_FromUnicode() cannot fail with 16-bit wchar_t
self.skipTest("specific to 32-bit wchar_t")
a = array.array('u', invalid_str)
self.assertRaises(ValueError, a.tounicode)
self.assertRaises(ValueError, str, a)
PyUnicode_FromWideChar() should raise ValueError when u is out of unicode range.
There was a problem hiding this comment.
Does not it do this? unicode_char() is an implementation of Python's chr().
There was a problem hiding this comment.
assert(ch <= MAX_UNICODE); is in top of unicode_char()
| /* Single character Unicode objects can be shared when using this | ||
| constructor. */ | ||
| if (size == 1) { | ||
| return unicode_char((Py_UCS4)*u); |
There was a problem hiding this comment.
assert(ch <= MAX_UNICODE); is in top of unicode_char()
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be poked with soft cushions! |
|
I expect the Japan Inquisition! |
|
@serhiy-storchaka, shouldn't this go in? Just add a NEWS entry... |
|
I have doubts because of diverse feedback on this proposition. This PR adds complexity in the code, and the gain is small. Most likely I'll close this PR unless other core devs have good need of this microoptimization. |
|
@serhiy-storchaka, based on your last comment, do you think this should be closed now? |
|
@serhiy-storchaka, let's close this PR? |
https://bugs.python.org/issue31484