Author: Matti Picus <matti.pi...@gmail.com> Branch: Changeset: r91850:ac54af67d3c2 Date: 2017-07-10 22:56 +0300 http://bitbucket.org/pypy/pypy/changeset/ac54af67d3c2/
Log: test, fix for PyCFunction_Check and builtins (there is no PyCFunction_CheckExact) 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,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, - build_type_checkers, cpython_api, generic_cpy_call, + build_type_checkers, cpython_api, generic_cpy_call, CANNOT_FAIL, PyTypeObjectPtr, slot_function, cts) from pypy.module.cpyext.pyobject import ( Py_DecRef, from_ref, make_ref, as_pyobj, make_typedescr) @@ -113,8 +113,14 @@ "built-in method '%s' of '%s' object" % (self.name, self.w_objclass.getname(self.space))) -PyCFunction_Check, PyCFunction_CheckExact = build_type_checkers( - "CFunction", W_PyCFunctionObject) +@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL) +def PyCFunction_Check(space, w_obj): + from pypy.interpreter.function import BuiltinFunction + if w_obj is None: + return False + if isinstance(w_obj, W_PyCFunctionObject): + return True + return isinstance(w_obj, BuiltinFunction) class W_PyCClassMethodObject(W_PyCFunctionObject): w_self = None diff --git a/pypy/module/cpyext/test/test_methodobject.py b/pypy/module/cpyext/test/test_methodobject.py --- a/pypy/module/cpyext/test/test_methodobject.py +++ b/pypy/module/cpyext/test/test_methodobject.py @@ -93,6 +93,31 @@ assert mod.isSameFunction(mod.getarg_O) raises(SystemError, mod.isSameFunction, 1) + def test_check(self): + mod = self.import_extension('foo', [ + ('check', 'METH_O', + ''' + return PyLong_FromLong(PyCFunction_Check(args)); + '''), + ]) + from math import degrees + assert mod.check(degrees) == 1 + assert mod.check(list) == 0 + assert mod.check(sorted) == 1 + def func(): + pass + class A(object): + def meth(self): + pass + @staticmethod + def stat(): + pass + assert mod.check(func) == 0 + assert mod.check(A) == 0 + assert mod.check(A.meth) == 0 + assert mod.check(A.stat) == 0 + + class TestPyCMethodObject(BaseApiTest): def test_repr(self, space, api): """ _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit