Add Limited API macros into api/public headers
This is mainly just preparation for sorting out pymutex in public headers (since I think we'll want to use the Limited API macros to support it).
However - it also simplifies the import and export code slightly and is one less thing to remember to do differently in this header code.
Added a test since it seemed pretty untested.
We are only adding Cython specific macros to the public header files here, and including them from Cython modules will just let them do the same thing that those modules would do already.
I think this should be ok, but it ties us to the current definitions for all future. We should probably add a warning to InitLimitedAPI that this section must remain strictly minimal and that any modifications may not be reflected in existing header files that the user module might be including (and might be including at a later point in the module, where the module internal definitions already had an effect).
But I think we should guard the whole section against redefinition when included in Cython modules, as we do for the import code.
it ties us to the current definitions for all future.
True.
I did consider adding the $cyversion suffix to the things defined in the header (like we do for the import functions). But that's another think we'd need to remember to use.
I wonder if this change is worthwhile right now? Maybe we should keep using the explicit defined(Py_LIMITED_API) && Py_LIMITED_API > ... for now, and only do this when we have a real problem.
I'd still like to include the test though - the api stuff if really untested as far as I can tell.
I think we should guard the whole section against redefinition when included in Cython modules
Thinking about this a bit more, adding a new macro guard isn't safe either because it would only apply to newly generated Cython modules. C code generated by older Cythons will not set the guard and may end up with duplicate and potentially conflicting definitions when including newer header files that expect it.
I think we need to prevent redefinitions of __PYX_LIMITED_VERSION_HEX, at the very least.
Sorry, I lost this from sight for 3.2. I think the PyMutex fixes are important, and this probably is as well.
I think the PyMutex changes don't depend on this any more, so it might be better to pick the PyMutex changes and treat this as a post-3.2 cleanup.
I remember being a bit unsure if these macros would help or conflict between headers, so probably no need to do it now.