Author: Ronan Lamy <ronan.l...@gmail.com> Branch: py3.5 Changeset: r87903:080540f91c5d Date: 2016-10-20 18:06 +0100 http://bitbucket.org/pypy/pypy/changeset/080540f91c5d/
Log: hg merge default 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 @@ -78,11 +78,16 @@ CONST_STRING = lltype.Ptr(lltype.Array(lltype.Char, hints={'nolength': True}), use_cache=False) +CONST_STRINGP = lltype.Ptr(lltype.Array(rffi.CCHARP, + hints={'nolength': True}), + use_cache=False) CONST_WSTRING = lltype.Ptr(lltype.Array(lltype.UniChar, hints={'nolength': True}), use_cache=False) assert CONST_STRING is not rffi.CCHARP assert CONST_STRING == rffi.CCHARP +assert CONST_STRINGP is not rffi.CCHARPP +assert CONST_STRINGP == rffi.CCHARPP assert CONST_WSTRING is not rffi.CWCHARP assert CONST_WSTRING == rffi.CWCHARP @@ -1006,6 +1011,8 @@ for i, argtype in enumerate(func.argtypes): if argtype is CONST_STRING: arg = 'const char *@' + elif argtype is CONST_STRINGP: + arg = 'const char **@' elif argtype is CONST_WSTRING: arg = 'const wchar_t *@' else: diff --git a/pypy/module/cpyext/memoryobject.py b/pypy/module/cpyext/memoryobject.py --- a/pypy/module/cpyext/memoryobject.py +++ b/pypy/module/cpyext/memoryobject.py @@ -1,6 +1,6 @@ from pypy.module.cpyext.api import (cpython_api, Py_buffer, CANNOT_FAIL, Py_MAX_FMT, Py_MAX_NDIMS, build_type_checkers, Py_ssize_tP) -from pypy.module.cpyext.pyobject import PyObject, make_ref, incref +from pypy.module.cpyext.pyobject import PyObject, make_ref, incref, from_ref from rpython.rtyper.lltypesystem import lltype, rffi from rpython.rlib.rarithmetic import widen from pypy.objspace.std.memoryobject import W_MemoryView @@ -106,11 +106,24 @@ def PyMemoryView_FromObject(space, w_obj): return space.call_method(space.builtin, "memoryview", w_obj) +@cpython_api([lltype.Ptr(Py_buffer)], PyObject) +def PyMemoryView_FromBuffer(space, view): + """Create a memoryview object wrapping the given buffer structure view. + The memoryview object then owns the buffer represented by view, which + means you shouldn't try to call PyBuffer_Release() yourself: it + will be done on deallocation of the memoryview object.""" + if not view.c_buf: + raise oefmt(space.w_ValueError, + "cannot make memory view from a buffer with a NULL data " + "pointer") + buf = CBuffer(space, view.c_buf, view.c_len, view.c_obj) + return space.wrap(W_MemoryView(buf)) + @cpython_api([PyObject], PyObject) def PyMemoryView_GET_BASE(space, w_obj): # return the obj field of the Py_buffer created by PyMemoryView_GET_BUFFER # XXX needed for numpy on py3k - raise NotImplementedError('PyMemoryView_GET_BUFFER') + raise NotImplementedError('PyMemoryView_GET_BASE') @cpython_api([PyObject], lltype.Ptr(Py_buffer), error=CANNOT_FAIL) def PyMemoryView_GET_BUFFER(space, w_obj): @@ -138,15 +151,3 @@ isstr = True return view -@cpython_api([lltype.Ptr(Py_buffer)], PyObject) -def PyMemoryView_FromBuffer(space, view): - """Create a memoryview object wrapping the given buffer structure view. - The memoryview object then owns the buffer represented by view, which - means you shouldn't try to call PyBuffer_Release() yourself: it - will be done on deallocation of the memoryview object.""" - if not view.c_buf: - raise oefmt(space.w_ValueError, - "cannot make memory view from a buffer with a NULL data " - "pointer") - buf = CBuffer(space, view.c_buf, view.c_len, view.c_obj) - return space.wrap(W_MemoryView(buf)) diff --git a/pypy/module/cpyext/methodobject.py b/pypy/module/cpyext/methodobject.py --- a/pypy/module/cpyext/methodobject.py +++ b/pypy/module/cpyext/methodobject.py @@ -301,7 +301,7 @@ def PyClassMethod_New(space, w_func): return space.wrap(ClassMethod(w_func)) -@cpython_api([PyObject, lltype.Ptr(PyMethodDef)], PyObject) +@cpython_api([PyTypeObjectPtr, lltype.Ptr(PyMethodDef)], PyObject) def PyDescr_NewMethod(space, w_type, method): return space.wrap(W_PyCMethodObject(space, method, w_type)) diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py --- a/pypy/module/cpyext/object.py +++ b/pypy/module/cpyext/object.py @@ -3,7 +3,7 @@ cpython_api, generic_cpy_call, CANNOT_FAIL, Py_ssize_t, Py_ssize_tP, PyVarObject, Py_buffer, size_t, Py_TPFLAGS_HEAPTYPE, Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, - Py_GE, CONST_STRING, FILEP, fwrite) + Py_GE, CONST_STRING, CONST_STRINGP, FILEP, fwrite) from pypy.module.cpyext.pyobject import ( PyObject, PyObjectP, create_ref, from_ref, Py_IncRef, Py_DecRef, get_typedescr, _Py_NewReference) @@ -426,7 +426,7 @@ is active then NULL is returned but PyErr_Occurred() will return false.""" return space.call_function(space.builtin.get('dir'), w_o) -@cpython_api([PyObject, rffi.CCHARPP, Py_ssize_tP], rffi.INT_real, error=-1) +@cpython_api([PyObject, CONST_STRINGP, Py_ssize_tP], rffi.INT_real, error=-1) def PyObject_AsCharBuffer(space, obj, bufferp, sizep): """Returns a pointer to a read-only memory location usable as character-based input. The obj argument must support the single-segment 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 @@ -29,6 +29,12 @@ assert w_view.c_len == 5 o = rffi.charp2str(w_view.c_buf) assert o == 'hello' + w_mv = api.PyMemoryView_FromBuffer(w_view) + for f in ('format', 'itemsize', 'ndim', 'readonly', + 'shape', 'strides', 'suboffsets'): + w_f = space.wrap(f) + assert space.eq_w(space.getattr(w_mv, w_f), + space.getattr(w_memoryview, w_f)) class AppTestPyBuffer_FillInfo(AppTestCpythonExtensionBase): def test_fillWithObject(self): diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py --- a/rpython/rlib/rposix.py +++ b/rpython/rlib/rposix.py @@ -236,6 +236,8 @@ 'utime.h', 'sys/time.h', 'sys/times.h', 'grp.h', 'dirent.h', 'sys/stat.h', 'fcntl.h', 'signal.h', 'sys/utsname.h', _ptyh] + if sys.platform.startswith('freebsd'): + includes.append('sys/ttycom.h') libraries = ['util'] eci = ExternalCompilationInfo( includes=includes, _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit