[pypy-svn] r73656 - in pypy/branch/cpython-extension/pypy/module/cpyext: . include src
xoraxax at codespeak.net
xoraxax at codespeak.net
Sun Apr 11 22:48:06 CEST 2010
Author: xoraxax
Date: Sun Apr 11 22:48:04 2010
New Revision: 73656
Added:
pypy/branch/cpython-extension/pypy/module/cpyext/src/object.c (contents, props changed)
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/api.py
pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h
Log:
Add PyObject_CheckReadBuffer and PyObject_AsReadBuffer.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/api.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/api.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/api.py Sun Apr 11 22:48:04 2010
@@ -237,10 +237,10 @@
FUNCTIONS_C = [ # XXX rename to SYMBOLS_C
'Py_FatalError', 'PyOS_snprintf', 'PyOS_vsnprintf', 'PyArg_Parse',
'PyArg_ParseTuple', 'PyArg_UnpackTuple', 'PyArg_ParseTupleAndKeywords',
- 'PyString_FromFormat', 'PyString_FromFormatV', 'PyModule_AddObject',
+ 'PyString_FromFormat', 'PyString_FromFormatV', 'PyModule_AddObject',
'Py_BuildValue', 'PyTuple_Pack', 'PyErr_Format',
'PyBuffer_FromMemory', 'PyBuffer_Type', 'init_bufferobject',
- '_PyArg_NoKeywords',
+ '_PyArg_NoKeywords', 'PyObject_AsReadBuffer', 'PyObject_CheckReadBuffer',
]
TYPES = {}
GLOBALS = { # this needs to include all prebuilt pto, otherwise segfaults occur
@@ -622,7 +622,8 @@
source_dir / "stringobject.c",
source_dir / "mysnprintf.c",
source_dir / "pythonrun.c",
- source_dir / "bufferobject.c"
+ source_dir / "bufferobject.c",
+ source_dir / "object.c",
],
separate_module_sources = [code],
export_symbols=export_symbols_eci,
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 Sun Apr 11 22:48:04 2010
@@ -463,9 +463,14 @@
} \
} while (0)
-#define PyObject_Length PyObject_Size
+/* Copied from CPython ----------------------------- */
+int PyObject_AsReadBuffer(PyObject *, void **, Py_ssize_t *);
+int PyObject_CheckReadBuffer(PyObject *);
+
/* PyPy internal ----------------------------------- */
int PyPyType_Register(PyTypeObject *);
+#define PyObject_Length PyObject_Size
+
#endif
Added: pypy/branch/cpython-extension/pypy/module/cpyext/src/object.c
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/src/object.c Sun Apr 11 22:48:04 2010
@@ -0,0 +1,58 @@
+// contains code from abstract.c
+#include <Python.h>
+
+
+static PyObject *
+null_error(void)
+{
+ if (!PyErr_Occurred())
+ PyErr_SetString(PyExc_SystemError,
+ "null argument to internal routine");
+ return NULL;
+}
+
+int PyObject_AsReadBuffer(PyObject *obj,
+ const void **buffer,
+ Py_ssize_t *buffer_len)
+{
+ PyBufferProcs *pb;
+ void *pp;
+ Py_ssize_t len;
+
+ if (obj == NULL || buffer == NULL || buffer_len == NULL) {
+ null_error();
+ return -1;
+ }
+ pb = obj->ob_type->tp_as_buffer;
+ if (pb == NULL ||
+ pb->bf_getreadbuffer == NULL ||
+ pb->bf_getsegcount == NULL) {
+ PyErr_SetString(PyExc_TypeError,
+ "expected a readable buffer object");
+ return -1;
+ }
+ if ((*pb->bf_getsegcount)(obj, NULL) != 1) {
+ PyErr_SetString(PyExc_TypeError,
+ "expected a single-segment buffer object");
+ return -1;
+ }
+ len = (*pb->bf_getreadbuffer)(obj, 0, &pp);
+ if (len < 0)
+ return -1;
+ *buffer = pp;
+ *buffer_len = len;
+ return 0;
+}
+
+int
+PyObject_CheckReadBuffer(PyObject *obj)
+{
+ PyBufferProcs *pb = obj->ob_type->tp_as_buffer;
+
+ if (pb == NULL ||
+ pb->bf_getreadbuffer == NULL ||
+ pb->bf_getsegcount == NULL ||
+ (*pb->bf_getsegcount)(obj, NULL) != 1)
+ return 0;
+ return 1;
+}
More information about the Pypy-commit
mailing list