[pypy-svn] r73623 - in pypy/branch/cpython-extension/pypy/module/cpyext: include test
jandem at codespeak.net
jandem at codespeak.net
Sat Apr 10 16:08:20 CEST 2010
Author: jandem
Date: Sat Apr 10 16:08:19 2010
New Revision: 73623
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h
pypy/branch/cpython-extension/pypy/module/cpyext/include/pymem.h
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py
Log:
Add some macros from CPython, remove unused import
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h Sat Apr 10 16:08:19 2010
@@ -447,6 +447,23 @@
(typeobj), (n)) )
*/
+#define PyObject_GC_New(type, typeobj) \
+ ( (type *) _PyObject_GC_New(typeobj) )
+
+/* Utility macro to help write tp_traverse functions.
+ * To use this macro, the tp_traverse function must name its arguments
+ * "visit" and "arg". This is intended to keep tp_traverse functions
+ * looking as much alike as possible.
+ */
+#define Py_VISIT(op) \
+ do { \
+ if (op) { \
+ int vret = visit((PyObject *)(op), arg); \
+ if (vret) \
+ return vret; \
+ } \
+ } while (0)
+
/* PyPy internal ----------------------------------- */
int PyPyType_Register(PyTypeObject *);
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/include/pymem.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/include/pymem.h (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/pymem.h Sat Apr 10 16:08:19 2010
@@ -7,8 +7,44 @@
/* XXX use obmalloc like cpython and pypy do, otherwise we might get segfaults */
#define PyObject_MALLOC PyMem_MALLOC
-//#define PyObject_REALLOC PyMem_REALLOC
+#define PyObject_REALLOC PyMem_REALLOC
#define PyObject_FREE PyMem_FREE
#define PyMem_Malloc PyMem_MALLOC
#define PyMem_Free PyMem_FREE
+
+/*
+ * Type-oriented memory interface
+ * ==============================
+ *
+ * Allocate memory for n objects of the given type. Returns a new pointer
+ * or NULL if the request was too large or memory allocation failed. Use
+ * these macros rather than doing the multiplication yourself so that proper
+ * overflow checking is always done.
+ */
+
+#define PyMem_New(type, n) \
+ ( ((n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL : \
+ ( (type *) PyMem_Malloc((n) * sizeof(type)) ) )
+#define PyMem_NEW(type, n) \
+ ( ((n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL : \
+ ( (type *) PyMem_MALLOC((n) * sizeof(type)) ) )
+
+/*
+ * The value of (p) is always clobbered by this macro regardless of success.
+ * The caller MUST check if (p) is NULL afterwards and deal with the memory
+ * error if so. This means the original value of (p) MUST be saved for the
+ * caller's memory error handler to not lose track of it.
+ */
+#define PyMem_Resize(p, type, n) \
+ ( (p) = ((n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL : \
+ (type *) PyMem_Realloc((p), (n) * sizeof(type)) )
+#define PyMem_RESIZE(p, type, n) \
+ ( (p) = ((n) > PY_SSIZE_T_MAX / sizeof(type)) ? NULL : \
+ (type *) PyMem_REALLOC((p), (n) * sizeof(type)) )
+
+/* PyMem{Del,DEL} are left over from ancient days, and shouldn't be used
+ * anymore. They're just confusing aliases for PyMem_{Free,FREE} now.
+ */
+#define PyMem_Del PyMem_Free
+#define PyMem_DEL PyMem_FREE
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py Sat Apr 10 16:08:19 2010
@@ -4,7 +4,6 @@
from pypy.rpython.lltypesystem import rffi, lltype
from pypy.module.cpyext.api import Py_LT, Py_LE, Py_NE, Py_EQ,\
Py_GE, Py_GT
-from pypy.module.cpyext.pyobject import make_ref
class TestObject(BaseApiTest):
def test_IsTrue(self, space, api):
More information about the Pypy-commit
mailing list