[pypy-commit] pypy cpyext-gc-cycle: Implemented wrapper for tp_finalize

2019-02-21 Thread stevie_92
Author: Stefan Beyer 
Branch: cpyext-gc-cycle
Changeset: r96124:78d356baf93c
Date: 2019-02-21 15:33 +0100
http://bitbucket.org/pypy/pypy/changeset/78d356baf93c/

Log:Implemented wrapper for tp_finalize

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,
-getbufferproc, ssizessizeobjargproc)
+getbufferproc, ssizessizeobjargproc, destructor)
 from pypy.module.cpyext.pyobject import make_ref, from_ref, as_pyobj, decref
 from pypy.module.cpyext.pyerrors import PyErr_Occurred
 from pypy.module.cpyext.memoryobject import fill_Py_buffer
@@ -438,6 +438,16 @@
 fq.register_finalizer(buf)
 return buf.wrap(space)
 
+class wrap_del(W_PyCWrapperObject):
+def call(self, space, w_self, __args__):
+self.check_args(__args__, 0)
+func = self.get_func_to_call()
+func_target = rffi.cast(destructor, func)
+res = generic_cpy_call(space, func_target, w_self)
+if res == -1:
+space.fromcache(State).check_and_raise_exception(always=True)
+return space.w_None
+
 def get_richcmp_func(OP_CONST):
 class wrap_richcmp(W_PyCWrapperObject):
 def call(self, space, w_self, __args__):
@@ -832,8 +842,21 @@
 return 0
 return slot_tp_descr_set
 
+@slot_factory('tp_finalize')
+def make_tp_finalize(space, typedef, name, attr):
+w_type = space.gettypeobject(typedef)
+new_fn = w_type.lookup('__del__')
+if new_fn is None:
+return
 
-missing_wrappers = ['wrap_indexargfunc', 'wrap_del']
+@slot_function([PyObject], lltype.Void)
+@func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), typedef.name))
+def slot_tp_finalize(space, w_self):
+args = Arguments(space, [])
+return space.call_args(w_self, args)
+return slot_tp_finalize
+
+missing_wrappers = ['wrap_indexargfunc']
 for name in missing_wrappers:
 assert name not in globals()
 class missing_wrapper(W_PyCWrapperObject):
