[Numpy-discussion] Detecting C API mismatch (was Managing Python with NumPy and many external libraries on multiple Windows machines)

David Cournapeau cournape@gmail....
Sun May 10 00:45:54 CDT 2009


Hi,

I worked on some code to detect C API mismatches both for developers
and for users:

http://github.com/cournape/numpy/tree/runtime_feature

It adds the following:
 - if a numpy or ufunc function is added in the C API without the
NPY_FEATURE_VERSION to be updated, a warning is generated at built
time (the warning is turned into an exception for release)
 - I added a function PyArray_GetNDArrayCFeatureVersion which returns
the C API version, and the version is checked in import_array. If the
compile-time version > import-time version, an import error is raised,
so the following happens (assuming the ABI is not changed).

So we keep backward compatibility (building an extension with say
numpy 1.2.1 will still work after installing numpy 1.3), and forward
incompatibility is detected (building an extension with numpy 1.3.0
and importing it with installed numpy 1.2.1 will fail).

Ironically, adding the function means that we have to add one function
to the C API, so this will not be useful for numpy < 1.4, but I don't
think it is possible to do it without modifying the C API.

cheers,

David


More information about the Numpy-discussion mailing list