Commit 4989639e authored by Boxiang Sun's avatar Boxiang Sun

Add new PyCode_HasFreeVars implementation

In Pyston the PyCodeObject just an opaque pointer. Which can't calculate
the number of freevars. Implement a function to check whether there has
freevars in BoxedCode object.
parent af389a7b
......@@ -74,7 +74,10 @@ PyAPI_DATA(PyTypeObject*) code_cls;
#define PyCode_Type (*code_cls)
#define PyCode_Check(op) (Py_TYPE(op) == &PyCode_Type)
#define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars))
// Pyston change: disable this macro.
// In Pyston the PyCodeObject is just an opaque pointer, get its size
// directly will cause error.
// #define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars))
/* Public interface */
PyAPI_FUNC(PyCodeObject *) PyCode_New(
......@@ -95,6 +98,7 @@ PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int) PYSTON_NOEXCEPT;
PyAPI_FUNC(int) PyCode_GetArgCount(PyCodeObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(BORROWED(PyObject*)) PyCode_GetFilename(PyCodeObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(BORROWED(PyObject*)) PyCode_GetName(PyCodeObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(int) PyCode_HasFreeVars(PyCodeObject* ) PYSTON_NOEXCEPT;
/* for internal use only */
#define _PyCode_GETCODEPTR(co, pp) \
......
......@@ -200,11 +200,17 @@ extern "C" BORROWED(PyObject*) PyCode_GetFilename(PyCodeObject* op) noexcept {
RELEASE_ASSERT(PyCode_Check((Box*)op), "");
return BoxedCode::filename((Box*)op, NULL);
}
extern "C" BORROWED(PyObject*) PyCode_GetName(PyCodeObject* op) noexcept {
RELEASE_ASSERT(PyCode_Check((Box*)op), "");
return BoxedCode::name((Box*)op, NULL);
}
extern "C" int PyCode_HasFreeVars(PyCodeObject* _code) noexcept {
BoxedCode* code = (BoxedCode*)_code;
return code->f->source->getScopeInfo()->takesClosure() ? 1 : 0;
}
void setupCode() {
code_cls
= BoxedClass::create(type_cls, object_cls, 0, 0, sizeof(BoxedCode), false, "code", false,
......
......@@ -347,6 +347,7 @@ extern "C" PyFrameObject* PyFrame_New(PyThreadState* tstate, PyCodeObject* code,
extern "C" BORROWED(PyObject*) PyFrame_GetGlobals(PyFrameObject* f) noexcept {
return BoxedFrame::globals((Box*)f, NULL);
}
extern "C" BORROWED(PyObject*) PyFrame_GetCode(PyFrameObject* f) noexcept {
return BoxedFrame::code((Box*)f, NULL);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment