-
Notifications
You must be signed in to change notification settings - Fork 126
[feature] Port python-ldap to PEP 630 (Isolating Extension Modules) #540
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
Comments
tiran
added a commit
to tiran/python-ldap
that referenced
this issue
Oct 30, 2023
Merge all header files except `constants_generated.h` into a single header file `pythonldap.h`. A single header file makes it far easier to port python-ldap to heap types and module state for Per-Interpreter GIL. `pythonldap.h` uses new macros `PYLDAP_FUNC` and `PYLDAP_DATA` to declare functions and data, which are used across C files. Remove unused macro `streq`. See: python-ldap#540 Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran
added a commit
to tiran/python-ldap
that referenced
this issue
Oct 30, 2023
Merge all header files except `constants_generated.h` into a single header file `pythonldap.h`. A single header file makes it far easier to port python-ldap to heap types and module state for Per-Interpreter GIL. `pythonldap.h` uses new macros `PYLDAP_FUNC` and `PYLDAP_DATA` to declare functions and data, which are used across C files. Remove unused macro `streq`. See: python-ldap#540 Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran
added a commit
to tiran/python-ldap
that referenced
this issue
Oct 30, 2023
Merge all header files except `constants_generated.h` into a single header file `pythonldap.h`. A single header file makes it far easier to port python-ldap to heap types and module state for Per-Interpreter GIL. `pythonldap.h` uses new macros `PYLDAP_FUNC` and `PYLDAP_DATA` to declare functions and data, which are used across C files. Remove unused macro `streq`. See: python-ldap#540 Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran
added a commit
to tiran/python-ldap
that referenced
this issue
Oct 30, 2023
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` * `PyBytes_AsStringAndSize` -> `PyUnicode_AsUTF8String` + `PyBytes_AsStringAndSize`. The function `PyUnicode_AsUTF8AndSize` is not in limited API before Python 3.10. * `const char *tp_name` -> `Py_TYPE()` string representation See: python-ldap#540 Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran
added a commit
to tiran/python-ldap
that referenced
this issue
Nov 1, 2023
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` * `PyUnicode_AsUTF8AndSize` -> `PyUnicode_AsUTF8String` + `PyBytes_AsStringAndSize`. The function `PyUnicode_AsUTF8AndSize` is not in limited API before Python 3.10. * `const char *tp_name` -> `Py_TYPE()` string representation See: python-ldap#540 Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran
added a commit
that referenced
this issue
Nov 3, 2023
Merge all header files except `constants_generated.h` into a single header file `pythonldap.h`. A single header file makes it far easier to port python-ldap to heap types and module state for Per-Interpreter GIL. `pythonldap.h` uses new macros `PYLDAP_FUNC` and `PYLDAP_DATA` to declare functions and data, which are used across C files. Remove unused macro `streq`. See: #540 Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran
added a commit
to tiran/python-ldap
that referenced
this issue
Nov 3, 2023
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>
tiran
added a commit
to tiran/python-ldap
that referenced
this issue
Nov 3, 2023
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>
tiran
added a commit
to tiran/python-ldap
that referenced
this issue
Nov 3, 2023
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>
tiran
added a commit
to tiran/python-ldap
that referenced
this issue
Nov 3, 2023
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` * `PyUnicode_AsUTF8AndSize` -> `PyUnicode_AsUTF8String` + `PyBytes_AsStringAndSize`. The function `PyUnicode_AsUTF8AndSize` is not in limited API before Python 3.10. * `const char *tp_name` -> `Py_TYPE()` string representation See: python-ldap#540 Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran
added a commit
to tiran/python-ldap
that referenced
this issue
Nov 3, 2023
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` * `PyUnicode_AsUTF8AndSize` -> `PyUnicode_AsUTF8String` + `PyBytes_AsStringAndSize`. The function `PyUnicode_AsUTF8AndSize` is not in limited API before Python 3.10. * `const char *tp_name` -> `Py_TYPE()` string representation See: python-ldap#540 Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran
added a commit
to tiran/python-ldap
that referenced
this issue
Nov 6, 2023
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>
tiran
added a commit
to tiran/python-ldap
that referenced
this issue
Nov 7, 2023
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>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Isolated C extension module will give us two major benefits:
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.Required changes
PyTypeObject LDAP_Type
to heap type.PyTypeObject LDAP_Type
withPyType_Slot
andPyType_Spec
PyObject_GC_New
and free it withPyObject_GC_UnTrack
/PyObject_GC_Del
PyType_FromSpec
_ldap
C extension module with multi-phase initializationfunctions.c
andldapcontrol.c
. This also gets rid ofLDAPadd_methods
hack,LDAPinit_functions
, andLDAPinit_control
PyModuleDef_Slot
to init type, constants, and pkginfoPyModuleDef
global staticPyModuleDef_Init
LDAP_Type
,LDAPexception_class
, anderrobjects
in favor of module state struct.LDAPModState
and add it toPyModuleDef
LDAPObject
.PyType_GetModuleState()
is not available in Python < 3.9 and became part of the stable ABI in 3.10.LDAPerror
.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._ldap
extension module with limited API and stable ABI parameters.The text was updated successfully, but these errors were encountered: