Lisandro Dalcin, 16.04.2010 05:58:
> Stefan, I would like to push a patch that starts like below... As time
> passes and all us get more and more used to Py3 API, it is very easy
> to forget compatibility with Py<2.6 ... For ejample, one of your
> previous commits broke the testsuite because you used
> PyBytes_GET_SIZE...

Right. I set up test jobs on Hudson for Py2.4 and Py2.5 now. I initially 
wanted to safe processing time, but it looks like we need those, too.


> As the PyBytes_XXX API's are official in Py3 and
> moreover Py2.6 provides the compatibility definitions to PyString_XXX,
> I think we should just exten the PyBytes ->  PyString defs to Py<=2.5
>
> What do you think?
>
>
> diff -r fe69c27824be Cython/Compiler/ModuleNode.py
> --- a/Cython/Compiler/ModuleNode.py   Thu Apr 15 23:18:28 2010 +0200
> +++ b/Cython/Compiler/ModuleNode.py   Fri Apr 16 00:51:19 2010 -0300
> @@ -522,11 +522,19 @@
>
>   #if PY_MAJOR_VERSION>= 3
>     #define PyBaseString_Type            PyUnicode_Type
> +  #define PyStringObject               PyUnicodeObject
>     #define PyString_Type                PyUnicode_Type
> +  #define PyString_Check               PyUnicode_Check
>     #define PyString_CheckExact          PyUnicode_CheckExact
> -#else
> +#elif PY_VERSION_HEX<  0x02060000
> +  #define PyBytesObject                PyStringObject
>     #define PyBytes_Type                 PyString_Type
> +  #define PyBytes_Check                PyString_Check
>     #define PyBytes_CheckExact           PyString_CheckExact
> +  #define PyBytes_FromString           PyString_FromString
> +  #define PyBytes_FromStringAndSize    PyString_FromStringAndSize
> +  #define PyBytes_AsString             PyString_AsString
> +  #define PyBytes_GET_SIZE             PyString_GET_SIZE
>   #endif

We should be aware that any defines that we use at the global level can 
interfere with user code, e.g. if the user (or an imported header file) 
decides to define PyString_Check as a check for plain bytes. The patch 
above shows that we already redefine PyString_CheckExact, so we should 
either switch to defining PyString_Check alike or to replacing everything 
with __Pyx_PyString*.

I think the reason why we need the Py3 defines above in the first place is 
that Cython can end up generating those names for the 'str' type, right? 
Maybe there are other places where we can fix this, so that we do not need 
to define PyString_* at all. If we could use __Pyx_PyString_* in all places 
where we need Cython's 'str' semantics, we could remove all PyString 
definitions above. Similarly, PyBaseString_Type would become 
__Pyx_PyBaseString_Type.

Regarding the last part, I'm all for #defining the PyBytes_* API in Py<=2.5 
and using those names wherever we refer to the bytes type. They are the 
safe path.

Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to