[pypy-svn] r74773 - in pypy/trunk/pypy/module/cpyext: . test

afa at codespeak.net afa at codespeak.net
Wed May 26 14:15:33 CEST 2010


Author: afa
Date: Wed May 26 14:15:31 2010
New Revision: 74773

Modified:
   pypy/trunk/pypy/module/cpyext/methodobject.py
   pypy/trunk/pypy/module/cpyext/modsupport.py
   pypy/trunk/pypy/module/cpyext/test/foo.c
   pypy/trunk/pypy/module/cpyext/test/test_typeobject.py
Log:
Support METH_STATIC, add PyStaticMethod_New


Modified: pypy/trunk/pypy/module/cpyext/methodobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/methodobject.py	(original)
+++ pypy/trunk/pypy/module/cpyext/methodobject.py	Wed May 26 14:15:31 2010
@@ -5,7 +5,7 @@
 from pypy.interpreter.typedef import interp_attrproperty, interp_attrproperty_w
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.function import BuiltinFunction, Method
+from pypy.interpreter.function import BuiltinFunction, Method, StaticMethod
 from pypy.rpython.lltypesystem import rffi, lltype
 from pypy.module.cpyext.pyobject import (PyObject, from_ref, make_ref, make_typedescr,
                                          Py_DecRef)
@@ -228,6 +228,10 @@
 def PyCFunction_NewEx(space, ml, w_self, w_name):
     return space.wrap(W_PyCFunctionObject(space, ml, w_self, w_name))
 
+ at cpython_api([PyObject], PyObject)
+def PyStaticMethod_New(space, w_func):
+    return space.wrap(StaticMethod(w_func))
+
 def PyDescr_NewMethod(space, w_type, method):
     return space.wrap(W_PyCMethodObject(space, method, w_type))
 

Modified: pypy/trunk/pypy/module/cpyext/modsupport.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/modsupport.py	(original)
+++ pypy/trunk/pypy/module/cpyext/modsupport.py	Wed May 26 14:15:31 2010
@@ -3,7 +3,9 @@
         METH_STATIC, METH_CLASS, METH_COEXIST, CANNOT_FAIL, CONST_STRING
 from pypy.module.cpyext.pyobject import PyObject, borrow_from
 from pypy.interpreter.module import Module
-from pypy.module.cpyext.methodobject import W_PyCFunctionObject, PyCFunction_NewEx, PyDescr_NewMethod, PyMethodDef, PyCFunction
+from pypy.module.cpyext.methodobject import (
+    W_PyCFunctionObject, PyCFunction_NewEx, PyDescr_NewMethod,
+    PyMethodDef, PyCFunction, PyStaticMethod_New)
 from pypy.module.cpyext.pyerrors import PyErr_BadInternalCall
 from pypy.module.cpyext.state import State
 from pypy.interpreter.error import OperationError
@@ -90,8 +92,7 @@
                     w_obj = space.w_Ellipsis # XXX
                 elif flags & METH_STATIC:
                     w_func = PyCFunction_NewEx(space, method, None, None)
-                    w_obj = space.w_Ellipsis # XXX
-                    #w_obj = PyStaticMethod_New(space, w_func)
+                    w_obj = PyStaticMethod_New(space, w_func)
                 else:
                     w_obj = PyDescr_NewMethod(space, w_type, method)
 

Modified: pypy/trunk/pypy/module/cpyext/test/foo.c
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/foo.c	(original)
+++ pypy/trunk/pypy/module/cpyext/test/foo.c	Wed May 26 14:15:31 2010
@@ -53,6 +53,12 @@
 }
 
 static PyObject *
+foo_create(fooobject *self)
+{
+    return newfooobject();
+}
+
+static PyObject *
 foo_unset(fooobject *self)
 {
     self->foo_string = NULL;
@@ -62,6 +68,7 @@
 
 static PyMethodDef foo_methods[] = {
     {"copy",      (PyCFunction)foo_copy,      METH_NOARGS,  NULL},
+    {"create",    (PyCFunction)foo_create,    METH_NOARGS|METH_STATIC,  NULL},
     {"unset_string_member", (PyCFunction)foo_unset, METH_NOARGS, NULL},
     {NULL, NULL}                 /* sentinel */
 };

Modified: pypy/trunk/pypy/module/cpyext/test/test_typeobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_typeobject.py	(original)
+++ pypy/trunk/pypy/module/cpyext/test/test_typeobject.py	Wed May 26 14:15:31 2010
@@ -89,6 +89,13 @@
         raises(TypeError, "obj.char_member = 'spam'")
         raises(TypeError, "obj.char_member = 42")
 
+    def test_staticmethod(self):
+        module = self.import_module(name="foo")
+        obj = module.fooType.create()
+        assert obj.foo == 42
+        obj2 = obj.create()
+        assert obj2.foo == 42
+
     def test_new(self):
         module = self.import_module(name='foo')
         obj = module.new()



More information about the Pypy-commit mailing list