-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-40130: _PyUnicode_AsKind() should not be exported. #19265
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
bpo-40130: _PyUnicode_AsKind() should not be exported. #19265
Conversation
Make it a static function, and pass known attributes (kind, data, length) instead of the PyUnicode object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. It's fine to remove private functions whenever we want, especially before a release.
First, I wasn't sure if it's a good idea to require the (kind, data, len) triplet rather than PyObject*
, but after I read the issue, I think that it's ok.
@@ -2458,13 +2458,15 @@ unicode_adjust_maxchar(PyObject **p_unicode) | |||
if (max_char >= 256) | |||
return; | |||
} | |||
else { | |||
else if (kind == PyUnicode_4BYTE_KIND) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a switch/case would be more appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe. I left a chain of ifs because I am sure that in this case the compiler would generate the optimal code for PyUnicode_1BYTE_KIND, and I am not so sure about this in the case of switch/case. It may be a matter of other issue, I do not want to introduce regression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was just a remark. You can leave the code as it is, I already approved your PR.
Objects/unicodeobject.c
Outdated
@@ -2525,8 +2517,8 @@ _PyUnicode_AsKind(PyObject *s, unsigned int kind) | |||
assert(skind == PyUnicode_1BYTE_KIND); | |||
_PyUnicode_CONVERT_BYTES( | |||
Py_UCS1, Py_UCS2, | |||
PyUnicode_1BYTE_DATA(s), | |||
PyUnicode_1BYTE_DATA(s) + len, | |||
(Py_UCS1 *)data, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be const Py_UCS1*
, no?
Make it a static function, and pass known attributes (kind, data, length) instead of the PyUnicode object.
https://bugs.python.org/issue40130