Skip to content

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

Merged
merged 2 commits into from
Apr 1, 2020

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Mar 31, 2020

Make it a static function, and pass known attributes (kind, data, length) instead of the PyUnicode object.

https://bugs.python.org/issue40130

Make it a static function, and pass known attributes
(kind, data, length) instead of the PyUnicode object.
Copy link
Member

@vstinner vstinner left a 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) {
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

@@ -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,
Copy link
Member

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?

@serhiy-storchaka serhiy-storchaka merged commit 17b4733 into python:master Apr 1, 2020
@serhiy-storchaka serhiy-storchaka deleted the pyunicode_askind branch April 1, 2020 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants