[pypy-svn] r79291 - in pypy/branch/reflex-support/pypy/module/cppyy: . test
wlav at codespeak.net
wlav at codespeak.net
Fri Nov 19 22:11:24 CET 2010
Author: wlav
Date: Fri Nov 19 22:11:17 2010
New Revision: 79291
Modified:
pypy/branch/reflex-support/pypy/module/cppyy/converter.py
pypy/branch/reflex-support/pypy/module/cppyy/helper.py
pypy/branch/reflex-support/pypy/module/cppyy/test/test_helper.py
Log:
reduce number of possible call points in get_converter
Modified: pypy/branch/reflex-support/pypy/module/cppyy/converter.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/converter.py (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/converter.py Fri Nov 19 22:11:17 2010
@@ -19,7 +19,7 @@
class TypeConverter(object):
- def __init__(self, space, extra=-1):
+ def __init__(self, space, array_size):
pass
def _get_fieldptr(self, space, w_obj, offset):
@@ -43,6 +43,14 @@
lltype.free(arg, flavor='raw')
+class ArrayTypeConverter(TypeConverter):
+ def __init__(self, space, array_size):
+ if array_size <= 0:
+ self.size = sys.maxint
+ else:
+ self.size = array_size
+
+
class VoidConverter(TypeConverter):
def __init__(self, space, name):
self.name = name
@@ -178,11 +186,8 @@
return rffi.cast(rffi.VOIDP, x)
-class ShortPtrConverter(TypeConverter):
+class ShortPtrConverter(ArrayTypeConverter):
_immutable_ = True
- def __init__(self, space, detail=sys.maxint):
- self.size = detail
-
def convert_argument(self, space, w_obj):
assert 0, "not yet implemented"
@@ -209,11 +214,8 @@
for i in range(min(self.size*2, buf.getlength())):
fieldptr[i] = buf.getitem(i)
-class LongPtrConverter(TypeConverter):
+class LongPtrConverter(ArrayTypeConverter):
_immutable_ = True
- def __init__(self, space, detail=sys.maxint):
- self.size = detail
-
def convert_argument(self, space, w_obj):
assert 0, "not yet implemented"
@@ -276,7 +278,7 @@
# 1) full, exact match
try:
- return _converters[name](space)
+ return _converters[name](space, -1)
except KeyError, k:
pass
@@ -284,17 +286,20 @@
compound = helper.compound(name)
clean_name = helper.clean_type(name)
try:
- array_index = helper.array_index(name)
- if array_index:
- return _converters[clean_name+compound](space, array_index)
- return _converters[clean_name+compound](space)
+ # array_index may be negative to indicate no size or no size found
+ array_size = helper.array_size(name)
+ return _converters[clean_name+compound](space, array_size)
except KeyError, k:
pass
-
+
+ # 5) generalized cases (covers basically all user classes)
cpptype = interp_cppyy.type_byname(space, clean_name)
if compound == "*":
return InstancePtrConverter(space, cpptype)
+
+ # 6) void converter, which fails on use
+ #
# return a void converter here, so that the class can be build even
# when some types are unknown; this overload will simply fail on use
return VoidConverter(space, name)
Modified: pypy/branch/reflex-support/pypy/module/cppyy/helper.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/helper.py (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/helper.py Fri Nov 19 22:11:17 2010
@@ -7,7 +7,7 @@
i = _find_qualifier_index(name)
return "".join(name[i:].split(" "))
-def array_index(name):
+def array_size(name):
name = "".join(rstring.split(name, "const")) # poor man's replace
if name[-1] == "]": # array type
i = _find_qualifier_index(name)
@@ -15,7 +15,7 @@
c = name[i]
if c == "[":
return int(name[i+1:-1])
- return 0
+ return -1
def _find_qualifier_index(name):
i = len(name)
Modified: pypy/branch/reflex-support/pypy/module/cppyy/test/test_helper.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/test/test_helper.py (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/test/test_helper.py Fri Nov 19 22:11:17 2010
@@ -5,7 +5,7 @@
assert helper.compound("int* const *&") == "**&"
assert helper.compound("std::vector<int>*") == "*"
assert helper.compound("unsigned long int[5]") == "[]"
- assert helper.array_index("unsigned long int[5]") == 5
+ assert helper.array_size("unsigned long int[5]") == 5
def test_clean_type():
More information about the Pypy-commit
mailing list