[pypy-commit] pypy cpyext-fast-typecheck: port wrap_call to the new style, reusing most of the logic we use also W_PyCFunction.call_keywords
antocuni
pypy.commits at gmail.com
Thu Mar 22 13:03:10 EDT 2018
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: cpyext-fast-typecheck
Changeset: r94086:edf304aa6652
Date: 2018-03-22 17:33 +0100
http://bitbucket.org/pypy/pypy/changeset/edf304aa6652/
Log: port wrap_call to the new style, reusing most of the logic we use
also W_PyCFunction.call_keywords
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
@@ -45,6 +45,18 @@
from pypy.module.cpyext.object import _dealloc
_dealloc(space, py_obj)
+def w_kwargs_from_args(space, __args__):
+ w_kwargs = None
+ if __args__.keywords:
+ # CCC: we should probably have a @jit.look_inside_iff if the
+ # keyword count is constant, as we do in Arguments.unpack
+ w_kwargs = space.newdict()
+ for i in range(len(__args__.keywords)):
+ key = __args__.keywords[i]
+ w_obj = __args__.keywords_w[i]
+ space.setitem(w_kwargs, space.newtext(key), w_obj)
+ return w_kwargs
+
class W_PyCFunctionObject(W_Root):
_immutable_fields_ = ["flags"]
@@ -103,15 +115,7 @@
def call_keywords(self, space, w_self, __args__):
func = rffi.cast(PyCFunctionKwArgs, self.ml.c_ml_meth)
py_args = tuple_from_args_w(space, __args__.arguments_w)
- w_kwargs = None
- if __args__.keywords:
- # CCC: we should probably have a @jit.look_inside_iff if the
- # keyword count is constant, as we do in Arguments.unpack
- w_kwargs = space.newdict()
- for i in range(len(__args__.keywords)):
- key = __args__.keywords[i]
- w_obj = __args__.keywords_w[i]
- space.setitem(w_kwargs, space.newtext(key), w_obj)
+ w_kwargs = w_kwargs_from_args(space, __args__)
try:
return generic_cpy_call(space, func, w_self, py_args, w_kwargs)
finally:
@@ -283,6 +287,7 @@
self.wrapper_func_kwds = wrapper_func_kwds
def call(self, space, w_self, __args__):
+ #xxx
args_w, kw_w = __args__.unpack()
w_args = space.newtuple(args_w)
w_kw = space.newdict()
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
@@ -19,7 +19,8 @@
from pypy.module.cpyext.state import State
from pypy.module.cpyext import userslot
from pypy.module.cpyext.buffer import CBuffer, CPyBuffer, fq
-from pypy.module.cpyext.methodobject import W_PyCWrapperObject
+from pypy.module.cpyext.methodobject import (W_PyCWrapperObject, tuple_from_args_w,
+ w_kwargs_from_args)
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.argument import Arguments
from rpython.rlib.unroll import unrolling_iterable
@@ -223,9 +224,13 @@
if rffi.cast(lltype.Signed, res) == -1:
space.fromcache(State).check_and_raise_exception(always=True)
-def wrap_call(space, w_self, w_args, func, w_kwds):
- func_target = rffi.cast(ternaryfunc, func)
- return generic_cpy_call(space, func_target, w_self, w_args, w_kwds)
+class wrap_call(W_PyCWrapperObject):
+ def call(self, space, w_self, __args__):
+ func = self.get_func_to_call()
+ func_target = rffi.cast(ternaryfunc, func)
+ py_args = tuple_from_args_w(space, __args__.arguments_w)
+ w_kwargs = w_kwargs_from_args(space, __args__)
+ return generic_cpy_call(space, func_target, w_self, py_args, w_kwargs)
def wrap_ssizessizeobjargproc(space, w_self, w_args, func):
func_target = rffi.cast(ssizessizeobjargproc, func)
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
@@ -343,6 +343,9 @@
# XXX: this is just a quick hack to distinguish the old wrappers from
# the new ones: eventually, all of them will be subclasses of
# W_PyCWrapperObject
+ if type(wrapper_func_kwds) is type:
+ assert wrapper_func is None
+ wrapper_func = wrapper_func_kwds
if type(wrapper_func) is type and issubclass(wrapper_func, W_PyCWrapperObject):
# new style
wrapper_class = wrapper_func
More information about the pypy-commit
mailing list