@@ -848,7 +871,6 @@
 
 missing_builtin_slots = [
 'tp_print', 'tp_compare', 'tp_getattr', 'tp_setattr', 'tp_setattro',
-'tp_finalize',
 'tp_richcompare', 'tp_del', 'tp_as_buffer.c_bf_getwritebuffer',
 'tp_as_number.c_nb_bool', 'tp_as_number.c_nb_coerce',
 'tp_as_number.c_nb_inplace_add', 'tp_as_number.c_nb_inplace_subtract',
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: Issue #402

2019-02-21 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r3227:edac34833b64
Date: 2019-02-21 15:10 +0100
http://bitbucket.org/cffi/cffi/changeset/edac34833b64/

Log:Issue #402

Fix bug in documentation

diff --git a/doc/source/ref.rst b/doc/source/ref.rst
--- a/doc/source/ref.rst
+++ b/doc/source/ref.rst
@@ -157,8 +157,9 @@
 -  use ``file.write()`` and ``file.readinto()`` with
such a buffer (for files opened in binary mode)
 
--  use ``ffi.buffer(mystruct[0])[:] = socket.recv(len(buffer))`` to read
-   into a struct over a socket, rewriting the contents of mystruct[0]
+-  overwrite the content of a struct: if ``p`` is a cdata pointing to
+   it, use ``ffi.buffer(p)[:] = newcontent``, where ``newcontent`` is
+   a bytes object (``str`` in Python 2).
 
 Remember that like in C, you can use ``array + index`` to get the pointer
 to the index'th item of an array.  (In C you might more naturally write
@@ -175,7 +176,7 @@
 - ``buf[:] = newstr``: change the original content (or ``buf[start:end]
   = newstr``)
 
-- ``len(buf), buf[index], buf[index] = newchar``: access as a sequence
+- ``len(buf)``, ``buf[index]``, ``buf[index] = newchar``: access as a sequence
   of characters.
 
 The buffer object returned by ``ffi.buffer(cdata)`` keeps alive the
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix

2019-02-21 Thread mattip
Author: Matti Picus 
Branch: 
Changeset: r96122:789d5650e3af
Date: 2019-02-21 12:56 +0200
http://bitbucket.org/pypy/pypy/changeset/789d5650e3af/

Log:fix

diff --git a/rpython/rlib/test/test_rutf8.py b/rpython/rlib/test/test_rutf8.py
--- a/rpython/rlib/test/test_rutf8.py
+++ b/rpython/rlib/test/test_rutf8.py
@@ -200,7 +200,7 @@
 
 def test_utf8_string_builder_bad_code():
 s = rutf8.Utf8StringBuilder()
-with pytest.raises(ValueError):
+with pytest.raises(rutf8.OutOfRange):
 s.append_code(0x11)
 assert s.build() == ''
 assert s.getlength() == 0
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: close 3.5 branch to focus on py3.6

2019-02-21 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: py3.5
Changeset: r96121:eb6e70a9658e
Date: 2019-02-21 11:35 +0100
http://bitbucket.org/pypy/pypy/changeset/eb6e70a9658e/

Log:close 3.5 branch to focus on py3.6

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.6: copy slightly lengthy test from cpython to find the (crashing) bug in set_lineno

2019-02-21 Thread cfbolz
Author: Carl Friedrich Bolz-Tereick 
Branch: py3.6
Changeset: r96120:1d06586fec74
Date: 2019-02-21 11:26 +0100
http://bitbucket.org/pypy/pypy/changeset/1d06586fec74/

Log:copy slightly lengthy test from cpython to find the (crashing) bug
in set_lineno

diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -739,6 +739,7 @@
 delta_iblock = min_delta_iblock = 0# see below for comment
 addr = min_addr
 while addr < max_addr:
+assert addr & 1 == 0
 op = ord(code[addr])
 
 if op in (SETUP_LOOP, SETUP_EXCEPT, SETUP_FINALLY, SETUP_WITH,
@@ -749,10 +750,7 @@
 if delta_iblock < min_delta_iblock:
 min_delta_iblock = delta_iblock
 
-if op >= HAVE_ARGUMENT:
-addr += 3
-else:
-addr += 1
+addr += 2
 
 # 'min_delta_iblock' is <= 0; its absolute value is the number of
 # blocks we exit.  'go_iblock' is the delta number of blocks
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
@@ -179,6 +179,61 @@
 ('return', 5)]
 """
 
+def test_set_lineno_jump_out_of_block(self):
+import sys
+class JumpTracer:
+def __init__(self, function):
+self.function = function
+self.jumpFrom = function.jump[0]
+self.jumpTo = function.jump[1]
+self.done = False
+
+def trace(self, frame, event, arg):
+if not self.done and frame.f_code == self.function.__code__:
+firstLine = frame.f_code.co_firstlineno
+if event == 'line' and frame.f_lineno == firstLine + 
self.jumpFrom:
+# Cope with non-integer self.jumpTo (because of
+# no_jump_to_non_integers below).
+try:
+frame.f_lineno = firstLine + self.jumpTo
+except TypeError:
+frame.f_lineno = self.jumpTo
+self.done = True
+return self.trace
+
+def run_test(func):
+tracer = JumpTracer(func)
+sys.settrace(tracer.trace)
+output = []
+func(output)
+sys.settrace(None)
+assert func.output == output
+
+# copied from cpython test suite
+def jump_out_of_block_forwards(output):
+for i in 1, 2:
+output.append(2)
+for j in [3]:  # Also tests jumping over a block
+output.append(4)
+output.append(5)
+
+jump_out_of_block_forwards.jump = (3, 5)
+jump_out_of_block_forwards.output = [2, 5]
+#run_test(jump_out_of_block_forwards)
+
+def jump_out_of_block_backwards(output):
+output.append(1)
+for i in [1]:
+output.append(3)
+for j in [2]:  # Also tests jumping over a block
+output.append(5)
+output.append(6)
+output.append(7)
+
+jump_out_of_block_backwards.jump = (6, 1)
+jump_out_of_block_backwards.output = [1, 3, 5, 1, 3, 5, 6, 7]
+run_test(jump_out_of_block_backwards)
+
 def test_f_back(self):
 import sys
 def f():
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit