[pypy-commit] pypy pyarg-parsetuple-s-star-buffer: Try to teach cpyext about buffer objects
exarkun
noreply at buildbot.pypy.org
Mon Dec 12 21:24:59 CET 2011
Author: Jean-Paul Calderone <exarkun at twistedmatrix.com>
Branch: pyarg-parsetuple-s-star-buffer
Changeset: r50442:1396a5482b12
Date: 2011-12-12 15:24 -0500
http://bitbucket.org/pypy/pypy/changeset/1396a5482b12/
Log: Try to teach cpyext about buffer objects
diff --git a/pypy/module/cpyext/__init__.py b/pypy/module/cpyext/__init__.py
--- a/pypy/module/cpyext/__init__.py
+++ b/pypy/module/cpyext/__init__.py
@@ -46,6 +46,7 @@
import pypy.module.cpyext.listobject
import pypy.module.cpyext.sequence
import pypy.module.cpyext.buffer
+import pypy.module.cpyext.bufferobject
import pypy.module.cpyext.eval
import pypy.module.cpyext.import_
import pypy.module.cpyext.mapping
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -317,6 +317,10 @@
INTERPLEVEL_API = {}
FUNCTIONS = {}
+
+# These are C symbols which cpyext will export, but which are defined in .c
+# files somewhere in the implementation of cpyext (rather than being defined in
+# RPython).
SYMBOLS_C = [
'Py_FatalError', 'PyOS_snprintf', 'PyOS_vsnprintf', 'PyArg_Parse',
'PyArg_ParseTuple', 'PyArg_UnpackTuple', 'PyArg_ParseTupleAndKeywords',
@@ -1055,7 +1059,6 @@
boxed_args = ()
to_decref = []
assert len(args) == len(FT.ARGS)
- import pdb; pdb.set_trace()
for i, ARG in unrolling_arg_types:
arg = args[i]
if is_PyObject(ARG):
diff --git a/pypy/module/cpyext/bufferobject.py b/pypy/module/cpyext/bufferobject.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/bufferobject.py
@@ -0,0 +1,62 @@
+from pypy.rpython.lltypesystem import rffi, lltype
+from pypy.module.cpyext.api import (
+ cpython_api, Py_ssize_t, cpython_struct, bootstrap_function,
+ PyObjectFields, PyObject)
+from pypy.module.cpyext.pyobject import make_typedescr
+from pypy.interpreter.buffer import Buffer, StringBuffer, SubBuffer
+
+
+PyBufferObjectStruct = lltype.ForwardReference()
+PyBufferObject = lltype.Ptr(PyBufferObjectStruct)
+PyBufferObjectFields = PyObjectFields + (
+ ("b_base", PyObject),
+ ("b_ptr", rffi.VOIDP),
+ ("b_size", Py_ssize_t),
+ ("b_offset", Py_ssize_t),
+ ("b_readonly", rffi.INT),
+ ("b_hash", rffi.LONG),
+ )
+
+cpython_struct("PyBufferObject", PyBufferObjectFields, PyBufferObjectStruct)
+
+ at bootstrap_function
+def init_bufferobject(space):
+ "Type description of PyBufferObject"
+ make_typedescr(space.gettypefor(Buffer).instancetypedef,
+ basestruct=PyBufferObject.TO,
+ attach=buffer_attach,
+ # dealloc=buffer_dealloc,
+ realize=buffer_realize)
+
+def buffer_attach(space, py_obj, w_obj):
+ """
+ Fills a newly allocated PyBufferObject with the given (str) buffer object.
+ """
+ py_buf = rffi.cast(PyBufferObject, py_obj)
+ py_buf.c_b_offset = 0
+ py_buf.c_b_readonly = 1
+ py_buf.c_b_hash = -1
+
+ if isinstance(w_obj, SubBuffer):
+ py_buf.c_b_offset = w_obj.offset
+ w_obj = w_obj.buffer
+
+ if isinstance(w_obj, StringBuffer):
+ py_buf.c_b_base = rffi.cast(PyObject, 0) # space.wrap(w_obj.value)
+ py_buf.c_b_ptr = rffi.cast(rffi.VOIDP, rffi.str2charp(w_obj.as_str()))
+ py_buf.c_b_size = w_obj.getlength()
+ else:
+ raise Exception("Fail fail fail fail fail")
+
+
+def buffer_realize(space, py_obj):
+ """
+ Creates the buffer in the PyPy interpreter from a cpyext representation.
+ """
+ raise Exception("realize fail fail fail")
+
+
+
+# @cpython_api([PyObject], lltype.Void, external=False)
+# def buffer_dealloc(space, py_obj):
+
diff --git a/pypy/module/cpyext/pyobject.py b/pypy/module/cpyext/pyobject.py
--- a/pypy/module/cpyext/pyobject.py
+++ b/pypy/module/cpyext/pyobject.py
@@ -113,6 +113,8 @@
@specialize.memo()
def _get_typedescr_1(typedef):
+ if typedef.name == "buffer":
+ import pdb; pdb.set_trace()
try:
return typedescr_cache[typedef]
except KeyError:
More information about the pypy-commit
mailing list