Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r89945:6a45f8963c90
Date: 2017-02-05 17:55 +0100
http://bitbucket.org/pypy/pypy/changeset/6a45f8963c90/
Log: hg merge default
diff --git a/lib_pypy/cffi/api.py b/lib_pypy/cffi/api.py
--- a/lib_pypy/cffi/api.py
+++ b/lib_pypy/cffi/api.py
@@ -93,6 +93,7 @@
# ctypes backend: attach these constants to the instance
self.NULL = self.cast(self.BVoidP, 0)
self.CData, self.CType = backend._get_types()
+ self.buffer = backend.buffer
def cdef(self, csource, override=False, packed=False):
"""Parse the given C source. This registers all declared functions,
@@ -316,18 +317,18 @@
"""
return self._backend.unpack(cdata, length)
- def buffer(self, cdata, size=-1):
- """Return a read-write buffer object that references the raw C data
- pointed to by the given 'cdata'. The 'cdata' must be a pointer or
- an array. Can be passed to functions expecting a buffer, or directly
- manipulated with:
-
- buf[:] get a copy of it in a regular string, or
- buf[idx] as a single character
- buf[:] = ...
- buf[idx] = ... change the content
- """
- return self._backend.buffer(cdata, size)
+ #def buffer(self, cdata, size=-1):
+ # """Return a read-write buffer object that references the raw C data
+ # pointed to by the given 'cdata'. The 'cdata' must be a pointer or
+ # an array. Can be passed to functions expecting a buffer, or directly
+ # manipulated with:
+ #
+ # buf[:] get a copy of it in a regular string, or
+ # buf[idx] as a single character
+ # buf[:] = ...
+ # buf[idx] = ... change the content
+ # """
+ # note that 'buffer' is a type, set on this instance by __init__
def from_buffer(self, python_buffer):
"""Return a <cdata 'char[]'> that points to the data of the
@@ -593,11 +594,15 @@
ensure('extra_link_args', '/MANIFEST')
def set_source(self, module_name, source, source_extension='.c', **kwds):
+ import os
if hasattr(self, '_assigned_source'):
raise ValueError("set_source() cannot be called several times "
"per ffi object")
if not isinstance(module_name, basestring):
raise TypeError("'module_name' must be a string")
+ if os.sep in module_name or (os.altsep and os.altsep in module_name):
+ raise ValueError("'module_name' must not contain '/': use a dotted
"
+ "name to make a 'package.module' location")
self._assigned_source = (str(module_name), source,
source_extension, kwds)
diff --git a/pypy/module/_cffi_backend/__init__.py
b/pypy/module/_cffi_backend/__init__.py
--- a/pypy/module/_cffi_backend/__init__.py
+++ b/pypy/module/_cffi_backend/__init__.py
@@ -50,7 +50,7 @@
'string': 'func.string',
'unpack': 'func.unpack',
- 'buffer': 'cbuffer.buffer',
+ 'buffer': 'cbuffer.MiniBuffer',
'memmove': 'func.memmove',
'get_errno': 'cerrno.get_errno',
diff --git a/pypy/module/_cffi_backend/cbuffer.py
b/pypy/module/_cffi_backend/cbuffer.py
--- a/pypy/module/_cffi_backend/cbuffer.py
+++ b/pypy/module/_cffi_backend/cbuffer.py
@@ -75,18 +75,8 @@
self.buffer.setslice(start, value.as_str())
-MiniBuffer.typedef = TypeDef(
- "_cffi_backend.buffer",
- __len__ = interp2app(MiniBuffer.descr_len),
- __getitem__ = interp2app(MiniBuffer.descr_getitem),
- __setitem__ = interp2app(MiniBuffer.descr_setitem),
- __weakref__ = make_weakref_descr(MiniBuffer),
- )
-MiniBuffer.typedef.acceptable_as_base_class = False
-
-
@unwrap_spec(w_cdata=cdataobj.W_CData, size=int)
-def buffer(space, w_cdata, size=-1):
+def MiniBuffer___new__(space, w_subtype, w_cdata, size=-1):
ctype = w_cdata.ctype
if isinstance(ctype, ctypeptr.W_CTypePointer):
if size < 0:
@@ -107,3 +97,24 @@
"don't know the size pointed to by '%s'", ctype.name)
ptr = w_cdata.unsafe_escaping_ptr() # w_cdata kept alive by MiniBuffer()
return space.wrap(MiniBuffer(LLBuffer(ptr, size), w_cdata))
+
+MiniBuffer.typedef = TypeDef(
+ "_cffi_backend.buffer",
+ __new__ = interp2app(MiniBuffer___new__),
+ __len__ = interp2app(MiniBuffer.descr_len),
+ __getitem__ = interp2app(MiniBuffer.descr_getitem),
+ __setitem__ = interp2app(MiniBuffer.descr_setitem),
+ __weakref__ = make_weakref_descr(MiniBuffer),
+ __doc__ = """ffi.buffer(cdata[, byte_size]):
+Return a read-write buffer object that references the raw C data
+pointed to by the given 'cdata'. The 'cdata' must be a pointer or an
+array. Can be passed to functions expecting a buffer, or directly
+manipulated with:
+
+ buf[:] get a copy of it in a regular string, or
+ buf[idx] as a single character
+ buf[:] = ...
+ buf[idx] = ... change the content
+""",
+ )
+MiniBuffer.typedef.acceptable_as_base_class = False
diff --git a/pypy/module/_cffi_backend/ffi_obj.py
b/pypy/module/_cffi_backend/ffi_obj.py
--- a/pypy/module/_cffi_backend/ffi_obj.py
+++ b/pypy/module/_cffi_backend/ffi_obj.py
@@ -265,22 +265,6 @@
return self.space.wrap(align)
- @unwrap_spec(w_cdata=W_CData, size=int)
- def descr_buffer(self, w_cdata, size=-1):
- """\
-Return a read-write buffer object that references the raw C data
-ointed to by the given 'cdata'. The 'cdata' must be a pointer or an
-array. Can be passed to functions expecting a buffer, or directly
-manipulated with:
-
- buf[:] get a copy of it in a regular string, or
- buf[idx] as a single character
- buf[:] = ...
- buf[idx] = ... change the content"""
- #
- return cbuffer.buffer(self.space, w_cdata, size)
-
-
@unwrap_spec(w_name=WrappedDefault(None),
w_error=WrappedDefault(None),
w_onerror=WrappedDefault(None))
@@ -751,6 +735,9 @@
return space.appexec([], """():
return type('error', (Exception,), {'__module__': 'ffi'})""")
+def make_buffer(space):
+ return space.gettypefor(cbuffer.MiniBuffer)
+
_extras = get_dict_rtld_constants()
if sys.platform == 'win32':
_extras['getwinerror'] = interp2app(W_FFIObject.descr_getwinerror)
@@ -770,7 +757,7 @@
cls=W_FFIObject),
addressof = interp2app(W_FFIObject.descr_addressof),
alignof = interp2app(W_FFIObject.descr_alignof),
- buffer = interp2app(W_FFIObject.descr_buffer),
+ buffer = ClassAttr(make_buffer),
callback = interp2app(W_FFIObject.descr_callback),
cast = interp2app(W_FFIObject.descr_cast),
def_extern = interp2app(W_FFIObject.descr_def_extern),
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -2288,6 +2288,7 @@
buf = buffer(c)
assert repr(buf).startswith('<_cffi_backend.buffer object at 0x')
assert bytes(buf) == b"hi there\x00"
+ assert type(buf) is buffer
if sys.version_info < (3,):
assert str(buf) == "hi there\x00"
assert unicode(buf) == u+"hi there\x00"
diff --git a/pypy/module/_cffi_backend/test/test_ffi_obj.py
b/pypy/module/_cffi_backend/test/test_ffi_obj.py
--- a/pypy/module/_cffi_backend/test/test_ffi_obj.py
+++ b/pypy/module/_cffi_backend/test/test_ffi_obj.py
@@ -256,6 +256,8 @@
ffi = _cffi1_backend.FFI()
a = ffi.new("signed char[]", [5, 6, 7])
assert ffi.buffer(a)[:] == b'\x05\x06\x07'
+ assert ffi.buffer(cdata=a, size=2)[:] == b'\x05\x06'
+ assert type(ffi.buffer(a)) is ffi.buffer
def test_ffi_from_buffer(self):
import _cffi_backend as _cffi1_backend
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
@@ -1078,7 +1078,8 @@
struct PyPyAPI {
%(members)s
} _pypyAPI;
- RPY_EXTERN struct PyPyAPI* pypyAPI = &_pypyAPI;
+ RPY_EXTERN struct PyPyAPI* pypyAPI;
+ struct PyPyAPI* pypyAPI = &_pypyAPI;
""" % dict(members=structmembers)
global_objects = []
diff --git a/pypy/module/cpyext/genobject.py b/pypy/module/cpyext/genobject.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/genobject.py
@@ -0,0 +1,5 @@
+from pypy.interpreter.generator import GeneratorIterator
+from pypy.module.cpyext.api import build_type_checkers
+
+
+PyGen_Check, PyGen_CheckExact = build_type_checkers("Gen", GeneratorIterator)
diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py
--- a/pypy/module/cpyext/stubs.py
+++ b/pypy/module/cpyext/stubs.py
@@ -660,17 +660,6 @@
extension modules."""
raise NotImplementedError
-@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
-def PyGen_Check(space, ob):
- """Return true if ob is a generator object; ob must not be NULL."""
- raise NotImplementedError
-
-@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
-def PyGen_CheckExact(space, ob):
- """Return true if ob's type is PyGen_Type is a generator object; ob must
not
- be NULL."""
- raise NotImplementedError
-
@cpython_api([PyFrameObject], PyObject)
def PyGen_New(space, frame):
"""Create and return a new generator object based on the frame object. A
diff --git a/pypy/module/cpyext/test/test_genobject.py
b/pypy/module/cpyext/test/test_genobject.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/test/test_genobject.py
@@ -0,0 +1,15 @@
+from pypy.module.cpyext.test.test_api import BaseApiTest
+from pypy.module.cpyext.genobject import PyGen_Check, PyGen_CheckExact
+
+
+class TestGenObject(BaseApiTest):
+ def test_genobject(self, space):
+ w_geniter = space.appexec([], """():
+ def f():
+ yield 42
+ return f()
+ """)
+ assert PyGen_Check(space, w_geniter)
+ assert PyGen_CheckExact(space, w_geniter)
+ assert not PyGen_Check(space, space.wrap(2))
+ assert not PyGen_CheckExact(space, space.wrap("b"))
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi0/backend_tests.py
b/pypy/module/test_lib_pypy/cffi_tests/cffi0/backend_tests.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi0/backend_tests.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/cffi0/backend_tests.py
@@ -1131,6 +1131,7 @@
b = ffi.buffer(a)
except NotImplementedError as e:
py.test.skip(str(e))
+ assert type(b) is ffi.buffer
content = b[:]
assert len(content) == len(b) == 2
if sys.byteorder == 'little':
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_ffi_obj.py
b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_ffi_obj.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_ffi_obj.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_ffi_obj.py
@@ -234,6 +234,7 @@
a = ffi.new("signed char[]", [5, 6, 7])
assert ffi.buffer(a)[:] == b'\x05\x06\x07'
assert ffi.buffer(cdata=a, size=2)[:] == b'\x05\x06'
+ assert type(ffi.buffer(a)) is ffi.buffer
def test_ffi_from_buffer():
import array
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
@@ -37,6 +37,11 @@
['-Werror'])
return recompiler._verify(ffi, module_name, source, *args, **kwds)
+def test_set_source_no_slashes():
+ ffi = FFI()
+ py.test.raises(ValueError, ffi.set_source, "abc/def", None)
+ py.test.raises(ValueError, ffi.set_source, "abc/def", "C code")
+
def test_type_table_func():
check_type_table("double sin(double);",
diff --git a/rpython/rlib/rposix_stat.py b/rpython/rlib/rposix_stat.py
--- a/rpython/rlib/rposix_stat.py
+++ b/rpython/rlib/rposix_stat.py
@@ -602,7 +602,7 @@
if rposix.HAVE_FSTATAT:
from rpython.rlib.rposix import AT_FDCWD, AT_SYMLINK_NOFOLLOW
- c_fstatat = rffi.llexternal('fstatat',
+ c_fstatat = rffi.llexternal('fstatat64' if _LINUX else 'fstatat',
[rffi.INT, rffi.CCHARP, STAT_STRUCT, rffi.INT], rffi.INT,
compilation_info=compilation_info,
save_err=rffi.RFFI_SAVE_ERRNO, macro=True)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit