Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
I am trying my hand at creating a custom dtype from within Python's C API. After trying and failing for a bit to get the dtype working I narrowed down the problem to when I call PyArray_RegisterDataType. After calling the function Python crashes. I tried following an example from within the Numpy library (rational_tests.c https://github.com/numpy/numpy/blob/410a89ef04a2d3c50dd2dba2ad403c872c3745ac/numpy/core/src/umath/_rational_tests.c.src) to see if I could narrow down what was causing the program to crash. However, it seems if I copy and paste the example up to where rational is added via PyArray_RegisterDataType, PyArray_RegisterDataType continues to crash. I took a look at the source code for PyArray_RegisterDataType to see if I could narrow down what is causing the crash. If I setup the PyArray_Descr with incorrect information I do receive error messages informing me of the ill-formed descriptor (i.e. if I set the elsize to 0, etc.). The farthest I could get into the function before crashing, as far as I can tell, was the call to dtypemeta_wrap_legacy_descriptor(). Is there anything obvious I might be missing (maybe something along the lines of forgetting to call import_array())? The code also spans several files, but I have correctly added the necessary defines for the PyArray_API value to be set properly.