Commit 32657208 authored by Boxiang Sun's avatar Boxiang Sun

apply pyston changes to make PyErr_WarnEx could work

parent 1cac93a3
...@@ -114,6 +114,7 @@ file(GLOB_RECURSE STDPYTHON_SRCS Python ...@@ -114,6 +114,7 @@ file(GLOB_RECURSE STDPYTHON_SRCS Python
Python-ast.c Python-ast.c
random.c random.c
structmember.c structmember.c
_warnings.c
) )
# compile specified files in from_cpython/Python # compile specified files in from_cpython/Python
......
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
#include "classobject.h" #include "classobject.h"
#include "cobject.h" #include "cobject.h"
#include "fileobject.h" #include "fileobject.h"
#include "frameobject.h"
#include "pycapsule.h" #include "pycapsule.h"
#include "traceback.h" #include "traceback.h"
#include "sliceobject.h" #include "sliceobject.h"
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
extern "C" { extern "C" {
#endif #endif
// Pyston changes: we don't use it for now.
#if 0
typedef struct { typedef struct {
int b_type; /* what kind of block this is */ int b_type; /* what kind of block this is */
int b_handler; /* where to jump to find handler */ int b_handler; /* where to jump to find handler */
...@@ -79,9 +81,16 @@ PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int); ...@@ -79,9 +81,16 @@ PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);
PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *); PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
PyAPI_FUNC(int) PyFrame_ClearFreeList(void); PyAPI_FUNC(int) PyFrame_ClearFreeList(void);
#endif
typedef struct _PyFrameObject PyFrameObject;
/* Return the line of code the frame is currently executing. */ /* Return the line of code the frame is currently executing. */
PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *); PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *) PYSTON_NOEXCEPT;
// Pyston changes: add a function to get globals
PyAPI_FUNC(PyObject *) PyFrame_GetGlobals(PyFrameObject *) PYSTON_NOEXCEPT;
// Pyston changes: add a function to get frame object by level
PyAPI_FUNC(PyFrameObject *) PyFrame_ForStackLevel(int stack_level) PYSTON_NOEXCEPT;
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -25,6 +25,9 @@ PyAPI_FUNC(void) PySys_ResetWarnOptions(void) PYSTON_NOEXCEPT; ...@@ -25,6 +25,9 @@ PyAPI_FUNC(void) PySys_ResetWarnOptions(void) PYSTON_NOEXCEPT;
PyAPI_FUNC(void) PySys_AddWarnOption(char *) PYSTON_NOEXCEPT; PyAPI_FUNC(void) PySys_AddWarnOption(char *) PYSTON_NOEXCEPT;
PyAPI_FUNC(int) PySys_HasWarnOptions(void) PYSTON_NOEXCEPT; PyAPI_FUNC(int) PySys_HasWarnOptions(void) PYSTON_NOEXCEPT;
// Pyston change: add this API to get sys modules dict
PyAPI_FUNC(PyObject *) PySys_GetModulesDict(void) PYSTON_NOEXCEPT;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -446,16 +446,26 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, ...@@ -446,16 +446,26 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
PyObject *globals; PyObject *globals;
/* Setup globals and lineno. */ /* Setup globals and lineno. */
PyFrameObject *f = PyThreadState_GET()->frame; // Pyston changes: use Pyston's BoxedFrame instead PyFrameObject
while (--stack_level > 0 && f != NULL) // to get globals and lineno.
f = f->f_back; /* PyFrameObject *f = PyThreadState_GET()->frame; */
/* while (--stack_level > 0 && f != NULL) */
if (f == NULL) { /* f = f->f_back; */
globals = PyThreadState_Get()->interp->sysdict; /* */
} /* if (f == NULL) { */
else { /* globals = PyThreadState_Get()->interp->sysdict; */
globals = f->f_globals; /* } */
*lineno = PyFrame_GetLineNumber(f); /* else { */
/* globals = f->f_globals; */
/* *lineno = PyFrame_GetLineNumber(f); */
/* } */
PyFrameObject* frame = PyFrame_ForStackLevel(stack_level - 1);
if (!frame) {
globals = PySys_GetModulesDict();
*lineno = 1;
} else {
globals = PyFrame_GetGlobals(frame);
*lineno = PyFrame_GetLineNumber(frame);
} }
*module = NULL; *module = NULL;
...@@ -890,6 +900,8 @@ _PyWarnings_Init(void) ...@@ -890,6 +900,8 @@ _PyWarnings_Init(void)
_filters = init_filters(); _filters = init_filters();
if (_filters == NULL) if (_filters == NULL)
return; return;
// Pyston change: let the GC scan the filters
PyGC_AddPotentialRoot(_filters, sizeof(_filters));
Py_INCREF(_filters); Py_INCREF(_filters);
if (PyModule_AddObject(m, "filters", _filters) < 0) if (PyModule_AddObject(m, "filters", _filters) < 0)
return; return;
...@@ -897,6 +909,8 @@ _PyWarnings_Init(void) ...@@ -897,6 +909,8 @@ _PyWarnings_Init(void)
_once_registry = PyDict_New(); _once_registry = PyDict_New();
if (_once_registry == NULL) if (_once_registry == NULL)
return; return;
// Pyston change: let the GC scan the registry
PyGC_AddPotentialRoot(_once_registry, sizeof(_once_registry));
Py_INCREF(_once_registry); Py_INCREF(_once_registry);
if (PyModule_AddObject(m, "once_registry", _once_registry) < 0) if (PyModule_AddObject(m, "once_registry", _once_registry) < 0)
return; return;
...@@ -904,6 +918,8 @@ _PyWarnings_Init(void) ...@@ -904,6 +918,8 @@ _PyWarnings_Init(void)
_default_action = PyString_FromString("default"); _default_action = PyString_FromString("default");
if (_default_action == NULL) if (_default_action == NULL)
return; return;
// Pyston change: let the GC scan the action
PyGC_AddPotentialRoot(_default_action, sizeof(_default_action));
Py_INCREF(_default_action); Py_INCREF(_default_action);
if (PyModule_AddObject(m, "default_action", _default_action) < 0) if (PyModule_AddObject(m, "default_action", _default_action) < 0)
return; return;
......
...@@ -41,6 +41,7 @@ BoxedDict* sys_modules_dict; ...@@ -41,6 +41,7 @@ BoxedDict* sys_modules_dict;
extern "C" { extern "C" {
// supposed to be exposed through sys.flags // supposed to be exposed through sys.flags
int Py_BytesWarningFlag = 0; int Py_BytesWarningFlag = 0;
int Py_DivisionWarningFlag = 0;
int Py_HashRandomizationFlag = 0; int Py_HashRandomizationFlag = 0;
} }
...@@ -400,6 +401,10 @@ extern "C" const char* Py_GetPlatform() noexcept { ...@@ -400,6 +401,10 @@ extern "C" const char* Py_GetPlatform() noexcept {
#endif #endif
} }
extern "C" PyObject* PySys_GetModulesDict() noexcept {
return getSysModulesDict();
}
static PyObject* sys_excepthook(PyObject* self, PyObject* args) noexcept { static PyObject* sys_excepthook(PyObject* self, PyObject* args) noexcept {
PyObject* exc, *value, *tb; PyObject* exc, *value, *tb;
if (!PyArg_UnpackTuple(args, "excepthook", 3, 3, &exc, &value, &tb)) if (!PyArg_UnpackTuple(args, "excepthook", 3, 3, &exc, &value, &tb))
......
...@@ -585,8 +585,11 @@ extern "C" int PyObject_IsTrue(PyObject* o) noexcept { ...@@ -585,8 +585,11 @@ extern "C" int PyObject_IsTrue(PyObject* o) noexcept {
extern "C" int PyObject_Not(PyObject* o) noexcept { extern "C" int PyObject_Not(PyObject* o) noexcept {
fatalOrError(PyExc_NotImplementedError, "unimplemented"); int res;
return -1; res = PyObject_IsTrue(o);
if (res < 0)
return res;
return res == 0;
} }
extern "C" PyObject* PyObject_Call(PyObject* callable_object, PyObject* args, PyObject* kw) noexcept { extern "C" PyObject* PyObject_Call(PyObject* callable_object, PyObject* args, PyObject* kw) noexcept {
...@@ -1034,16 +1037,6 @@ extern "C" PyObject* PyErr_Occurred() noexcept { ...@@ -1034,16 +1037,6 @@ extern "C" PyObject* PyErr_Occurred() noexcept {
return cur_thread_state.curexc_type; return cur_thread_state.curexc_type;
} }
extern "C" int PyErr_WarnEx(PyObject* category, const char* text, Py_ssize_t stacklevel) noexcept {
// These warnings are silenced by default:
// We should copy the real CPython code in here
if (category == PyExc_DeprecationWarning)
return 0;
fatalOrError(PyExc_NotImplementedError, "unimplemented");
return -1;
}
extern "C" void* PyObject_Malloc(size_t sz) noexcept { extern "C" void* PyObject_Malloc(size_t sz) noexcept {
return gc_compat_malloc(sz); return gc_compat_malloc(sz);
} }
...@@ -1924,13 +1917,6 @@ Box* BoxedCApiFunction::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgPa ...@@ -1924,13 +1917,6 @@ Box* BoxedCApiFunction::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgPa
return rtn; return rtn;
} }
/* Warning with explicit origin */
extern "C" int PyErr_WarnExplicit(PyObject* category, const char* text, const char* filename_str, int lineno,
const char* module_str, PyObject* registry) noexcept {
Py_FatalError("unimplemented");
}
/* extension modules might be compiled with GC support so these /* extension modules might be compiled with GC support so these
functions must always be available */ functions must always be available */
......
...@@ -149,6 +149,22 @@ Box* getFrame(int depth) { ...@@ -149,6 +149,22 @@ Box* getFrame(int depth) {
return BoxedFrame::boxFrame(std::move(it)); return BoxedFrame::boxFrame(std::move(it));
} }
extern "C" int PyFrame_GetLineNumber(PyFrameObject* f) noexcept {
BoxedInt* lineno = (BoxedInt*)BoxedFrame::lineno((Box*)f, NULL);
return lineno->n;
}
extern "C" PyObject* PyFrame_GetGlobals(PyFrameObject* f) noexcept {
Box* globals = BoxedFrame::globals((Box*)f, NULL);
if (globals->cls == attrwrapper_cls)
return attrwrapperToDict(globals);
return globals;
}
extern "C" PyFrameObject* PyFrame_ForStackLevel(int stack_level) noexcept {
return (PyFrameObject*)getFrame(stack_level);
}
void setupFrame() { void setupFrame() {
frame_cls frame_cls
= BoxedClass::create(type_cls, object_cls, &BoxedFrame::gchandler, 0, 0, sizeof(BoxedFrame), false, "frame"); = BoxedClass::create(type_cls, object_cls, &BoxedFrame::gchandler, 0, 0, sizeof(BoxedFrame), false, "frame");
......
...@@ -126,6 +126,10 @@ static Box* traceback_tb_next(Box* self, void*) { ...@@ -126,6 +126,10 @@ static Box* traceback_tb_next(Box* self, void*) {
return traceback->tb_next; return traceback->tb_next;
} }
extern "C" int _Py_DisplaySourceLine(PyObject* f, const char* filename, int lineno, int indent) noexcept {
RELEASE_ASSERT(0, "Not implemented.");
}
void setupTraceback() { void setupTraceback() {
traceback_cls = BoxedClass::create(type_cls, object_cls, BoxedTraceback::gcHandler, 0, 0, sizeof(BoxedTraceback), traceback_cls = BoxedClass::create(type_cls, object_cls, BoxedTraceback::gcHandler, 0, 0, sizeof(BoxedTraceback),
false, "traceback"); false, "traceback");
......
...@@ -77,6 +77,7 @@ extern "C" void initzlib(); ...@@ -77,6 +77,7 @@ extern "C" void initzlib();
extern "C" void init_codecs(); extern "C" void init_codecs();
extern "C" void init_socket(); extern "C" void init_socket();
extern "C" void _PyUnicode_Init(); extern "C" void _PyUnicode_Init();
extern "C" void _PyWarnings_Init() noexcept;
extern "C" void _string_init(); extern "C" void _string_init();
extern "C" void initunicodedata(); extern "C" void initunicodedata();
extern "C" void init_weakref(); extern "C" void init_weakref();
...@@ -3937,6 +3938,7 @@ void setupRuntime() { ...@@ -3937,6 +3938,7 @@ void setupRuntime() {
setupClassobj(); setupClassobj();
setupSuper(); setupSuper();
_PyUnicode_Init(); _PyUnicode_Init();
_PyWarnings_Init();
_string_init(); _string_init();
setupDescr(); setupDescr();
setupTraceback(); setupTraceback();
......
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