[pypy-commit] pypy missing-tp_new: add more userslot functions, cleanup slotdefs for repeated definitions of __getattr__
mattip
pypy.commits at gmail.com
Wed Nov 9 01:22:36 EST 2016
Author: Matti Picus <matti.picus at gmail.com>
Branch: missing-tp_new
Changeset: r88245:1b0451031b2e
Date: 2016-11-02 00:32 +0200
http://bitbucket.org/pypy/pypy/changeset/1b0451031b2e/
Log: add more userslot functions, cleanup slotdefs for repeated
definitions of __getattr__
diff --git a/pypy/module/cpyext/include/pyport.h b/pypy/module/cpyext/include/pyport.h
--- a/pypy/module/cpyext/include/pyport.h
+++ b/pypy/module/cpyext/include/pyport.h
@@ -64,6 +64,7 @@
# error "Python needs a typedef for Py_uintptr_t in pyport.h."
#endif /* HAVE_UINTPTR_T */
+#include <time.h>
/*******************************
* stat() and fstat() fiddling *
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
@@ -748,7 +748,7 @@
static slotdef slotdefs[] = {
SQSLOT("__len__", sq_length, slot_sq_length, wrap_lenfunc,
"x.__len__() <==> len(x)"),
- SQSLOT("__add__", sq_concat, NULL, wrap_binaryfunc,
+ SQSLOT("__add__", sq_concat, slot_sq_concat, wrap_binaryfunc,
"x.__add__(y) <==> x+y"),
SQSLOT("__mul__", sq_repeat, NULL, wrap_indexargfunc,
"x.__mul__(n) <==> x*n"),
@@ -896,9 +896,7 @@
"x.__call__(...) <==> x(...)", PyWrapperFlag_KEYWORDS),
TPSLOT("__getattribute__", tp_getattro, slot_tp_getattr_hook,
wrap_binaryfunc, "x.__getattribute__('name') <==> x.name"),
- TPSLOT("__getattribute__", tp_getattr, NULL, NULL, ""),
- TPSLOT("__getattr__", tp_getattro, slot_tp_getattr_hook, NULL, ""),
- TPSLOT("__getattr__", tp_getattr, NULL, NULL, ""),
+ TPSLOT("__getattr__", tp_getattro, slot_tp_getattr, NULL, ""),
TPSLOT("__setattr__", tp_setattro, slot_tp_setattro, wrap_setattr,
"x.__setattr__('name', value) <==> x.name = value"),
TPSLOT("__setattr__", tp_setattr, NULL, NULL, ""),
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
@@ -14,23 +14,86 @@
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
-
+from rpython.rtyper.lltypesystem import rffi, lltype
@cpython_api([PyObject], Py_ssize_t, error=-1, header=None)
def slot_sq_length(space, w_obj):
return space.int_w(space.len(w_obj))
+ at cpython_api([PyObject], lltype.Signed, header=None, error=-1)
+def slot_tp_hash(space, w_obj):
+ return space.int_w(space.hash(w_obj))
+
@cpython_api([PyObject, Py_ssize_t], PyObject, header=None)
def slot_sq_item(space, w_obj, index):
return space.getitem(w_obj, space.wrap(index))
+ at cpython_api([PyTypeObjectPtr, PyObject, PyObject], PyObject, header=None)
+def slot_tp_new(space, w_type, w_args, w_kwds):
+ w_impl = space.getattr(w_type, space.wrap('__new__'))
+ import pdb;pdb.set_trace()
+ args = Arguments(space, [w_type],
+ w_stararg=w_args, w_starstararg=w_kwds)
+ return space.call_args(w_impl, args)
+
+# unary functions
+
+ at cpython_api([PyObject], PyObject, header=None)
+def slot_tp_str(space, w_obj):
+ return space.str(w_obj)
+
+ at cpython_api([PyObject], PyObject, header=None)
+def slot_tp_repr(space, w_obj):
+ return space.repr(w_obj)
+
+#binary functions
+
@cpython_api([PyObject, PyObject], PyObject, header=None)
def slot_nb_add(space, w_obj1, w_obj2):
return space.add(w_obj1, w_obj2)
- at cpython_api([PyTypeObjectPtr, PyObject, PyObject], PyObject, header=None)
-def slot_tp_new(space, w_type, w_args, w_kwds):
- w_impl = space.getattr(w_type, space.wrap('__new__'))
- args = Arguments(space, [w_type],
- w_stararg=w_args, w_starstararg=w_kwds)
- return space.call_args(w_impl, args)
+ at cpython_api([PyObject, PyObject], PyObject, header=None)
+def slot_nb_subtract(space, w_obj1, w_obj2):
+ return space.add(w_obj1, w_obj2)
+
+ at cpython_api([PyObject, PyObject], PyObject, header=None)
+def slot_nb_multiply(space, w_obj1, w_obj2):
+ return space.add(w_obj1, w_obj2)
+
+ at cpython_api([PyObject, PyObject], PyObject, header=None)
+def slot_nb_divide(space, w_obj1, w_obj2):
+ return space.add(w_obj1, w_obj2)
+
+ at cpython_api([PyObject, PyObject], PyObject, header=None)
+def slot_nb_inplace_add(space, w_obj1, w_obj2):
+ return space.add(w_obj1, w_obj2)
+
+ at cpython_api([PyObject, PyObject], PyObject, header=None)
+def slot_nb_inplace_subtract(space, w_obj1, w_obj2):
+ return space.add(w_obj1, w_obj2)
+
+ at cpython_api([PyObject, PyObject], PyObject, header=None)
+def slot_nb_inplace_multiply(space, w_obj1, w_obj2):
+ return space.add(w_obj1, w_obj2)
+
+ at cpython_api([PyObject, PyObject], PyObject, header=None)
+def slot_nb_inplace_divide(space, w_obj1, w_obj2):
+ return space.add(w_obj1, w_obj2)
+
+ at cpython_api([PyObject, PyObject], PyObject, header=None)
+def slot_sq_concat(space, w_obj1, w_obj2):
+ return space.add(w_obj1, w_obj2)
+
+ at cpython_api([PyObject, PyObject], PyObject, header=None)
+def slot_sq_inplace_concat(space, w_obj1, w_obj2):
+ return space.add(w_obj1, w_obj2)
+
+ at cpython_api([PyObject, PyObject], PyObject, header=None)
+def slot_mp_subscript(space, w_obj1, w_obj2):
+ return space.add(w_obj1, w_obj2)
+
+ at cpython_api([PyObject, PyObject], PyObject, header=None)
+def slot_tp_getattr(space, w_obj1, w_obj2):
+ return space.getattr(w_obj1, w_obj2)
+
+
More information about the pypy-commit
mailing list