Lisandro Dalcin wrote:
>Looks fine, but I think you should follow the i/I rules. Any other opinion?

I hesitated to speculate why it might have been capital Z in the first
place.  Someone might have been thinking of using lowercase z for the
unsigned version Py_size_t, but that isn't in use anywhere [ or else the
letter slot would be used :) ].  Given that there is more of an existing
indirection case convention, I agree that seems clearer.

There are also a couple (more implicit) Signature uses in Builtin.py
as well as TypeSlots.py.

So, if you prefer (as I and Lisandro do) the z/Z scalar/pointer version
of all this, I've gone ahead and attached that version of this fix as
well, in hg export format this time.  This is more invasive and harder
to guarantee to be non-impacting of other code.  There are no other uses
of Signature() objects that I can find besides Bultin and Typeslots,
though, at least by searching for '\<Signature\>('.

This one also deletes getreadbufferproc and the other get*buffer*
Signature variables as they are no longer relevant.  (The C signatures
are all the same with the Cython compatibility typedef making them
actually different.  So, the upstream Python typename shufflng around
with gets coming and going no longer matters).

I also tested this version against 2.4, 2.5, 2.6, and 3.1.
# HG changeset patch
# User cb
# Date 1276099380 14400
# Node ID 425f43eeb32a15e2904b6f33284618f1b8dee931
# Parent  fe6066e3be002cb8523ef3b356730115b03fa240
Fix Py_ssize_t/Py_ssize_t* issues in buffer API signatures by renaming
format_map['Z'] => format_map['z'] to make room for a new Z=>Py_ssize_t*.
Also update existing uses of Z in TypeSlots.py and Builtin.py and delete
no longer needed "get"-prefixed versions of readbufferproc & friends.

diff -r fe6066e3be00 -r 425f43eeb32a Cython/Compiler/Builtin.py
--- a/Cython/Compiler/Builtin.py        Wed Jun 09 11:15:22 2010 -0400
+++ b/Cython/Compiler/Builtin.py        Wed Jun 09 12:03:00 2010 -0400
@@ -32,7 +32,7 @@
     ('isinstance', "OO",   "b",     "PyObject_IsInstance"),
     ('issubclass', "OO",   "b",     "PyObject_IsSubclass"),
     #('iter',       "O",    "O",     "PyObject_GetIter"),   # optimised later 
on
-    ('len',        "O",    "Z",     "PyObject_Length"),
+    ('len',        "O",    "z",     "PyObject_Length"),
     ('locals',     "",     "O",     "__pyx_locals"),
     #('map',       "",     "",      ""),
     #('max',       "",     "",      ""),
@@ -103,7 +103,7 @@
 
     ("tuple",   "PyTuple_Type",    []),
 
-    ("list",    "PyList_Type",     [("insert", "OZO",  "i", "PyList_Insert")]),
+    ("list",    "PyList_Type",     [("insert", "OzO",  "i", "PyList_Insert")]),
 
     ("dict",    "PyDict_Type",     [("items", "O",   "O", "PyDict_Items"),
                                     ("keys",  "O",   "O", "PyDict_Keys"),
diff -r fe6066e3be00 -r 425f43eeb32a Cython/Compiler/TypeSlots.py
--- a/Cython/Compiler/TypeSlots.py      Wed Jun 09 11:15:22 2010 -0400
+++ b/Cython/Compiler/TypeSlots.py      Wed Jun 09 12:03:00 2010 -0400
@@ -29,7 +29,8 @@
     #    'b'  bint
     #    'I'  int *
     #    'l'  long
-    #    'Z'  Py_ssize_t
+    #    'z'  Py_ssize_t
+    #    'Z'  Py_ssize_t *
     #    's'  char *
     #    'S'  char **
     #    'r'  int used only to signal exception
@@ -48,7 +49,8 @@
         'b': PyrexTypes.c_bint_type,
         'I': PyrexTypes.c_int_ptr_type,
         'l': PyrexTypes.c_long_type,
-        'Z': PyrexTypes.c_py_ssize_t_type,
+        'z': PyrexTypes.c_py_ssize_t_type,
+        'Z': PyrexTypes.c_py_ssize_t_ptr_type,
         's': PyrexTypes.c_char_ptr_type,
         'S': PyrexTypes.c_char_ptr_ptr_type,
         'r': PyrexTypes.c_returncode_type,
@@ -63,7 +65,7 @@
         'b': "-1",
         'l': "-1",
         'r': "-1",
-        'Z': "-1",
+        'z': "-1",
     }
     
     def __init__(self, arg_format, ret_format):
@@ -484,30 +486,26 @@
 iternaryfunc = Signature("TOO", "O")       # typedef PyObject * 
(*ternaryfunc)(PyObject *, PyObject *, PyObject *);
 callfunc = Signature("T*", "O")            # typedef PyObject * 
(*ternaryfunc)(PyObject *, PyObject *, PyObject *);
 inquiry = Signature("T", "i")              # typedef int (*inquiry)(PyObject 
*);
-lenfunc = Signature("T", "Z")              # typedef Py_ssize_t 
(*lenfunc)(PyObject *);
+lenfunc = Signature("T", "z")              # typedef Py_ssize_t 
(*lenfunc)(PyObject *);
 
                                            # typedef int (*coercion)(PyObject 
**, PyObject **);
 intargfunc = Signature("Ti", "O")          # typedef PyObject 
*(*intargfunc)(PyObject *, int);
-ssizeargfunc = Signature("TZ", "O")        # typedef PyObject 
*(*ssizeargfunc)(PyObject *, Py_ssize_t);
+ssizeargfunc = Signature("Tz", "O")        # typedef PyObject 
*(*ssizeargfunc)(PyObject *, Py_ssize_t);
 intintargfunc = Signature("Tii", "O")      # typedef PyObject 
*(*intintargfunc)(PyObject *, int, int);
-ssizessizeargfunc = Signature("TZZ", "O")  # typedef PyObject 
*(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);
+ssizessizeargfunc = Signature("Tzz", "O")  # typedef PyObject 
*(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);
 intobjargproc = Signature("TiO", 'r')      # typedef 
int(*intobjargproc)(PyObject *, int, PyObject *);
-ssizeobjargproc = Signature("TZO", 'r')    # typedef 
int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);
+ssizeobjargproc = Signature("TzO", 'r')    # typedef 
int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);
 intintobjargproc = Signature("TiiO", 'r')  # typedef 
int(*intintobjargproc)(PyObject *, int, int, PyObject *);
-ssizessizeobjargproc = Signature("TZZO", 'r') # typedef 
int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
+ssizessizeobjargproc = Signature("TzzO", 'r') # typedef 
int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
 
 intintargproc = Signature("Tii", 'r')
-ssizessizeargproc = Signature("TZZ", 'r')
+ssizessizeargproc = Signature("Tzz", 'r')
 objargfunc = Signature("TO", "O")
 objobjargproc = Signature("TOO", 'r')      # typedef int 
(*objobjargproc)(PyObject *, PyObject *, PyObject *);
-getreadbufferproc = Signature("TiP", 'i')  # typedef int 
(*getreadbufferproc)(PyObject *, int, void **);
-getwritebufferproc = Signature("TiP", 'i') # typedef int 
(*getwritebufferproc)(PyObject *, int, void **);
-getsegcountproc = Signature("TI", 'i')     # typedef int 
(*getsegcountproc)(PyObject *, int *);
-getcharbufferproc = Signature("TiS", 'i')  # typedef int 
(*getcharbufferproc)(PyObject *, int, const char **);
-readbufferproc = Signature("TZP", "Z")     # typedef Py_ssize_t 
(*readbufferproc)(PyObject *, Py_ssize_t, void **);
-writebufferproc = Signature("TZP", "Z")    # typedef Py_ssize_t 
(*writebufferproc)(PyObject *, Py_ssize_t, void **);
-segcountproc = Signature("TZ", "Z")        # typedef Py_ssize_t 
(*segcountproc)(PyObject *, Py_ssize_t *);
-charbufferproc = Signature("TZS", "Z")     # typedef Py_ssize_t 
(*charbufferproc)(PyObject *, Py_ssize_t, char **);
+readbufferproc = Signature("TzP", "z")     # typedef Py_ssize_t 
(*readbufferproc)(PyObject *, Py_ssize_t, void **);
+writebufferproc = Signature("TzP", "z")    # typedef Py_ssize_t 
(*writebufferproc)(PyObject *, Py_ssize_t, void **);
+segcountproc = Signature("TZ", "z")        # typedef Py_ssize_t 
(*segcountproc)(PyObject *, Py_ssize_t *);
+charbufferproc = Signature("TzS", "z")     # typedef Py_ssize_t 
(*charbufferproc)(PyObject *, Py_ssize_t, char **);
 objargproc = Signature("TO", 'r')          # typedef int 
(*objobjproc)(PyObject *, PyObject *);
                                            # typedef int (*visitproc)(PyObject 
*, void *);
                                            # typedef int 
(*traverseproc)(PyObject *, visitproc, void *);
@@ -625,10 +623,10 @@
 )
 
 PyBufferProcs = (
-    MethodSlot(getreadbufferproc, "bf_getreadbuffer", "__getreadbuffer__", py3 
= False),
-    MethodSlot(getwritebufferproc, "bf_getwritebuffer", "__getwritebuffer__", 
py3 = False),
-    MethodSlot(getsegcountproc, "bf_getsegcount", "__getsegcount__", py3 = 
False),
-    MethodSlot(getcharbufferproc, "bf_getcharbuffer", "__getcharbuffer__", py3 
= False),
+    MethodSlot(readbufferproc, "bf_getreadbuffer", "__getreadbuffer__", py3 = 
False),
+    MethodSlot(writebufferproc, "bf_getwritebuffer", "__getwritebuffer__", py3 
= False),
+    MethodSlot(segcountproc, "bf_getsegcount", "__getsegcount__", py3 = False),
+    MethodSlot(charbufferproc, "bf_getcharbuffer", "__getcharbuffer__", py3 = 
False),
 
     MethodSlot(getbufferproc, "bf_getbuffer", "__getbuffer__", ifdef = 
"PY_VERSION_HEX >= 0x02060000"),
     MethodSlot(releasebufferproc, "bf_releasebuffer", "__releasebuffer__", 
ifdef = "PY_VERSION_HEX >= 0x02060000")
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to