gh-148464: Add missing __ctype_le/be__ attributes for complex types in the ctype module#148485
gh-148464: Add missing __ctype_le/be__ attributes for complex types in the ctype module#148485skirpichev wants to merge 2 commits intopython:mainfrom
__ctype_le/be__ attributes for complex types in the ctype module#148485Conversation
…ex types in the ctype module
226aaab to
1e45180
Compare
| stginfo->ffi_type_pointer.size = fmt->pffi_type->size; | ||
| stginfo->ffi_type_pointer.alignment = fmt->pffi_type->alignment; | ||
| stginfo->ffi_type_pointer.type = fmt->pffi_type->type; | ||
| stginfo->ffi_type_pointer.elements = PyMem_Malloc(els_size); |
There was a problem hiding this comment.
According to https://www.chiark.greenend.org.uk/doc/libffi-dev/html/Structures.html the elements should be a NULL terminated list of pointers. With this allocation we are missing the NULL. According to Claude this is no problem for the current implementation, but it is a breach of contract and a latent bug.
There was a problem hiding this comment.
This is for primitive types (section above), not for structures.
There was a problem hiding this comment.
Could you put the duplicated code in a helper function, like fill_stginfo_from_pffi_type?
| stginfo->ffi_type_pointer.size = fmt->pffi_type->size; | ||
| stginfo->ffi_type_pointer.alignment = fmt->pffi_type->alignment; | ||
| stginfo->ffi_type_pointer.type = fmt->pffi_type->type; | ||
| stginfo->ffi_type_pointer.elements = PyMem_Malloc(els_size); |
There was a problem hiding this comment.
Could you put the duplicated code in a helper function, like fill_stginfo_from_pffi_type?
| D_get_sw(void *ptr, Py_ssize_t size) | ||
| { | ||
| assert(NUM_BITS(size) || (size == 2*sizeof(double))); | ||
| return PyComplex_FromDoubles(PyFloat_Unpack8(ptr, PY_BIG_ENDIAN), |
There was a problem hiding this comment.
Could you add error handling for the unpacks here and PyFloat_Unpack4 below?
if (x == -1.0 && PyErr_Occurred()) {
I'd be happier if ctypes didn't rely on an undocumented implementation detail here.
__ctype_{be,le}__attributes missing forctypes.c_*_complextypes #148464