[pypy-commit] pypy refactor-slots: Move get_slot_tp_function() to slotdefs.py and kill build_slot_tp_function()

rlamy pypy.commits at gmail.com
Sat Jan 13 14:04:32 EST 2018


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: refactor-slots
Changeset: r93663:1ed2ce30fef0
Date: 2018-01-13 19:03 +0000
http://bitbucket.org/pypy/pypy/changeset/1ed2ce30fef0/

Log:	Move get_slot_tp_function() to slotdefs.py and kill
	build_slot_tp_function()

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
@@ -6,7 +6,7 @@
 from rpython.rlib.rarithmetic import widen
 from pypy.module.cpyext.api import (
     slot_function, generic_cpy_call, PyObject, Py_ssize_t,
-    Py_TPFLAGS_CHECKTYPES, Py_buffer, Py_bufferP, PyTypeObjectPtr, cts)
+    Py_TPFLAGS_CHECKTYPES, Py_buffer, Py_bufferP, PyTypeObjectPtr)
 from pypy.module.cpyext.typeobjectdefs import (
     unaryfunc, ternaryfunc, binaryfunc,
     getattrfunc, getattrofunc, setattrofunc, lenfunc, ssizeargfunc, inquiry,
@@ -143,7 +143,6 @@
 def wrap_inquirypred(space, w_self, w_args, func):
     func_inquiry = rffi.cast(inquiry, func)
     check_num_args(space, w_args, 0)
-    args_w = space.fixedview(w_args)
     res = generic_cpy_call(space, func_inquiry, w_self)
     res = rffi.cast(lltype.Signed, res)
     if res == -1:
@@ -431,14 +430,26 @@
     return decorate
 
 
-def build_slot_tp_function(space, typedef, name, method_name):
-    if name in SLOT_FACTORIES:
-        return SLOT_FACTORIES[name](space, typedef, name, method_name)
-    else:
+SLOTS = {}
+ at specialize.memo()
+def get_slot_tp_function(space, typedef, name, method_name):
+    """Return a description of the slot C function to use for the built-in
+    type for 'typedef'.  The 'name' is the slot name.  This is a memo
+    function that, after translation, returns one of a built-in finite set.
+    """
+    if name not in SLOT_FACTORIES:
         # missing: tp_as_number.nb_nonzero, tp_as_number.nb_coerce
         # tp_as_sequence.c_sq_contains, tp_as_sequence.c_sq_length
         # richcmpfunc(s)
-        return
+        return None
+    key = (typedef, name)
+    try:
+        return SLOTS[key]
+    except KeyError:
+        slot_func = SLOT_FACTORIES[name](space, typedef, name, method_name)
+        llfunc = llslot(space, slot_func) if slot_func else None
+        SLOTS[key] = llfunc
+        return llfunc
 
 
 def make_unary_slot(space, typedef, name, attr):
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
@@ -31,7 +31,7 @@
     PyObject, make_ref, from_ref, get_typedescr, make_typedescr,
     track_reference, decref, as_pyobj)
 from pypy.module.cpyext.slotdefs import (
-    slotdefs_for_tp_slots, slotdefs_for_wrappers, build_slot_tp_function,
+    slotdefs_for_tp_slots, slotdefs_for_wrappers, get_slot_tp_function,
     llslot)
 from pypy.module.cpyext.state import State
 from pypy.module.cpyext.structmember import PyMember_GetOne, PyMember_SetOne
@@ -226,22 +226,6 @@
             dict_w[name] = w_descr
             i += 1
 
-SLOTS = {}
- at specialize.memo()
-def get_slot_tp_function(space, typedef, name, method_name):
-    """Return a description of the slot C function to use for the built-in
-    type for 'typedef'.  The 'name' is the slot name.  This is a memo
-    function that, after translation, returns one of a built-in finite set.
-    """
-    key = (typedef, name)
-    try:
-        return SLOTS[key]
-    except KeyError:
-        slot_func = build_slot_tp_function(space, typedef, name, method_name)
-        api_func = slot_func.api_func if slot_func else None
-        SLOTS[key] = api_func
-        return api_func
-
 missing_slots={}
 def warn_missing_slot(space, method_name, slot_name, w_type):
     if not we_are_translated():
@@ -281,12 +265,11 @@
 def update_all_slots_builtin(space, w_type, pto):
     typedef = w_type.layout.typedef
     for method_name, slot_name, slot_names, slot_apifunc in slotdefs_for_tp_slots:
-        slot_apifunc = get_slot_tp_function(space, typedef, slot_name, method_name)
-        if not slot_apifunc:
+        slot_llfunc = get_slot_tp_function(space, typedef, slot_name, method_name)
+        if not slot_llfunc:
             warn_missing_slot(space, method_name, slot_name, w_type)
             continue
-        slot_func_helper = slot_apifunc.get_llhelper(space)
-        fill_slot(space, pto, w_type, slot_names, slot_func_helper)
+        fill_slot(space, pto, w_type, slot_names, slot_llfunc)
 
 @specialize.arg(3)
 def fill_slot(space, pto, w_type, slot_names, slot_func_helper):
@@ -332,7 +315,7 @@
 
 def add_operators(space, dict_w, pto):
     from pypy.module.cpyext.object import PyObject_HashNotImplemented
-    hash_not_impl = PyObject_HashNotImplemented.api_func.get_llhelper(space)
+    hash_not_impl = llslot(space, PyObject_HashNotImplemented)
     for method_name, slot_names, wrapper_func, wrapper_func_kwds, doc in slotdefs_for_wrappers:
         if method_name in dict_w:
             continue


More information about the pypy-commit mailing list