Author: Armin Rigo <[email protected]>
Branch: missing-tp_new
Changeset: r87996:c0e856a6f037
Date: 2016-10-30 17:47 +0100
http://bitbucket.org/pypy/pypy/changeset/c0e856a6f037/

Log:    slot_tp_new

diff --git a/pypy/module/cpyext/userslot.py b/pypy/module/cpyext/userslot.py
--- a/pypy/module/cpyext/userslot.py
+++ b/pypy/module/cpyext/userslot.py
@@ -10,7 +10,10 @@
 '__xxx__' special methods) after initalization of the PyTypeObject.
 """
 
+from pypy.interpreter.error import oefmt
+from pypy.interpreter.argument import Arguments
 from pypy.module.cpyext.api import cpython_api, PyObject, Py_ssize_t
+from pypy.module.cpyext.api import PyTypeObjectPtr
 
 
 @cpython_api([PyObject], Py_ssize_t, error=-1, header=None)
@@ -24,3 +27,13 @@
 @cpython_api([PyObject, PyObject], PyObject, header=None)
 def slot_nb_add(space, w_obj1, w_obj2):
     return space.add(w_obj1, w_obj2)
+
+@cpython_api([PyTypeObjectPtr, PyObject, PyObject], PyObject, header=None)
+def slot_tp_new(space, w_type, w_args, w_kwds):
+    _, w_descr = space.lookup_in_type_where(w_type, '__new__')
+    if w_descr is None:
+        raise oefmt(space.w_RuntimeError, "cpyext: '__new__' not found")
+    # w_descr is typically a StaticMethod
+    args = Arguments(space, [w_type],
+                     w_stararg=w_args, w_starstararg=w_kwds)
+    return space.call_args(space.get(w_descr, w_type), args)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to