Skip to content

Port module to Stable ABI + multi-phase module initialization - #641

Open
mistotebe wants to merge 14 commits into
python-ldap:mainfrom
mistotebe:module_startup
Open

mistotebe wants to merge 14 commits into
python-ldap:mainfrom
mistotebe:module_startup

Conversation

@mistotebe

Copy link
Copy Markdown
Contributor

Fixes: #540

@mistotebe mistotebe added this to the 3.5.0 milestone Sep 8, 2026
@mistotebe
mistotebe force-pushed the module_startup branch 2 times, most recently from 7f36b4a to 060c151 Compare September 8, 2026 13:01
@mistotebe
mistotebe force-pushed the module_startup branch 3 times, most recently from 37595c3 to 5327e67 Compare September 10, 2026 13:39

@droideck droideck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have a couple of concerns but otherwise, looks great!

Comment thread Modules/LDAPObject.c Outdated
Comment thread Modules/ldapmodule.c
mistotebe and others added 9 commits September 15, 2026 16:12
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 <[email protected]>
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 <[email protected]>
Signed-off-by: Ondřej Kuzník <[email protected]>
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 <[email protected]>
@mistotebe
mistotebe force-pushed the module_startup branch 2 times, most recently from dab6f8c to af948e9 Compare September 15, 2026 16:14
Comment thread Modules/constants.c Outdated

@droideck droideck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great!
Really happy to see the change:)

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.

[feature] Port python-ldap to PEP 630 (Isolating Extension Modules)

3 participants