[pypy-commit] pypy py3.5: hg merge default

2017-09-29 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92521:45380b7b402f
Date: 2017-09-30 00:42 +0200
http://bitbucket.org/pypy/pypy/changeset/45380b7b402f/

Log:hg merge default

diff --git a/pypy/doc/release-v5.9.0.rst b/pypy/doc/release-v5.9.0.rst
--- a/pypy/doc/release-v5.9.0.rst
+++ b/pypy/doc/release-v5.9.0.rst
@@ -148,8 +148,7 @@
   * Issue 2590_: fix the bounds in the GC when allocating a lot of objects 
with finalizers
   * Replace magical NOT RPYTHON comment with a decorator
   * Implement ``socket.sendmsg()``/``.recvmsg()`` for py3.5
-  * Reduce excessive ``memory_pressure`` for ``_SSLContext`` objects and add
-``memory_pressure`` for ``_SSLSocket`` objects
+  * Add ``memory_pressure`` for ``_SSLSocket`` objects
 
 * Degredations
 
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
@@ -669,6 +669,10 @@
 'PySlice_Type': 'space.gettypeobject(W_SliceObject.typedef)',
 'PyStaticMethod_Type': 'space.gettypeobject(StaticMethod.typedef)',
 'PyCFunction_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCFunctionObject.typedef)',
+'PyClassMethodDescr_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCClassMethodObject.typedef)',
+'PyGetSetDescr_Type': 
'space.gettypeobject(cpyext.typeobject.W_GetSetPropertyEx.typedef)',
+'PyMemberDescr_Type': 
'space.gettypeobject(cpyext.typeobject.W_MemberDescr.typedef)',
+'PyMethodDescr_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCMethodObject.typedef)',
 'PyWrapperDescr_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCWrapperObject.typedef)',
 'PyInstanceMethod_Type': 
'space.gettypeobject(cpyext.classobject.InstanceMethod.typedef)',
 }.items():
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
@@ -1362,6 +1362,11 @@
 
 assert B() == 42
 
+# a even more hackiness
+class C(A):
+pass
+C(42)   # assert is not aborting
+
 
 class AppTestHashable(AppTestCpythonExtensionBase):
 def test_unhashable(self):
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
@@ -682,14 +682,30 @@
 #   it can fail if self.__base__ happens not to be the first base.
 #
 from pypy.module.cpyext.methodobject import W_PyCFunctionObject
+
+if isinstance(w_newdescr, W_PyCFunctionObject):
+return self._really_hack_which_new_to_call(w_newtype, w_newdescr)
+else:
+return w_newtype, w_newdescr
+
+def _really_hack_which_new_to_call(self, w_newtype, w_newdescr):
+# This logic is moved in yet another helper function that
+# is recursive.  We call this only if we see a
+# W_PyCFunctionObject.  That's a performance optimization
+# because in the common case, we won't call any function that
+# contains the stack checks.
+from pypy.module.cpyext.methodobject import W_PyCFunctionObject
 from pypy.module.cpyext.typeobject import is_tp_new_wrapper
 
 if (isinstance(w_newdescr, W_PyCFunctionObject) and
+w_newtype is not self and
 is_tp_new_wrapper(self.space, w_newdescr.ml)):
 w_bestbase = find_best_base(self.bases_w)
-return w_bestbase.lookup_where('__new__')
-else:
-return w_newtype, w_newdescr
+if w_bestbase is not None:
+w_newtype, w_newdescr = w_bestbase.lookup_where('__new__')
+return w_bestbase._really_hack_which_new_to_call(w_newtype,
+ w_newdescr)
+return w_newtype, w_newdescr
 
 def descr_repr(self, space):
 w_mod = self.get_module()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Expose the Descr_Types, like on CPython 3.*

2017-09-29 Thread rlamy
Author: Ronan Lamy 
Branch: 
Changeset: r92520:fb1ae9b91f2f
Date: 2017-09-30 00:39 +0200
http://bitbucket.org/pypy/pypy/changeset/fb1ae9b91f2f/

Log:Expose the Descr_Types, like on CPython 3.*

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
@@ -654,6 +654,10 @@
 'PyClass_Type': 'space.gettypeobject(W_ClassObject.typedef)',
 'PyStaticMethod_Type': 'space.gettypeobject(StaticMethod.typedef)',
 'PyCFunction_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCFunctionObject.typedef)',
+'PyClassMethodDescr_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCClassMethodObject.typedef)',
+'PyGetSetDescr_Type': 
'space.gettypeobject(cpyext.typeobject.W_GetSetPropertyEx.typedef)',
+'PyMemberDescr_Type': 
'space.gettypeobject(cpyext.typeobject.W_MemberDescr.typedef)',
+'PyMethodDescr_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCMethodObject.typedef)',
 'PyWrapperDescr_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCWrapperObject.typedef)',
 }.items():
 register_global(cpyname, 'PyTypeObject*', pypyexpr, header=pypy_decl)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-jit: don't look inside this for now, else it raises InvalidCast; probably it is possible to work-around it by casting both operands to void*, but didn't try yet

2017-09-29 Thread antocuni
Author: Antonio Cuni 
Branch: cpyext-jit
Changeset: r92519:31cea4ce3c8c
Date: 2017-09-29 21:41 +0100
http://bitbucket.org/pypy/pypy/changeset/31cea4ce3c8c/

Log:don't look inside this for now, else it raises InvalidCast; probably
it is possible to work-around it by casting both operands to void*,
but didn't try yet

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
@@ -394,6 +394,7 @@
 ptr = get_new_method_def(space)
 ptr.c_ml_meth = rffi.cast(PyCFunction, llslot(space, tp_new_wrapper))
 
+@jit.dont_look_inside
 def is_tp_new_wrapper(space, ml):
 return ml.c_ml_meth == rffi.cast(PyCFunction, llslot(space, 
tp_new_wrapper))
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: update per 1721ac9f04a9

2017-09-29 Thread pjenvey
Author: Philip Jenvey 
Branch: 
Changeset: r92518:f5e9d7a6acf1
Date: 2017-09-29 13:36 -0700
http://bitbucket.org/pypy/pypy/changeset/f5e9d7a6acf1/

Log:update per 1721ac9f04a9

diff --git a/pypy/doc/release-v5.9.0.rst b/pypy/doc/release-v5.9.0.rst
--- a/pypy/doc/release-v5.9.0.rst
+++ b/pypy/doc/release-v5.9.0.rst
@@ -148,8 +148,7 @@
   * Issue 2590_: fix the bounds in the GC when allocating a lot of objects 
with finalizers
   * Replace magical NOT RPYTHON comment with a decorator
   * Implement ``socket.sendmsg()``/``.recvmsg()`` for py3.5
-  * Reduce excessive ``memory_pressure`` for ``_SSLContext`` objects and add
-``memory_pressure`` for ``_SSLSocket`` objects
+  * Add ``memory_pressure`` for ``_SSLSocket`` objects
 
 * Degredations
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: Fix vmprof test.

2017-09-29 Thread mjacob
Author: Manuel Jacob 
Branch: py3.5
Changeset: r92517:42233a3efdd4
Date: 2017-09-29 20:44 +0200
http://bitbucket.org/pypy/pypy/changeset/42233a3efdd4/

Log:Fix vmprof test.

diff --git a/pypy/module/_vmprof/test/test__vmprof.py 
b/pypy/module/_vmprof/test/test__vmprof.py
--- a/pypy/module/_vmprof/test/test__vmprof.py
+++ b/pypy/module/_vmprof/test/test__vmprof.py
@@ -45,10 +45,10 @@
 _, size = struct.unpack("ll", s[i:i + 2 * WORD])
 count += 1
 i += 2 * WORD + size
-elif s[i] == '\x06':
+elif s[i] == 6:
 print(s[i:i+24])
 i += 1+8+8+8
-elif s[i] == '\x07':
+elif s[i] == 7:
 i += 1
 # skip string
 size, = struct.unpack("l", s[i:i + WORD])
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: bump the limit back

2017-09-29 Thread fijal
Author: fijal
Branch: 
Changeset: r92516:1721ac9f04a9
Date: 2017-09-29 19:52 +0200
http://bitbucket.org/pypy/pypy/changeset/1721ac9f04a9/

Log:bump the limit back

diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -1316,7 +1316,7 @@
 if not ctx:
 raise ssl_error(space, "failed to allocate SSL context")
 
-rgc.add_memory_pressure(10 * 1024)
+rgc.add_memory_pressure(10 * 1024 * 1024)
 self = space.allocate_instance(_SSLContext, w_subtype)
 self.ctx = ctx
 self.check_hostname = False
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy memory-accounting: change back to 10M seems less insane

2017-09-29 Thread fijal
Author: fijal
Branch: memory-accounting
Changeset: r92515:ddd3bbb41771
Date: 2017-09-29 19:50 +0200
http://bitbucket.org/pypy/pypy/changeset/ddd3bbb41771/

Log:change back to 10M seems less insane

diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -1317,7 +1317,7 @@
 
 self = space.allocate_instance(_SSLContext, w_subtype)
 assert isinstance(self, _SSLContext)
-rgc.add_memory_pressure(10 * 1024, self)
+rgc.add_memory_pressure(10 * 1024 * 1024, self)
 self.ctx = ctx
 self.check_hostname = False
 self.register_finalizer(space)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.6: hg merge py3.5

2017-09-29 Thread mjacob
Author: Manuel Jacob 
Branch: py3.6
Changeset: r92514:d4a38e82d0d7
Date: 2017-09-29 19:50 +0200
http://bitbucket.org/pypy/pypy/changeset/d4a38e82d0d7/

Log:hg merge py3.5

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
@@ -669,7 +669,7 @@
 'PySlice_Type': 'space.gettypeobject(W_SliceObject.typedef)',
 'PyStaticMethod_Type': 'space.gettypeobject(StaticMethod.typedef)',
 'PyCFunction_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCFunctionObject.typedef)',
-'PyWrapperDescr_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCMethodObject.typedef)',
+'PyWrapperDescr_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCWrapperObject.typedef)',
 'PyInstanceMethod_Type': 
'space.gettypeobject(cpyext.classobject.InstanceMethod.typedef)',
 }.items():
 register_global(cpyname, 'PyTypeObject*', pypyexpr, header=pypy_decl)
@@ -1338,17 +1338,20 @@
 for decl in FORWARD_DECLS:
 decls[pypy_decl].append("%s;" % (decl,))
 decls[pypy_decl].append("""
-/* hack for https://bugs.python.org/issue29943 */
-PyAPI_FUNC(int) %s(PySliceObject *arg0,
-   Signed arg1, Signed *arg2,
-   Signed *arg3, Signed *arg4, Signed *arg5);
-static int PySlice_GetIndicesEx(PySliceObject *arg0, Py_ssize_t arg1,
-Py_ssize_t *arg2, Py_ssize_t *arg3, Py_ssize_t *arg4,
-Py_ssize_t *arg5) {
-return %s(arg0, arg1, arg2, arg3,
-  arg4, arg5);
-}
-""" % ((mangle_name(prefix, 'PySlice_GetIndicesEx'),)*2))
+/* hack for https://bugs.python.org/issue29943 */
+
+PyAPI_FUNC(int) %s(PyObject *arg0,
+Signed arg1, Signed *arg2,
+Signed *arg3, Signed *arg4, Signed *arg5);
+#ifdef __GNUC__
+__attribute__((__unused__))
+#endif
+static int PySlice_GetIndicesEx(PyObject *arg0, Py_ssize_t arg1,
+Py_ssize_t *arg2, Py_ssize_t *arg3, Py_ssize_t *arg4,
+Py_ssize_t *arg5) {
+return %s(arg0, arg1, arg2, arg3,
+arg4, arg5);
+}""" % ((mangle_name(prefix, 'PySlice_GetIndicesEx'),)*2))
 
 for header_name, header_functions in FUNCTIONS_BY_HEADER.iteritems():
 header = decls[header_name]
diff --git a/pypy/module/cpyext/include/descrobject.h 
b/pypy/module/cpyext/include/descrobject.h
--- a/pypy/module/cpyext/include/descrobject.h
+++ b/pypy/module/cpyext/include/descrobject.h
@@ -1,34 +1,6 @@
 #ifndef Py_DESCROBJECT_H
 #define Py_DESCROBJECT_H
 
-#define PyDescr_COMMON \
-PyObject_HEAD \
-PyTypeObject *d_type; \
-PyObject *d_name
-
-typedef struct {
-PyDescr_COMMON;
-} PyDescrObject;
-
-typedef struct {
-PyDescr_COMMON;
-PyMethodDef *d_method;
-} PyMethodDescrObject;
-
-typedef struct {
-PyDescr_COMMON;
-struct PyMemberDef *d_member;
-} PyMemberDescrObject;
-
-typedef struct {
-PyDescr_COMMON;
-PyGetSetDef *d_getset;
-} PyGetSetDescrObject;
-
-typedef struct {
-PyDescr_COMMON;
-struct wrapperbase *d_base;
-void *d_wrapped; /* This can be any function pointer */
-} PyWrapperDescrObject;
+#include "cpyext_descrobject.h"
 
 #endif
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
@@ -1,4 +1,4 @@
-from rpython.rtyper.lltypesystem import lltype, rffi, llmemory
+from rpython.rtyper.lltypesystem import lltype, rffi
 
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.error import OperationError, oefmt
@@ -10,8 +10,8 @@
 from pypy.module.cpyext.api import (
 CONST_STRING, METH_CLASS, METH_COEXIST, METH_KEYWORDS, METH_NOARGS, METH_O,
 METH_STATIC, METH_VARARGS, PyObject, bootstrap_function,
-cpython_api, generic_cpy_call, CANNOT_FAIL,
-PyTypeObjectPtr, slot_function, cts)
+cpython_api, generic_cpy_call, CANNOT_FAIL, slot_function, cts,
+build_type_checkers)
 from pypy.module.cpyext.pyobject import (
 Py_DecRef, from_ref, make_ref, as_pyobj, make_typedescr)
 
@@ -102,7 +102,7 @@
 return self.space.unwrap(self.descr_method_repr())
 
 def descr_method_repr(self):
-w_objclass = self.w_objclass 
+w_objclass = self.w_objclass
 assert isinstance(w_objclass, W_TypeObject)
 return self.space.newtext("" % (
 self.name, w_objclass.name))
@@ -110,7 +110,7 @@
 def descr_call(self, space, __args__):
 args_w, kw_w = __args__.unpack()
 if len(args_w) < 1:
-w_objclass = self.w_objclass 
+w_objclass = self.w_objclass
 assert isinstance(w_objclass, W_TypeObject)
 raise oefmt(space.w_TypeError,
 "descriptor '%8' of '%s' object needs an argument",
@@ -118,7 +118,7 @@
 w_instance = args_w[0]
 # XXX: needs a stricter 

[pypy-commit] pypy cpyext-jit: hg merge default

2017-09-29 Thread antocuni
Author: Antonio Cuni 
Branch: cpyext-jit
Changeset: r92513:820724c1b021
Date: 2017-09-29 19:48 +0200
http://bitbucket.org/pypy/pypy/changeset/820724c1b021/

Log:hg merge default

diff too long, truncating to 2000 out of 20222 lines

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -25,16 +25,17 @@
 ^pypy/module/cpyext/test/.+\.manifest$
 ^pypy/module/test_lib_pypy/ctypes_tests/.+\.o$
 ^pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test\.o$
-^pypy/module/cppyy/src/.+\.o$
-^pypy/module/cppyy/bench/.+\.so$
-^pypy/module/cppyy/bench/.+\.root$
-^pypy/module/cppyy/bench/.+\.d$
-^pypy/module/cppyy/src/.+\.errors$
-^pypy/module/cppyy/test/.+_rflx\.cpp$
-^pypy/module/cppyy/test/.+\.so$
-^pypy/module/cppyy/test/.+\.rootmap$
-^pypy/module/cppyy/test/.+\.exe$
-^pypy/module/cppyy/test/.+_cint.h$
+^pypy/module/_cppyy/src/.+\.o$
+^pypy/module/_cppyy/bench/.+\.so$
+^pypy/module/_cppyy/bench/.+\.root$
+^pypy/module/_cppyy/bench/.+\.d$
+^pypy/module/_cppyy/src/.+\.errors$
+^pypy/module/_cppyy/test/.+_rflx\.cpp$
+^pypy/module/_cppyy/test/.+\.so$
+^pypy/module/_cppyy/test/.+\.rootmap$
+^pypy/module/_cppyy/test/.+\.exe$
+^pypy/module/_cppyy/test/.+_cint.h$
+^pypy/module/_cppyy/.+/*\.pcm$
 ^pypy/module/test_lib_pypy/cffi_tests/__pycache__.+$
 ^pypy/doc/.+\.html$
 ^pypy/doc/config/.+\.rst$
@@ -88,6 +89,3 @@
 ^release/
 ^rpython/_cache$
 
-pypy/module/cppyy/.+/*\.pcm
-
-
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -60,8 +60,8 @@
   Wim Lavrijsen
   Eric van Riet Paap
   Richard Emslie
+  Remi Meier
   Alexander Schremmer
-  Remi Meier
   Dan Villiom Podlaski Christiansen
   Lukas Diekmann
   Sven Hager
@@ -102,6 +102,7 @@
   Michael Foord
   Stephan Diehl
   Stefano Rivera
+  Jean-Paul Calderone
   Stefan Schwarzer
   Tomek Meka
   Valentino Volonghi
@@ -110,14 +111,13 @@
   Bob Ippolito
   Bruno Gola
   David Malcolm
-  Jean-Paul Calderone
   Squeaky
   Edd Barrett
   Timo Paulssen
   Marius Gedminas
+  Nicolas Truessel
   Alexandre Fayolle
   Simon Burton
-  Nicolas Truessel
   Martin Matusiak
   Laurence Tratt
   Wenzhu Man
@@ -156,6 +156,7 @@
   Stefan H. Muller
   Tim Felgentreff
   Eugene Oden
+  Dodan Mihai
   Jeff Terrace
   Henry Mason
   Vasily Kuznetsov
@@ -182,11 +183,13 @@
   Rocco Moretti
   Gintautas Miliauskas
   Lucian Branescu Mihaila
+  Mariano Anaya
   anatoly techtonik
-  Dodan Mihai
   Karl Bartel
+  Stefan Beyer
   Gabriel Lavoie
   Jared Grubb
+  Alecsandru Patrascu
   Olivier Dormond
   Wouter van Heyst
   Sebastian Pawlu
@@ -194,6 +197,7 @@
   Victor Stinner
   Andrews Medina
   Aaron Iles
+  p_ziesch...@yahoo.de
   Toby Watson
   Daniel Patrick
   Stuart Williams
@@ -204,6 +208,7 @@
   Michael Cheng
   Mikael Schnenberg
   Stanislaw Halik
+  Mihnea Saracin
   Berkin Ilbeyi
   Gasper Zejn
   Faye Zhao
@@ -214,14 +219,12 @@
   Jonathan David Riehl
   Beatrice During
   Alex Perry
-  p_ziesch...@yahoo.de
   Robert Zaremba
   Alan McIntyre
   Alexander Sedov
   Vaibhav Sood
   Reuben Cummings
   Attila Gobi
-  Alecsandru Patrascu
   Christopher Pope
   Tristan Arthur
   Christian Tismer 
@@ -243,7 +246,6 @@
   Jacek Generowicz
   Sylvain Thenault
   Jakub Stasiak
-  Stefan Beyer
   Andrew Dalke
   Alejandro J. Cura
   Vladimir Kryachko
@@ -275,6 +277,7 @@
   Christoph Gerum
   Miguel de Val Borro
   Artur Lisiecki
+  afteryu
   Toni Mattis
   Laurens Van Houtven
   Bobby Impollonia
@@ -305,6 +308,7 @@
   Anna Katrina Dominguez
   Kim Jin Su
   Amber Brown
+  Anthony Sottile
   Nate Bragg
   Ben Darnell
   Juan Francisco Cantero Hurtado
@@ -325,12 +329,14 @@
   Mike Bayer
   Rodrigo Arajo
   Daniil Yarancev
+  Min RK
   OlivierBlanvillain
   Jonas Pfannschmidt
   Zearin
   Andrey Churin
   Dan Crosta
   reub...@gmail.com
+  Stanisaw Halik
   Julien Phalip
   Roman Podoliaka
   Eli Stevens
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@
 RUNINTERP = $(PYPY_EXECUTABLE)
 endif
 
-.PHONY: cffi_imports
+.PHONY: pypy-c cffi_imports
 
 pypy-c:
@echo
@@ -32,7 +32,7 @@
@echo 
""
@echo
@sleep 5
-   $(RUNINTERP) rpython/bin/rpython -Ojit pypy/goal/targetpypystandalone.py
+   cd pypy/goal && $(RUNINTERP) ../../rpython/bin/rpython -Ojit 
targetpypystandalone.py
 
 # Note: the -jN option, or MAKEFLAGS=-jN, are not usable.  They are
 # replaced with an opaque --jobserver option by the time this Makefile
@@ -40,4 +40,4 @@
 # http://lists.gnu.org/archive/html/help-make/2010-08/msg00106.html
 
 cffi_imports: pypy-c
-   PYTHONPATH=. ./pypy-c pypy/tool/build_cffi_imports.py || /bin/true
+   PYTHONPATH=. pypy/goal/pypy-c pypy/tool/build_cffi_imports.py || 
/bin/true
diff --git a/lib-python/2.7/ctypes/__init__.py 
b/lib-python/2.7/ctypes/__init__.py
--- a/lib-python/2.7/ctypes/__init__.py
+++ b/lib-python/2.7/ctypes/__init__.py
@@ -361,17 +361,20 @@
 
 if handle is None:
 if flags & _FUNCFLAG_CDECL:

[pypy-commit] pypy len_w: The idea is to do this change, to make space.len_w() actually

2017-09-29 Thread arigo
Author: Armin Rigo 
Branch: len_w
Changeset: r92512:6bb19d21ddea
Date: 2017-09-29 19:46 +0200
http://bitbucket.org/pypy/pypy/changeset/6bb19d21ddea/

Log:The idea is to do this change, to make space.len_w() actually not
allocate a temporary W_IntObject even if the call to space.len_w()
is not JITted.

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -328,6 +328,11 @@
 raise oefmt(space.w_TypeError,
 "ord() expected string of length 1, but %T found", self)
 
+def len_w(self, space):
+# NOTE: you still need to override __len__ in your specific
+# subclass' typedef; this is only here for optimization.
+return space.int_w(space.len(self))
+
 def spacebind(self, space):
 """ Return a version of the object bound to a specific object space
 instance. This is used for objects (like e.g. TypeDefs) that are
@@ -800,7 +805,7 @@
 
 def len_w(self, w_obj):
 """shortcut for space.int_w(space.len(w_obj))"""
-return self.int_w(self.len(w_obj))
+return w_obj.len_w(self)
 
 def contains_w(self, w_container, w_item):
 """shortcut for space.is_true(space.contains(w_container, w_item))"""
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -308,6 +308,9 @@
 def length(self):
 return self.strategy.length(self)
 
+def len_w(self, space):
+return self.length()
+
 def getitem(self, index):
 """Returns the wrapped object that is found in the
 list at the given index. The index must be unwrapped.
diff --git a/pypy/objspace/std/tupleobject.py b/pypy/objspace/std/tupleobject.py
--- a/pypy/objspace/std/tupleobject.py
+++ b/pypy/objspace/std/tupleobject.py
@@ -283,6 +283,9 @@
 def length(self):
 return len(self.wrappeditems)
 
+def len_w(self, space):
+return self.length()
+
 def descr_hash(self, space):
 if _unroll_condition(self):
 return self._descr_hash_unroll(space)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy len_w: Branch to make "len_w()" a method on W_Root, for optimization purposes

2017-09-29 Thread arigo
Author: Armin Rigo 
Branch: len_w
Changeset: r92511:6136622851dc
Date: 2017-09-29 19:36 +0200
http://bitbucket.org/pypy/pypy/changeset/6136622851dc/

Log:Branch to make "len_w()" a method on W_Root, for optimization
purposes

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


[pypy-commit] pypy memory-accounting: whack for a bit until we a) initialize to 0 and b) have it not on W_Root

2017-09-29 Thread fijal
Author: fijal
Branch: memory-accounting
Changeset: r92510:4420cc75f88e
Date: 2017-09-29 19:37 +0200
http://bitbucket.org/pypy/pypy/changeset/4420cc75f88e/

Log:whack for a bit until we a) initialize to 0 and b) have it not on
W_Root

diff --git a/pypy/module/__pypy__/interp_magic.py 
b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -146,10 +146,10 @@
 """ Add memory pressure of estimate bytes. Useful when calling a C function
 that internally allocates a big chunk of memory. This instructs the GC to
 garbage collect sooner than it would otherwise."""
-if space.is_none(w_obj):
-rgc.add_memory_pressure(estimate)
-else:
-rgc.add_memory_pressure(estimate, w_obj)
+#if space.is_none(w_obj):
+rgc.add_memory_pressure(estimate)
+#else:
+#rgc.add_memory_pressure(estimate, w_obj)
 
 @unwrap_spec(w_frame=PyFrame)
 def locals_to_fast(space, w_frame):
diff --git a/pypy/module/_cffi_backend/cdataobj.py 
b/pypy/module/_cffi_backend/cdataobj.py
--- a/pypy/module/_cffi_backend/cdataobj.py
+++ b/pypy/module/_cffi_backend/cdataobj.py
@@ -447,7 +447,10 @@
 with self as ptr:
 w_res = W_CDataGCP(space, ptr, self.ctype, self, w_destructor)
 if size != 0:
-rgc.add_memory_pressure(size, w_res)
+if isinstance(w_res, W_CDataGCP):
+rgc.add_memory_pressure(size, w_res)
+else:
+rgc.add_memory_pressure(size, self)
 return w_res
 
 def unpack(self, length):
diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -1316,6 +1316,7 @@
 raise ssl_error(space, "failed to allocate SSL context")
 
 self = space.allocate_instance(_SSLContext, w_subtype)
+assert isinstance(self, _SSLContext)
 rgc.add_memory_pressure(10 * 1024, self)
 self.ctx = ctx
 self.check_hostname = False
diff --git a/rpython/rtyper/rclass.py b/rpython/rtyper/rclass.py
--- a/rpython/rtyper/rclass.py
+++ b/rpython/rtyper/rclass.py
@@ -15,6 +15,7 @@
 RuntimeTypeInfo, getRuntimeTypeInfo, typeOf, Void, FuncType, Bool, Signed,
 functionptr, attachRuntimeTypeInfo)
 from rpython.rtyper.lltypesystem.lloperation import llop
+from rpython.rtyper.llannotation import lltype_to_annotation
 from rpython.rtyper.llannotation import SomePtr
 from rpython.rtyper.lltypesystem import rstr
 from rpython.rtyper.rmodel import (
@@ -536,6 +537,9 @@
 # the parent type
 if not 
self.has_special_memory_pressure(self.rbase.object_type):
 llfields.append(('special_memory_pressure', lltype.Signed))
+fields['special_memory_pressure'] = (
+'special_memory_pressure',
+
self.rtyper.getrepr(lltype_to_annotation(lltype.Signed)))
 
 object_type = MkStruct(self.classdef.name,
('super', self.rbase.object_type),
@@ -677,6 +681,8 @@
 while base.classdef is not None:
 base = base.rbase
 for fieldname in base.fields:
+if fieldname == 'special_memory_pressure':
+continue
 try:
 mangled, r = base._get_field(fieldname)
 except KeyError:
@@ -731,6 +737,9 @@
resulttype=Ptr(self.object_type))
 ctypeptr = inputconst(CLASSTYPE, self.rclass.getvtable())
 self.setfield(vptr, '__class__', ctypeptr, llops)
+if self.has_special_memory_pressure(self.object_type):
+self.setfield(vptr, 'special_memory_pressure',
+inputconst(lltype.Signed, 0), llops)
 # initialize instance attributes from their defaults from the class
 if self.classdef is not None:
 flds = self.allinstancefields.keys()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: (antocuni, arigo)

2017-09-29 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r92509:094524b8baa4
Date: 2017-09-29 18:32 +0200
http://bitbucket.org/pypy/pypy/changeset/094524b8baa4/

Log:(antocuni, arigo)

aa even more hacking

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
@@ -1403,6 +1403,11 @@
 
 assert B() == 42
 
+# a even more hackiness
+class C(A):
+pass
+C(42)   # assert is not aborting
+
 
 class AppTestHashable(AppTestCpythonExtensionBase):
 def test_unhashable(self):
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
@@ -667,15 +667,30 @@
 #   it can fail if self.__base__ happens not to be the first base.
 #
 from pypy.module.cpyext.methodobject import W_PyCFunctionObject
+
+if isinstance(w_newdescr, W_PyCFunctionObject):
+return self._really_hack_which_new_to_call(w_newtype, w_newdescr)
+else:
+return w_newtype, w_newdescr
+
+def _really_hack_which_new_to_call(self, w_newtype, w_newdescr):
+# This logic is moved in yet another helper function that
+# is recursive.  We call this only if we see a
+# W_PyCFunctionObject.  That's a performance optimization
+# because in the common case, we won't call any function that
+# contains the stack checks.
+from pypy.module.cpyext.methodobject import W_PyCFunctionObject
 from pypy.module.cpyext.typeobject import is_tp_new_wrapper
 
 if (isinstance(w_newdescr, W_PyCFunctionObject) and
 w_newtype is not self and
 is_tp_new_wrapper(self.space, w_newdescr.ml)):
 w_bestbase = find_best_base(self.bases_w)
-return w_bestbase.lookup_where('__new__')
-else:
-return w_newtype, w_newdescr
+if w_bestbase is not None:
+w_newtype, w_newdescr = w_bestbase.lookup_where('__new__')
+return w_bestbase._really_hack_which_new_to_call(w_newtype,
+ w_newdescr)
+return w_newtype, w_newdescr
 
 def descr_repr(self, space):
 w_mod = self.get_module()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: (antocuni, arigo)

2017-09-29 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r92507:075a4ef2fb28
Date: 2017-09-29 17:48 +0200
http://bitbucket.org/pypy/pypy/changeset/075a4ef2fb28/

Log:(antocuni, arigo)

oops, fix for 3f4fc7771154 (some tests in cpyext fail)

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
@@ -670,6 +670,7 @@
 from pypy.module.cpyext.typeobject import is_tp_new_wrapper
 
 if (isinstance(w_newdescr, W_PyCFunctionObject) and
+w_newtype is not self and
 is_tp_new_wrapper(self.space, w_newdescr.ml)):
 w_bestbase = find_best_base(self.bases_w)
 return w_bestbase.lookup_where('__new__')
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: merge heads

2017-09-29 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r92508:c4d6cc4a81fe
Date: 2017-09-29 17:52 +0200
http://bitbucket.org/pypy/pypy/changeset/c4d6cc4a81fe/

Log:merge heads

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
@@ -10,7 +10,8 @@
 from pypy.module.cpyext.api import (
 CONST_STRING, METH_CLASS, METH_COEXIST, METH_KEYWORDS, METH_NOARGS, METH_O,
 METH_STATIC, METH_VARARGS, PyObject, bootstrap_function,
-cpython_api, generic_cpy_call, CANNOT_FAIL, slot_function, cts)
+cpython_api, generic_cpy_call, CANNOT_FAIL, slot_function, cts,
+build_type_checkers)
 from pypy.module.cpyext.pyobject import (
 Py_DecRef, from_ref, make_ref, as_pyobj, make_typedescr)
 
@@ -136,6 +137,10 @@
 ret = self.call(space, w_instance, w_args, w_kw)
 return ret
 
+# PyPy addition, for Cython
+_, _ = build_type_checkers("MethodDescr", W_PyCMethodObject)
+
+
 @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
 def PyCFunction_Check(space, w_obj):
 from pypy.interpreter.function import BuiltinFunction
@@ -162,6 +167,7 @@
 (self.name, self.w_objclass.getname(self.space)))
 
 
+
 class W_PyCWrapperObject(W_Root):
 def __init__(self, space, pto, method_name, wrapper_func,
  wrapper_func_kwds, doc, func, offset=None):
diff --git a/pypy/module/cpyext/test/foo.c b/pypy/module/cpyext/test/foo.c
--- a/pypy/module/cpyext/test/foo.c
+++ b/pypy/module/cpyext/test/foo.c
@@ -83,19 +83,32 @@
 return cls;
 }
 
+// for CPython
+#ifndef PyMethodDescr_Check
+int PyMethodDescr_Check(PyObject* method)
+{
+PyObject *meth = PyObject_GetAttrString((PyObject*)_Type, "append");
+if (!meth) return 0;
+int res = PyObject_TypeCheck(method, meth->ob_type);
+Py_DECREF(meth);
+return res;
+}
+#endif
+
 PyObject* make_classmethod(PyObject* method)
 {
 // adapted from __Pyx_Method_ClassMethod
-if (PyObject_TypeCheck(method, _Type)) {
-return PyClassMethod_New(method);
+if (PyMethodDescr_Check(method)) {
+PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
+PyTypeObject *d_type = descr->d_type;
+return PyDescr_NewClassMethod(d_type, descr->d_method);
 }
 else if (PyMethod_Check(method)) {
 return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
 }
 else {
-PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
-PyTypeObject *d_type = descr->d_type;
-return PyDescr_NewClassMethod(d_type, descr->d_method);
+PyErr_SetString(PyExc_TypeError, "unknown method kind");
+return NULL;
 }
 }
 
@@ -825,6 +838,8 @@
 
 fake_classmeth = PyDict_GetItemString((PyObject *)fooType.tp_dict, 
"fake_classmeth");
 classmeth = make_classmethod(fake_classmeth);
+if (classmeth == NULL)
+INITERROR;
 if (PyDict_SetItemString((PyObject *)fooType.tp_dict, "fake_classmeth", 
classmeth) < 0)
 INITERROR;
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy memory-accounting: * Review all the places that add memory pressure outside of numpy and cpyext

2017-09-29 Thread fijal
Author: fijal
Branch: memory-accounting
Changeset: r92506:f8fd62a0f087
Date: 2017-09-29 17:19 +0200
http://bitbucket.org/pypy/pypy/changeset/f8fd62a0f087/

Log:* Review all the places that add memory pressure outside of numpy
and cpyext
* Add a test
* Fixes about cast_pointer in the presence of subclasses
* Write down the app-level interface to that

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -35,7 +35,7 @@
 except ImportError:
 assert '__pypy__' not in sys.builtin_module_names
 newlist_hint = lambda sizehint: []
-add_memory_pressure = lambda size: None
+add_memory_pressure = lambda size, obj: None
 
 if sys.version_info[0] >= 3:
 StandardError = Exception
@@ -153,9 +153,10 @@
 factory = Connection if not factory else factory
 # an sqlite3 db seems to be around 100 KiB at least (doesn't matter if
 # backed by :memory: or a file)
-add_memory_pressure(100 * 1024)
-return factory(database, timeout, detect_types, isolation_level,
+res = factory(database, timeout, detect_types, isolation_level,
 check_same_thread, factory, cached_statements)
+add_memory_pressure(100 * 1024, res)
+return res
 
 
 def _unicode_text_factory(x):
diff --git a/pypy/module/__pypy__/interp_magic.py 
b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -142,11 +142,14 @@
   space.newbool(debug))
 
 @unwrap_spec(estimate=int)
-def add_memory_pressure(estimate):
+def add_memory_pressure(space, estimate, w_obj=None):
 """ Add memory pressure of estimate bytes. Useful when calling a C function
 that internally allocates a big chunk of memory. This instructs the GC to
 garbage collect sooner than it would otherwise."""
-rgc.add_memory_pressure(estimate)
+if space.is_none(w_obj):
+rgc.add_memory_pressure(estimate)
+else:
+rgc.add_memory_pressure(estimate, w_obj)
 
 @unwrap_spec(w_frame=PyFrame)
 def locals_to_fast(space, w_frame):
diff --git a/pypy/module/_cffi_backend/allocator.py 
b/pypy/module/_cffi_backend/allocator.py
--- a/pypy/module/_cffi_backend/allocator.py
+++ b/pypy/module/_cffi_backend/allocator.py
@@ -21,13 +21,13 @@
 if self.w_alloc is None:
 if self.should_clear_after_alloc:
 ptr = lltype.malloc(rffi.CCHARP.TO, datasize,
-flavor='raw', zero=True,
-add_memory_pressure=True)
+flavor='raw', zero=True)
 else:
 ptr = lltype.malloc(rffi.CCHARP.TO, datasize,
-flavor='raw', zero=False,
-add_memory_pressure=True)
-return cdataobj.W_CDataNewStd(space, ptr, ctype, length)
+flavor='raw', zero=False)
+w_res = cdataobj.W_CDataNewStd(space, ptr, ctype, length)
+rgc.add_memory_pressure(datasize, w_res)
+return w_res
 else:
 w_raw_cdata = space.call_function(self.w_alloc,
   space.newint(datasize))
@@ -53,7 +53,7 @@
 if self.w_free is not None:
 res.w_free = self.w_free
 res.register_finalizer(space)
-rgc.add_memory_pressure(datasize)
+rgc.add_memory_pressure(datasize, res)
 return res
 
 @unwrap_spec(w_init=WrappedDefault(None))
diff --git a/pypy/module/_cffi_backend/cdataobj.py 
b/pypy/module/_cffi_backend/cdataobj.py
--- a/pypy/module/_cffi_backend/cdataobj.py
+++ b/pypy/module/_cffi_backend/cdataobj.py
@@ -447,7 +447,7 @@
 with self as ptr:
 w_res = W_CDataGCP(space, ptr, self.ctype, self, w_destructor)
 if size != 0:
-rgc.add_memory_pressure(size)
+rgc.add_memory_pressure(size, w_res)
 return w_res
 
 def unpack(self, length):
diff --git a/pypy/module/_hashlib/interp_hashlib.py 
b/pypy/module/_hashlib/interp_hashlib.py
--- a/pypy/module/_hashlib/interp_hashlib.py
+++ b/pypy/module/_hashlib/interp_hashlib.py
@@ -61,7 +61,8 @@
 ctx = ropenssl.EVP_MD_CTX_new()
 if ctx is None:
 raise MemoryError
-rgc.add_memory_pressure(ropenssl.HASH_MALLOC_SIZE + self.digest_size)
+rgc.add_memory_pressure(ropenssl.HASH_MALLOC_SIZE + self.digest_size,
+self)
 try:
 if copy_from:
 if not ropenssl.EVP_MD_CTX_copy(ctx, copy_from):
diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -1315,8 +1315,8 @@
 if not ctx:
 raise ssl_error(space, "failed to allocate SSL context")
 
-

[pypy-commit] pypy py3.5: hg merge default

2017-09-29 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92505:a0fe3f649ba8
Date: 2017-09-29 17:14 +0200
http://bitbucket.org/pypy/pypy/changeset/a0fe3f649ba8/

Log:hg merge default

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
@@ -10,7 +10,8 @@
 from pypy.module.cpyext.api import (
 CONST_STRING, METH_CLASS, METH_COEXIST, METH_KEYWORDS, METH_NOARGS, METH_O,
 METH_STATIC, METH_VARARGS, PyObject, bootstrap_function,
-cpython_api, generic_cpy_call, CANNOT_FAIL, slot_function, cts)
+cpython_api, generic_cpy_call, CANNOT_FAIL, slot_function, cts,
+build_type_checkers)
 from pypy.module.cpyext.pyobject import (
 Py_DecRef, from_ref, make_ref, as_pyobj, make_typedescr)
 
@@ -129,6 +130,10 @@
 ret = self.call(space, w_instance, w_args, w_kw)
 return ret
 
+# PyPy addition, for Cython
+_, _ = build_type_checkers("MethodDescr", W_PyCMethodObject)
+
+
 @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
 def PyCFunction_Check(space, w_obj):
 from pypy.interpreter.function import BuiltinFunction
@@ -155,6 +160,7 @@
 (self.name.decode('utf-8'), self.w_objclass.getname(self.space)))
 
 
+
 class W_PyCWrapperObject(W_Root):
 def __init__(self, space, pto, method_name, wrapper_func,
  wrapper_func_kwds, doc, func, offset=None):
diff --git a/pypy/module/cpyext/test/foo.c b/pypy/module/cpyext/test/foo.c
--- a/pypy/module/cpyext/test/foo.c
+++ b/pypy/module/cpyext/test/foo.c
@@ -83,19 +83,32 @@
 return cls;
 }
 
+// for CPython
+#ifndef PyMethodDescr_Check
+int PyMethodDescr_Check(PyObject* method)
+{
+PyObject *meth = PyObject_GetAttrString((PyObject*)_Type, "append");
+if (!meth) return 0;
+int res = PyObject_TypeCheck(method, meth->ob_type);
+Py_DECREF(meth);
+return res;
+}
+#endif
+
 PyObject* make_classmethod(PyObject* method)
 {
 // adapted from __Pyx_Method_ClassMethod
-if (PyObject_TypeCheck(method, _Type)) {
-return PyClassMethod_New(method);
+if (PyMethodDescr_Check(method)) {
+PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
+PyTypeObject *d_type = descr->d_common.d_type;
+return PyDescr_NewClassMethod(d_type, descr->d_method);
 }
 else if (PyMethod_Check(method)) {
 return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
 }
 else {
-PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
-PyTypeObject *d_type = descr->d_common.d_type;
-return PyDescr_NewClassMethod(d_type, descr->d_method);
+PyErr_SetString(PyExc_TypeError, "unknown method kind");
+return NULL;
 }
 }
 
@@ -828,6 +841,8 @@
 
 fake_classmeth = PyDict_GetItemString((PyObject *)fooType.tp_dict, 
"fake_classmeth");
 classmeth = make_classmethod(fake_classmeth);
+if (classmeth == NULL)
+INITERROR;
 if (PyDict_SetItemString((PyObject *)fooType.tp_dict, "fake_classmeth", 
classmeth) < 0)
 INITERROR;
 
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
@@ -1321,6 +1321,47 @@
 assert Asize == Bsize
 assert Asize > basesize
 
+def test_multiple_inheritance_bug1(self):
+module = self.import_extension('foo', [
+   ("get_type", "METH_NOARGS",
+'''
+Py_INCREF(_Type);
+return (PyObject *)_Type;
+'''
+), ("forty_two", "METH_O",
+'''
+return PyLong_FromLong(42);
+'''
+)], prologue='''
+static PyTypeObject Foo_Type = {
+PyVarObject_HEAD_INIT(NULL, 0)
+"foo.foo",
+};
+static PyObject *dummy_new(PyTypeObject *t, PyObject *a,
+   PyObject *k)
+{
+abort();   /* never actually called in CPython */
+}
+''', more_init = '''
+Foo_Type.tp_base = (PyTypeObject *)PyExc_Exception;
+Foo_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
+Foo_Type.tp_new = dummy_new;
+if (PyType_Ready(_Type) < 0) INITERROR;
+''')
+Foo = module.get_type()
+class A(Foo, SyntaxError):
+pass
+assert A.__base__ is SyntaxError
+A(42)# assert is not aborting
+
+class Bar(Exception):
+__new__ = module.forty_two
+
+class B(Bar, SyntaxError):
+pass
+
+assert B() == 42
+
 
 class AppTestHashable(AppTestCpythonExtensionBase):
 def test_unhashable(self):
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ 

[pypy-commit] pypy default: Add a PyMethodDescr_Check() (not in the CPython API) for Cython's benefit

2017-09-29 Thread rlamy
Author: Ronan Lamy 
Branch: 
Changeset: r92504:5acb984186b5
Date: 2017-09-29 16:33 +0200
http://bitbucket.org/pypy/pypy/changeset/5acb984186b5/

Log:Add a PyMethodDescr_Check() (not in the CPython API) for Cython's
benefit

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
@@ -10,7 +10,8 @@
 from pypy.module.cpyext.api import (
 CONST_STRING, METH_CLASS, METH_COEXIST, METH_KEYWORDS, METH_NOARGS, METH_O,
 METH_STATIC, METH_VARARGS, PyObject, bootstrap_function,
-cpython_api, generic_cpy_call, CANNOT_FAIL, slot_function, cts)
+cpython_api, generic_cpy_call, CANNOT_FAIL, slot_function, cts,
+build_type_checkers)
 from pypy.module.cpyext.pyobject import (
 Py_DecRef, from_ref, make_ref, as_pyobj, make_typedescr)
 
@@ -136,6 +137,10 @@
 ret = self.call(space, w_instance, w_args, w_kw)
 return ret
 
+# PyPy addition, for Cython
+_, _ = build_type_checkers("MethodDescr", W_PyCMethodObject)
+
+
 @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
 def PyCFunction_Check(space, w_obj):
 from pypy.interpreter.function import BuiltinFunction
@@ -162,6 +167,7 @@
 (self.name, self.w_objclass.getname(self.space)))
 
 
+
 class W_PyCWrapperObject(W_Root):
 def __init__(self, space, pto, method_name, wrapper_func,
  wrapper_func_kwds, doc, func, offset=None):
diff --git a/pypy/module/cpyext/test/foo.c b/pypy/module/cpyext/test/foo.c
--- a/pypy/module/cpyext/test/foo.c
+++ b/pypy/module/cpyext/test/foo.c
@@ -83,19 +83,32 @@
 return cls;
 }
 
+// for CPython
+#ifndef PyMethodDescr_Check
+int PyMethodDescr_Check(PyObject* method)
+{
+PyObject *meth = PyObject_GetAttrString((PyObject*)_Type, "append");
+if (!meth) return 0;
+int res = PyObject_TypeCheck(method, meth->ob_type);
+Py_DECREF(meth);
+return res;
+}
+#endif
+
 PyObject* make_classmethod(PyObject* method)
 {
 // adapted from __Pyx_Method_ClassMethod
-if (PyObject_TypeCheck(method, _Type)) {
-return PyClassMethod_New(method);
+if (PyMethodDescr_Check(method)) {
+PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
+PyTypeObject *d_type = descr->d_type;
+return PyDescr_NewClassMethod(d_type, descr->d_method);
 }
 else if (PyMethod_Check(method)) {
 return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
 }
 else {
-PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
-PyTypeObject *d_type = descr->d_type;
-return PyDescr_NewClassMethod(d_type, descr->d_method);
+PyErr_SetString(PyExc_TypeError, "unknown method kind");
+return NULL;
 }
 }
 
@@ -825,6 +838,8 @@
 
 fake_classmeth = PyDict_GetItemString((PyObject *)fooType.tp_dict, 
"fake_classmeth");
 classmeth = make_classmethod(fake_classmeth);
+if (classmeth == NULL)
+INITERROR;
 if (PyDict_SetItemString((PyObject *)fooType.tp_dict, "fake_classmeth", 
classmeth) < 0)
 INITERROR;
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: (antocuni, arigo) Issue #2666

2017-09-29 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r92503:3f4fc7771154
Date: 2017-09-29 15:23 +0200
http://bitbucket.org/pypy/pypy/changeset/3f4fc7771154/

Log:(antocuni, arigo) Issue #2666

Mess with cpyext. See comments.

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
@@ -1362,6 +1362,47 @@
 assert Asize == Bsize
 assert Asize > basesize
 
+def test_multiple_inheritance_bug1(self):
+module = self.import_extension('foo', [
+   ("get_type", "METH_NOARGS",
+'''
+Py_INCREF(_Type);
+return (PyObject *)_Type;
+'''
+), ("forty_two", "METH_O",
+'''
+return PyInt_FromLong(42);
+'''
+)], prologue='''
+static PyTypeObject Foo_Type = {
+PyVarObject_HEAD_INIT(NULL, 0)
+"foo.foo",
+};
+static PyObject *dummy_new(PyTypeObject *t, PyObject *a,
+   PyObject *k)
+{
+abort();   /* never actually called in CPython */
+}
+''', more_init = '''
+Foo_Type.tp_base = (PyTypeObject *)PyExc_Exception;
+Foo_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
+Foo_Type.tp_new = dummy_new;
+if (PyType_Ready(_Type) < 0) INITERROR;
+''')
+Foo = module.get_type()
+class A(Foo, SyntaxError):
+pass
+assert A.__base__ is SyntaxError
+A(42)# assert is not aborting
+
+class Bar(Exception):
+__new__ = module.forty_two
+
+class B(Bar, SyntaxError):
+pass
+
+assert B() == 42
+
 
 class AppTestHashable(AppTestCpythonExtensionBase):
 def test_unhashable(self):
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
@@ -394,6 +394,9 @@
 ptr = get_new_method_def(space)
 ptr.c_ml_meth = rffi.cast(PyCFunction, llslot(space, tp_new_wrapper))
 
+def is_tp_new_wrapper(space, ml):
+return ml.c_ml_meth == rffi.cast(PyCFunction, llslot(space, 
tp_new_wrapper))
+
 def add_tp_new_wrapper(space, dict_w, pto):
 if "__new__" in dict_w:
 return
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
@@ -626,6 +626,12 @@
 if w_newdescr is None:# see test_crash_mro_without_object_1
 raise oefmt(space.w_TypeError, "cannot create '%N' instances",
 self)
+#
+# issue #2666
+if space.config.objspace.usemodules.cpyext:
+w_newtype, w_newdescr = self.hack_which_new_to_call(
+w_newtype, w_newdescr)
+#
 w_newfunc = space.get(w_newdescr, self)
 if (space.config.objspace.std.newshortcut and
 not we_are_jitted() and
@@ -646,6 +652,30 @@
 "__init__() should return None")
 return w_newobject
 
+def hack_which_new_to_call(self, w_newtype, w_newdescr):
+# issue #2666: for cpyext, we need to hack in order to reproduce
+# an "optimization" of CPython that actually changes behaviour
+# in corner cases.
+#
+# * Normally, we use the __new__ found in the MRO in the normal way.
+#
+# * If by chance this __new__ happens to be implemented as a C
+#   function, then instead, we discard it and use directly
+#   self.__base__.tp_new.
+#
+# * Most of the time this is the same (and faster for CPython), but
+#   it can fail if self.__base__ happens not to be the first base.
+#
+from pypy.module.cpyext.methodobject import W_PyCFunctionObject
+from pypy.module.cpyext.typeobject import is_tp_new_wrapper
+
+if (isinstance(w_newdescr, W_PyCFunctionObject) and
+is_tp_new_wrapper(self.space, w_newdescr.ml)):
+w_bestbase = find_best_base(self.bases_w)
+return w_bestbase.lookup_where('__new__')
+else:
+return w_newtype, w_newdescr
+
 def descr_repr(self, space):
 w_mod = self.get_module()
 if w_mod is None or not space.isinstance_w(w_mod, space.w_text):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix Cython issue with classmethods in cdef classes

2017-09-29 Thread rlamy
Author: Ronan Lamy 
Branch: 
Changeset: r92502:484db8c81ec1
Date: 2017-09-29 12:17 +0200
http://bitbucket.org/pypy/pypy/changeset/484db8c81ec1/

Log:fix Cython issue with classmethods in cdef classes

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
@@ -654,7 +654,7 @@
 'PyClass_Type': 'space.gettypeobject(W_ClassObject.typedef)',
 'PyStaticMethod_Type': 'space.gettypeobject(StaticMethod.typedef)',
 'PyCFunction_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCFunctionObject.typedef)',
-'PyWrapperDescr_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCMethodObject.typedef)'
+'PyWrapperDescr_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCWrapperObject.typedef)',
 }.items():
 register_global(cpyname, 'PyTypeObject*', pypyexpr, header=pypy_decl)
 
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
@@ -1,4 +1,4 @@
-from rpython.rtyper.lltypesystem import lltype, rffi, llmemory
+from rpython.rtyper.lltypesystem import lltype, rffi
 
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.error import OperationError, oefmt
@@ -10,8 +10,7 @@
 from pypy.module.cpyext.api import (
 CONST_STRING, METH_CLASS, METH_COEXIST, METH_KEYWORDS, METH_NOARGS, METH_O,
 METH_STATIC, METH_VARARGS, PyObject, bootstrap_function,
-cpython_api, generic_cpy_call, CANNOT_FAIL,
-PyTypeObjectPtr, slot_function, cts)
+cpython_api, generic_cpy_call, CANNOT_FAIL, slot_function, cts)
 from pypy.module.cpyext.pyobject import (
 Py_DecRef, from_ref, make_ref, as_pyobj, make_typedescr)
 
@@ -109,7 +108,7 @@
 return self.space.unwrap(self.descr_method_repr())
 
 def descr_method_repr(self):
-w_objclass = self.w_objclass 
+w_objclass = self.w_objclass
 assert isinstance(w_objclass, W_TypeObject)
 return self.space.newtext("" % (
 self.name, w_objclass.name))
@@ -117,7 +116,7 @@
 def descr_call(self, space, __args__):
 args_w, kw_w = __args__.unpack()
 if len(args_w) < 1:
-w_objclass = self.w_objclass 
+w_objclass = self.w_objclass
 assert isinstance(w_objclass, W_TypeObject)
 raise oefmt(space.w_TypeError,
 "descriptor '%s' of '%s' object needs an argument",
@@ -125,7 +124,7 @@
 w_instance = args_w[0]
 # XXX: needs a stricter test
 if not space.isinstance_w(w_instance, self.w_objclass):
-w_objclass = self.w_objclass 
+w_objclass = self.w_objclass
 assert isinstance(w_objclass, W_TypeObject)
 raise oefmt(space.w_TypeError,
 "descriptor '%s' requires a '%s' object but received a '%T'",
@@ -333,11 +332,15 @@
 def PyClassMethod_New(space, w_func):
 return ClassMethod(w_func)
 
-@cpython_api([PyTypeObjectPtr, lltype.Ptr(PyMethodDef)], PyObject)
+@cts.decl("""
+PyObject *
+PyDescr_NewClassMethod(PyTypeObject *type, PyMethodDef *method)""")
 def PyDescr_NewMethod(space, w_type, method):
 return W_PyCMethodObject(space, method, w_type)
 
-@cpython_api([PyObject, lltype.Ptr(PyMethodDef)], PyObject)
+@cts.decl("""
+PyObject *
+PyDescr_NewClassMethod(PyTypeObject *type, PyMethodDef *method)""")
 def PyDescr_NewClassMethod(space, w_type, method):
 return W_PyCClassMethodObject(space, method, w_type)
 
diff --git a/pypy/module/cpyext/test/foo.c b/pypy/module/cpyext/test/foo.c
--- a/pypy/module/cpyext/test/foo.c
+++ b/pypy/module/cpyext/test/foo.c
@@ -83,6 +83,22 @@
 return cls;
 }
 
+PyObject* make_classmethod(PyObject* method)
+{
+// adapted from __Pyx_Method_ClassMethod
+if (PyObject_TypeCheck(method, _Type)) {
+return PyClassMethod_New(method);
+}
+else if (PyMethod_Check(method)) {
+return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
+}
+else {
+PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
+PyTypeObject *d_type = descr->d_type;
+return PyDescr_NewClassMethod(d_type, descr->d_method);
+}
+}
+
 static PyObject *
 foo_unset(fooobject *self)
 {
@@ -95,6 +111,7 @@
 {"copy",  (PyCFunction)foo_copy,  METH_NOARGS,  NULL},
 {"create",(PyCFunction)foo_create,METH_NOARGS|METH_STATIC,  NULL},
 {"classmeth", (PyCFunction)foo_classmeth, METH_NOARGS|METH_CLASS,  NULL},
+{"fake_classmeth", (PyCFunction)foo_classmeth, METH_NOARGS,  NULL},
 {"unset_string_member", (PyCFunction)foo_unset, METH_NOARGS, NULL},
 {NULL, NULL} /* sentinel */
 };
@@ -167,19 +184,19 @@
 /* copied from numpy scalartypes.c for inherited classes */
 if (t->tp_bases && (PyTuple_GET_SIZE(t->tp_bases) > 1))
 {
-PyTypeObject *sup; 
-/* We are 

[pypy-commit] pypy memory-accounting: (arigo, fijal) add accounting for basic memory pressure done by raw mallocs

2017-09-29 Thread fijal
Author: fijal
Branch: memory-accounting
Changeset: r92501:f0e56ca3a8d6
Date: 2017-09-29 13:01 +0200
http://bitbucket.org/pypy/pypy/changeset/f0e56ca3a8d6/

Log:(arigo, fijal) add accounting for basic memory pressure done by raw
mallocs

diff --git a/rpython/memory/gc/base.py b/rpython/memory/gc/base.py
--- a/rpython/memory/gc/base.py
+++ b/rpython/memory/gc/base.py
@@ -83,7 +83,9 @@
 has_custom_trace,
 fast_path_tracing,
 has_gcptr,
-cannot_pin):
+cannot_pin,
+has_memory_pressure,
+get_memory_pressure_ofs):
 self.finalizer_handlers = finalizer_handlers
 self.destructor_or_custom_trace = destructor_or_custom_trace
 self.is_old_style_finalizer = is_old_style_finalizer
@@ -103,6 +105,8 @@
 self.fast_path_tracing = fast_path_tracing
 self.has_gcptr = has_gcptr
 self.cannot_pin = cannot_pin
+self.has_memory_pressure = has_memory_pressure
+self.get_memory_pressure_ofs = get_memory_pressure_ofs
 
 def get_member_index(self, type_id):
 return self.member_index(type_id)
diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py
--- a/rpython/memory/gc/incminimark.py
+++ b/rpython/memory/gc/incminimark.py
@@ -2920,6 +2920,12 @@
 self.old_objects_with_weakrefs = new_with_weakref
 
 def get_stats(self, stats_no):
+from rpython.memory.gc import inspector
+
+if stats_no == rgc.TOTAL_MEMORY:
+return 0
+elif stats_no == rgc.TOTAL_MEMORY_PRESSURE:
+return inspector.count_memory_pressure(self)
 return 0
 
 
diff --git a/rpython/memory/gc/inspector.py b/rpython/memory/gc/inspector.py
--- a/rpython/memory/gc/inspector.py
+++ b/rpython/memory/gc/inspector.py
@@ -92,17 +92,12 @@
 
 AddressStack = get_address_stack()
 
-class HeapDumper(object):
-_alloc_flavor_ = "raw"
-BUFSIZE = 8192 # words
+class BaseWalker(object):
+_alloc_flavor_ = 'raw'
 
-def __init__(self, gc, fd):
+def __init__(self, gc):
 self.gc = gc
 self.gcflag = gc.gcflag_extra
-self.fd = rffi.cast(rffi.INT, fd)
-self.writebuffer = lltype.malloc(rffi.SIGNEDP.TO, self.BUFSIZE,
- flavor='raw')
-self.buf_count = 0
 if self.gcflag == 0:
 self.seen = AddressDict()
 self.pending = AddressStack()
@@ -111,8 +106,102 @@
 if self.gcflag == 0:
 self.seen.delete()
 self.pending.delete()
+free_non_gc_object(self)
+
+def add_roots(self):
+self.gc.enumerate_all_roots(_hd_add_root, self)
+pendingroots = self.pending
+self.pending = AddressStack()
+self.walk(pendingroots)
+pendingroots.delete()
+self.end_add_roots_marker()
+
+def end_add_roots_marker(self):
+pass
+
+def add(self, obj):
+if self.gcflag == 0:
+if not self.seen.contains(obj):
+self.seen.setitem(obj, obj)
+self.pending.append(obj)
+else:
+hdr = self.gc.header(obj)
+if (hdr.tid & self.gcflag) == 0:
+hdr.tid |= self.gcflag
+self.pending.append(obj)
+
+def walk(self, pending):
+while pending.non_empty():
+self.processobj(pending.pop())
+
+# --
+# A simplified copy of the above, to make sure we walk again all the
+# objects to clear the 'gcflag'.
+
+def unobj(self, obj):
+gc = self.gc
+gc.trace(obj, self._unref, None)
+
+def _unref(self, pointer, _):
+obj = pointer.address[0]
+self.unadd(obj)
+
+def unadd(self, obj):
+assert self.gcflag != 0
+hdr = self.gc.header(obj)
+if (hdr.tid & self.gcflag) != 0:
+hdr.tid &= ~self.gcflag
+self.pending.append(obj)
+
+def clear_gcflag_again(self):
+self.gc.enumerate_all_roots(_hd_unadd_root, self)
+pendingroots = self.pending
+self.pending = AddressStack()
+self.unwalk(pendingroots)
+pendingroots.delete()
+
+def unwalk(self, pending):
+while pending.non_empty():
+self.unobj(pending.pop())
+
+def finish_processing(self):
+if self.gcflag != 0:
+self.clear_gcflag_again()
+self.unwalk(self.pending)
+
+def process(self):
+self.add_roots()
+self.walk(self.pending)
+
+
+class MemoryPressureCounter(BaseWalker):
+
+def __init__(self, gc):
+self.count = 0
+BaseWalker.__init__(self, gc)
+
+def processobj(self, obj):
+gc = self.gc
+typeid = gc.get_type_id(obj)
+if gc.has_memory_pressure(typeid):
+ofs = gc.get_memory_pressure_ofs(typeid)
+val = (obj + 

[pypy-commit] pypy py3.5: fix Cython issue with classmethods in cdef classes

2017-09-29 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92500:3c8212fb97a5
Date: 2017-09-29 12:17 +0200
http://bitbucket.org/pypy/pypy/changeset/3c8212fb97a5/

Log:fix Cython issue with classmethods in cdef classes

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
@@ -669,7 +669,7 @@
 'PySlice_Type': 'space.gettypeobject(W_SliceObject.typedef)',
 'PyStaticMethod_Type': 'space.gettypeobject(StaticMethod.typedef)',
 'PyCFunction_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCFunctionObject.typedef)',
-'PyWrapperDescr_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCMethodObject.typedef)',
+'PyWrapperDescr_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCWrapperObject.typedef)',
 'PyInstanceMethod_Type': 
'space.gettypeobject(cpyext.classobject.InstanceMethod.typedef)',
 }.items():
 register_global(cpyname, 'PyTypeObject*', pypyexpr, header=pypy_decl)
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
@@ -1,4 +1,4 @@
-from rpython.rtyper.lltypesystem import lltype, rffi, llmemory
+from rpython.rtyper.lltypesystem import lltype, rffi
 
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.error import OperationError, oefmt
@@ -10,8 +10,7 @@
 from pypy.module.cpyext.api import (
 CONST_STRING, METH_CLASS, METH_COEXIST, METH_KEYWORDS, METH_NOARGS, METH_O,
 METH_STATIC, METH_VARARGS, PyObject, bootstrap_function,
-cpython_api, generic_cpy_call, CANNOT_FAIL,
-PyTypeObjectPtr, slot_function, cts)
+cpython_api, generic_cpy_call, CANNOT_FAIL, slot_function, cts)
 from pypy.module.cpyext.pyobject import (
 Py_DecRef, from_ref, make_ref, as_pyobj, make_typedescr)
 
@@ -102,7 +101,7 @@
 return self.space.unwrap(self.descr_method_repr())
 
 def descr_method_repr(self):
-w_objclass = self.w_objclass 
+w_objclass = self.w_objclass
 assert isinstance(w_objclass, W_TypeObject)
 return self.space.newtext("" % (
 self.name, w_objclass.name))
@@ -110,7 +109,7 @@
 def descr_call(self, space, __args__):
 args_w, kw_w = __args__.unpack()
 if len(args_w) < 1:
-w_objclass = self.w_objclass 
+w_objclass = self.w_objclass
 assert isinstance(w_objclass, W_TypeObject)
 raise oefmt(space.w_TypeError,
 "descriptor '%8' of '%s' object needs an argument",
@@ -118,7 +117,7 @@
 w_instance = args_w[0]
 # XXX: needs a stricter test
 if not space.isinstance_w(w_instance, self.w_objclass):
-w_objclass = self.w_objclass 
+w_objclass = self.w_objclass
 assert isinstance(w_objclass, W_TypeObject)
 raise oefmt(space.w_TypeError,
 "descriptor '%8' requires a '%s' object but received a '%T'",
@@ -323,11 +322,15 @@
 def PyClassMethod_New(space, w_func):
 return ClassMethod(w_func)
 
-@cpython_api([PyTypeObjectPtr, lltype.Ptr(PyMethodDef)], PyObject)
+@cts.decl("""
+PyObject *
+PyDescr_NewClassMethod(PyTypeObject *type, PyMethodDef *method)""")
 def PyDescr_NewMethod(space, w_type, method):
 return W_PyCMethodObject(space, method, w_type)
 
-@cpython_api([PyObject, lltype.Ptr(PyMethodDef)], PyObject)
+@cts.decl("""
+PyObject *
+PyDescr_NewClassMethod(PyTypeObject *type, PyMethodDef *method)""")
 def PyDescr_NewClassMethod(space, w_type, method):
 return W_PyCClassMethodObject(space, method, w_type)
 
diff --git a/pypy/module/cpyext/test/foo.c b/pypy/module/cpyext/test/foo.c
--- a/pypy/module/cpyext/test/foo.c
+++ b/pypy/module/cpyext/test/foo.c
@@ -83,6 +83,22 @@
 return cls;
 }
 
+PyObject* make_classmethod(PyObject* method)
+{
+// adapted from __Pyx_Method_ClassMethod
+if (PyObject_TypeCheck(method, _Type)) {
+return PyClassMethod_New(method);
+}
+else if (PyMethod_Check(method)) {
+return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
+}
+else {
+PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
+PyTypeObject *d_type = descr->d_common.d_type;
+return PyDescr_NewClassMethod(d_type, descr->d_method);
+}
+}
+
 static PyObject *
 foo_unset(fooobject *self)
 {
@@ -95,6 +111,7 @@
 {"copy",  (PyCFunction)foo_copy,  METH_NOARGS,  NULL},
 {"create",(PyCFunction)foo_create,METH_NOARGS|METH_STATIC,  NULL},
 {"classmeth", (PyCFunction)foo_classmeth, METH_NOARGS|METH_CLASS,  NULL},
+{"fake_classmeth", (PyCFunction)foo_classmeth, METH_NOARGS,  NULL},
 {"unset_string_member", (PyCFunction)foo_unset, METH_NOARGS, NULL},
 {NULL, NULL} /* sentinel */
 };
@@ -167,19 +184,19 @@
 /* copied from numpy scalartypes.c for inherited classes */
 

[pypy-commit] pypy py3.5: fix test

2017-09-29 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92499:2fef598a1c41
Date: 2017-09-29 11:36 +0200
http://bitbucket.org/pypy/pypy/changeset/2fef598a1c41/

Log:fix test

diff --git a/pypy/module/cpyext/test/test_fileobject.py 
b/pypy/module/cpyext/test/test_fileobject.py
--- a/pypy/module/cpyext/test/test_fileobject.py
+++ b/pypy/module/cpyext/test/test_fileobject.py
@@ -7,7 +7,7 @@
 module = self.import_extension('foo', [
 ("defenc", "METH_NOARGS",
  """
-return PyString_FromString(Py_FileSystemDefaultEncoding);
+return PyUnicode_FromString(Py_FileSystemDefaultEncoding);
  """),
 ])
 assert module.defenc() == sys.getfilesystemencoding()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: help testrunner find pypy3 exe on win32

2017-09-29 Thread mattip
Author: Matti Picus 
Branch: py3.5
Changeset: r92498:48bda039069f
Date: 2017-09-29 11:37 +0300
http://bitbucket.org/pypy/pypy/changeset/48bda039069f/

Log:help testrunner find pypy3 exe on win32

diff --git a/pypy/pytest-A.cfg b/pypy/pytest-A.cfg
--- a/pypy/pytest-A.cfg
+++ b/pypy/pytest-A.cfg
@@ -1,5 +1,8 @@
+import sys
 cherrypick = ['interpreter', 'objspace/test', 'objspace/std', 'module']
 
 interp = ['python']
-test_driver = ['test_all.py', '-A', '--python=goal/pypy3-c']
-
+if sys.platform == 'win32':
+test_driver = ['test_all.py', '-A', '--python=goal/pypy3-cw.exe']
+else:
+test_driver = ['test_all.py', '-A', '--python=goal/pypy3-c']
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit