Commit dbd89db6 authored by Lisandro Dalcin's avatar Lisandro Dalcin

Special handling of Py_ssize_t and size_t in the parser (related to #207)

parent b33174e7
...@@ -1688,6 +1688,11 @@ def p_c_simple_base_type(s, self_flag, nonempty): ...@@ -1688,6 +1688,11 @@ def p_c_simple_base_type(s, self_flag, nonempty):
if looking_at_base_type(s): if looking_at_base_type(s):
#print "p_c_simple_base_type: looking_at_base_type at", s.position() #print "p_c_simple_base_type: looking_at_base_type at", s.position()
is_basic = 1 is_basic = 1
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:
signed, longness = p_sign_and_longness(s) 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 basic_c_type_names:
name = s.systring name = s.systring
...@@ -1811,12 +1816,18 @@ def looking_at_dotted_name(s): ...@@ -1811,12 +1816,18 @@ def looking_at_dotted_name(s):
else: else:
return 0 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") sign_and_longness_words = ("short", "long", "signed", "unsigned")
base_type_start_words = \ 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): def p_sign_and_longness(s):
signed = 1 signed = 1
......
...@@ -1283,8 +1283,8 @@ modifiers_and_name_to_type = { ...@@ -1283,8 +1283,8 @@ modifiers_and_name_to_type = {
(2, 1, "int"): c_slong_type, (2, 1, "int"): c_slong_type,
(2, 2, "int"): c_slonglong_type, (2, 2, "int"): c_slonglong_type,
(1, 0, "Py_ssize_t"): c_py_ssize_t_type, (2, 0, "Py_ssize_t"): c_py_ssize_t_type,
(1, 0, "size_t") : c_size_t_type, (0, 0, "size_t") : c_size_t_type,
(1, 0, "long"): c_long_type, (1, 0, "long"): c_long_type,
(1, 0, "short"): c_short_type, (1, 0, "short"): c_short_type,
......
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 signed float e
cdef unsigned float f cdef unsigned float f
cdef signed double g cdef signed double g
...@@ -17,8 +13,4 @@ _ERRORS = u""" ...@@ -17,8 +13,4 @@ _ERRORS = u"""
4:5: Unrecognised type modifier combination 4:5: Unrecognised type modifier combination
5:5: Unrecognised type modifier combination 5:5: Unrecognised type modifier combination
6: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
""" """
...@@ -35,6 +35,10 @@ Traceback (most recent call last): ...@@ -35,6 +35,10 @@ Traceback (most recent call last):
OverflowError: ... OverflowError: ...
""" """
# XXX This should generate a warning !!!
cdef extern from *:
ctypedef unsigned long size_t
def test(size_t i): def test(size_t i):
return i return i
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment