[pypy-svn] r25938 - in pypy/dist/pypy/rpython: . rctypes rctypes/test
arigo at codespeak.net
arigo at codespeak.net
Tue Apr 18 12:30:40 CEST 2006
Author: arigo
Date: Tue Apr 18 12:30:38 2006
New Revision: 25938
Modified:
pypy/dist/pypy/rpython/rbuiltin.py
pypy/dist/pypy/rpython/rctypes/rpointer.py
pypy/dist/pypy/rpython/rctypes/test/test_overhead.py
pypy/dist/pypy/rpython/rctypes/test/test_rpointer.py
Log:
More passing minimal-overhead tests. Avoid generating dummy
operations to add a zero offset.
Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/rbuiltin.py Tue Apr 18 12:30:38 2006
@@ -327,16 +327,21 @@
c_ofs1 = inputconst(lltype.Signed, llmemory.ArrayItemsOffset(SRCTYPE))
v_array_items_adr = llops.genop('adr_add', [v_array_adr, c_ofs1],
resulttype = llmemory.Address)
- c_ofs2 = inputconst(lltype.Signed, llmemory.ItemOffset(SRCTYPE.OF))
- v_ofs3 = llops.genop('int_mul', [c_ofs2, v_baseoffset],
- resulttype = lltype.Signed)
- v_base_adr = llops.genop('adr_add', [v_array_items_adr, v_ofs3],
- resulttype = llmemory.Address)
+ if isinstance(v_baseoffset, Constant) and v_baseoffset.value == 0:
+ v_base_adr = v_array_items_adr
+ else:
+ c_ofs2 = inputconst(lltype.Signed, llmemory.ItemOffset(SRCTYPE.OF))
+ v_ofs3 = llops.genop('int_mul', [c_ofs2, v_baseoffset],
+ resulttype = lltype.Signed)
+ v_base_adr = llops.genop('adr_add', [v_array_items_adr, v_ofs3],
+ resulttype = llmemory.Address)
return llops.genop('cast_adr_to_ptr', [v_base_adr],
resulttype = ARRAYPTRTYPE)
def gen_add_itemoffset_to_pointer(llops, ITEMTYPE, v_ptr, v_index):
"Generates address manipulations equivalent to the C expression ptr+index."
+ if isinstance(v_index, Constant) and v_index.value == 0:
+ return v_ptr
from pypy.rpython.lltypesystem import llmemory
v_adr = llops.genop('cast_ptr_to_adr', [v_ptr],
resulttype = llmemory.Address)
Modified: pypy/dist/pypy/rpython/rctypes/rpointer.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/rpointer.py (original)
+++ pypy/dist/pypy/rpython/rctypes/rpointer.py Tue Apr 18 12:30:38 2006
@@ -66,12 +66,9 @@
self = r_ptr
v_ptr, v_index = hop.inputargs(self, lltype.Signed)
v_c_ptr = self.getvalue(hop.llops, v_ptr)
- if hop.args_s[1].is_constant() and hop.args_s[1].const == 0:
- pass # skip adding the offset
- else:
- v_c_ptr = gen_add_itemoffset_to_pointer(hop.llops,
- r_ptr.r_contents.ll_type,
- v_c_ptr, v_index)
+ v_c_ptr = gen_add_itemoffset_to_pointer(hop.llops,
+ r_ptr.r_contents.ll_type,
+ v_c_ptr, v_index)
return self.r_contents.return_c_data(hop.llops, v_c_ptr)
def rtype_setitem((r_ptr, _), hop):
Modified: pypy/dist/pypy/rpython/rctypes/test/test_overhead.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/test_overhead.py (original)
+++ pypy/dist/pypy/rpython/rctypes/test/test_overhead.py Tue Apr 18 12:30:38 2006
@@ -37,3 +37,19 @@
mallocs = find_mallocs(func, [int])
assert not mallocs
+
+def test_labs():
+ from pypy.rpython.rctypes.test import test_rfunc
+ def func(n):
+ return test_rfunc.labs(n)
+
+ mallocs = find_mallocs(func, [int])
+ assert not mallocs
+
+def test_atoi():
+ from pypy.rpython.rctypes.test import test_rfunc
+ def func(s):
+ return test_rfunc.atoi(s)
+
+ mallocs = find_mallocs(func, [str])
+ assert not mallocs
Modified: pypy/dist/pypy/rpython/rctypes/test/test_rpointer.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/test_rpointer.py (original)
+++ pypy/dist/pypy/rpython/rctypes/test/test_rpointer.py Tue Apr 18 12:30:38 2006
@@ -9,6 +9,11 @@
from pypy.rpython.test.test_llinterp import interpret
from pypy.translator.c.test.test_genc import compile
+try:
+ import ctypes
+except ImportError:
+ py.test.skip("this test needs ctypes installed")
+
from ctypes import c_int, c_float, POINTER, pointer, Structure
class Test_annotation:
More information about the Pypy-commit
mailing list