Special handling of Py_ssize_t and size_t in the parser (related to #207)
authorLisandro Dalcin <dalcinl@gmail.com>
Fri, 20 Feb 2009 14:35:57 +0000 (12:35 -0200)
committerLisandro Dalcin <dalcinl@gmail.com>
Fri, 20 Feb 2009 14:35:57 +0000 (12:35 -0200)
Cython/Compiler/Parsing.py
Cython/Compiler/PyrexTypes.py
tests/errors/e_nosignword.pyx
tests/run/size_t.pyx

index ec492d61c7de598d70df44c25e2f714269acde87..65cd6ca2c41893a8fdd46a0de64428bf7adf4a78 100644 (file)
@@ -1688,12 +1688,17 @@ def p_c_simple_base_type(s, self_flag, nonempty):
     if looking_at_base_type(s):
         #print "p_c_simple_base_type: looking_at_base_type at", s.position()
         is_basic = 1
-        signed, longness = p_sign_and_longness(s)
-        if s.sy == 'IDENT' and s.systring in basic_c_type_names:
+        if s.sy == 'IDENT' and s.systring in special_basic_c_types:
+            signed, longness = special_basic_c_types[s.systring]
             name = s.systring
             s.next()
         else:
-            name = 'int'
+            signed, longness = p_sign_and_longness(s)
+            if s.sy == 'IDENT' and s.systring in basic_c_type_names:
+                name = s.systring
+                s.next()
+            else:
+                name = 'int'
     elif looking_at_dotted_name(s):
         #print "p_c_simple_base_type: looking_at_type_name at", s.position()
         name = s.systring
@@ -1811,12 +1816,18 @@ def looking_at_dotted_name(s):
     else:
         return 0
 
-basic_c_type_names = ("void", "char", "int", "float", "double", "Py_ssize_t", "size_t", "bint")
+basic_c_type_names = ("void", "char", "int", "float", "double", "bint")
+
+special_basic_c_types = {
+    # name : (signed, longness)
+    "Py_ssize_t" : (2, 0),
+    "size_t"     : (0, 0),
+}
 
 sign_and_longness_words = ("short", "long", "signed", "unsigned")
 
 base_type_start_words = \
-    basic_c_type_names + sign_and_longness_words
+    basic_c_type_names + sign_and_longness_words + tuple(special_basic_c_types)
 
 def p_sign_and_longness(s):
     signed = 1
index c118e15e2d11a5625c7332ac6d7c5434fc00047c..4df3b25ca62a46ee01dc81e146b64c471814daea 100644 (file)
@@ -1283,8 +1283,8 @@ modifiers_and_name_to_type = {
     (2, 1, "int"): c_slong_type,
     (2, 2, "int"): c_slonglong_type,
 
-    (1, 0, "Py_ssize_t"): c_py_ssize_t_type,
-    (1, 0, "size_t") : c_size_t_type,
+    (2, 0, "Py_ssize_t"): c_py_ssize_t_type,
+    (0, 0, "size_t") : c_size_t_type,
 
     (1, 0, "long"): c_long_type,
     (1, 0, "short"): c_short_type,
index 9a5c86d4cb1a1cc89742fb929706cbcd5d6ee599..1931f46759416b72eb2a60046c35e8bb5a14e8c2 100644 (file)
@@ -1,7 +1,3 @@
-cdef signed   Py_ssize_t  a
-cdef unsigned Py_ssize_t  b
-cdef signed   size_t      c
-cdef unsigned size_t      d
 cdef signed   float       e
 cdef unsigned float       f
 cdef signed   double      g
@@ -17,8 +13,4 @@ _ERRORS = u"""
 4:5: Unrecognised type modifier combination
 5:5: Unrecognised type modifier combination
 6:5: Unrecognised type modifier combination
-7:5: Unrecognised type modifier combination
-8:5: Unrecognised type modifier combination
-9:5: Unrecognised type modifier combination
-10:5: Unrecognised type modifier combination
 """
index 70324328d0612a79bb8c8a52be23b68771d1307d..0ef62b0250320da19a65fcb6bbd63775f8b81a98 100644 (file)
@@ -35,13 +35,17 @@ Traceback (most recent call last):
 OverflowError: ...
 """
 
+# XXX This should generate a warning !!!
+cdef extern from *:
+    ctypedef unsigned long size_t
+
 def test(size_t i):
     return i
 
 cdef class A:
     cdef public size_t a
     cdef readonly size_t b
-    
+
     def __init__(self, size_t a, object b):
         self.a = a
         self.b = b