[pypy-commit] pypy default: Implement PyFunction_GetCode()
amauryfa
noreply at buildbot.pypy.org
Fri Sep 9 01:27:27 CEST 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r47173:0d46b9d3db65
Date: 2011-09-08 00:17 +0200
http://bitbucket.org/pypy/pypy/changeset/0d46b9d3db65/
Log: Implement PyFunction_GetCode()
diff --git a/pypy/module/cpyext/funcobject.py b/pypy/module/cpyext/funcobject.py
--- a/pypy/module/cpyext/funcobject.py
+++ b/pypy/module/cpyext/funcobject.py
@@ -40,6 +40,13 @@
from pypy.module.cpyext.object import PyObject_dealloc
PyObject_dealloc(space, py_obj)
+ at cpython_api([PyObject], PyObject)
+def PyFunction_GetCode(space, w_func):
+ """Return the code object associated with the function object op."""
+ func = space.interp_w(Function, w_func)
+ w_code = space.wrap(func.code)
+ return borrow_from(w_func, w_code)
+
@cpython_api([PyObject, PyObject, PyObject], PyObject)
def PyMethod_New(space, w_func, w_self, w_cls):
"""Return a new method object, with func being any callable object; this is the
diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py
--- a/pypy/module/cpyext/stubs.py
+++ b/pypy/module/cpyext/stubs.py
@@ -920,12 +920,6 @@
raise NotImplementedError
@cpython_api([PyObject], PyObject)
-def PyFunction_GetCode(space, op):
- """Return the code object associated with the function object op."""
- borrow_from()
- raise NotImplementedError
-
- at cpython_api([PyObject], PyObject)
def PyFunction_GetGlobals(space, op):
"""Return the globals dictionary associated with the function object op."""
borrow_from()
diff --git a/pypy/module/cpyext/test/test_funcobject.py b/pypy/module/cpyext/test/test_funcobject.py
--- a/pypy/module/cpyext/test/test_funcobject.py
+++ b/pypy/module/cpyext/test/test_funcobject.py
@@ -36,6 +36,14 @@
w_method2 = api.PyMethod_New(w_function, w_self, w_class)
assert space.eq_w(w_method, w_method2)
+ def test_getcode(self, space, api):
+ w_function = space.appexec([], """():
+ def func(x): return x
+ return func
+ """)
+ w_code = api.PyFunction_GetCode(w_function)
+ assert w_code.co_name == "func"
+
def test_newcode(self, space, api):
filename = rffi.str2charp('filename')
funcname = rffi.str2charp('funcname')
More information about the pypy-commit
mailing list