Conversation
mistotebe
force-pushed
the
module_startup
branch
2 times, most recently
from
September 8, 2026 13:01
7f36b4a to
060c151
Compare
The `LDAP` type has been converted from a static type to a heap type.
The limited API does not support static types.
Heap types behave more closely like Python classes. They are allocated
on the heap and reference counted. Instances have a strong reference to
their type and must use GC protocol to track this reference.
The LDAP type can no longer be instantiated by Python code. This was
never supported and resulted in an invalid LDAP connection. Code like
`type(_ldap.initialize(""))()" now fails with a `TypeError`.
See: python-ldap#540
Signed-off-by: Christian Heimes <cheimes@redhat.com>
The `_ldap` module now uses modern multi-phase module initialization. Replace `LDAPadd_methods` hack with proper PyMethodDef for module-level functions. The old approache is incompatible with multi-phase init. Module-level functions are now prefixed with `LDAPMod_` and exported. Use `PyModuleDef_Slot` to initialize the `_ldap` C extension. See: python-ldap#540 Signed-off-by: Christian Heimes <cheimes@redhat.com> Signed-off-by: Ondřej Kuzník <ondra@mistotebe.net>
Replace unsafe macros and direct struct access with functions from the subset of limited API functions. * `PySequence_Fast_GET_ITEM` -> `PySequence_GetItem` * `PyTuple_SET_ITEM` -> `PyTuple_SetItem` * `PyList_SET_ITEM` -> `PyList_SetItem` * `const char *tp_name` -> `Py_TYPE()` string representation See: python-ldap#540 Signed-off-by: Christian Heimes <cheimes@redhat.com>
mistotebe
force-pushed
the
module_startup
branch
2 times, most recently
from
September 10, 2026 13:22
1049c04 to
37595c3
Compare
Python 3.12+ headers trigger it unless built with limited API.
mistotebe
force-pushed
the
module_startup
branch
from
September 10, 2026 13:39
37595c3 to
5327e67
Compare
droideck
requested changes
Sep 14, 2026
droideck
left a comment
Member
There was a problem hiding this comment.
I have a couple of concerns but otherwise, looks great!
| goto error; | ||
| } | ||
| str = PyUnicode_AsUTF8AndSize(item, &strlen); | ||
| Py_DECREF(item); |
Member
There was a problem hiding this comment.
I think we should move this decref after memcpy and release item on the error paths too.
str points into item, so IIUC releasing our reference before copying leaves the buffer dependent on the caller’s list remaining unchanged during free-threaded execution.
| static struct PyModuleDef ldap_moduledef = { | ||
| .m_base = PyModuleDef_HEAD_INIT, | ||
| .m_name = "_ldap", | ||
| .m_size = sizeof(LDAPModState), |
Member
There was a problem hiding this comment.
IIUC, this module/type reference cycle needs m_traverse, m_clear, and m_free so GC can collect it.
And add_err from constants.c similarly might need to release the previous array entry when another exception shares its error code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #540