[pypy-svn] r74651 - in pypy/trunk/pypy/module/cpyext: . include test
afa at codespeak.net
afa at codespeak.net
Fri May 21 21:27:36 CEST 2010
Author: afa
Date: Fri May 21 21:27:35 2010
New Revision: 74651
Modified:
pypy/trunk/pypy/module/cpyext/funcobject.py
pypy/trunk/pypy/module/cpyext/include/funcobject.h
pypy/trunk/pypy/module/cpyext/test/test_funcobject.py
Log:
Add PyMethod_Self() and PyMethod_GET_SELF()
Modified: pypy/trunk/pypy/module/cpyext/funcobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/funcobject.py (original)
+++ pypy/trunk/pypy/module/cpyext/funcobject.py Fri May 21 21:27:35 2010
@@ -50,6 +50,13 @@
return borrow_from(w_method, w_method.w_function)
@cpython_api([PyObject], PyObject)
+def PyMethod_Self(space, w_method):
+ """Return the instance associated with the method meth if it is bound,
+ otherwise return NULL."""
+ assert isinstance(w_method, Method)
+ return borrow_from(w_method, w_method.w_instance)
+
+ at cpython_api([PyObject], PyObject)
def PyMethod_Class(space, w_method):
"""Return the class object from which the method meth was created; if this was
created from an instance, it will be the class of the instance."""
Modified: pypy/trunk/pypy/module/cpyext/include/funcobject.h
==============================================================================
--- pypy/trunk/pypy/module/cpyext/include/funcobject.h (original)
+++ pypy/trunk/pypy/module/cpyext/include/funcobject.h Fri May 21 21:27:35 2010
@@ -12,8 +12,9 @@
PyObject *func_name; /* The __name__ attribute, a string object */
} PyFunctionObject;
-#define PyMethod_GET_CLASS(obj) PyMethod_Class(obj)
-#define PyMethod_GET_FUNCTION(obj) PyMethod_Function(obj)
+#define PyMethod_GET_FUNCTION(obj) PyMethod_Function((PyObject*)(obj))
+#define PyMethod_GET_SELF(obj) PyMethod_Self((PyObject*)(obj))
+#define PyMethod_GET_CLASS(obj) PyMethod_Class((PyObject*)(obj))
#ifdef __cplusplus
}
Modified: pypy/trunk/pypy/module/cpyext/test/test_funcobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_funcobject.py (original)
+++ pypy/trunk/pypy/module/cpyext/test/test_funcobject.py Fri May 21 21:27:35 2010
@@ -26,9 +26,12 @@
""")
w_function = space.getattr(w_method, space.wrap("im_func"))
+ w_self = space.getattr(w_method, space.wrap("im_self"))
+ w_class = space.getattr(w_method, space.wrap("im_class"))
+
assert space.is_w(api.PyMethod_Function(w_method), w_function)
+ assert space.is_w(api.PyMethod_Self(w_method), w_self)
+ assert space.is_w(api.PyMethod_Class(w_method), w_class)
- w_class = space.getattr(w_method, space.wrap("im_class"))
- w_self = space.getattr(w_method, space.wrap("im_self"))
w_method2 = api.PyMethod_New(w_function, w_self, w_class)
assert space.eq_w(w_method, w_method2)
More information about the Pypy-commit
mailing list