[pypy-svn] r46846 - in pypy/dist/pypy: objspace/cpy/test translator/c/src

arigo at codespeak.net arigo at codespeak.net
Mon Sep 24 10:41:42 CEST 2007


Author: arigo
Date: Mon Sep 24 10:41:41 2007
New Revision: 46846

Modified:
   pypy/dist/pypy/objspace/cpy/test/test_typedef.py
   pypy/dist/pypy/translator/c/src/mem.h
Log:
Try to use the official way to build PyObjects, instead of
the broken hack that forgot about CPython's GC.


Modified: pypy/dist/pypy/objspace/cpy/test/test_typedef.py
==============================================================================
--- pypy/dist/pypy/objspace/cpy/test/test_typedef.py	(original)
+++ pypy/dist/pypy/objspace/cpy/test/test_typedef.py	Mon Sep 24 10:41:41 2007
@@ -48,7 +48,7 @@
     fn = compile(make_mytype, [],
                  annotatorpolicy = CPyAnnotatorPolicy(space))
 
-    res = fn(expected_extra_mallocs=1)
+    res = fn()
     assert type(res).__name__ == 'MyType'
 
 
@@ -70,9 +70,9 @@
     fn = compile(make_mytype, [int],
                  annotatorpolicy = CPyAnnotatorPolicy(space))
 
-    res2 = fn(1, expected_extra_mallocs=1)
+    res2 = fn(1)
     assert type(res2).__name__ == 'MyType2'
-    res = fn(0, expected_extra_mallocs=2)
+    res = fn(0)
     assert type(res).__name__ == 'MyType'
 
 
@@ -99,19 +99,19 @@
     fn = compile(fn, [object],
                  annotatorpolicy = CPyAnnotatorPolicy(space))
 
-    res, abc = fn(None, expected_extra_mallocs=1)
+    res, abc = fn(None)
     assert abc == 2
     assert type(res).__name__ == 'MyType'
 
-    res2, abc = fn(res, expected_extra_mallocs=1)
+    res2, abc = fn(res)
     assert abc == 4
     assert res2 is res
 
-    res2, abc = fn(res, expected_extra_mallocs=1)
+    res2, abc = fn(res)
     assert abc == 8
     assert res2 is res
 
-    res2, abc = fn(res, expected_extra_mallocs=1)
+    res2, abc = fn(res)
     assert abc == 16
     assert res2 is res
 
@@ -126,7 +126,7 @@
     fn = compile(make_mytype, [],
                  annotatorpolicy = CPyAnnotatorPolicy(space))
 
-    res = fn(expected_extra_mallocs=1)
+    res = fn()
     assert type(res).__name__ == 'MyType'
     assert res.hello == 7
     assert type(res).hello == 7
@@ -143,7 +143,7 @@
     fn = compile(make_mytype, [],
                  annotatorpolicy = CPyAnnotatorPolicy(space))
 
-    res = fn(expected_extra_mallocs=1)
+    res = fn()
     assert type(res).__name__ == 'MyType'
     assert res.multiply(3) == 369
 
@@ -158,7 +158,7 @@
     fn = compile(make_mytype, [],
                  annotatorpolicy = CPyAnnotatorPolicy(space))
 
-    res = fn(expected_extra_mallocs=1)
+    res = fn()
     assert type(res).__name__ == 'MyType'
     assert res * 3 == 369
 
@@ -187,12 +187,12 @@
     fn = compile(fn, [object],
                  annotatorpolicy = CPyAnnotatorPolicy(space))
 
-    res, x = fn(None, expected_extra_mallocs=1)
+    res, x = fn(None)
     assert type(res).__name__ == 'MyType'
     assert x == 2
     assert res.x == 2
 
-    res2, x = fn(res, expected_extra_mallocs=1)
+    res2, x = fn(res)
     assert res2 is res
     assert x == 4
     assert res.x == 4
@@ -223,14 +223,14 @@
     fn = compile(fn, [object],
                  annotatorpolicy = CPyAnnotatorPolicy(space))
 
-    res, x = fn(None, expected_extra_mallocs=1)
+    res, x = fn(None)
     assert type(res).__name__ == 'MyType'
     assert x == 2
     assert res.x == 2
     res.x += 100
     assert res.x == 102
 
-    res2, x = fn(res, expected_extra_mallocs=1)
+    res2, x = fn(res)
     assert res2 is res
     assert x == 204
     assert res.x == 204
@@ -288,7 +288,7 @@
 
     fn = compile(build, [],
                  annotatorpolicy = CPyAnnotatorPolicy(space))
-    res = fn(expected_extra_mallocs=1)
+    res = fn()
     assert type(res).__name__ == 'MyType'
     assert res.x == 42
 
@@ -315,7 +315,7 @@
 
     fn = compile(build, [],
                  annotatorpolicy = CPyAnnotatorPolicy(space))
-    res = fn(expected_extra_mallocs=1)
+    res = fn()
     assert type(res).__name__ == 'MyType'
     assert res.x == 42
 
@@ -338,7 +338,7 @@
 
     fn = compile(build, [],
                  annotatorpolicy = CPyAnnotatorPolicy(space))
-    res = fn(expected_extra_mallocs=1)
+    res = fn()
     assert type(res).__name__ == 'MyType'
     assert res.x == 42
 
@@ -372,7 +372,7 @@
 
     fn = compile(build, [],
                  annotatorpolicy = CPyAnnotatorPolicy(space))
-    res = fn(expected_extra_mallocs=1)
+    res = fn()
     assert type(res).__name__ == 'MyType'
 
 def test_prebuilt_instance():
@@ -394,7 +394,7 @@
 
     fn = compile(build, [],
                  annotatorpolicy = CPyAnnotatorPolicy(space))
-    res = fn(expected_extra_mallocs=0)
+    res = fn()
     assert type(res).__name__ == 'MyType'
 
 def test_prebuilt_instance_inside_pyobj():
@@ -415,7 +415,7 @@
 
     fn = compile(build, [],
                  annotatorpolicy = CPyAnnotatorPolicy(space))
-    res = fn(expected_extra_mallocs=0)
+    res = fn()
     assert type(res) is dict
     assert res.keys() == ['hello']
     assert type(res['hello']).__name__ == 'MyType'
@@ -432,5 +432,5 @@
 
     fn = compile(entry_point, [int],
                  annotatorpolicy = CPyAnnotatorPolicy(space))
-    res = fn(42, expected_extra_mallocs=1)
+    res = fn(42)
     assert res.hello == 7

Modified: pypy/dist/pypy/translator/c/src/mem.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/mem.h	(original)
+++ pypy/dist/pypy/translator/c/src/mem.h	Mon Sep 24 10:41:41 2007
@@ -113,15 +113,12 @@
 /************************************************************/
 /* rcpy support */
 
-#define OP_CPY_MALLOC(cpytype, r, restype)  {			\
-	/* XXX add tp_itemsize later */				\
-	OP_RAW_MALLOC(((PyTypeObject *)cpytype)->tp_basicsize, r, restype); \
-	if (r) {						\
-	    OP_RAW_MEMCLEAR(r, ((PyTypeObject *)cpytype)->tp_basicsize, /* */); \
-	    PyObject_Init((PyObject *)r, (PyTypeObject *)cpytype); \
-	}							\
+#define OP_CPY_MALLOC(cpytype, r, restype)  {				\
+	/* XXX add tp_itemsize later */					\
+	r = ((PyTypeObject *)cpytype)->tp_alloc((PyTypeObject *)cpytype, 0); \
+	if (!r) RPyConvertExceptionFromCPython();			\
     }
-#define OP_CPY_FREE(x)   OP_RAW_FREE(x, /*nothing*/)
+#define OP_CPY_FREE(x)   XXX "this shouldn't be used any more"
 
 /************************************************************/
 /* weakref support */



More information about the Pypy-commit mailing list