Closed as not planned
Description
I propose to port python-ldap to PEP 630. Actually, I have already done the work and have a working prototype. PEP 630 is an informational PEP that covers three PEPs
- PEP 384 – Defining a Stable ABI
- PEP 489 – Multi-phase extension module initialization
- PEP 573 – Module State Access from C Extension Methods
Isolated C extension module will give us two major benefits:
- Stable ABI / limited API will allow us / our users to create
abi3
binary wheels. My prototype implementscp36-abi3-linux_x86_64.whl
support. The wheels is compatible with all Python versions from 3.6 to 3.12, as well as future versions of Python 3 with ABI3. For example @cgohlke won't need to create Windows binaries for each Python version. - It makes python-ldap compatible with PEP 684 Per-Interpreter GIL and safe to use with multiple subinterpreters.
Required changes
- Port
PyTypeObject LDAP_Type
to heap type.- Replace static
PyTypeObject LDAP_Type
withPyType_Slot
andPyType_Spec
- Allocate object with
PyObject_GC_New
and free it withPyObject_GC_UnTrack
/PyObject_GC_Del
- Add GC protocol (traverse, clear) to track the heap reference to the type
- Initialize type with
PyType_FromSpec
- Replace static
- Create
_ldap
C extension module with multi-phase initialization- Export module-level functions from
functions.c
andldapcontrol.c
. This also gets rid ofLDAPadd_methods
hack,LDAPinit_functions
, andLDAPinit_control
- Define
PyModuleDef_Slot
to init type, constants, and pkginfo - Make
PyModuleDef
global static - Initialize module with
PyModuleDef_Init
- Export module-level functions from
- Remove static globals
LDAP_Type
,LDAPexception_class
, anderrobjects
in favor of module state struct.- Define
LDAPModState
and add it toPyModuleDef
- Add state pointer to
LDAPObject
.PyType_GetModuleState()
is not available in Python < 3.9 and became part of the stable ABI in 3.10. - Change all functions to get reference to type or exceptions from module state. This change is the largest diff and requires changes to several helper functions, especially error functions like
LDAPerror
.
- Define
- Replace some macros with limited API functions, e.g.
PySequence_Fast_GET_ITEM()
withPySequence_GetItem()
. We use unsafe macros in a few places. In theory the macros are a tiny bit faster. In practice it doesn't make a difference except for lots of calls in a hot path. I don't except a performance impact. - Build
_ldap
extension module with limited API and stable ABI parameters.
Metadata
Metadata
Assignees
Labels
No labels