[pypy-svn] r75896 - in pypy/branch/reflex-support/pypy/module/cppyy: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Jul 6 12:50:13 CEST 2010
Author: cfbolz
Date: Tue Jul 6 12:50:11 2010
New Revision: 75896
Modified:
pypy/branch/reflex-support/pypy/module/cppyy/interp_cppyy.py
pypy/branch/reflex-support/pypy/module/cppyy/test/example01.cxx
pypy/branch/reflex-support/pypy/module/cppyy/test/test_cppyy.py
Log:
(antocuni, wlav, cfbolz, arigo around): fix memory leak. test overloading by
number of arguments.
Modified: pypy/branch/reflex-support/pypy/module/cppyy/interp_cppyy.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/interp_cppyy.py (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/interp_cppyy.py Tue Jul 6 12:50:11 2010
@@ -91,11 +91,18 @@
if len(args_w) != len(argtypes):
raise OperationError(space.w_TypeError, space.wrap("wrong number of args"))
args = lltype.malloc(rffi.CArray(rffi.VOIDP), len(args_w), flavor='raw')
- for i in range(len(args_w)):
- argtype = argtypes[i]
- conv = converter.get_converter(argtype)
- # XXX this can leak so far
- args[i] = conv.convert_argument(space, args_w[i])
+ try:
+ i = 0 # appease RPython: i is used below
+ for i in range(len(args_w)):
+ argtype = argtypes[i]
+ conv = converter.get_converter(argtype)
+ args[i] = conv.convert_argument(space, args_w[i])
+ except:
+ # fun :-(
+ for j in range(i):
+ lltype.free(args[j])
+ lltype.free(args, flavor='raw')
+ raise
return args
def free_arguments(args, numargs):
@@ -178,6 +185,8 @@
except OperationError, e:
if not e.match(space, space.w_TypeError):
raise
+ except KeyError:
+ pass
# XXX better error reporting
raise OperationError(space.w_TypeError, space.wrap("none of the overloads matched"))
Modified: pypy/branch/reflex-support/pypy/module/cppyy/test/example01.cxx
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/test/example01.cxx (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/test/example01.cxx Tue Jul 6 12:50:11 2010
@@ -29,6 +29,9 @@
static int add1(int a) {
return a + 1;
}
+ static int add1(int a, int b) {
+ return a + b + 1;
+ }
static double adddouble(double a) {
return a + 0.01;
}
Modified: pypy/branch/reflex-support/pypy/module/cppyy/test/test_cppyy.py
==============================================================================
--- pypy/branch/reflex-support/pypy/module/cppyy/test/test_cppyy.py (original)
+++ pypy/branch/reflex-support/pypy/module/cppyy/test/test_cppyy.py Tue Jul 6 12:50:11 2010
@@ -8,6 +8,9 @@
space = gettestobjspace(usemodules=['cppyy'])
+def setup_module(mod):
+ os.system("make")
+
class TestCPPYYImplementation:
def test_class_query(self):
lib = interp_cppyy.load_lib(space, shared_lib)
@@ -28,8 +31,11 @@
def test_example01static(self):
t = self.example01.type_byname("example01")
+ # also tests overloading by number of args
res = t.invoke("add1", 1)
assert res == 2
+ res = t.invoke("add1", 1, 2)
+ assert res == 4
def test_example01static_double(self):
t = self.example01.type_byname("example01")
More information about the Pypy-commit
mailing list