-
Notifications
You must be signed in to change notification settings - Fork 127
Change memory handling in attrs_from_List() #106
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
Conversation
08b0ae9
to
c392093
Compare
Codecov Report
@@ Coverage Diff @@
## master #106 +/- ##
==========================================
+ Coverage 68% 68.08% +0.08%
==========================================
Files 48 48
Lines 4675 4684 +9
Branches 784 787 +3
==========================================
+ Hits 3179 3189 +10
+ Misses 1145 1143 -2
- Partials 351 352 +1
Continue to review full report at Codecov.
|
@@ -289,16 +294,27 @@ attrs_from_List( PyObject *attrlist, char***attrsp, PyObject** seq) { | |||
LDAPerror_TypeError("expected bytes in list", item); |
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.
As I was reading this, I also changed the comment “Encoded by Python to UTF-8” to “Encoded in Python to UTF-8”, since it's python-ldap's Python code doing the encoding.
Modules/LDAPObject.c
Outdated
const char *str; | ||
#else | ||
char *str; | ||
#endif |
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's should be fine to use const char
everywhere.
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.
well, everywhere but Python 2.
210a6ce
to
06b8ac1
Compare
Rebased with the two changes above folded in. |
attrs_from_List() no longer uses internal buffers of bytes/str PyObject* to maintain memory. Instead it creates its own copies, which are then passed to ldap_search_ext() and then cleaned up. The modification is required for Python 3.7. PyUnicode_AsUTF8() returns const char* but ldap_search_ext() does not use const. Closes: python-ldap#105 Signed-off-by: Christian Heimes <cheimes@redhat.com>
06b8ac1
to
3a9c490
Compare
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.
The version check was correct.
if (*seq == NULL) | ||
PyObject *item = NULL; | ||
Py_ssize_t i, len, strlen; | ||
#if PY_MAJOR_VERSION >= 3 |
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.
That's wrong, it must be #if PY_VERSION_HEX >= 0x03070000
. Python < 3.7 has PyAPI_FUNC(char *) PyUnicode_AsUTF8AndSize()
. Only 3.7+ has PyAPI_FUNC(const char *) PyUnicode_AsUTF8AndSize()
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 thought implicitly converting char *
to const char *
is perfectly fine – it just limits what can be done with the string later.
Why is const char *str = PyUnicode_AsUTF8AndSize(...)
a problem on 3.6-?
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 discussed the issue with @vstinner. He assured me that const is always fine here. Let's go for your version check.
#endif | ||
/* Make a copy. PyBytes_AsString* / PyUnicode_AsUTF8* return | ||
* internal values that must be treated like const char. Python | ||
* 3.7 actually returns a const char. |
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.
See here
Your modifications LGTM |
attrs_from_List() no longer uses internal buffers of bytes/str PyObject*
to maintain memory. Instead it creates its own copies, which are then
passed to ldap_search_ext() and then cleaned up.
The modification is required for Python 3.7. PyUnicode_AsUTF8() returns
const char* but ldap_search_ext() does not use const.
Closes: #105
Signed-off-by: Christian Heimes cheimes@redhat.com