[Python-checkins] python/dist/src/Python ceval.c,2.339,2.340 pystate.c,2.21,2.22

mwh@users.sourceforge.net mwh@users.sourceforge.net
Fri, 08 Nov 2002 04:53:13 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv5667/Python

Modified Files:
	ceval.c pystate.c 
Log Message:
Assorted patches from Armin Rigo:

[ 617309 ] getframe hook (Psyco #1)
[ 617311 ] Tiny profiling info (Psyco #2)
[ 617312 ] debugger-controlled jumps (Psyco #3)

These are forward ports from 2.2.2.



Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.339
retrieving revision 2.340
diff -C2 -d -r2.339 -r2.340
*** ceval.c	6 Nov 2002 15:17:32 -0000	2.339
--- ceval.c	8 Nov 2002 12:53:10 -0000	2.340
***************
*** 52,56 ****
  				 PyFrameObject *, int);
  static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *);
! static void maybe_call_line_trace(int, Py_tracefunc, PyObject *, 
  				  PyFrameObject *, int *, int *);
  
--- 52,56 ----
  				 PyFrameObject *, int);
  static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *);
! static void maybe_call_line_trace(Py_tracefunc, PyObject *, 
  				  PyFrameObject *, int *, int *);
  
***************
*** 600,621 ****
  
  	tstate->frame = f;
- 	co = f->f_code;
- 	names = co->co_names;
- 	consts = co->co_consts;
- 	fastlocals = f->f_localsplus;
- 	freevars = f->f_localsplus + f->f_nlocals;
- 	_PyCode_GETCODEPTR(co, &first_instr);
- 	/* An explanation is in order for the next line.
- 
- 	   f->f_lasti now refers to the index of the last instruction
- 	   executed.  You might think this was obvious from the name, but
- 	   this wasn't always true before 2.3!  PyFrame_New now sets
- 	   f->f_lasti to -1 (i.e. the index *before* the first instruction)
- 	   and YIELD_VALUE doesn't fiddle with f_lasti any more.  So this
- 	   does work.  Promise. */
- 	next_instr = first_instr + f->f_lasti + 1;
- 	stack_pointer = f->f_stacktop;
- 	assert(stack_pointer != NULL);
- 	f->f_stacktop = NULL;	/* remains NULL unless yield suspends frame */
  
  	if (tstate->use_tracing) {
--- 600,603 ----
***************
*** 656,659 ****
--- 638,660 ----
  	}
  
+ 	co = f->f_code;
+ 	names = co->co_names;
+ 	consts = co->co_consts;
+ 	fastlocals = f->f_localsplus;
+ 	freevars = f->f_localsplus + f->f_nlocals;
+ 	_PyCode_GETCODEPTR(co, &first_instr);
+ 	/* An explanation is in order for the next line.
+ 
+ 	   f->f_lasti now refers to the index of the last instruction
+ 	   executed.  You might think this was obvious from the name, but
+ 	   this wasn't always true before 2.3!  PyFrame_New now sets
+ 	   f->f_lasti to -1 (i.e. the index *before* the first instruction)
+ 	   and YIELD_VALUE doesn't fiddle with f_lasti any more.  So this
+ 	   does work.  Promise. */
+ 	next_instr = first_instr + f->f_lasti + 1;
+ 	stack_pointer = f->f_stacktop;
+ 	assert(stack_pointer != NULL);
+ 	f->f_stacktop = NULL;	/* remains NULL unless yield suspends frame */
+ 
  #ifdef LLTRACE
  	lltrace = PyDict_GetItemString(f->f_globals,"__lltrace__") != NULL;
***************
*** 682,685 ****
--- 683,687 ----
  		if (--_Py_Ticker < 0) {
  			_Py_Ticker = _Py_CheckInterval;
+ 			tstate->tick_counter++;
  			if (things_to_do) {
  				if (Py_MakePendingCalls() < 0) {
***************
*** 717,724 ****
  
  	fast_next_opcode:
- 		/* Extract opcode and argument */
- 
  		f->f_lasti = INSTR_OFFSET();
  
  		opcode = NEXTOP();
  		if (HAS_ARG(opcode))
--- 719,742 ----
  
  	fast_next_opcode:
  		f->f_lasti = INSTR_OFFSET();
  
+ 		/* line-by-line tracing support */
+ 
+ 		if (tstate->c_tracefunc != NULL && !tstate->tracing) {
+ 			/* see maybe_call_line_trace
+ 			   for expository comments */
+ 			f->f_stacktop = stack_pointer;
+ 			maybe_call_line_trace(tstate->c_tracefunc,
+ 					      tstate->c_traceobj,
+ 					      f, &instr_lb, &instr_ub);
+ 			/* Reload possibly changed frame fields */
+ 			JUMPTO(f->f_lasti);
+ 			stack_pointer = f->f_stacktop;
+ 			assert(stack_pointer != NULL);
+ 			f->f_stacktop = NULL;
+ 		}
+ 
+ 		/* Extract opcode and argument */
+ 
  		opcode = NEXTOP();
  		if (HAS_ARG(opcode))
***************
*** 748,762 ****
  #endif
  
- 		/* line-by-line tracing support */
- 
- 		if (tstate->c_tracefunc != NULL && !tstate->tracing) {
- 			/* see maybe_call_line_trace
- 			   for expository comments */
- 			maybe_call_line_trace(opcode, 
- 					      tstate->c_tracefunc,
- 					      tstate->c_traceobj,
- 					      f, &instr_lb, &instr_ub);
- 		}
- 
  		/* Main switch on opcode */
  
--- 766,769 ----
***************
*** 2867,2871 ****
  
  static void
! maybe_call_line_trace(int opcode, Py_tracefunc func, PyObject *obj, 
  		      PyFrameObject *frame, int *instr_lb, int *instr_ub)
  {
--- 2874,2878 ----
  
  static void
! maybe_call_line_trace(Py_tracefunc func, PyObject *obj, 
  		      PyFrameObject *frame, int *instr_lb, int *instr_ub)
  {
***************
*** 3026,3033 ****
  PyEval_GetBuiltins(void)
  {
! 	PyThreadState *tstate = PyThreadState_Get();
! 	PyFrameObject *current_frame = tstate->frame;
  	if (current_frame == NULL)
! 		return tstate->interp->builtins;
  	else
  		return current_frame->f_builtins;
--- 3033,3039 ----
  PyEval_GetBuiltins(void)
  {
! 	PyFrameObject *current_frame = (PyFrameObject *)PyEval_GetFrame();
  	if (current_frame == NULL)
! 		return PyThreadState_Get()->interp->builtins;
  	else
  		return current_frame->f_builtins;
***************
*** 3037,3041 ****
  PyEval_GetLocals(void)
  {
! 	PyFrameObject *current_frame = PyThreadState_Get()->frame;
  	if (current_frame == NULL)
  		return NULL;
--- 3043,3047 ----
  PyEval_GetLocals(void)
  {
! 	PyFrameObject *current_frame = (PyFrameObject *)PyEval_GetFrame();
  	if (current_frame == NULL)
  		return NULL;
***************
*** 3047,3051 ****
  PyEval_GetGlobals(void)
  {
! 	PyFrameObject *current_frame = PyThreadState_Get()->frame;
  	if (current_frame == NULL)
  		return NULL;
--- 3053,3057 ----
  PyEval_GetGlobals(void)
  {
! 	PyFrameObject *current_frame = (PyFrameObject *)PyEval_GetFrame();
  	if (current_frame == NULL)
  		return NULL;
***************
*** 3057,3062 ****
  PyEval_GetFrame(void)
  {
! 	PyFrameObject *current_frame = PyThreadState_Get()->frame;
! 	return (PyObject *)current_frame;
  }
  
--- 3063,3068 ----
  PyEval_GetFrame(void)
  {
! 	PyThreadState *tstate = PyThreadState_Get();
! 	return _PyThreadState_GetFrame((PyObject *)tstate);
  }
  
***************
*** 3064,3068 ****
  PyEval_GetRestricted(void)
  {
! 	PyFrameObject *current_frame = PyThreadState_Get()->frame;
  	return current_frame == NULL ? 0 : current_frame->f_restricted;
  }
--- 3070,3074 ----
  PyEval_GetRestricted(void)
  {
! 	PyFrameObject *current_frame = (PyFrameObject *)PyEval_GetFrame();
  	return current_frame == NULL ? 0 : current_frame->f_restricted;
  }
***************
*** 3071,3075 ****
  PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
  {
! 	PyFrameObject *current_frame = PyThreadState_Get()->frame;
  	int result = 0;
  
--- 3077,3081 ----
  PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
  {
! 	PyFrameObject *current_frame = (PyFrameObject *)PyEval_GetFrame();
  	int result = 0;
  

Index: pystate.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pystate.c,v
retrieving revision 2.21
retrieving revision 2.22
diff -C2 -d -r2.21 -r2.22
*** pystate.c	3 Sep 2002 20:24:31 -0000	2.21
--- pystate.c	8 Nov 2002 12:53:11 -0000	2.22
***************
*** 36,39 ****
--- 36,40 ----
  
  PyThreadState *_PyThreadState_Current = NULL;
+ unaryfunc _PyThreadState_GetFrame = NULL;
  
  
***************
*** 114,121 ****
--- 115,131 ----
  
  
+ /* Default implementation for _PyThreadState_GetFrame */
+ static struct _frame *
+ threadstate_getframe(PyThreadState *self)
+ {
+ 	return self->frame;
+ }
+ 
  PyThreadState *
  PyThreadState_New(PyInterpreterState *interp)
  {
  	PyThreadState *tstate = PyMem_NEW(PyThreadState, 1);
+ 	if (_PyThreadState_GetFrame == NULL)
+ 		_PyThreadState_GetFrame = (unaryfunc)threadstate_getframe;
  
  	if (tstate != NULL) {
***************
*** 126,129 ****
--- 136,140 ----
  		tstate->tracing = 0;
  		tstate->use_tracing = 0;
+ 		tstate->tick_counter = 0;
  
  		tstate->dict = NULL;