[pypy-commit] pypy missing-tp_new: use the full w_type not just the w_type.layout.typedef when looking up functions

mattip pypy.commits at gmail.com
Wed Oct 19 11:17:46 EDT 2016


Author: Matti Picus <matti.picus at gmail.com>
Branch: missing-tp_new
Changeset: r87878:f6ba0b987cc7
Date: 2016-10-19 18:13 +0300
http://bitbucket.org/pypy/pypy/changeset/f6ba0b987cc7/

Log:	use the full w_type not just the w_type.layout.typedef when looking
	up functions

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
@@ -429,20 +429,19 @@
 SLOTS = {}
 
 @specialize.memo()
-def get_slot_tp_function(space, typedef, name):
-    key = (typedef, name)
+def get_slot_tp_function(space, w_type, name):
+    key = (w_type, name)
     try:
         return SLOTS[key]
     except KeyError:
-        ret = build_slot_tp_function(space, typedef, name)
+        ret = build_slot_tp_function(space, w_type, name)
         SLOTS[key] = ret
         return ret
 
-def build_slot_tp_function(space, typedef, name):
-    w_type = space.gettypeobject(typedef)
+def build_slot_tp_function(space, w_type, name):
 
     header = pypy_decl
-    if mangle_name('', typedef.name) is None:
+    if mangle_name('', w_type.name) is None:
         header = None
     handled = False
     # unary functions
@@ -466,7 +465,7 @@
                 return
 
             @cpython_api([PyObject], PyObject, header=header)
-            @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), typedef.name))
+            @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), w_type.name))
             def slot_func(space, w_self):
                 return space.call_function(slot_fn, w_self)
             api_func = slot_func.api_func
@@ -493,7 +492,7 @@
                 return
 
             @cpython_api([PyObject, PyObject], PyObject, header=header)
-            @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), typedef.name))
+            @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), w_type.name))
             def slot_func(space, w_self, w_arg):
                 return space.call_function(slot_fn, w_self, w_arg)
             api_func = slot_func.api_func
@@ -511,7 +510,7 @@
                 return
 
             @cpython_api([PyObject, Py_ssize_t], PyObject, header=header)
-            @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), typedef.name))
+            @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), w_type.name))
             def slot_func(space, w_self, arg):
                 return space.call_function(slot_fn, w_self, space.wrap(arg))
             api_func = slot_func.api_func
@@ -526,7 +525,7 @@
                 return
 
             @cpython_api([PyObject, PyObject, PyObject], PyObject, header=header)
-            @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), typedef.name))
+            @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), w_type.name))
             def slot_func(space, w_self, w_arg1, w_arg2):
                 return space.call_function(slot_fn, w_self, w_arg1, w_arg2)
             api_func = slot_func.api_func
@@ -542,7 +541,7 @@
 
         @cpython_api([PyObject, PyObject, PyObject], rffi.INT_real,
                      error=-1, header=header)
-        @func_renamer("cpyext_tp_setattro_%s" % (typedef.name,))
+        @func_renamer("cpyext_tp_setattro_%s" % (w_type.name,))
         def slot_tp_setattro(space, w_self, w_name, w_value):
             if w_value is not None:
                 space.call_function(setattr_fn, w_self, w_name, w_value)
@@ -556,7 +555,7 @@
             return
 
         @cpython_api([PyObject, PyObject], PyObject, header=header)
-        @func_renamer("cpyext_tp_getattro_%s" % (typedef.name,))
+        @func_renamer("cpyext_tp_getattro_%s" % (w_type.name,))
         def slot_tp_getattro(space, w_self, w_name):
             return space.call_function(getattr_fn, w_self, w_name)
         api_func = slot_tp_getattro.api_func
@@ -566,7 +565,7 @@
             return
 
         @cpython_api([PyObject, PyObject, PyObject], PyObject, header=header)
-        @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), typedef.name))
+        @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), w_type.name))
         def slot_tp_call(space, w_self, w_args, w_kwds):
             args = Arguments(space, [w_self],
                              w_stararg=w_args, w_starstararg=w_kwds)
@@ -579,7 +578,7 @@
             return
 
         @cpython_api([PyObject], PyObject, header=header)
-        @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), typedef.name))
+        @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), w_type.name))
         def slot_tp_iternext(space, w_self):
             try:
                 return space.call_function(iternext_fn, w_self)
@@ -596,7 +595,7 @@
 
         @cpython_api([PyObject, PyObject, PyObject], rffi.INT_real, error=-1,
                      header=header)
-        @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), typedef.name))
+        @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), w_type.name))
         def slot_tp_init(space, w_self, w_args, w_kwds):
             args = Arguments(space, [w_self],
                              w_stararg=w_args, w_starstararg=w_kwds)
@@ -609,7 +608,7 @@
             return
 
         @cpython_api([PyTypeObjectPtr, PyObject, PyObject], PyObject, header=None)
-        @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), typedef.name))
+        @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), w_type.name))
         def slot_tp_new(space, w_self, w_args, w_kwds):
             args = Arguments(space, [w_self],
                              w_stararg=w_args, w_starstararg=w_kwds)
@@ -621,7 +620,7 @@
             return
         @cpython_api([PyObject, Py_bufferP, rffi.INT_real], 
                 rffi.INT_real, header=None, error=-1)
-        @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), typedef.name))
+        @func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), w_type.name))
         def buff_w(space, w_self, view, flags):
             args = Arguments(space, [space.newint(flags)])
             w_obj = space.call_args(space.get(buff_fn, w_self), args)
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
@@ -256,7 +256,7 @@
         slot_func_helper = None
 
         if slot_func is None and typedef is not None:
-            get_slot = get_slot_tp_function(space, typedef, slot_name)
+            get_slot = get_slot_tp_function(space, w_type, slot_name)
             if get_slot:
                 slot_func_helper = get_slot()
         elif slot_func:


More information about the pypy-commit mailing list