[pypy-svn] r78852 - in pypy/branch/fast-forward/pypy/module/cpyext: . test
afa at codespeak.net
afa at codespeak.net
Mon Nov 8 00:08:05 CET 2010
Author: afa
Date: Mon Nov 8 00:08:04 2010
New Revision: 78852
Modified:
pypy/branch/fast-forward/pypy/module/cpyext/funcobject.py
pypy/branch/fast-forward/pypy/module/cpyext/test/test_funcobject.py
Log:
Add PyCode_NewEmpty
Modified: pypy/branch/fast-forward/pypy/module/cpyext/funcobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/cpyext/funcobject.py (original)
+++ pypy/branch/fast-forward/pypy/module/cpyext/funcobject.py Mon Nov 8 00:08:04 2010
@@ -1,10 +1,11 @@
from pypy.rpython.lltypesystem import rffi, lltype
from pypy.module.cpyext.api import (
- PyObjectFields, generic_cpy_call,
+ PyObjectFields, generic_cpy_call, CONST_STRING,
cpython_api, bootstrap_function, cpython_struct, build_type_checkers)
from pypy.module.cpyext.pyobject import (
PyObject, make_ref, from_ref, Py_DecRef, make_typedescr, borrow_from)
from pypy.interpreter.function import Function, Method
+from pypy.interpreter.pycode import PyCode
PyFunctionObjectStruct = lltype.ForwardReference()
PyFunctionObject = lltype.Ptr(PyFunctionObjectStruct)
@@ -63,3 +64,22 @@
assert isinstance(w_method, Method)
return borrow_from(w_method, w_method.w_class)
+ at cpython_api([CONST_STRING, CONST_STRING, rffi.INT_real], PyObject)
+def PyCode_NewEmpty(space, filename, funcname, firstlineno):
+ """Creates a new empty code object with the specified source location."""
+ return space.wrap(PyCode(space,
+ argcount=0,
+ nlocals=0,
+ stacksize=0,
+ flags=0,
+ code="",
+ consts=[],
+ names=[],
+ varnames=[],
+ filename=rffi.charp2str(filename),
+ name=rffi.charp2str(funcname),
+ firstlineno=firstlineno,
+ lnotab="",
+ freevars=[],
+ cellvars=[]))
+
Modified: pypy/branch/fast-forward/pypy/module/cpyext/test/test_funcobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/cpyext/test/test_funcobject.py (original)
+++ pypy/branch/fast-forward/pypy/module/cpyext/test/test_funcobject.py Mon Nov 8 00:08:04 2010
@@ -35,3 +35,12 @@
w_method2 = api.PyMethod_New(w_function, w_self, w_class)
assert space.eq_w(w_method, w_method2)
+
+ def test_newcode(self, space, api):
+ filename = rffi.str2charp('filename')
+ funcname = rffi.str2charp('funcname')
+ w_code = api.PyCode_NewEmpty(filename, funcname, 3)
+ assert w_code.co_filename == 'filename'
+ assert w_code.co_firstlineno == 3
+ rffi.free_charp(filename)
+ rffi.free_charp(funcname)
More information about the Pypy-commit
mailing list