Author: Ronan Lamy <[email protected]>
Branch:
Changeset: r95057:b9cf6798af7e
Date: 2018-09-01 15:39 +0200
http://bitbucket.org/pypy/pypy/changeset/b9cf6798af7e/
Log: merge heads
diff --git a/lib_pypy/_ctypes/primitive.py b/lib_pypy/_ctypes/primitive.py
--- a/lib_pypy/_ctypes/primitive.py
+++ b/lib_pypy/_ctypes/primitive.py
@@ -393,9 +393,11 @@
_init_no_arg_ = __init__
def _ensure_objects(self):
- if self._type_ not in 'zZP':
- assert self._objects is None
- return self._objects
+ # No '_objects' is the common case for primitives. Examples
+ # where there is an _objects is if _type in 'zZP', or if
+ # self comes from 'from_buffer(buf)'. See module/test_lib_pypy/
+ # ctypes_test/test_buffers.py: test_from_buffer_keepalive.
+ return getattr(self, '_objects', None)
def _getvalue(self):
return self._buffer[0]
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_buffers.py
b/pypy/module/test_lib_pypy/ctypes_tests/test_buffers.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_buffers.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_buffers.py
@@ -39,6 +39,15 @@
assert b.value in (1684234849, # little endian
1633837924) # big endian
+ def test_from_buffer_keepalive(self):
+ # Issue #2878
+ b1 = bytearray("ab")
+ array = (c_uint16 * 32)()
+ array[6] = c_uint16.from_buffer(b1)
+ # this is also what we get on CPython. I don't think it makes
+ # sense because the array contains just a copy of the number.
+ assert array._objects == {'6': b1}
+
try:
c_wchar
except NameError:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit