[pypy-commit] pypy newmemoryview-app-level: fix translation, extend class for python2 and use it in _ctypes
mattip
pypy.commits at gmail.com
Thu Feb 28 12:39:59 EST 2019
Author: Matti Picus <matti.picus at gmail.com>
Branch: newmemoryview-app-level
Changeset: r96193:6118585acf9c
Date: 2019-02-28 15:27 +0200
http://bitbucket.org/pypy/pypy/changeset/6118585acf9c/
Log: fix translation, extend class for python2 and use it in _ctypes
diff --git a/lib_pypy/_ctypes/basics.py b/lib_pypy/_ctypes/basics.py
--- a/lib_pypy/_ctypes/basics.py
+++ b/lib_pypy/_ctypes/basics.py
@@ -2,8 +2,15 @@
from _rawffi import alt as _ffi
import sys
-try: from __pypy__ import builtinify
-except ImportError: builtinify = lambda f: f
+try:
+ from __pypy__ import builtinify
+except ImportError:
+ builtinify = lambda f: f
+
+try:
+ from __pypy__.bufferable import bufferable
+except ImportError:
+ bufferable = object
keepalive_key = str # XXX fix this when provided with test
@@ -64,7 +71,7 @@
'resbuffer' is a _rawffi array of length 1 containing the value,
and this returns a general Python object that corresponds.
"""
- res = object.__new__(self)
+ res = bufferable.__new__(self)
res.__class__ = self
res.__dict__['_buffer'] = resbuffer
if base is not None:
@@ -158,7 +165,7 @@
def __ne__(self, other):
return self._obj != other
-class _CData(object):
+class _CData(bufferable):
""" The most basic object for all ctypes types
"""
__metaclass__ = _CDataMeta
diff --git a/pypy/module/__pypy__/interp_buffer.py b/pypy/module/__pypy__/interp_buffer.py
--- a/pypy/module/__pypy__/interp_buffer.py
+++ b/pypy/module/__pypy__/interp_buffer.py
@@ -13,11 +13,11 @@
pass
def descr_buffer(self, space, w_flags):
- if self is W_Bufferable:
+ if type(self) is W_Bufferable:
raise oefmt(space.w_ValueError, "override __buffer__ in a subclass")
return space.call_method(self, '__buffer__', w_flags)
-W_Bufferable.typedef = TypeDef("Bufferable",
+W_Bufferable.typedef = TypeDef("Bufferable", None, None, 'read-write',
__doc__ = """a helper class for a app-level class (like _ctypes.Array)
that want to support tp_as_buffer.bf_getbuffer via a __buffer__ method""",
__new__ = generic_new_descr(W_Bufferable),
diff --git a/pypy/module/cpyext/test/test_memoryobject.py b/pypy/module/cpyext/test/test_memoryobject.py
--- a/pypy/module/cpyext/test/test_memoryobject.py
+++ b/pypy/module/cpyext/test/test_memoryobject.py
@@ -47,6 +47,8 @@
py_obj = make_ref(space, w_obj)
assert py_obj.c_ob_type.c_tp_as_buffer
assert py_obj.c_ob_type.c_tp_as_buffer.c_bf_getbuffer
+ assert py_obj.c_ob_type.c_tp_as_buffer.c_bf_getreadbuffer
+ assert py_obj.c_ob_type.c_tp_as_buffer.c_bf_getwritebuffer
class AppTestPyBuffer_FillInfo(AppTestCpythonExtensionBase):
More information about the pypy-commit
mailing list