[pypy-commit] pypy cpyext-refactor-methodobject: kill the now-obsolete W_PyCFunctionObject_{NOARGS, O, VARARGS}
antocuni
pypy.commits at gmail.com
Sat Oct 21 19:59:26 EDT 2017
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: cpyext-refactor-methodobject
Changeset: r92821:6a0f6b5d4571
Date: 2017-10-22 00:01 +0200
http://bitbucket.org/pypy/pypy/changeset/6a0f6b5d4571/
Log: kill the now-obsolete W_PyCFunctionObject_{NOARGS,O,VARARGS}
diff --git a/pypy/module/cpyext/__init__.py b/pypy/module/cpyext/__init__.py
--- a/pypy/module/cpyext/__init__.py
+++ b/pypy/module/cpyext/__init__.py
@@ -17,16 +17,11 @@
method = pypy.module.cpyext.typeobject.get_new_method_def(space)
# the w_self argument here is a dummy, the only thing done with w_obj
# is call type() on it
- objs_w = [cls(space, method, space.w_None) for cls in [
- pypy.module.cpyext.methodobject.W_PyCFunctionObject,
- pypy.module.cpyext.methodobject.W_PyCFunctionObject_NOARGS,
- pypy.module.cpyext.methodobject.W_PyCFunctionObject_O,
- pypy.module.cpyext.methodobject.W_PyCFunctionObject_VARARGS]]
- w_objs = space.newtuple(objs_w)
- space.appexec([w_objs], """(methods):
+ w_obj = pypy.module.cpyext.methodobject.W_PyCFunctionObject(space,
+ method, space.w_None)
+ space.appexec([w_obj], """(meth):
from pickle import Pickler
- for meth in methods:
- Pickler.dispatch[type(meth)] = Pickler.save_global
+ Pickler.dispatch[type(meth)] = Pickler.save_global
""")
def register_atexit(self, function):
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
@@ -137,53 +137,6 @@
else:
return space.w_None
-class W_PyCFunctionObject_NOARGS(W_PyCFunctionObject):
- # METH_NOARGS
-
- # CCC I think we can condense descr_call and call into one, can't we?
- def descr_call(self, space, __args__):
- if len(__args__.arguments_w) != 0:
- raise oefmt(space.w_TypeError,
- "%s() takes no arguments", self.name)
- return self.call(space, None, None, None)
-
- def call(self, space, w_self, w_args, w_kw):
- # Call the C function
- if w_self is None:
- w_self = self.w_self
- func = self.ml.c_ml_meth
- return generic_cpy_call(space, func, w_self, None)
-
-class W_PyCFunctionObject_O(W_PyCFunctionObject):
- # METH_O
-
- # CCC I think we can condense descr_call and call into one, can't we?
- def descr_call(self, space, __args__):
- if len(__args__.arguments_w) != 1:
- raise oefmt(space.w_TypeError,
- "%s() takes exactly one argument", self.name)
- w_o = __args__.arguments_w[0]
- return self.call(space, None, w_o, None)
-
- def call(self, space, w_self, w_o, w_kw):
- if w_self is None:
- w_self = self.w_self
- func = self.ml.c_ml_meth
- return generic_cpy_call(space, func, w_self, w_o)
-
-class W_PyCFunctionObject_VARARGS(W_PyCFunctionObject):
- # METH_VARARGS
-
- def descr_call(self, space, args_w):
- state = space.fromcache(State)
- w_self = self.w_self
- func = self.ml.c_ml_meth
- py_args = tuple_from_args_w(space, args_w)
- try:
- return generic_cpy_call(space, func, w_self, py_args)
- finally:
- decref(space, py_args)
-
class W_PyCMethodObject(W_PyCFunctionObject):
w_self = None
def __init__(self, space, ml, w_type):
@@ -351,36 +304,6 @@
)
W_PyCFunctionObject.typedef.acceptable_as_base_class = False
-W_PyCFunctionObject_NOARGS.typedef = TypeDef(
- 'builtin_function_or_method', W_PyCFunctionObject.typedef,
- __call__ = interp2app(W_PyCFunctionObject_NOARGS.descr_call),
- __doc__ = GetSetProperty(W_PyCFunctionObject_NOARGS.get_doc),
- __module__ = interp_attrproperty_w('w_module', cls=W_PyCFunctionObject_NOARGS),
- __name__ = interp_attrproperty('name', cls=W_PyCFunctionObject_NOARGS,
- wrapfn="newtext_or_none"),
- )
-W_PyCFunctionObject_NOARGS.typedef.acceptable_as_base_class = False
-
-W_PyCFunctionObject_O.typedef = TypeDef(
- 'builtin_function_or_method', W_PyCFunctionObject.typedef,
- __call__ = interp2app(W_PyCFunctionObject_O.descr_call),
- __doc__ = GetSetProperty(W_PyCFunctionObject_O.get_doc),
- __module__ = interp_attrproperty_w('w_module', cls=W_PyCFunctionObject_O),
- __name__ = interp_attrproperty('name', cls=W_PyCFunctionObject_O,
- wrapfn="newtext_or_none"),
- )
-W_PyCFunctionObject_O.typedef.acceptable_as_base_class = False
-
-W_PyCFunctionObject_VARARGS.typedef = TypeDef(
- 'builtin_function_or_method', W_PyCFunctionObject.typedef,
- __call__ = interp2app(W_PyCFunctionObject_VARARGS.descr_call),
- __doc__ = GetSetProperty(W_PyCFunctionObject_VARARGS.get_doc),
- __module__ = interp_attrproperty_w('w_module', cls=W_PyCFunctionObject_VARARGS),
- __name__ = interp_attrproperty('name', cls=W_PyCFunctionObject_VARARGS,
- wrapfn="newtext_or_none"),
- )
-W_PyCFunctionObject_VARARGS.typedef.acceptable_as_base_class = False
-
W_PyCMethodObject.typedef = TypeDef(
'method_descriptor',
__get__ = interp2app(cmethod_descr_get),
diff --git a/pypy/module/cpyext/modsupport.py b/pypy/module/cpyext/modsupport.py
--- a/pypy/module/cpyext/modsupport.py
+++ b/pypy/module/cpyext/modsupport.py
@@ -6,9 +6,7 @@
from pypy.interpreter.module import Module
from pypy.module.cpyext.methodobject import (
W_PyCFunctionObject, PyCFunction_NewEx, PyDescr_NewMethod,
- PyMethodDef, PyDescr_NewClassMethod, PyStaticMethod_New,
- W_PyCFunctionObject_NOARGS, W_PyCFunctionObject_O,
- W_PyCFunctionObject_VARARGS)
+ PyMethodDef, PyDescr_NewClassMethod, PyStaticMethod_New)
from pypy.module.cpyext.pyerrors import PyErr_BadInternalCall
from pypy.module.cpyext.state import State
from pypy.interpreter.error import oefmt
@@ -82,16 +80,6 @@
space.newtext(rffi.charp2str(doc)))
return w_mod # borrowed result kept alive in PyImport_AddModule()
-def _create_pyc_function_object(space, method, w_self, w_name, flags):
- ## flags &= ~(METH_CLASS | METH_STATIC | METH_COEXIST)
- ## if flags == METH_NOARGS:
- ## return W_PyCFunctionObject_NOARGS(space, method, w_self, w_name)
- ## if flags == METH_O:
- ## return W_PyCFunctionObject_O(space, method, w_self, w_name)
- ## if flags == METH_VARARGS:
- ## return W_PyCFunctionObject_VARARGS(space, method, w_self, w_name)
- return W_PyCFunctionObject(space, method, w_self, w_name)
-
def convert_method_defs(space, dict_w, methods, w_type, w_self=None, name=None):
w_name = space.newtext_or_none(name)
methods = rffi.cast(rffi.CArrayPtr(PyMethodDef), methods)
@@ -110,8 +98,7 @@
raise oefmt(space.w_ValueError,
"module functions cannot set METH_CLASS or "
"METH_STATIC")
- w_obj = _create_pyc_function_object(space, method, w_self,
- w_name, flags)
+ w_obj = W_PyCFunctionObject(space, method, w_self, w_name)
else:
if methodname in dict_w and not (flags & METH_COEXIST):
continue
More information about the pypy-commit
mailing list