[pypy-commit] pypy.org extradoc: update the values
Author: Armin RigoBranch: extradoc Changeset: r832:6e0717c2 Date: 2016-12-12 10:17 +0100 http://bitbucket.org/pypy/pypy.org/changeset/6e0717c2/ Log:update the values diff --git a/don4.html b/don4.html --- a/don4.html +++ b/don4.html @@ -17,7 +17,7 @@ 2nd call: - $59010 of $8 (73.8%) + $59030 of $8 (73.8%) @@ -29,7 +29,7 @@
[pypy-commit] pypy py3.5: merge heads
Author: Armin RigoBranch: py3.5 Changeset: r89017:310d51b5e3ba Date: 2016-12-12 13:46 +0100 http://bitbucket.org/pypy/pypy/changeset/310d51b5e3ba/ Log:merge heads diff --git a/pypy/module/cpyext/structmember.py b/pypy/module/cpyext/structmember.py --- a/pypy/module/cpyext/structmember.py +++ b/pypy/module/cpyext/structmember.py @@ -93,7 +93,7 @@ if (flags & READONLY or member_type in [T_STRING, T_STRING_INPLACE]): -raise oefmt(space.w_TypeError, "readonly attribute") +raise oefmt(space.w_AttributeError, "readonly attribute") elif w_value is None: if member_type == T_OBJECT_EX: if not rffi.cast(PyObjectP, addr)[0]: diff --git a/pypy/module/cpyext/test/test_typeobject.py b/pypy/module/cpyext/test/test_typeobject.py --- a/pypy/module/cpyext/test/test_typeobject.py +++ b/pypy/module/cpyext/test/test_typeobject.py @@ -310,7 +310,7 @@ ("setattr", "METH_O", ''' int ret; -PyObject* name = PyString_FromString("mymodule"); +PyObject* name = PyBytes_FromString("mymodule"); PyObject *obj = PyType_Type.tp_alloc(_Type, 0); PyHeapTypeObject *type = (PyHeapTypeObject*)obj; if ((type->ht_type.tp_flags & Py_TPFLAGS_HEAPTYPE) == 0) @@ -1152,7 +1152,7 @@ Base2->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE; Base12->tp_flags = Py_TPFLAGS_DEFAULT; Base12->tp_base = Base1; -Base12->tp_bases = PyTuple_Pack(2, Base1, Base2); +Base12->tp_bases = PyTuple_Pack(2, Base1, Base2); Base12->tp_doc = "The Base12 type or object"; if (PyType_Ready(Base1) < 0) return NULL; if (PyType_Ready(Base2) < 0) return NULL; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: hg merge default
Author: Armin RigoBranch: py3.5 Changeset: r89016:e45017387ad8 Date: 2016-12-12 13:45 +0100 http://bitbucket.org/pypy/pypy/changeset/e45017387ad8/ Log:hg merge default diff --git a/lib_pypy/greenlet.egg-info b/lib_pypy/greenlet.egg-info --- a/lib_pypy/greenlet.egg-info +++ b/lib_pypy/greenlet.egg-info @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: greenlet -Version: 0.4.10 +Version: 0.4.11 Summary: Lightweight in-process concurrent programming Home-page: https://github.com/python-greenlet/greenlet Author: Ralf Schmitt (for CPython), PyPy team diff --git a/lib_pypy/greenlet.py b/lib_pypy/greenlet.py --- a/lib_pypy/greenlet.py +++ b/lib_pypy/greenlet.py @@ -2,7 +2,7 @@ import __pypy__ import _continuation -__version__ = "0.4.10" +__version__ = "0.4.11" # # Exceptions diff --git a/pypy/interpreter/test/test_pyframe.py b/pypy/interpreter/test/test_pyframe.py --- a/pypy/interpreter/test/test_pyframe.py +++ b/pypy/interpreter/test/test_pyframe.py @@ -663,6 +663,8 @@ g() sys.settrace(None) print('seen:', seen) +# on Python 3 we get an extra 'exception' when 'for' catches +# StopIteration assert seen == ['call', 'line', 'call', 'return', 'exception', 'return'] def test_clear_locals(self): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: A passing test which fails on py3.5
Author: Armin RigoBranch: Changeset: r89015:ee017a393e9e Date: 2016-12-12 13:44 +0100 http://bitbucket.org/pypy/pypy/changeset/ee017a393e9e/ Log:A passing test which fails on py3.5 diff --git a/pypy/interpreter/test/test_pyframe.py b/pypy/interpreter/test/test_pyframe.py --- a/pypy/interpreter/test/test_pyframe.py +++ b/pypy/interpreter/test/test_pyframe.py @@ -580,3 +580,25 @@ pass sys.settrace(None) assert seen == ['call', 'exception', 'return'] + +def test_generator_trace_stopiteration(self): +import sys +def f(): +yield 5 +gen = f() +assert next(gen) == 5 +seen = [] +def trace_func(frame, event, *args): +print('TRACE:', frame, event, args) +seen.append(event) +return trace_func +def g(): +for x in gen: +never_entered +sys.settrace(trace_func) +g() +sys.settrace(None) +print 'seen:', seen +# on Python 3 we get an extra 'exception' when 'for' catches +# StopIteration +assert seen == ['call', 'line', 'call', 'return', 'return'] ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: Test for missing the internal StopIteration
Author: Armin RigoBranch: py3.5 Changeset: r89014:3a45764f6ee1 Date: 2016-12-12 12:53 +0100 http://bitbucket.org/pypy/pypy/changeset/3a45764f6ee1/ Log:Test for missing the internal StopIteration diff --git a/pypy/interpreter/test/test_pyframe.py b/pypy/interpreter/test/test_pyframe.py --- a/pypy/interpreter/test/test_pyframe.py +++ b/pypy/interpreter/test/test_pyframe.py @@ -645,6 +645,26 @@ sys.settrace(None) assert seen == ['call', 'exception', 'return'] +def test_generator_trace_stopiteration(self): +import sys +def f(): +yield 5 +gen = f() +assert next(gen) == 5 +seen = [] +def trace_func(frame, event, *args): +print('TRACE:', frame, event, args) +seen.append(event) +return trace_func +def g(): +for x in gen: +never_entered +sys.settrace(trace_func) +g() +sys.settrace(None) +print('seen:', seen) +assert seen == ['call', 'line', 'call', 'return', 'exception', 'return'] + def test_clear_locals(self): def make_frames(): def outer(): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: Fix exception type when trying to delete a readonly member
Author: Ronan LamyBranch: py3.5 Changeset: r89013:db801833173a Date: 2016-12-12 11:55 + http://bitbucket.org/pypy/pypy/changeset/db801833173a/ Log:Fix exception type when trying to delete a readonly member diff --git a/pypy/module/cpyext/structmember.py b/pypy/module/cpyext/structmember.py --- a/pypy/module/cpyext/structmember.py +++ b/pypy/module/cpyext/structmember.py @@ -93,7 +93,7 @@ if (flags & READONLY or member_type in [T_STRING, T_STRING_INPLACE]): -raise oefmt(space.w_TypeError, "readonly attribute") +raise oefmt(space.w_AttributeError, "readonly attribute") elif w_value is None: if member_type == T_OBJECT_EX: if not rffi.cast(PyObjectP, addr)[0]: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: fix for 3a45764f6ee1
Author: Armin RigoBranch: py3.5 Changeset: r89018:3840ecbe977d Date: 2016-12-12 13:51 +0100 http://bitbucket.org/pypy/pypy/changeset/3840ecbe977d/ Log:fix for 3a45764f6ee1 diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py --- a/pypy/interpreter/pyopcode.py +++ b/pypy/interpreter/pyopcode.py @@ -1154,6 +1154,7 @@ if not e.match(self.space, self.space.w_StopIteration): raise # iterator exhausted +self.space.getexecutioncontext().exception_trace(self, e) self.popvalue() next_instr += jumpby else: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy better-PyDict_Next: add a passing test, does not exercise the c-level getter (which is NULL but should not be)
Author: Matti PicusBranch: better-PyDict_Next Changeset: r89022:0bd4f1974653 Date: 2016-12-12 16:18 +0200 http://bitbucket.org/pypy/pypy/changeset/0bd4f1974653/ Log:add a passing test, does not exercise the c-level getter (which is NULL but should not be) diff --git a/pypy/module/cpyext/test/test_dictobject.py b/pypy/module/cpyext/test/test_dictobject.py --- a/pypy/module/cpyext/test/test_dictobject.py +++ b/pypy/module/cpyext/test/test_dictobject.py @@ -181,7 +181,7 @@ raises(OperationError, space.call_method, w_proxy, 'clear') assert api.PyDictProxy_Check(w_proxy) -def test_typedict(self, space, api): +def test_typedict1(self, space, api): py_type = make_ref(space, space.w_int) py_dict = rffi.cast(PyTypeObjectPtr, py_type).c_tp_dict ppos = lltype.malloc(Py_ssize_tP.TO, 1, flavor='raw') @@ -246,3 +246,17 @@ d = {"a": 1} raises(AttributeError, module.update, d, [("c", 2)]) +def test_typedict2(self): +module = self.import_extension('foo', [ +("get_type_dict", "METH_O", + ''' +PyObject* value = args->ob_type->tp_dict; +if (value == NULL) value = Py_None; +Py_INCREF(value); +return value; + '''), +]) +d = module.get_type_dict(1) +print type(d['real']) +assert d['real'].__get__(1, 1) == 1 + ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: fix pickling reversed(list)
Author: Armin RigoBranch: py3.5 Changeset: r89023:fc7ceff2ed1f Date: 2016-12-12 15:03 +0100 http://bitbucket.org/pypy/pypy/changeset/fc7ceff2ed1f/ Log:fix pickling reversed(list) diff --git a/pypy/objspace/std/iterobject.py b/pypy/objspace/std/iterobject.py --- a/pypy/objspace/std/iterobject.py +++ b/pypy/objspace/std/iterobject.py @@ -164,7 +164,6 @@ index = space.int_w(w_state) if self.w_seq is not None: length = space.int_w(space.len(self.w_seq)) -if index < 0: index = 0 if index >= length: index = length-1 self.index = index diff --git a/pypy/objspace/std/test/test_iterobject.py b/pypy/objspace/std/test/test_iterobject.py --- a/pypy/objspace/std/test/test_iterobject.py +++ b/pypy/objspace/std/test/test_iterobject.py @@ -82,6 +82,17 @@ assert next(iterable) == 1 iterable.__setstate__(3) assert next(iterable) == 4 +iterable.__setstate__(-1) +raises(StopIteration, next, iterable) +# +iterable = reversed([1,2,3,4]) +iterable.__setstate__(-100) +raises(StopIteration, next, iterable) +# +iterable = reversed([1,2,3,4]) +iterable.__setstate__(100) +assert next(iterable) == 4 +assert next(iterable) == 3 def test_forward_iter_reduce(self): T = "abc" ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy better-PyDict_Next: merge default into branch
Author: Matti PicusBranch: better-PyDict_Next Changeset: r89024:d9b07fbc433c Date: 2016-12-12 16:23 +0200 http://bitbucket.org/pypy/pypy/changeset/d9b07fbc433c/ Log:merge default into branch diff --git a/pypy/interpreter/test/test_unicodehelper.py b/pypy/interpreter/test/test_unicodehelper.py new file mode 100644 --- /dev/null +++ b/pypy/interpreter/test/test_unicodehelper.py @@ -0,0 +1,26 @@ +from pypy.interpreter.unicodehelper import encode_utf8, decode_utf8 + +class FakeSpace: +pass + +def test_encode_utf8(): +space = FakeSpace() +assert encode_utf8(space, u"abc") == "abc" +assert encode_utf8(space, u"\u1234") == "\xe1\x88\xb4" +assert encode_utf8(space, u"\ud800") == "\xed\xa0\x80" +assert encode_utf8(space, u"\udc00") == "\xed\xb0\x80" +# for the following test, go to lengths to avoid CPython's optimizer +# and .pyc file storage, which collapse the two surrogates into one +c = u"\udc00" +assert encode_utf8(space, u"\ud800" + c) == "\xf0\x90\x80\x80" + +def test_decode_utf8(): +space = FakeSpace() +assert decode_utf8(space, "abc") == u"abc" +assert decode_utf8(space, "\xe1\x88\xb4") == u"\u1234" +assert decode_utf8(space, "\xed\xa0\x80") == u"\ud800" +assert decode_utf8(space, "\xed\xb0\x80") == u"\udc00" +got = decode_utf8(space, "\xed\xa0\x80\xed\xb0\x80") +assert map(ord, got) == [0xd800, 0xdc00] +got = decode_utf8(space, "\xf0\x90\x80\x80") +assert map(ord, got) == [0x1] diff --git a/pypy/interpreter/unicodehelper.py b/pypy/interpreter/unicodehelper.py --- a/pypy/interpreter/unicodehelper.py +++ b/pypy/interpreter/unicodehelper.py @@ -51,6 +51,10 @@ return result def decode_utf8(space, string): +# Surrogates are accepted and not treated specially at all. +# If there happen to be two 3-bytes encoding a pair of surrogates, +# you still get two surrogate unicode characters in the result. +# These are the Python2 rules; Python3 differs. result, consumed = runicode.str_decode_utf_8( string, len(string), "strict", final=True, errorhandler=decode_error_handler(space), @@ -59,8 +63,9 @@ def encode_utf8(space, uni): # Note that this function never raises UnicodeEncodeError, -# since surrogate pairs are allowed. -# This is not the case with Python3. +# since surrogates are allowed, either paired or lone. +# A paired surrogate is considered like the non-BMP character +# it stands for. These are the Python2 rules; Python3 differs. return runicode.unicode_encode_utf_8( uni, len(uni), "strict", errorhandler=raise_unicode_exception_encode, diff --git a/pypy/module/cpyext/pyobject.py b/pypy/module/cpyext/pyobject.py --- a/pypy/module/cpyext/pyobject.py +++ b/pypy/module/cpyext/pyobject.py @@ -25,11 +25,9 @@ basestruct = PyObject.TO W_BaseObject = W_ObjectObject -def get_dealloc(self, space): +def get_dealloc(self): from pypy.module.cpyext.typeobject import subtype_dealloc -return llhelper( -subtype_dealloc.api_func.functype, -subtype_dealloc.api_func.get_wrapper(space)) +return subtype_dealloc def allocate(self, space, w_type, itemcount=0): # similar to PyType_GenericAlloc? @@ -109,10 +107,8 @@ return tp_alloc(space, w_type, itemcount) if tp_dealloc: -def get_dealloc(self, space): -return llhelper( -tp_dealloc.api_func.functype, -tp_dealloc.api_func.get_wrapper(space)) +def get_dealloc(self): +return tp_dealloc if tp_attach: def attach(self, space, pyobj, w_obj, w_userdata=None): diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py --- a/pypy/module/cpyext/slotdefs.py +++ b/pypy/module/cpyext/slotdefs.py @@ -59,6 +59,9 @@ "expected %d-%d arguments, got %d", low, high, space.len_w(w_ob)) +def llslot(space, func): +return llhelper(func.api_func.functype, func.api_func.get_wrapper(space)) + def wrap_init(space, w_self, w_args, func, w_kwargs): func_init = rffi.cast(initproc, func) res = generic_cpy_call(space, func_init, w_self, w_args, w_kwargs) @@ -106,7 +109,7 @@ args_w = space.fixedview(w_args) arg3 = space.w_None if len(args_w) > 1: -arg3 = args_w[1] +arg3 = args_w[1] return generic_cpy_call(space, func_ternary, w_self, args_w[0], arg3) def wrap_ternaryfunc_r(space, w_self, w_args, func): @@ -121,7 +124,7 @@ Py_DecRef(space, ref) arg3 = space.w_None if len(args_w) > 1: -arg3 = args_w[1] +arg3 = args_w[1] return generic_cpy_call(space, func_ternary, args_w[0], w_self, arg3) @@ -322,7 +325,7 @@ self.strides = [1] else: self.strides = strides -self.ndim = ndim +self.ndim =
[pypy-commit] pypy better-PyDict_Next: merge default into branch
Author: Matti PicusBranch: better-PyDict_Next Changeset: r89027:c32d9bbf4564 Date: 2016-12-12 17:24 +0200 http://bitbucket.org/pypy/pypy/changeset/c32d9bbf4564/ Log:merge default into branch diff --git a/lib_pypy/greenlet.egg-info b/lib_pypy/greenlet.egg-info --- a/lib_pypy/greenlet.egg-info +++ b/lib_pypy/greenlet.egg-info @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: greenlet -Version: 0.4.10 +Version: 0.4.11 Summary: Lightweight in-process concurrent programming Home-page: https://github.com/python-greenlet/greenlet Author: Ralf Schmitt (for CPython), PyPy team diff --git a/lib_pypy/greenlet.py b/lib_pypy/greenlet.py --- a/lib_pypy/greenlet.py +++ b/lib_pypy/greenlet.py @@ -1,7 +1,7 @@ import sys import _continuation -__version__ = "0.4.10" +__version__ = "0.4.11" # # Exceptions diff --git a/pypy/interpreter/test/test_pyframe.py b/pypy/interpreter/test/test_pyframe.py --- a/pypy/interpreter/test/test_pyframe.py +++ b/pypy/interpreter/test/test_pyframe.py @@ -580,3 +580,25 @@ pass sys.settrace(None) assert seen == ['call', 'exception', 'return'] + +def test_generator_trace_stopiteration(self): +import sys +def f(): +yield 5 +gen = f() +assert next(gen) == 5 +seen = [] +def trace_func(frame, event, *args): +print('TRACE:', frame, event, args) +seen.append(event) +return trace_func +def g(): +for x in gen: +never_entered +sys.settrace(trace_func) +g() +sys.settrace(None) +print 'seen:', seen +# on Python 3 we get an extra 'exception' when 'for' catches +# StopIteration +assert seen == ['call', 'line', 'call', 'return', 'return'] diff --git a/pypy/module/cpyext/pyobject.py b/pypy/module/cpyext/pyobject.py --- a/pypy/module/cpyext/pyobject.py +++ b/pypy/module/cpyext/pyobject.py @@ -27,7 +27,7 @@ def get_dealloc(self): from pypy.module.cpyext.typeobject import subtype_dealloc -return subtype_dealloc +return subtype_dealloc.api_func def allocate(self, space, w_type, itemcount=0): # similar to PyType_GenericAlloc? @@ -108,7 +108,7 @@ if tp_dealloc: def get_dealloc(self): -return tp_dealloc +return tp_dealloc.api_func if tp_attach: def attach(self, space, pyobj, w_obj, w_userdata=None): diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py --- a/pypy/module/cpyext/slotdefs.py +++ b/pypy/module/cpyext/slotdefs.py @@ -8,12 +8,12 @@ cpython_api, generic_cpy_call, PyObject, Py_ssize_t, Py_TPFLAGS_CHECKTYPES, mangle_name, pypy_decl, Py_buffer, Py_bufferP) from pypy.module.cpyext.typeobjectdefs import ( -unaryfunc, wrapperfunc, ternaryfunc, PyTypeObjectPtr, binaryfunc, ternaryfunc, +unaryfunc, ternaryfunc, PyTypeObjectPtr, binaryfunc, getattrfunc, getattrofunc, setattrofunc, lenfunc, ssizeargfunc, inquiry, ssizessizeargfunc, ssizeobjargproc, iternextfunc, initproc, richcmpfunc, cmpfunc, hashfunc, descrgetfunc, descrsetfunc, objobjproc, objobjargproc, readbufferproc, getbufferproc, ssizessizeobjargproc) -from pypy.module.cpyext.pyobject import from_ref, make_ref, Py_DecRef +from pypy.module.cpyext.pyobject import make_ref, Py_DecRef from pypy.module.cpyext.pyerrors import PyErr_Occurred from pypy.module.cpyext.memoryobject import fill_Py_buffer from pypy.module.cpyext.state import State @@ -21,8 +21,10 @@ from pypy.interpreter.argument import Arguments from rpython.rlib.buffer import Buffer from rpython.rlib.unroll import unrolling_iterable -from rpython.rlib.objectmodel import specialize +from rpython.rlib.objectmodel import specialize, not_rpython from rpython.tool.sourcetools import func_renamer +from rpython.flowspace.model import Constant +from rpython.flowspace.specialcase import register_flow_sc from rpython.rtyper.annlowlevel import llhelper from pypy.module.sys.version import CPYTHON_VERSION @@ -59,9 +61,17 @@ "expected %d-%d arguments, got %d", low, high, space.len_w(w_ob)) +@not_rpython def llslot(space, func): return llhelper(func.api_func.functype, func.api_func.get_wrapper(space)) +@register_flow_sc(llslot) +def sc_llslot(ctx, v_space, v_func): +assert isinstance(v_func, Constant) +get_llhelper = v_func.value.api_func.get_llhelper +return ctx.appcall(get_llhelper, v_space) + + def wrap_init(space, w_self, w_args, func, w_kwargs): func_init = rffi.cast(initproc, func) res = generic_cpy_call(space, func_init, w_self, w_args, w_kwargs) @@ -440,9 +450,10 @@ try: return SLOTS[key] except KeyError: -ret = build_slot_tp_function(space, typedef, name) -SLOTS[key] = ret -return ret +
[pypy-commit] pypy better-PyDict_Next: cleanup
Author: Matti PicusBranch: better-PyDict_Next Changeset: r89026:1d0306628f20 Date: 2016-12-12 16:39 +0200 http://bitbucket.org/pypy/pypy/changeset/1d0306628f20/ Log:cleanup diff --git a/pypy/module/cpyext/test/test_dictobject.py b/pypy/module/cpyext/test/test_dictobject.py --- a/pypy/module/cpyext/test/test_dictobject.py +++ b/pypy/module/cpyext/test/test_dictobject.py @@ -257,6 +257,5 @@ '''), ]) d = module.get_type_dict(1) -print type(d['real']) assert d['real'].__get__(1, 1) == 1 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: fix pickling deque_iterator and deque_reverse_iterator
Author: Armin RigoBranch: py3.5 Changeset: r89021:e47c8f353a9e Date: 2016-12-12 14:54 +0100 http://bitbucket.org/pypy/pypy/changeset/e47c8f353a9e/ Log:fix pickling deque_iterator and deque_reverse_iterator diff --git a/pypy/module/_collections/interp_deque.py b/pypy/module/_collections/interp_deque.py --- a/pypy/module/_collections/interp_deque.py +++ b/pypy/module/_collections/interp_deque.py @@ -610,6 +610,14 @@ self.lock = deque.getlock() check_nonneg(self.index) +def _move_to(self, index): +if index < 0: +return +self.counter = self.deque.len - index +if self.counter <= 0: +return +self.block, self.index = self.deque.locate(index) + def iter(self): return self.space.wrap(self) @@ -621,7 +629,7 @@ if self.lock is not self.deque.lock: self.counter = 0 raise oefmt(space.w_RuntimeError, "deque mutated during iteration") -if self.counter == 0: +if self.counter <= 0: raise OperationError(space.w_StopIteration, space.w_None) self.counter -= 1 ri = self.index @@ -634,15 +642,19 @@ return w_x def reduce(self): +w_i = self.space.wrap(self.deque.len - self.counter) return self.space.newtuple([self.space.gettypefor(W_DequeIter), -self.space.newtuple([self.deque])]) +self.space.newtuple([self.deque, w_i])]) -def W_DequeIter__new__(space, w_subtype, w_deque): +@unwrap_spec(index=int) +def W_DequeIter__new__(space, w_subtype, w_deque, index=0): w_self = space.allocate_instance(W_DequeIter, w_subtype) if not isinstance(w_deque, W_Deque): raise oefmt(space.w_TypeError, "must be collections.deque, not %T", w_deque) -W_DequeIter.__init__(space.interp_w(W_DequeIter, w_self), w_deque) +self = space.interp_w(W_DequeIter, w_self) +W_DequeIter.__init__(self, w_deque) +self._move_to(index) return w_self W_DequeIter.typedef = TypeDef("_collections.deque_iterator", @@ -666,6 +678,14 @@ self.lock = deque.getlock() check_nonneg(self.index) +def _move_to(self, index): +if index < 0: +return +self.counter = self.deque.len - index +if self.counter <= 0: +return +self.block, self.index = self.deque.locate(self.counter - 1) + def iter(self): return self.space.wrap(self) @@ -677,7 +697,7 @@ if self.lock is not self.deque.lock: self.counter = 0 raise oefmt(space.w_RuntimeError, "deque mutated during iteration") -if self.counter == 0: +if self.counter <= 0: raise OperationError(space.w_StopIteration, space.w_None) self.counter -= 1 ri = self.index @@ -690,15 +710,19 @@ return w_x def reduce(self): +w_i = self.space.wrap(self.deque.len - self.counter) return self.space.newtuple([self.space.gettypefor(W_DequeRevIter), -self.space.newtuple([self.deque])]) +self.space.newtuple([self.deque, w_i])]) -def W_DequeRevIter__new__(space, w_subtype, w_deque): +@unwrap_spec(index=int) +def W_DequeRevIter__new__(space, w_subtype, w_deque, index=0): w_self = space.allocate_instance(W_DequeRevIter, w_subtype) if not isinstance(w_deque, W_Deque): raise oefmt(space.w_TypeError, "must be collections.deque, not %T", w_deque) -W_DequeRevIter.__init__(space.interp_w(W_DequeRevIter, w_self), w_deque) +self = space.interp_w(W_DequeRevIter, w_self) +W_DequeRevIter.__init__(self, w_deque) +self._move_to(index) return w_self W_DequeRevIter.typedef = TypeDef("_collections.deque_reverse_iterator", diff --git a/pypy/module/_collections/test/test_deque.py b/pypy/module/_collections/test/test_deque.py --- a/pypy/module/_collections/test/test_deque.py +++ b/pypy/module/_collections/test/test_deque.py @@ -331,18 +331,28 @@ def test_DequeIter_pickle(self): from _collections import deque import pickle -d = deque([1,2,3]) -iterator = iter(d) -copy = pickle.loads(pickle.dumps(iterator)) -assert list(iterator) == list(copy) +for i in range(4): +d = deque([1,2,3]) +iterator = iter(d) +assert iterator.__reduce__() == (type(iterator), (d, 0)) +for j in range(i): +next(iterator) +assert iterator.__reduce__() == (type(iterator), (d, i)) +copy = pickle.loads(pickle.dumps(iterator)) +assert list(iterator) == list(copy) def test_DequeRevIter_pickle(self): from _collections import deque import pickle -d = deque([1,2,3]) -iterator = reversed(d) -copy = pickle.loads(pickle.dumps(iterator)) -
[pypy-commit] pypy py3.5: Move qualname setting out of setup_*_type()
Author: Ronan LamyBranch: py3.5 Changeset: r89025:bdf046580d0a Date: 2016-12-12 14:22 + http://bitbucket.org/pypy/pypy/changeset/bdf046580d0a/ Log:Move qualname setting out of setup_*_type() diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py --- a/pypy/objspace/std/typeobject.py +++ b/pypy/objspace/std/typeobject.py @@ -186,6 +186,14 @@ else: layout = setup_user_defined_type(self, force_new_layout) self.layout = layout +if self.flag_heaptype: +w_qualname = self.dict_w.pop('__qualname__', None) +if w_qualname is not None: +self.qualname = space.unicode_w(w_qualname) +else: +self.qualname = self.getname(space) +else: +self.qualname = self.getname(space) if not is_mro_purely_of_types(self.mro_w): pass @@ -1178,12 +1186,6 @@ layout = create_all_slots(w_self, hasoldstylebase, w_bestbase, force_new_layout) -w_qualname = w_self.dict_w.pop('__qualname__', None) -if w_qualname is not None: -w_self.qualname = w_self.space.unicode_w(w_qualname) -else: -w_self.qualname = w_self.getname(w_self.space) - ensure_common_attributes(w_self) return layout @@ -1191,7 +1193,6 @@ w_self.hasdict = instancetypedef.hasdict w_self.weakrefable = instancetypedef.weakrefable w_self.w_doc = w_self.space.wrap(instancetypedef.doc) -w_self.qualname = w_self.getname(w_self.space) ensure_common_attributes(w_self) w_self.flag_heaptype = instancetypedef.heaptype # ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: fix test
Author: Armin RigoBranch: py3.5 Changeset: r89020:f04b5764c0e2 Date: 2016-12-12 14:30 +0100 http://bitbucket.org/pypy/pypy/changeset/f04b5764c0e2/ Log:fix test diff --git a/pypy/module/struct/test/test_struct.py b/pypy/module/struct/test/test_struct.py --- a/pypy/module/struct/test/test_struct.py +++ b/pypy/module/struct/test/test_struct.py @@ -377,7 +377,7 @@ assert bytes(b2) == self.struct.pack("ii", 17, 42) + (b'\x00' * 11) exc = raises(TypeError, self.struct.pack_into, "ii", b'test', 0, 17, 42) -assert str(exc.value) == "must be read-write buffer, not bytes" +assert str(exc.value) == "a read-write buffer is requried, not bytes" exc = raises(self.struct.error, self.struct.pack_into, "ii", b[0:1], 0, 17, 42) assert str(exc.value) == "pack_into requires a buffer of at least 8 bytes" ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy issue2444: try with _finalize_, but it is called too early
Author: Matti PicusBranch: issue2444 Changeset: r89035:fb9619c1a00a Date: 2016-12-12 23:43 +0200 http://bitbucket.org/pypy/pypy/changeset/fb9619c1a00a/ Log:try with _finalize_, but it is called too early diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py --- a/pypy/module/cpyext/slotdefs.py +++ b/pypy/module/cpyext/slotdefs.py @@ -340,11 +340,12 @@ self.ndim = ndim self.itemsize = itemsize self.readonly = readonly -self.releasebuffer = releasebuffer +self.releasebufferproc = releasebuffer -def __del__(self): -if self.releasebuffer: -func_target = rffi.cast(releasebufferproc, self.releasebuffer) +def releasebuffer(self): +print '--' +if self.releasebufferproc: +func_target = rffi.cast(releasebufferproc, self.releasebufferproc) with lltype.scoped_alloc(Py_buffer) as pybuf: pybuf.c_buf = self.ptr pybuf.c_len = self.size @@ -354,6 +355,7 @@ pybuf.c_strides[i] = self.strides[i] pybuf.c_format = rffi.str2charp(self.format) generic_cpy_call(self.space, func_target, self.w_obj, pybuf) +self.releasebufferproc = None def getlength(self): return self.size diff --git a/pypy/module/cpyext/test/test_bufferobject.py b/pypy/module/cpyext/test/test_bufferobject.py --- a/pypy/module/cpyext/test/test_bufferobject.py +++ b/pypy/module/cpyext/test/test_bufferobject.py @@ -114,7 +114,9 @@ """, ) import gc assert module.get_cnt() == 0 +print '++' a = memoryview(module.create_test()) +print 'xxx' assert module.get_cnt() == 1 del a assert module.get_cnt() == 0 diff --git a/pypy/objspace/std/bufferobject.py b/pypy/objspace/std/bufferobject.py --- a/pypy/objspace/std/bufferobject.py +++ b/pypy/objspace/std/bufferobject.py @@ -17,6 +17,9 @@ assert isinstance(buf, Buffer) self.buf = buf +def _finalize_(self): +return self.buf.releasebuffer() + def buffer_w(self, space, flags): space.check_buf_flags(flags, self.buf.readonly) return self.buf diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py --- a/pypy/objspace/std/objspace.py +++ b/pypy/objspace/std/objspace.py @@ -321,8 +321,10 @@ def newseqiter(self, w_obj): return W_SeqIterObject(w_obj) -def newbuffer(self, w_obj): -return W_Buffer(w_obj) +def newbuffer(self, obj): +ret = W_Buffer(obj) +ret.register_finalizer(self) +return ret def newbytes(self, s): return W_BytesObject(s) diff --git a/rpython/rlib/buffer.py b/rpython/rlib/buffer.py --- a/rpython/rlib/buffer.py +++ b/rpython/rlib/buffer.py @@ -75,6 +75,9 @@ def getstrides(self): return [1] +def releasebuffer(self): +pass + class StringBuffer(Buffer): __slots__ = ['value'] _immutable_ = True ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] cffi default: typos
Author: Armin RigoBranch: Changeset: r2834:dc847ec359cc Date: 2016-12-12 12:30 +0100 http://bitbucket.org/cffi/cffi/changeset/dc847ec359cc/ Log:typos diff --git a/doc/source/ref.rst b/doc/source/ref.rst --- a/doc/source/ref.rst +++ b/doc/source/ref.rst @@ -263,7 +263,7 @@ For ``array = ffi.new("T[]", n)``, then ``ffi.sizeof(array)`` returns ``n * ffi.sizeof("T")``. *New in version 1.9:* Similar rules apply for -structures with aa variable-sized array at the end. More precisely, if +structures with a variable-sized array at the end. More precisely, if ``p`` was returned by ``ffi.new("struct foo *", ...)``, then ``ffi.sizeof(p[0])`` now returns the total allocated size. In previous versions, it used to just return ``ffi.sizeof(ffi.typeof(p[0]))``, which @@ -481,7 +481,7 @@ memory where the initial content can be left uninitialized, you can do:: # at module level -new_nonzero = ffi.new_allocator(should_clear_after_alloc) +new_nonzero = ffi.new_allocator(should_clear_after_alloc=False) # then replace `p = ffi.new("char[]", bigsize)` with: p = new_nonzero("char[]", bigsize) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: fix test
Author: Ronan LamyBranch: py3.5 Changeset: r89012:af50dbdbb236 Date: 2016-12-12 11:41 + http://bitbucket.org/pypy/pypy/changeset/af50dbdbb236/ Log:fix test diff --git a/pypy/module/cpyext/test/test_typeobject.py b/pypy/module/cpyext/test/test_typeobject.py --- a/pypy/module/cpyext/test/test_typeobject.py +++ b/pypy/module/cpyext/test/test_typeobject.py @@ -310,7 +310,7 @@ ("setattr", "METH_O", ''' int ret; -PyObject* name = PyString_FromString("mymodule"); +PyObject* name = PyBytes_FromString("mymodule"); PyObject *obj = PyType_Type.tp_alloc(_Type, 0); PyHeapTypeObject *type = (PyHeapTypeObject*)obj; if ((type->ht_type.tp_flags & Py_TPFLAGS_HEAPTYPE) == 0) @@ -1152,7 +1152,7 @@ Base2->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE; Base12->tp_flags = Py_TPFLAGS_DEFAULT; Base12->tp_base = Base1; -Base12->tp_bases = PyTuple_Pack(2, Base1, Base2); +Base12->tp_bases = PyTuple_Pack(2, Base1, Base2); Base12->tp_doc = "The Base12 type or object"; if (PyType_Ready(Base1) < 0) return NULL; if (PyType_Ready(Base2) < 0) return NULL; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy issue2444: test for calling bf_releasebuffer, pases with -A
Author: Matti PicusBranch: issue2444 Changeset: r89028:c8c4d41979cd Date: 2016-12-12 18:43 +0200 http://bitbucket.org/pypy/pypy/changeset/c8c4d41979cd/ Log:test for calling bf_releasebuffer, pases with -A diff --git a/pypy/module/cpyext/test/test_bufferobject.py b/pypy/module/cpyext/test/test_bufferobject.py --- a/pypy/module/cpyext/test/test_bufferobject.py +++ b/pypy/module/cpyext/test/test_bufferobject.py @@ -64,3 +64,57 @@ b = buffer(a) assert module.roundtrip(b) == 'text' +def test_releasebuffer(self): +module = self.import_extension('foo', [ +("create_test", "METH_NOARGS", + """ +PyObject *obj; +obj = PyObject_New(PyObject, (PyTypeObject*)type); +return obj; + """), +("get_cnt", "METH_NOARGS", + 'return PyLong_FromLong(cnt);')], prologue=""" +static float test_data = 42.f; +static int cnt=0; +static PyHeapTypeObject * type=NULL; + +int getbuffer(PyObject *obj, Py_buffer *view, int flags) { + +cnt ++; +memset(view, 0, sizeof(Py_buffer)); +view->obj = obj; +view->ndim = 0; +view->buf = (void *) _data; +view->itemsize = sizeof(float); +view->len = 1; +view->strides = NULL; +view->shape = NULL; +view->format = "f"; +return 0; +} + +void releasebuffer(PyObject *obj, Py_buffer *view) { +cnt --; +} +""", more_init=""" +type = (PyHeapTypeObject *) PyType_Type.tp_alloc(_Type, 0); + +type->ht_type.tp_name = "Test"; +type->ht_type.tp_basicsize = sizeof(PyObject); +type->ht_name = PyString_FromString("Test"); +type->ht_type.tp_flags |= Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | + Py_TPFLAGS_HEAPTYPE | Py_TPFLAGS_HAVE_NEWBUFFER; +type->ht_type.tp_flags &= ~Py_TPFLAGS_HAVE_GC; + +type->ht_type.tp_as_buffer = >as_buffer; +type->as_buffer.bf_getbuffer = getbuffer; +type->as_buffer.bf_releasebuffer = releasebuffer; + +if (PyType_Ready(>ht_type) < 0) INITERROR; +""", ) +import gc +assert module.get_cnt() == 0 +a = memoryview(module.create_test()) +assert module.get_cnt() == 1 +del a +assert module.get_cnt() == 0 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Set w_type.flag_heaptype from an explicitly given argument to the constructor
Author: Ronan LamyBranch: Changeset: r89029:deb24ecc88aa Date: 2016-12-12 17:03 + http://bitbucket.org/pypy/pypy/changeset/deb24ecc88aa/ Log:Set w_type.flag_heaptype from an explicitly given argument to the constructor diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py --- a/pypy/module/cpyext/typeobject.py +++ b/pypy/module/cpyext/typeobject.py @@ -466,9 +466,9 @@ new_layout = (pto.c_tp_basicsize > minsize or pto.c_tp_itemsize > 0) W_TypeObject.__init__(self, space, name, -bases_w or [space.w_object], dict_w, force_new_layout=new_layout) +bases_w or [space.w_object], dict_w, force_new_layout=new_layout, +is_heaptype=flag_heaptype) self.flag_cpytype = True -self.flag_heaptype = flag_heaptype # if a sequence or a mapping, then set the flag to force it if pto.c_tp_as_sequence and pto.c_tp_as_sequence.c_sq_item: self.flag_map_or_seq = 'S' diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py --- a/pypy/objspace/std/typeobject.py +++ b/pypy/objspace/std/typeobject.py @@ -162,7 +162,8 @@ @dont_look_inside def __init__(self, space, name, bases_w, dict_w, - overridetypedef=None, force_new_layout=False): + overridetypedef=None, force_new_layout=False, + is_heaptype=True): self.space = space self.name = name self.bases_w = bases_w @@ -172,7 +173,7 @@ self.weakrefable = False self.w_doc = space.w_None self.weak_subclasses = [] -self.flag_heaptype = False +self.flag_heaptype = is_heaptype self.flag_cpytype = False self.flag_abstract = False self.flag_sequence_bug_compat = False @@ -740,7 +741,7 @@ dict_w[key] = space.getitem(w_dict, w_key) w_type = space.allocate_instance(W_TypeObject, w_typetype) W_TypeObject.__init__(w_type, space, name, bases_w or [space.w_object], - dict_w) + dict_w, is_heaptype=True) w_type.ready() return w_type @@ -1138,7 +1139,6 @@ if len(w_self.bases_w) == 0: w_self.bases_w = [w_self.space.w_object] w_bestbase = check_and_find_best_base(w_self.space, w_self.bases_w) -w_self.flag_heaptype = True for w_base in w_self.bases_w: if not isinstance(w_base, W_TypeObject): continue @@ -1159,7 +1159,6 @@ w_self.weakrefable = instancetypedef.weakrefable w_self.w_doc = w_self.space.wrap(instancetypedef.doc) ensure_common_attributes(w_self) -w_self.flag_heaptype = instancetypedef.heaptype # # usually 'instancetypedef' is new, i.e. not seen in any base, # but not always (see Exception class) @@ -1333,7 +1332,8 @@ else: overridetypedef = typedef w_type = W_TypeObject(space, typedef.name, bases_w, dict_w, - overridetypedef=overridetypedef) + overridetypedef=overridetypedef, + is_heaptype=overridetypedef.heaptype) if typedef is not overridetypedef: w_type.w_doc = space.wrap(typedef.doc) if hasattr(typedef, 'flag_sequence_bug_compat'): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: hg merge default
Author: Ronan LamyBranch: py3.5 Changeset: r89030:cbf1cf403292 Date: 2016-12-12 17:09 + http://bitbucket.org/pypy/pypy/changeset/cbf1cf403292/ Log:hg merge default diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py --- a/pypy/module/cpyext/typeobject.py +++ b/pypy/module/cpyext/typeobject.py @@ -464,9 +464,9 @@ new_layout = (pto.c_tp_basicsize > minsize or pto.c_tp_itemsize > 0) W_TypeObject.__init__(self, space, name, -bases_w or [space.w_object], dict_w, force_new_layout=new_layout) +bases_w or [space.w_object], dict_w, force_new_layout=new_layout, +is_heaptype=flag_heaptype) self.flag_cpytype = True -self.flag_heaptype = flag_heaptype # if a sequence or a mapping, then set the flag to force it if pto.c_tp_as_sequence and pto.c_tp_as_sequence.c_sq_item: self.flag_map_or_seq = 'S' diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py --- a/pypy/objspace/std/typeobject.py +++ b/pypy/objspace/std/typeobject.py @@ -163,7 +163,8 @@ @dont_look_inside def __init__(self, space, name, bases_w, dict_w, - overridetypedef=None, force_new_layout=False): + overridetypedef=None, force_new_layout=False, + is_heaptype=True): self.space = space self.name = name self.qualname = None @@ -174,7 +175,7 @@ self.weakrefable = False self.w_doc = space.w_None self.weak_subclasses = [] -self.flag_heaptype = False +self.flag_heaptype = is_heaptype self.flag_cpytype = False self.flag_abstract = False self.flag_sequence_bug_compat = False @@ -727,7 +728,7 @@ dict_w[key] = space.getitem(w_dict, w_key) w_type = space.allocate_instance(W_TypeObject, w_typetype) W_TypeObject.__init__(w_type, space, name, bases_w or [space.w_object], - dict_w) + dict_w, is_heaptype=True) w_type.ready() return w_type @@ -1173,7 +1174,6 @@ if len(w_self.bases_w) == 0: w_self.bases_w = [w_self.space.w_object] w_bestbase = check_and_find_best_base(w_self.space, w_self.bases_w) -w_self.flag_heaptype = True for w_base in w_self.bases_w: if not isinstance(w_base, W_TypeObject): continue @@ -1194,7 +1194,6 @@ w_self.weakrefable = instancetypedef.weakrefable w_self.w_doc = w_self.space.wrap(instancetypedef.doc) ensure_common_attributes(w_self) -w_self.flag_heaptype = instancetypedef.heaptype # # usually 'instancetypedef' is new, i.e. not seen in any base, # but not always (see Exception class) @@ -1376,7 +1375,8 @@ else: overridetypedef = typedef w_type = W_TypeObject(space, typedef.name, bases_w, dict_w, - overridetypedef=overridetypedef) + overridetypedef=overridetypedef, + is_heaptype=overridetypedef.heaptype) if typedef is not overridetypedef: w_type.w_doc = space.wrap(typedef.doc) else: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: pfff, there are 2 cases here with the same error message but different exception types
Author: Ronan LamyBranch: py3.5 Changeset: r89031:0c79e8c786b3 Date: 2016-12-12 17:23 + http://bitbucket.org/pypy/pypy/changeset/0c79e8c786b3/ Log:pfff, there are 2 cases here with the same error message but different exception types diff --git a/pypy/module/cpyext/structmember.py b/pypy/module/cpyext/structmember.py --- a/pypy/module/cpyext/structmember.py +++ b/pypy/module/cpyext/structmember.py @@ -91,9 +91,10 @@ member_type = rffi.cast(lltype.Signed, w_member.c_type) flags = rffi.cast(lltype.Signed, w_member.c_flags) -if (flags & READONLY or -member_type in [T_STRING, T_STRING_INPLACE]): +if flags & READONLY: raise oefmt(space.w_AttributeError, "readonly attribute") +elif member_type in [T_STRING, T_STRING_INPLACE]: +raise oefmt(space.w_TypeError, "readonly attribute") elif w_value is None: if member_type == T_OBJECT_EX: if not rffi.cast(PyObjectP, addr)[0]: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy cling-support: check and protect against lookup failures
Author: Wim LavrijsenBranch: cling-support Changeset: r89033:b446d39f9f70 Date: 2016-12-12 10:36 -0800 http://bitbucket.org/pypy/pypy/changeset/b446d39f9f70/ Log:check and protect against lookup failures diff --git a/pypy/module/cppyy/interp_cppyy.py b/pypy/module/cppyy/interp_cppyy.py --- a/pypy/module/cppyy/interp_cppyy.py +++ b/pypy/module/cppyy/interp_cppyy.py @@ -842,6 +842,8 @@ def _make_datamember(self, dm_name, dm_idx): type_name = capi.c_datamember_type(self.space, self, dm_idx) offset = capi.c_datamember_offset(self.space, self, dm_idx) +if offset == -1: +raise self.missing_attribute_error(dm_name) datamember = W_CPPStaticData(self.space, self, type_name, offset) self.datamembers[dm_name] = datamember return datamember @@ -941,6 +943,8 @@ datamember_name = capi.c_datamember_name(self.space, self, i) type_name = capi.c_datamember_type(self.space, self, i) offset = capi.c_datamember_offset(self.space, self, i) +if offset == -1: +continue # dictionary problem; raises AttributeError on use is_static = bool(capi.c_is_staticdata(self.space, self, i)) if is_static: datamember = W_CPPStaticData(self.space, self, type_name, offset) diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx b/pypy/module/cppyy/src/clingcwrapper.cxx --- a/pypy/module/cppyy/src/clingcwrapper.cxx +++ b/pypy/module/cppyy/src/clingcwrapper.cxx @@ -1063,10 +1063,11 @@ TClassRef& cr = type_from_handle( scope ); if ( cr.GetClass() ) { TDataMember* m = (TDataMember*)cr->GetListOfDataMembers()->At( idata ); - return (ptrdiff_t)m->GetOffsetCint(); // yes, CINT ... + return (ptrdiff_t)m->GetOffsetCint(); // yes, CINT (GetOffset() is both wrong + // and caches that wrong result! } - return (ptrdiff_t)0; + return (ptrdiff_t)-1; } Cppyy::TCppIndex_t Cppyy::GetDatamemberIndex( TCppScope_t scope, const std::string& name ) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy cling-support: support signed char and long double in as much that rffi supports them
Author: Wim LavrijsenBranch: cling-support Changeset: r89032:026bbdbd61f5 Date: 2016-12-09 14:49 -0800 http://bitbucket.org/pypy/pypy/changeset/026bbdbd61f5/ Log:support signed char and long double in as much that rffi supports them diff --git a/pypy/module/cppyy/capi/builtin_capi.py b/pypy/module/cppyy/capi/builtin_capi.py --- a/pypy/module/cppyy/capi/builtin_capi.py +++ b/pypy/module/cppyy/capi/builtin_capi.py @@ -146,6 +146,13 @@ compilation_info=backend.eci) def c_call_d(space, cppmethod, cppobject, nargs, args): return _c_call_d(cppmethod, cppobject, nargs, args) +_c_call_ld = rffi.llexternal( +"cppyy_call_ld", +[C_METHOD, C_OBJECT, rffi.INT, rffi.VOIDP], rffi.LONGDOUBLE, +releasegil=ts_call, +compilation_info=backend.eci) +def c_call_ld(space, cppmethod, cppobject, nargs, args): +return _c_call_ld(cppmethod, cppobject, nargs, args) _c_call_r = rffi.llexternal( "cppyy_call_r", diff --git a/pypy/module/cppyy/capi/loadable_capi.py b/pypy/module/cppyy/capi/loadable_capi.py --- a/pypy/module/cppyy/capi/loadable_capi.py +++ b/pypy/module/cppyy/capi/loadable_capi.py @@ -125,23 +125,24 @@ # types (see capi/__init__.py), but by using strings here, that isn't guaranteed c_opaque_ptr = state.c_ulong -c_scope = c_opaque_ptr -c_type = c_scope -c_object = c_opaque_ptr -c_method = c_opaque_ptr -c_index = state.c_long +c_scope = c_opaque_ptr +c_type= c_scope +c_object = c_opaque_ptr +c_method = c_opaque_ptr +c_index = state.c_long c_index_array = state.c_voidp -c_void = state.c_void -c_char = state.c_char -c_uchar = state.c_uchar -c_short = state.c_short -c_int= state.c_int -c_long = state.c_long -c_llong = state.c_llong -c_ullong = state.c_ullong -c_float = state.c_float -c_double = state.c_double +c_void= state.c_void +c_char= state.c_char +c_uchar = state.c_uchar +c_short = state.c_short +c_int = state.c_int +c_long= state.c_long +c_llong = state.c_llong +c_ullong = state.c_ullong +c_float = state.c_float +c_double = state.c_double +c_ldouble = state.c_ldouble c_ccharp = state.c_ccharp c_voidp = state.c_voidp @@ -174,6 +175,7 @@ 'call_ll' : ([c_method, c_object, c_int, c_voidp], c_llong), 'call_f' : ([c_method, c_object, c_int, c_voidp], c_float), 'call_d' : ([c_method, c_object, c_int, c_voidp], c_double), +'call_ld' : ([c_method, c_object, c_int, c_voidp], c_ldouble), 'call_r' : ([c_method, c_object, c_int, c_voidp], c_voidp), # call_s actually takes an size_t* as last parameter, but this will do @@ -372,6 +374,9 @@ def c_call_d(space, cppmethod, cppobject, nargs, cargs): args = [_ArgH(cppmethod), _ArgH(cppobject), _ArgL(nargs), _ArgP(cargs)] return rffi.cast(rffi.DOUBLE, space.float_w(call_capi(space, 'call_d', args))) +def c_call_ld(space, cppmethod, cppobject, nargs, cargs): +args = [_ArgH(cppmethod), _ArgH(cppobject), _ArgL(nargs), _ArgP(cargs)] +return rffi.cast(rffi.LONGDOUBLE, space.float_w(call_capi(space, 'call_ld', args))) def c_call_r(space, cppmethod, cppobject, nargs, cargs): args = [_ArgH(cppmethod), _ArgH(cppobject), _ArgL(nargs), _ArgP(cargs)] diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py --- a/pypy/module/cppyy/converter.py +++ b/pypy/module/cppyy/converter.py @@ -3,7 +3,7 @@ from pypy.interpreter.error import OperationError, oefmt from rpython.rtyper.lltypesystem import rffi, lltype -from rpython.rlib.rarithmetic import r_singlefloat +from rpython.rlib.rarithmetic import r_singlefloat, r_longfloat from rpython.rlib import rfloat from pypy.module._rawffi.interp_rawffi import letter2tp @@ -351,7 +351,7 @@ def from_memory(self, space, w_obj, w_pycppclass, offset): address = self._get_raw_address(space, w_obj, offset) rffiptr = rffi.cast(self.c_ptrtype, address) -return space.wrap(float(rffiptr[0])) +return self._wrap_object(space, rffiptr[0]) class ConstFloatRefConverter(FloatConverter): _immutable_fields_ = ['typecode'] @@ -378,6 +378,25 @@ _immutable_fields_ = ['typecode'] typecode = 'd' +class LongDoubleConverter(ffitypes.typeid(rffi.LONGDOUBLE), FloatTypeConverterMixin, TypeConverter): +_immutable_fields_ = ['default'] + +def __init__(self, space, default): +if default: +fval = float(rfloat.rstring_to_float(default)) +else: +fval = float(0.) +self.default = r_longfloat(fval) + +def from_memory(self, space, w_obj, w_pycppclass, offset): +
[pypy-commit] pypy issue2444: massive hack of CPyBuffer.__del__ to call bf_releasebuffer, new idea needed
Author: Matti PicusBranch: issue2444 Changeset: r89034:9d872f71a438 Date: 2016-12-12 22:01 +0200 http://bitbucket.org/pypy/pypy/changeset/9d872f71a438/ Log:massive hack of CPyBuffer.__del__ to call bf_releasebuffer, new idea needed diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py --- a/pypy/module/cpyext/slotdefs.py +++ b/pypy/module/cpyext/slotdefs.py @@ -12,7 +12,7 @@ getattrfunc, getattrofunc, setattrofunc, lenfunc, ssizeargfunc, inquiry, ssizessizeargfunc, ssizeobjargproc, iternextfunc, initproc, richcmpfunc, cmpfunc, hashfunc, descrgetfunc, descrsetfunc, objobjproc, objobjargproc, -readbufferproc, getbufferproc, ssizessizeobjargproc) +readbufferproc, getbufferproc, releasebufferproc, ssizessizeobjargproc) from pypy.module.cpyext.pyobject import make_ref, Py_DecRef from pypy.module.cpyext.pyerrors import PyErr_Occurred from pypy.module.cpyext.memoryobject import fill_Py_buffer @@ -321,8 +321,10 @@ # Similar to Py_buffer _immutable_ = True -def __init__(self, ptr, size, w_obj, format='B', shape=None, -strides=None, ndim=1, itemsize=1, readonly=True): +def __init__(self, space, ptr, size, w_obj, format='B', shape=None, +strides=None, ndim=1, itemsize=1, readonly=True, +releasebuffer=None): +self.space = space self.ptr = ptr self.size = size self.w_obj = w_obj # kept alive @@ -338,6 +340,20 @@ self.ndim = ndim self.itemsize = itemsize self.readonly = readonly +self.releasebuffer = releasebuffer + +def __del__(self): +if self.releasebuffer: +func_target = rffi.cast(releasebufferproc, self.releasebuffer) +with lltype.scoped_alloc(Py_buffer) as pybuf: +pybuf.c_buf = self.ptr +pybuf.c_len = self.size +pybuf.c_ndim = rffi.cast(rffi.INT, self.ndim) +for i in range(self.ndim): +pybuf.c_shape[i] = self.shape[i] +pybuf.c_strides[i] = self.strides[i] +pybuf.c_format = rffi.str2charp(self.format) +generic_cpy_call(self.space, func_target, self.w_obj, pybuf) def getlength(self): return self.size @@ -369,24 +385,35 @@ def wrap_getreadbuffer(space, w_self, w_args, func): func_target = rffi.cast(readbufferproc, func) +py_obj = make_ref(space, w_self) +py_type = py_obj.c_ob_type +releasebuffer = py_type.c_tp_as_buffer and py_type.c_tp_as_buffer.c_bf_releasebuffer with lltype.scoped_alloc(rffi.VOIDPP.TO, 1) as ptr: index = rffi.cast(Py_ssize_t, 0) size = generic_cpy_call(space, func_target, w_self, index, ptr) if size < 0: space.fromcache(State).check_and_raise_exception(always=True) -return space.newbuffer(CPyBuffer(ptr[0], size, w_self)) +return space.newbuffer(CPyBuffer(space, ptr[0], size, w_self, + releasebuffer=releasebuffer)) def wrap_getwritebuffer(space, w_self, w_args, func): func_target = rffi.cast(readbufferproc, func) +py_obj = make_ref(space, w_self) +py_type = py_obj.c_ob_type +releasebuffer = py_type.c_tp_as_buffer and py_type.c_tp_as_buffer.c_bf_releasebuffer with lltype.scoped_alloc(rffi.VOIDPP.TO, 1) as ptr: index = rffi.cast(Py_ssize_t, 0) size = generic_cpy_call(space, func_target, w_self, index, ptr) if size < 0: space.fromcache(State).check_and_raise_exception(always=True) -return space.newbuffer(CPyBuffer(ptr[0], size, w_self, readonly=False)) +return space.newbuffer(CPyBuffer(space, ptr[0], size, w_self, readonly=False, + releasebuffer=releasebuffer)) def wrap_getbuffer(space, w_self, w_args, func): func_target = rffi.cast(getbufferproc, func) +py_obj = make_ref(space, w_self) +py_type = py_obj.c_ob_type +releasebuffer = py_type.c_tp_as_buffer and py_type.c_tp_as_buffer.c_bf_releasebuffer with lltype.scoped_alloc(Py_buffer) as pybuf: _flags = 0 if space.len_w(w_args) > 0: @@ -407,10 +434,11 @@ format = rffi.charp2str(pybuf.c_format) else: format = 'B' -return space.newbuffer(CPyBuffer(ptr, size, w_self, format=format, +return space.newbuffer(CPyBuffer(space, ptr, size, w_self, format=format, ndim=ndim, shape=shape, strides=strides, itemsize=pybuf.c_itemsize, -readonly=widen(pybuf.c_readonly))) +readonly=widen(pybuf.c_readonly), +releasebuffer = releasebuffer)) def get_richcmp_func(OP_CONST): def inner(space, w_self, w_args, func): diff --git a/pypy/module/cpyext/typeobjectdefs.py b/pypy/module/cpyext/typeobjectdefs.py ---