[pypy-svn] r31590 - in pypy/branch/no-zeroing-assumption/pypy/translator/c: . src
mwh at codespeak.net
mwh at codespeak.net
Thu Aug 24 12:40:23 CEST 2006
Author: mwh
Date: Thu Aug 24 12:40:21 2006
New Revision: 31590
Modified:
pypy/branch/no-zeroing-assumption/pypy/translator/c/funcgen.py
pypy/branch/no-zeroing-assumption/pypy/translator/c/gc.py
pypy/branch/no-zeroing-assumption/pypy/translator/c/src/mem.h
Log:
make it more possible to allocate non-zeroed memory.
don't actually allocate any non-zeroed memory, though.
Modified: pypy/branch/no-zeroing-assumption/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/translator/c/funcgen.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/translator/c/funcgen.py Thu Aug 24 12:40:21 2006
@@ -500,7 +500,7 @@
self.expr(op.args[0]),
self.expr(op.args[1]))
- def OP_MALLOC(self, op):
+ def OP_ZERO_MALLOC(self, op):
TYPE = self.lltypemap(op.result).TO
typename = self.db.gettype(TYPE)
eresult = self.expr(op.result)
@@ -508,6 +508,14 @@
return self.gcpolicy.zero_malloc(TYPE, esize, eresult)
+ def OP_MALLOC(self, op):
+ TYPE = self.lltypemap(op.result).TO
+ typename = self.db.gettype(TYPE)
+ eresult = self.expr(op.result)
+ esize = 'sizeof(%s)' % cdecl(typename, '')
+
+ return self.gcpolicy.malloc(TYPE, esize, eresult)
+
OP_ZERO_MALLOC = OP_MALLOC
def OP_MALLOC_VARSIZE(self, op):
@@ -553,7 +561,8 @@
def OP_RAW_MALLOC(self, op):
eresult = self.expr(op.result)
esize = self.expr(op.args[0])
- return "OP_RAW_MALLOC(%s, %s, void *);" % (esize, eresult)
+ return ("OP_RAW_MALLOC(%s, %s, void *);\n\t" % (esize, eresult) +
+ "if (%s) OP_RAW_MEM_ZERO(%s, %s);" % (eresult, eresult, esize))
def OP_FLAVORED_MALLOC(self, op):
TYPE = self.lltypemap(op.result).TO
Modified: pypy/branch/no-zeroing-assumption/pypy/translator/c/gc.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/translator/c/gc.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/translator/c/gc.py Thu Aug 24 12:40:21 2006
@@ -103,6 +103,8 @@
erestype = cdecl(typename, '*')
return 'OP_ZERO_MALLOC(%s, %s, %s);' % (esize, eresult, erestype)
+ malloc = zero_malloc
+
def OP_GC_CALL_RTTI_DESTRUCTOR(self, funcgen, op):
args = [funcgen.expr(v) for v in op.args]
line = '%s(%s);' % (args[0], ', '.join(args[1:]))
@@ -194,6 +196,8 @@
% (eresult, gcinfo.finalizer))
return result
+ malloc = zero_malloc
+
def gc_libraries(self):
if sys.platform == 'win32':
return ['gc_pypy']
@@ -339,6 +343,8 @@
TYPE, esize, eresult)
return result
+ malloc = zero_malloc
+
# to get an idea how it looks like with no refcount/gc at all
class NoneGcPolicy(BoehmGcPolicy):
@@ -401,6 +407,8 @@
erestype = cdecl(typename, '*')
return 'OP_ZERO_MALLOC(%s, %s, %s);' % (esize, eresult, erestype)
+ malloc = zero_malloc
+
class StacklessFrameworkGcPolicy(FrameworkGcPolicy):
transformerclass = gctransform.StacklessFrameworkGCTransformer
requires_stackless = True
Modified: pypy/branch/no-zeroing-assumption/pypy/translator/c/src/mem.h
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/translator/c/src/mem.h (original)
+++ pypy/branch/no-zeroing-assumption/pypy/translator/c/src/mem.h Thu Aug 24 12:40:21 2006
@@ -2,7 +2,20 @@
/************************************************************/
/*** C header subsection: operations on LowLevelTypes ***/
-#define OP_RAW_MALLOC(size,r,restype) OP_ZERO_MALLOC(size, r, restype)
+#define OP_RAW_MALLOC(size, r, restype) { \
+ r = (restype) PyObject_Malloc(size); \
+ if (r == NULL) { \
+ FAIL_EXCEPTION(PyExc_MemoryError, \
+ "out of memory"); \
+ } \
+ else { \
+ COUNT_MALLOC; \
+ } \
+ }
+
+#define OP_RAW_FREE(p, r) PyObject_Free(p); COUNT_FREE;
+
+#define OP_RAW_MEM_ZERO(p, size) memset((void*)p, 0, size)
#define OP_RAW_MALLOC_USAGE(size, r) r = size
@@ -17,7 +30,6 @@
if (r == NULL) FAIL_EXCEPTION(PyExc_MemoryError, "out of memory"); \
memset((void*) r, 0, size);
-#define OP_RAW_FREE(x,r) OP_FREE(x)
#define OP_RAW_MEMCOPY(x,y,size,r) memcpy(y,x,size);
/************************************************************/
@@ -41,16 +53,12 @@
other globals, plus one. This upper bound "approximation" will do... */
#define REFCOUNT_IMMORTAL (INT_MAX/2)
-#define OP_ZERO_MALLOC(size, r, restype) { \
- r = (restype) PyObject_Malloc(size); \
- if (r == NULL) {FAIL_EXCEPTION(PyExc_MemoryError, "out of memory"); } \
- else { \
- memset((void*) r, 0, size); \
- COUNT_MALLOC; \
- } \
- }
+#define OP_ZERO_MALLOC(size, r, restype) { \
+ OP_RAW_MALLOC(size, r, restype); \
+ if (r != NULL) OP_RAW_MEM_ZERO(r, size); \
+ }
-#define OP_FREE(p) { PyObject_Free(p); COUNT_FREE; }
+#define OP_FREE(p) OP_RAW_FREE(p, do_not_use)
/*------------------------------------------------------------*/
#ifndef COUNT_OP_MALLOCS
More information about the Pypy-commit
mailing list