Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r89885:761e1ebb572b
Date: 2017-02-01 15:24 +0100
http://bitbucket.org/pypy/pypy/changeset/761e1ebb572b/
Log: hg merge default
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
@@ -92,7 +92,11 @@
% (buf.nbytes, offset + size))
raw_addr = buf._pypy_raw_address() + offset
result = self.from_address(raw_addr)
- result._ensure_objects()['ffffffff'] = obj
+ objects = result._ensure_objects()
+ if objects is not None:
+ objects['ffffffff'] = obj
+ else: # case e.g. of a primitive type like c_int
+ result._objects = obj
return result
def from_buffer_copy(self, obj, offset=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
@@ -24,6 +24,16 @@
assert b[0] == "a"
assert b[:] == "abc\0"
+ def test_from_buffer(self):
+ b1 = bytearray("abcde")
+ b = (c_char * 5).from_buffer(b1)
+ assert b[2] == "c"
+ #
+ b1 = bytearray("abcd")
+ b = c_int.from_buffer(b1)
+ assert b.value in (1684234849, # little endian
+ 1633837924) # big endian
+
try:
c_wchar
except NameError:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit