Skip to content

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

Merged
merged 1 commit into from
Dec 11, 2017

Conversation

tiran
Copy link
Member

@tiran tiran commented Dec 6, 2017

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

@tiran tiran force-pushed the const_attrlist branch 2 times, most recently from 08b0ae9 to c392093 Compare December 6, 2017 08:22
@codecov
Copy link

codecov bot commented Dec 6, 2017

Codecov Report

Merging #106 into master will increase coverage by 0.08%.
The diff coverage is 81.48%.

@@            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
Impacted Files Coverage Δ
Modules/LDAPObject.c 67.69% <81.48%> (-0.02%) ⬇️
Lib/slapdtest/_slapdtest.py 82.88% <0%> (+1.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 31abc2e...3a9c490. Read the comment docs.

@@ -289,16 +294,27 @@ attrs_from_List( PyObject *attrlist, char***attrsp, PyObject** seq) {
LDAPerror_TypeError("expected bytes in list", item);
Copy link
Member

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.

const char *str;
#else
char *str;
#endif
Copy link
Member

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.

Copy link
Member

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.

@encukou
Copy link
Member

encukou commented Dec 7, 2017

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>
Copy link
Member Author

@tiran tiran left a 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
Copy link
Member Author

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()

Copy link
Member

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-?

Copy link
Member Author

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.
Copy link
Member Author

Choose a reason for hiding this comment

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

See here

@tiran
Copy link
Member Author

tiran commented Dec 8, 2017

Your modifications LGTM

@encukou encukou merged commit baa091f into python-ldap:master Dec 11, 2017
@tiran tiran deleted the const_attrlist branch December 11, 2017 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy