Skip to content

Removed PyString refs from extension modules #28322

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
Sep 7, 2019

Conversation

WillAyd
Copy link
Member

@WillAyd WillAyd commented Sep 6, 2019

We have some old PyString references hanging around in our extension modules. These are a relic of the old Py2 string handling and will be removed in Python 4 I think, so figured worth modernizing

https://docs.python.org/3/howto/cporting.html

@WillAyd WillAyd added the Clean label Sep 6, 2019
return PyString_FromString(data);
#endif
}
"""
object char_to_string(const char* data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldnt L14 be removed too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually used here:

result = util.char_to_string(formatted)

So maybe but would require a more comprehensive refactor

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that just becomes result = PyUnicode_FromString(formatted)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool - I'll give it a look. Seems like this caused a somewhat surprising failure so that might solve

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm so didn't realize the cdef of the tripled quoted string was actually using that as a macro. Was thinking of cimporting PyUnicode_FromString directly but looks like that isn't available until Cython 3.0.0

cython/cython#3010

For now going to revert to macro

@@ -2,23 +2,13 @@
from cpython cimport PyTypeObject

cdef extern from *:
"""
PyObject* char_to_string(const char* data) {
#if PY_VERSION_HEX >= 0x03000000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's one more PY_VERSION_HEX check in compat_helper that could go

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I was looking at that but I'm planning on the compat stuff in a separate PR

@jreback jreback added this to the 1.0 milestone Sep 7, 2019
@jreback jreback merged commit e24d9e5 into pandas-dev:master Sep 7, 2019
@jreback
Copy link
Contributor

jreback commented Sep 7, 2019

thanks @WillAyd

proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
* Removed PyString refs from extension modules

* Reverted macro
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
* Removed PyString refs from extension modules

* Reverted macro
@WillAyd WillAyd deleted the remove-pystring-refs branch January 16, 2020 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants