-
Notifications
You must be signed in to change notification settings - Fork 57
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
Make C modules Python 3 compatible #76
base: master
Are you sure you want to change the base?
Conversation
_baked.c was the most complicated one. Py3 Unicode implementation requires initialization. I left the Python 2 implementation alone because I'm not entirely sure of the overhead being saved with memcpy right now.
No detected performance regression with this. New: Spitfire template 9.65 ms Old: Spitfire template 9.84 ms |
Py_INCREF(value); | ||
return value; | ||
} | ||
PyObject *args = Py_BuildValue("(N)", value); |
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.
Can you add a comment on why you are choosing N
(and therefore not incrementing the reference count) instead of O
?
sp_mod, /* nb_remainder */ | ||
}; | ||
|
||
// SanitizedPlaceholder Type. | ||
static PyTypeObject SanitizedPlaceholderType = { | ||
PyObject_HEAD_INIT(NULL) | ||
0, /* ob_size */ | ||
PyVarObject_HEAD_INIT(NULL,0 ) |
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.
PyVarObject_HEAD_INIT(NULL,0 ) | |
PyVarObject_HEAD_INIT(NULL, 0) |
@@ -151,7 +186,7 @@ static PyTypeObject SanitizedPlaceholderType = { | |||
0, /* tp_methods */ | |||
0, /* tp_members */ | |||
0, /* tp_getset */ | |||
0, /* tp_base */ | |||
&PyUnicode_Type, /* tp_base */ |
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.
Since we're conditionally setting tp_base
below, let's not set it here too
&PyUnicode_Type, /* tp_base */ | |
0, /* tp_base */ |
@@ -72,7 +72,7 @@ udn_resolve_udn(PyObject *self, PyObject *args, PyObject *kargs) | |||
return NULL; | |||
} | |||
|
|||
if (!(PyUnicode_Check(name) || PyString_Check(name))) { | |||
if (!(PyUnicode_Check(name) || PyBytes_Check(name))) { |
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.
I think you need to either include bytesobject.h
for python2.6+ compatibility of PyBytes_Check
or add a PY_MAJOR_VERSION
check here like you do elsewhere
@@ -110,7 +110,7 @@ udn_resolve_from_search_list(PyObject *self, PyObject *args, PyObject *keywds) | |||
return NULL; | |||
} | |||
|
|||
if (!(PyUnicode_Check(name) || PyString_Check(name))) { | |||
if (!(PyUnicode_Check(name) || PyBytes_Check(name))) { |
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.
I think you need to either include bytesobject.h
for python2.6+ compatibility of PyBytes_Check
or add a PY_MAJOR_VERSION
check here like you do elsewhere
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.
Just a couple of changes, I think
Co-Authored-By: Alex Nicksay <nicksay@google.com>
_baked.c was the most complicated one. Py3 Unicode implementation
requires initialization. I left the Python 2 implementation alone
because I'm not entirely sure of the overhead being saved with memcpy
right now.