[pypy-svn] r73368 - pypy/branch/cpython-extension/pypy/module/cpyext
xoraxax at codespeak.net
xoraxax at codespeak.net
Sun Apr 4 19:21:12 CEST 2010
Author: xoraxax
Date: Sun Apr 4 19:21:11 2010
New Revision: 73368
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/methodobject.py
pypy/branch/cpython-extension/pypy/module/cpyext/modsupport.py
Log:
Move stuff around and implement FindModule.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/methodobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/methodobject.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/methodobject.py Sun Apr 4 19:21:11 2010
@@ -8,12 +8,24 @@
from pypy.interpreter.function import BuiltinFunction, Method
from pypy.rpython.lltypesystem import rffi, lltype
from pypy.module.cpyext.pyobject import PyObject, from_ref, make_ref
-from pypy.module.cpyext.api import generic_cpy_call
+from pypy.module.cpyext.api import generic_cpy_call, cpython_api, PyObject,\
+ cpython_struct
from pypy.module.cpyext.state import State
from pypy.module.cpyext.pyerrors import PyErr_Occurred
from pypy.rlib.objectmodel import we_are_translated
+PyCFunction = lltype.Ptr(lltype.FuncType([PyObject, PyObject], PyObject))
+
+PyMethodDef = cpython_struct(
+ 'PyMethodDef',
+ [('ml_name', rffi.CCHARP),
+ ('ml_meth', PyCFunction),
+ ('ml_flags', rffi.INT_real),
+ ('ml_doc', rffi.CCHARP),
+ ])
+
+
class W_PyCFunctionObject(Wrappable):
def __init__(self, space, ml, w_self, doc=None):
self.ml = ml
@@ -157,3 +169,24 @@
# not exactly the API sig
return space.wrap(W_PyCWrapperObject(space, pto, method_name,
wrapper_func, doc, flags, func))
+
+ at cpython_api([PyMethodDef, PyObject, rffi.CCHARP], PyObject)
+def Py_FindMethod(space, table, w_ob, name_ptr):
+ """Return a bound method object for an extension type implemented in C. This
+ can be useful in the implementation of a tp_getattro or
+ tp_getattr handler that does not use the
+ PyObject_GenericGetAttr() function."""
+ # XXX handle __doc__
+
+ name = rffi.charp2str(name_ptr)
+ methods = rffi.cast(rffi.CArrayPtr(PyMethodDef), methods)
+ if methods:
+ i = -1
+ while True:
+ i = i + 1
+ method = methods[i]
+ if not method.c_ml_name: break
+ if rffi.charp2str(method.c_ml_name) == name: # XXX expensive copying
+ return PyCFunction_NewEx(space, method, w_ob)
+ raise OperationError(space.w_AttributeError, space.wrap(name))
+
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/modsupport.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/modsupport.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/modsupport.py Sun Apr 4 19:21:11 2010
@@ -3,20 +3,10 @@
METH_STATIC, METH_CLASS, METH_COEXIST, CANNOT_FAIL
from pypy.module.cpyext.pyobject import PyObject, register_container
from pypy.interpreter.module import Module
-from pypy.module.cpyext.methodobject import W_PyCFunctionObject, PyCFunction_NewEx, PyDescr_NewMethod
+from pypy.module.cpyext.methodobject import W_PyCFunctionObject, PyCFunction_NewEx, PyDescr_NewMethod, PyMethodDef, PyCFunction
from pypy.module.cpyext.pyerrors import PyErr_BadInternalCall
from pypy.interpreter.error import OperationError
-PyCFunction = lltype.Ptr(lltype.FuncType([PyObject, PyObject], PyObject))
-
-PyMethodDef = cpython_struct(
- 'PyMethodDef',
- [('ml_name', rffi.CCHARP),
- ('ml_meth', PyCFunction),
- ('ml_flags', rffi.INT_real),
- ('ml_doc', rffi.CCHARP),
- ])
-
def PyImport_AddModule(space, name):
w_name = space.wrap(name)
w_mod = space.wrap(Module(space, w_name))
@@ -101,10 +91,8 @@
@cpython_api([PyObject], rffi.CCHARP, error=0)
def PyModule_GetName(space, module):
"""
-
-
-
Return module's __name__ value. If the module does not provide one,
or if it is not a string, SystemError is raised and NULL is returned."""
raise NotImplementedError
+
More information about the Pypy-commit
mailing list