Author: Maciej Fijalkowski <[email protected]>
Branch: kill-someobject
Changeset: r57955:fd19fa683cfe
Date: 2012-10-09 17:57 +0200
http://bitbucket.org/pypy/pypy/changeset/fd19fa683cfe/
Log: merge
diff --git a/pypy/rpython/lltypesystem/test/test_rffi.py
b/pypy/rpython/lltypesystem/test/test_rffi.py
--- a/pypy/rpython/lltypesystem/test/test_rffi.py
+++ b/pypy/rpython/lltypesystem/test/test_rffi.py
@@ -113,7 +113,7 @@
return len(res)
xf = self.compile(f, [], backendopt=False)
- assert xf(expected_extra_mallocs=-1) == 3
+ assert xf() == 3
def test_stringstar(self):
c_source = """
@@ -503,7 +503,8 @@
try:
for i in range(len(d)):
raw_buf[i] = d[i]
- return unicode_from_buffer(raw_buf, gc_buf, len(d), len(d)-1)
+ return (unicode_from_buffer(raw_buf, gc_buf, len(d), len(d)-1)
+ .encode('ascii'))
finally:
keep_unicodebuffer_alive_until_here(raw_buf, gc_buf)
assert f() == d[:-1]
diff --git a/pypy/rpython/tool/rffi_platform.py
b/pypy/rpython/tool/rffi_platform.py
--- a/pypy/rpython/tool/rffi_platform.py
+++ b/pypy/rpython/tool/rffi_platform.py
@@ -328,13 +328,14 @@
allfields = tuple(['c_' + name for name, _ in fields])
padfields = tuple(padfields)
name = self.name
- padding_drop = PaddingDrop(name, allfields, padfields,
- config_result.CConfig._compilation_info_)
+ eci = config_result.CConfig._compilation_info_
+ padding_drop = PaddingDrop(name, allfields, padfields, eci)
hints = {'align': info['align'],
'size': info['size'],
'fieldoffsets': tuple(fieldoffsets),
'padding': padfields,
- 'get_padding_drop': padding_drop}
+ 'get_padding_drop': padding_drop,
+ 'eci': eci}
if name.startswith('struct '):
name = name[7:]
else:
diff --git a/pypy/translator/c/genc.py b/pypy/translator/c/genc.py
--- a/pypy/translator/c/genc.py
+++ b/pypy/translator/c/genc.py
@@ -191,6 +191,11 @@
eci = node.compilation_info()
if eci:
all.append(eci)
+ for node in self.db.getstructdeflist():
+ try:
+ all.append(node.STRUCT._hints['eci'])
+ except (AttributeError, KeyError):
+ pass
self.merge_eci(*all)
def get_gcpolicyclass(self):
diff --git a/pypy/translator/c/src/main.h b/pypy/translator/c/src/main.h
--- a/pypy/translator/c/src/main.h
+++ b/pypy/translator/c/src/main.h
@@ -68,6 +68,8 @@
pypy_debug_catch_fatal_exception();
}
+ pypy_malloc_counters_results();
+
return exitcode;
memory_out:
diff --git a/pypy/translator/c/src/mem.h b/pypy/translator/c/src/mem.h
--- a/pypy/translator/c/src/mem.h
+++ b/pypy/translator/c/src/mem.h
@@ -103,6 +103,7 @@
r = (restype) PyObject_Malloc(size); \
if (r != NULL) { \
memset((void*)r, 0, size); \
+ COUNT_MALLOC; \
} \
}
@@ -110,11 +111,14 @@
#define OP_RAW_MALLOC(size, r, restype) { \
r = (restype) PyObject_Malloc(size); \
+ if (r != NULL) { \
+ COUNT_MALLOC; \
+ } \
}
#endif
-#define OP_RAW_FREE(p, r) PyObject_Free(p);
+#define OP_RAW_FREE(p, r) PyObject_Free(p); COUNT_FREE;
#define OP_RAW_MEMCLEAR(p, size, r) memset((void*)p, 0, size)
@@ -135,6 +139,31 @@
#define OP_FREE(p) OP_RAW_FREE(p, do_not_use)
+/*------------------------------------------------------------*/
+#ifndef COUNT_OP_MALLOCS
+/*------------------------------------------------------------*/
+
+#define COUNT_MALLOC /* nothing */
+#define COUNT_FREE /* nothing */
+
+#define pypy_malloc_counters_results() /* nothing */
+
+/*------------------------------------------------------------*/
+#else /*COUNT_OP_MALLOCS*/
+/*------------------------------------------------------------*/
+
+static int count_mallocs=0, count_frees=0;
+
+#define COUNT_MALLOC count_mallocs++
+#define COUNT_FREE count_frees++
+
+#define pypy_malloc_counters_results() \
+ printf("MALLOC COUNTERS: %d %d\n", count_mallocs, count_frees)
+
+/*------------------------------------------------------------*/
+#endif /*COUNT_OP_MALLOCS*/
+/*------------------------------------------------------------*/
+
/* for Boehm GC */
#ifdef USING_BOEHM_GC
diff --git a/pypy/translator/c/test/test_backendoptimized.py
b/pypy/translator/c/test/test_backendoptimized.py
--- a/pypy/translator/c/test/test_backendoptimized.py
+++ b/pypy/translator/c/test/test_backendoptimized.py
@@ -38,7 +38,7 @@
a = A()
return b.num_deleted
- fn = self.getcompiled(f, [int])
+ fn = self.getcompiled(f, [int], gcpolicy='ref')
res = f(5)
assert res == 5
res = fn(5)
@@ -70,7 +70,7 @@
return s.a_dels * 10 + s.b_dels
else:
return -1
- fn = self.getcompiled(f, [int])
+ fn = self.getcompiled(f, [int], gcpolicy='ref')
res = f(1)
assert res == 42
res = fn(1)
@@ -138,7 +138,7 @@
codegenerator = self.CodeGenerator()
fn = codegenerator.getcompiled(f, [r_uint])
for x in (0,1,2,3,9,27,48):
- assert fn(x) == f(x)
+ assert fn(r_uint(x)) == f(r_uint(x))
def test_longlong_switch(self):
def f(x):
@@ -152,7 +152,7 @@
codegenerator = self.CodeGenerator()
fn = codegenerator.getcompiled(f, [r_longlong])
for x in (0,1,2,3,9,27,48, -9):
- assert fn(x) == f(x)
+ assert fn(r_longlong(x)) == f(r_longlong(x))
def test_ulonglong_switch(self):
def f(x):
@@ -166,7 +166,7 @@
codegenerator = self.CodeGenerator()
fn = codegenerator.getcompiled(f, [r_ulonglong])
for x in (0,1,2,3,9,27,48, r_ulonglong(-9)):
- assert fn(x) == f(x)
+ assert fn(r_ulonglong(x)) == f(r_ulonglong(x))
def test_chr_switch(self):
def f(y):
diff --git a/pypy/translator/c/test/test_boehm.py
b/pypy/translator/c/test/test_boehm.py
--- a/pypy/translator/c/test/test_boehm.py
+++ b/pypy/translator/c/test/test_boehm.py
@@ -119,17 +119,17 @@
a3, b3, c3 = run_once()
a4, b4, c4 = run_once()
a5, b5, c5 = run_once()
- return (s.a_dels, s.b_dels,
- a1, b1, c1,
- a2, b2, c2,
- a3, b3, c3,
- a4, b4, c4,
- a5, b5, c5)
+ return str((s.a_dels, s.b_dels,
+ a1, b1, c1,
+ a2, b2, c2,
+ a3, b3, c3,
+ a4, b4, c4,
+ a5, b5, c5))
fn = self.getcompiled(f, [int])
# we can't demand that boehm has collected all of the objects,
# even with the gc__collect call.
res = fn(50)
- res1, res2 = res[:2]
+ res1, res2 = eval(res)[:2]
# if res1 or res2 is still 0, then we haven't tested anything so fail.
# it might be the test's fault though.
print res1, res2
@@ -391,14 +391,15 @@
#
def fn():
d2 = D()
- return (compute_hash(d2),
- current_object_addr_as_int(d2),
- compute_hash(c),
- compute_hash(d),
- compute_hash(("Hi", None, (7.5, 2, d))))
+ return str((compute_hash(d2),
+ current_object_addr_as_int(d2),
+ compute_hash(c),
+ compute_hash(d),
+ compute_hash(("Hi", None, (7.5, 2, d)))))
f = self.getcompiled(fn)
res = f()
+ res = eval(res)
# xxx the next line is too precise, checking the exact implementation
assert res[0] == ~res[1]
diff --git a/pypy/translator/c/test/test_genc.py
b/pypy/translator/c/test/test_genc.py
--- a/pypy/translator/c/test/test_genc.py
+++ b/pypy/translator/c/test/test_genc.py
@@ -4,7 +4,8 @@
from pypy.rlib.entrypoint import entrypoint
from pypy.rlib.unroll import unrolling_iterable
-from pypy.rlib.rarithmetic import r_longlong, r_ulonglong, intmask
+from pypy.rlib.rarithmetic import r_longlong, r_ulonglong, r_uint, intmask
+from pypy.rlib.objectmodel import specialize
from pypy.rpython.lltypesystem import lltype
from pypy.rpython.lltypesystem.lltype import *
from pypy.rpython.lltypesystem.rstr import STR
@@ -16,7 +17,7 @@
signed_ffffffff = r_longlong(0xffffffff)
unsigned_ffffffff = r_ulonglong(0xffffffff)
-def llrepr(v):
+def llrepr_in(v):
if isinstance(v, r_ulonglong):
return "%d:%d" % (intmask(v >> 32), intmask(v & unsigned_ffffffff))
elif isinstance(v, r_longlong):
@@ -25,6 +26,13 @@
return repr(v) # extra precision than str(v)
return str(v)
[email protected](0)
+def llrepr_out(v):
+ if isinstance(v, float):
+ from pypy.rlib.rfloat import formatd, DTSF_ADD_DOT_0
+ return formatd(v, 'r', 0, DTSF_ADD_DOT_0)
+ return v
+
def parse_longlong(a):
p0, p1 = a.split(":")
return (r_longlong(int(p0)) << 32) + (r_longlong(int(p1)) &
@@ -40,7 +48,8 @@
argtypes_unroll = unrolling_iterable(enumerate(argtypes))
for argtype in argtypes:
- if argtype not in [int, float, str, bool, r_ulonglong, r_longlong]:
+ if argtype not in [int, float, str, bool, r_ulonglong, r_longlong,
+ r_uint]:
raise Exception("Unsupported argtype, %r" % (argtype,))
def entry_point(argv):
@@ -49,6 +58,8 @@
a = argv[i + 1]
if argtype is int:
args += (int(a),)
+ elif argtype is r_uint:
+ args += (r_uint(int(a)),)
elif argtype is r_longlong:
args += (parse_longlong(a),)
elif argtype is r_ulonglong:
@@ -64,13 +75,14 @@
else:
args += (a,)
res = fn(*args)
- print "THE RESULT IS:", res, ";"
+ print "THE RESULT IS:", llrepr_out(res), ";"
return 0
t = Translation(entry_point, None, gc=gcpolicy, backend="c",
policy=annotatorpolicy, thread=thread)
if not backendopt:
t.disable(["backendopt_lltype"])
+ t.driver.config.translation.countmallocs = True
t.annotate()
t.compile_c()
ll_res = graphof(t.context, fn).getreturnvar().concretetype
@@ -79,15 +91,31 @@
t.view()
except AttributeError:
pass
- def f(*args):
+
+ def f(*args, **kwds):
+ if 'expected_extra_mallocs' in kwds:
+ expected_extra_mallocs = kwds.pop('expected_extra_mallocs')
+ else:
+ expected_extra_mallocs = 0
+ assert not kwds
assert len(args) == len(argtypes)
for arg, argtype in zip(args, argtypes):
assert isinstance(arg, argtype)
- stdout = t.driver.cbuilder.cmdexec(" ".join([llrepr(arg) for arg in
args]))
+ stdout = t.driver.cbuilder.cmdexec(" ".join([llrepr_in(arg) for arg in
args]))
print stdout
- assert stdout.endswith(' ;\n')
+ stdout, lastline, empty = stdout.rsplit('\n', 2)
+ assert empty == ''
+ assert lastline.startswith('MALLOC COUNTERS: ')
+ mallocs, frees = map(int, lastline.split()[2:])
+ assert stdout.endswith(' ;')
pos = stdout.rindex('THE RESULT IS: ')
- res = stdout[pos + len('THE RESULT IS: '):-3]
+ res = stdout[pos + len('THE RESULT IS: '):-2]
+ #
+ if isinstance(expected_extra_mallocs, int):
+ assert mallocs - frees == expected_extra_mallocs
+ else:
+ assert mallocs - frees in expected_extra_mallocs
+ #
if ll_res in [lltype.Signed, lltype.Unsigned, lltype.SignedLongLong,
lltype.UnsignedLongLong]:
return int(res)
diff --git a/pypy/translator/c/test/test_lltyped.py
b/pypy/translator/c/test/test_lltyped.py
--- a/pypy/translator/c/test/test_lltyped.py
+++ b/pypy/translator/c/test/test_lltyped.py
@@ -1,17 +1,19 @@
import py
from pypy.rpython.lltypesystem.lltype import *
-from pypy.translator.c.test import test_typed
+from pypy.translator.c.test.test_genc import compile
from pypy.tool.sourcetools import func_with_new_name
-class TestLowLevelType(test_typed.CompilationTestCase):
+class TestLowLevelType(object):
+ def getcompiled(self, func, argtypes):
+ return compile(func, argtypes, backendopt=False)
def test_simple(self):
S = GcStruct("s", ('v', Signed))
def llf():
s = malloc(S)
return s.v
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [])
assert fn() == 0
def test_simple2(self):
@@ -22,7 +24,7 @@
s.a.v = 6
s.b.v = 12
return s.a.v + s.b.v
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [])
assert fn() == 18
def test_fixedsizearray(self):
@@ -49,7 +51,7 @@
assert a42[0][0] == -5
assert a42[5][6] == -6
return len(a42)*100 + len(a42[4])
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [])
res = fn()
assert fn() == 607
@@ -62,7 +64,7 @@
tree.root[0].a = tree.root
tree.root[1].a = tree.other
assert tree.root[0].a[0].a[0].a[0].a[0].a[1].a == tree.other
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [])
fn()
def test_prebuilt_array(self):
@@ -78,7 +80,7 @@
for i in range(5):
s += chr(64+a[i])
assert s == "HELLO"
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [])
fn()
def test_call_with_fixedsizearray(self):
@@ -92,7 +94,7 @@
s = malloc(S)
s.a = a
return g(s.a)
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [])
res = fn()
assert res == 123
@@ -218,7 +220,7 @@
s.y += 1
return p1[0] + p2[0] + p3[0] + p4[0]
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [])
res = fn()
assert res == 8765
@@ -484,18 +486,12 @@
x = getmax(cls)
res1 = OP(x, nn)
result = result + (res1,)
- return result
-
- def assert_eq(a, b):
- # for better error messages when it fails
- assert len(a) == len(b)
- for i in range(len(a)):
- assert a[i] == b[i]
+ return str(result)
fn = self.getcompiled(f, [int])
res = fn(1)
print res
- assert_eq(res, (
+ assert eval(res) == (
# int
-sys.maxint, undefined, # add
undefined, sys.maxint-1, # sub
@@ -528,11 +524,11 @@
0, 0, # mod
0, maxlonglong*2, # lshift
0, maxlonglong, # rshift
- ))
+ )
res = fn(5)
print res
- assert_eq(res, (
+ assert eval(res) == (
# int
-sys.maxint+4, undefined, # add
undefined, sys.maxint-5, # sub
@@ -565,7 +561,7 @@
0, (maxlonglong*2+1)%5, # mod
0, maxlonglong*2-30, # lshift
0, maxlonglong>>4, # rshift
- ))
+ )
def test_direct_ptradd_barebone(self):
from pypy.rpython.lltypesystem import rffi
@@ -582,7 +578,7 @@
assert a2[i] == a[i + 2]
free(a, flavor='raw')
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [])
fn()
def test_r_singlefloat(self):
@@ -617,7 +613,7 @@
a[2][5] = 888000
def llf():
return b[3][4] + a[2][5]
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [])
assert fn() == 888999
def test_prebuilt_nolength_array(self):
@@ -633,7 +629,7 @@
for i in range(5):
s += chr(64+a[i])
assert s == "HELLO"
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [])
fn()
def test_prebuilt_nolength_char_array(self):
@@ -654,7 +650,7 @@
s += a[i]
print s
assert s == "85?!" + lastchar
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [])
fn()
def test_prebuilt_raw_arrays(self):
@@ -692,7 +688,7 @@
return i # returns the index of the failing function
i += 1
return -42
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [])
res = fn()
assert res == -42, "failing function: %r" % (records[res],)
@@ -714,7 +710,7 @@
s += a[i]
return 'abcd' == s
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [])
assert fn()
def test_ll2ctypes_array_from_c(self):
@@ -736,7 +732,7 @@
s += a[i]
print s
return s == 'abcd'
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [])
assert fn()
def test_cast_to_void_array(self):
@@ -744,13 +740,13 @@
def llf():
TYPE = Ptr(rffi.CArray(Void))
y = rffi.cast(TYPE, 0)
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [])
fn()
def test_llgroup(self):
from pypy.rpython.lltypesystem.test import test_llgroup
f = test_llgroup.build_test()
- fn = self.getcompiled(f)
+ fn = self.getcompiled(f, [])
res = fn()
assert res == 42
@@ -868,6 +864,7 @@
("l3", Signed)])
S = rffi_platform.configure(CConfig)['STRUCT']
assert 'get_padding_drop' in S._hints
+ assert 'eci' in S._hints
s1 = malloc(S, immortal=True)
s1.c_c1 = rffi.cast(S.c_c1, -12)
s1.c_s1 = rffi.cast(S.c_s1, -7843)
@@ -884,7 +881,6 @@
s = s2
return s.c_l3
#
- self.include_also_eci = eci
fn = self.getcompiled(f, [int])
res = fn(10)
assert res == -98765432
@@ -901,7 +897,7 @@
render_immortal(a2)
a2[0] = 3
return a1[0] + a2[0]
- fn = self.getcompiled(llf)
+ fn = self.getcompiled(llf, [])
assert fn() == 45
def test_rstring_to_float(self):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit