From Python 3.11 upwards you can use `Py_Version` (https://docs.python.org/3/c-api/apiabiversion.html#c.Py_Version) for fast C API access to the runtime version instead of `sys.version_info`.
In terms of `PY_VERSION_HEX` and the runtime version - the only question is "are you trying to use the stable ABI"? (If you haven't deliberately chosen to use the Stable ABI then you aren't using it!)
* if not, then the first 4 bytes of PY_VERSION_HEX will always
match the first two elements of sys.version_info so this should be
fine. The compiled module will simply not work otherwise.
* if you are using the stable ABI then you really need to be doing
runtime checks only. I don't think you are though given that
you're looking at internal C arrays (according to your PR).
David
Nils --
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/cython-users/a45a67f2-a1fa-45b5-9e82-8c5f3da68598n%40googlegroups.com.
Extensions built on different minor versions of Python are not compatible. So an extension built on Python 3.13 won't run on 3.14, and vice versa.
Extensions built on different micro versions are compatible (so 3.13.1 is compatible with 3.13.3, either way around).
This is mostly enforced by the name of the compiled extensions (e.g. "cpython-313-x86_64-linux-gnu" in the filename tells Python whether it's suitable) or the name of the wheel bundling the extension. So it's possible to trick Python by renaming things (in which case it either crash or fail to import for linking reasons). But normal users won't get the versions mixed up. And if they do, it's already broken - your changes aren't making it worse.
I don't think Cython adds any specific version checks because it would be very hard to write a "safe" check that actually works.
To view this discussion visit https://groups.google.com/d/msgid/cython-users/cfd328c2-8537-471a-a264-838c106780e1n%40googlegroups.com.
And if they do, it's already broken - your changes aren't making it worse.
If you deliberately compile with the Stable ABI then you can get a single extension that's compatible across a wide range of Python versions. For example, we can build Cython so a single wheel works from Python 3.9 upwards.
There are lots of restrictions - your access into the internal atexit structures just wouldn't work for example.
But it's definitely worthwhile in some cases.
But it's not something that happens accidentally so don't worry about it in the PR you linked.
--
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/cython-users/a91f7647-1f33-4ddd-806d-6d6119f57b59n%40googlegroups.com.
// Dummy function for Python < 3.14 (never called)
static PyObject* get_atexit_callbacks_list(PyObject *self) {
PyErr_SetString(PyExc_RuntimeError, "Python < 3.14 has no atexit list");
return NULL;
}Thank you for your answer. I would like to know if I runs this accidently,it will safely raise an error on Python level or go into segfault.
... and of course sagemath controls their own build process. So are in a
position to unilaterally make it the same time if it isn't already.