Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 55fa66d

Browse files
committed
Add comments about PyThreadState and the usage of its fields.
1 parent 527c469 commit 55fa66d

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

Include/pystate.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,16 @@ typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *);
5353
#define PyTrace_C_RETURN 6
5454

5555
typedef struct _ts {
56+
/* See Python/ceval.c for comments explaining most fields */
5657

5758
struct _ts *next;
5859
PyInterpreterState *interp;
5960

6061
struct _frame *frame;
6162
int recursion_depth;
63+
/* 'tracing' keeps track of the execution depth when tracing/profiling.
64+
This is to prevent the actual trace/profile code from being recorded in
65+
the trace/profile. */
6266
int tracing;
6367
int use_tracing;
6468

@@ -75,7 +79,7 @@ typedef struct _ts {
7579
PyObject *exc_value;
7680
PyObject *exc_traceback;
7781

78-
PyObject *dict;
82+
PyObject *dict; /* Stores per-thread state */
7983

8084
/* tick_counter is incremented whenever the check_interval ticker
8185
* reaches zero. The purpose is to give a useful measure of the number

Python/ceval.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3284,10 +3284,12 @@ PyEval_SetProfile(Py_tracefunc func, PyObject *arg)
32843284
Py_XINCREF(arg);
32853285
tstate->c_profilefunc = NULL;
32863286
tstate->c_profileobj = NULL;
3287+
/* Must make sure that tracing is not ignored if 'temp' is freed */
32873288
tstate->use_tracing = tstate->c_tracefunc != NULL;
32883289
Py_XDECREF(temp);
32893290
tstate->c_profilefunc = func;
32903291
tstate->c_profileobj = arg;
3292+
/* Flag that tracing or profiling is turned on */
32913293
tstate->use_tracing = (func != NULL) || (tstate->c_tracefunc != NULL);
32923294
}
32933295

@@ -3299,10 +3301,12 @@ PyEval_SetTrace(Py_tracefunc func, PyObject *arg)
32993301
Py_XINCREF(arg);
33003302
tstate->c_tracefunc = NULL;
33013303
tstate->c_traceobj = NULL;
3304+
/* Must make sure that profiling is not ignored if 'temp' is freed */
33023305
tstate->use_tracing = tstate->c_profilefunc != NULL;
33033306
Py_XDECREF(temp);
33043307
tstate->c_tracefunc = func;
33053308
tstate->c_traceobj = arg;
3309+
/* Flag that tracing or profiling is turned on */
33063310
tstate->use_tracing = ((func != NULL)
33073311
|| (tstate->c_profilefunc != NULL));
33083312
}

0 commit comments

Comments
 (0)