Author: Antonio Cuni <[email protected]>
Branch: jitypes2
Changeset: r44664:99077fec302e
Date: 2011-06-03 16:07 +0200
http://bitbucket.org/pypy/pypy/changeset/99077fec302e/
Log: port test_ctypes to test_pypy_c_new; we don't test it in a very
precise way, because the trace is still too complicated
diff --git a/pypy/module/pypyjit/test/test_pypy_c.py
b/pypy/module/pypyjit/test/test_pypy_c.py
--- a/pypy/module/pypyjit/test/test_pypy_c.py
+++ b/pypy/module/pypyjit/test/test_pypy_c.py
@@ -971,51 +971,6 @@
_, compare = self.get_by_bytecode("COMPARE_OP")
assert "call" not in compare.get_opnames()
- def test_ctypes_call(self):
- from pypy.rlib.test.test_libffi import get_libm_name
- libm_name = get_libm_name(sys.platform)
- out = self.run_source('''
- def main():
- import ctypes
- libm = ctypes.CDLL('%(libm_name)s')
- fabs = libm.fabs
- fabs.argtypes = [ctypes.c_double]
- fabs.restype = ctypes.c_double
- x = -4
- for i in range(2000):
- x = fabs(x)
- x = x - 100
- print fabs._ptr.getaddr()
- return x
- ''' % locals(),
- 10000, ([], -4.0),
- threshold=1000,
- filter_loops=True)
- fabs_addr = int(out.splitlines()[0])
- assert len(self.loops) == 1
- loop = self.loops[0]
- #
- # this is the call "fabs(x)"
- call_functions = self.get_by_bytecode('CALL_FUNCTION_VAR', loop=loop)
- assert len(call_functions) == 2
- call_funcptr = call_functions[0] # this is the _call_funcptr inside
CFuncPtrFast.__call__
- assert 'code object __call__' in str(call_funcptr.debug_merge_point)
- assert call_funcptr.get_opnames() == ['force_token']
- #
- # this is the ffi call inside ctypes
- call_ffi = call_functions[1]
- ops = [op.getopname() for op in call_ffi]
- assert ops == ['force_token',
- 'setfield_gc', # vable_token
- 'call_may_force',
- 'guard_not_forced',
- 'guard_no_exception']
- call = call_ffi[-3]
- assert call.getarg(0).value == fabs_addr
- #
- # finally, check that we don't force anything
- for op in loop.operations:
- assert op.getopname() != 'new_with_vtable'
class AppTestJIT(PyPyCJITTests):
def setup_class(cls):
diff --git a/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
--- a/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
@@ -1646,6 +1646,35 @@
# we only force the virtualref, not its content
assert opnames.count('new_with_vtable') == 1
+ def test_ctypes_call(self):
+ from pypy.rlib.test.test_libffi import get_libm_name
+ def main(libm_name):
+ import ctypes
+ libm = ctypes.CDLL(libm_name)
+ fabs = libm.fabs
+ fabs.argtypes = [ctypes.c_double]
+ fabs.restype = ctypes.c_double
+ x = -4
+ i = 0
+ while i < 300:
+ x = fabs(x)
+ x = x - 100
+ i += 1
+ return fabs._ptr.getaddr(), x
+
+ libm_name = get_libm_name(sys.platform)
+ log = self.run(main, [libm_name], threshold=200)
+ fabs_addr, res = log.result
+ assert res == -4.0
+ loop, = log.loops_by_filename(self.filepath)
+ ops = loop.allops()
+ opnames = log.opnames(ops)
+ assert opnames.count('new_with_vtable') == 1 # only the virtualref
+ assert opnames.count('call_release_gil') == 1
+ idx = opnames.index('call_release_gil')
+ call = ops[idx]
+ assert int(call.args[0]) == fabs_addr
+
def test_xor(self):
def main(b):
a = sa = 0
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit