Kaydet (Commit) 5e40e74b authored tarafından Michael W. Hudson's avatar Michael W. Hudson

This is Armin Rigo's patch:

[ 617309 ] getframe hook (Psyco #1)

Forward port candidate.
üst ddd3f0ea
...@@ -109,6 +109,9 @@ DL_IMPORT(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *); ...@@ -109,6 +109,9 @@ DL_IMPORT(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *);
DL_IMPORT(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *); DL_IMPORT(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);
DL_IMPORT(PyThreadState *) PyThreadState_Next(PyThreadState *); DL_IMPORT(PyThreadState *) PyThreadState_Next(PyThreadState *);
/* hook for PyEval_GetFrame(), requested for Psyco */
extern DL_IMPORT(unaryfunc) _PyThreadState_GetFrame;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -392,7 +392,7 @@ call_with_frame(PyCodeObject *c, PyObject* func, PyObject* args) ...@@ -392,7 +392,7 @@ call_with_frame(PyCodeObject *c, PyObject* func, PyObject* args)
f = PyFrame_New( f = PyFrame_New(
tstate, /*back*/ tstate, /*back*/
c, /*code*/ c, /*code*/
tstate->frame->f_globals, /*globals*/ PyEval_GetGlobals(), /*globals*/
NULL /*locals*/ NULL /*locals*/
); );
if (f == NULL) if (f == NULL)
......
...@@ -2949,10 +2949,9 @@ PyEval_SetTrace(Py_tracefunc func, PyObject *arg) ...@@ -2949,10 +2949,9 @@ PyEval_SetTrace(Py_tracefunc func, PyObject *arg)
PyObject * PyObject *
PyEval_GetBuiltins(void) PyEval_GetBuiltins(void)
{ {
PyThreadState *tstate = PyThreadState_Get(); PyFrameObject *current_frame = (PyFrameObject *)PyEval_GetFrame();
PyFrameObject *current_frame = tstate->frame;
if (current_frame == NULL) if (current_frame == NULL)
return tstate->interp->builtins; return PyThreadState_Get()->interp->builtins;
else else
return current_frame->f_builtins; return current_frame->f_builtins;
} }
...@@ -2960,7 +2959,7 @@ PyEval_GetBuiltins(void) ...@@ -2960,7 +2959,7 @@ PyEval_GetBuiltins(void)
PyObject * PyObject *
PyEval_GetLocals(void) PyEval_GetLocals(void)
{ {
PyFrameObject *current_frame = PyThreadState_Get()->frame; PyFrameObject *current_frame = (PyFrameObject *)PyEval_GetFrame();
if (current_frame == NULL) if (current_frame == NULL)
return NULL; return NULL;
PyFrame_FastToLocals(current_frame); PyFrame_FastToLocals(current_frame);
...@@ -2970,7 +2969,7 @@ PyEval_GetLocals(void) ...@@ -2970,7 +2969,7 @@ PyEval_GetLocals(void)
PyObject * PyObject *
PyEval_GetGlobals(void) PyEval_GetGlobals(void)
{ {
PyFrameObject *current_frame = PyThreadState_Get()->frame; PyFrameObject *current_frame = (PyFrameObject *)PyEval_GetFrame();
if (current_frame == NULL) if (current_frame == NULL)
return NULL; return NULL;
else else
...@@ -2980,21 +2979,21 @@ PyEval_GetGlobals(void) ...@@ -2980,21 +2979,21 @@ PyEval_GetGlobals(void)
PyObject * PyObject *
PyEval_GetFrame(void) PyEval_GetFrame(void)
{ {
PyFrameObject *current_frame = PyThreadState_Get()->frame; PyThreadState *tstate = PyThreadState_Get();
return (PyObject *)current_frame; return _PyThreadState_GetFrame((PyObject *)tstate);
} }
int int
PyEval_GetRestricted(void) PyEval_GetRestricted(void)
{ {
PyFrameObject *current_frame = PyThreadState_Get()->frame; PyFrameObject *current_frame = (PyFrameObject *)PyEval_GetFrame();
return current_frame == NULL ? 0 : current_frame->f_restricted; return current_frame == NULL ? 0 : current_frame->f_restricted;
} }
int int
PyEval_MergeCompilerFlags(PyCompilerFlags *cf) PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
{ {
PyFrameObject *current_frame = PyThreadState_Get()->frame; PyFrameObject *current_frame = (PyFrameObject *)PyEval_GetFrame();
int result = 0; int result = 0;
if (current_frame != NULL) { if (current_frame != NULL) {
......
...@@ -35,6 +35,7 @@ static PyThread_type_lock head_mutex = NULL; /* Protects interp->tstate_head */ ...@@ -35,6 +35,7 @@ static PyThread_type_lock head_mutex = NULL; /* Protects interp->tstate_head */
static PyInterpreterState *interp_head = NULL; static PyInterpreterState *interp_head = NULL;
PyThreadState *_PyThreadState_Current = NULL; PyThreadState *_PyThreadState_Current = NULL;
unaryfunc _PyThreadState_GetFrame = NULL;
PyInterpreterState * PyInterpreterState *
...@@ -114,10 +115,19 @@ PyInterpreterState_Delete(PyInterpreterState *interp) ...@@ -114,10 +115,19 @@ PyInterpreterState_Delete(PyInterpreterState *interp)
} }
/* Default implementation for _PyThreadState_GetFrame */
static struct _frame *
threadstate_getframe(PyThreadState *self)
{
return self->frame;
}
PyThreadState * PyThreadState *
PyThreadState_New(PyInterpreterState *interp) PyThreadState_New(PyInterpreterState *interp)
{ {
PyThreadState *tstate = PyMem_NEW(PyThreadState, 1); PyThreadState *tstate = PyMem_NEW(PyThreadState, 1);
if (_PyThreadState_GetFrame == NULL)
_PyThreadState_GetFrame = (unaryfunc)threadstate_getframe;
if (tstate != NULL) { if (tstate != NULL) {
tstate->interp = interp; tstate->interp = interp;
......
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