Author: Armin Rigo <ar...@tunes.org>
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*)&PyList_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, &PyWrapperDescr_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

Reply via email to