annotate Include/pystate.h @ 79691:05c8928362ee

Merge __next__ method link fixes with 3.3.
author Ezio Melotti <ezio.melotti@gmail.com>
date Fri, 12 Oct 2012 13:46:37 +0300
parents 800507fb0a7e
children 2e92d1567ad7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* Thread and interpreter state structures and their interfaces */
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
13443
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
5 #ifndef Py_PYSTATE_H
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
6 #define Py_PYSTATE_H
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
7 #ifdef __cplusplus
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
8 extern "C" {
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
9 #endif
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
10
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 /* State shared between threads */
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
5919
5da18e002b1a Mass checkin (more to follow for other directories).
Guido van Rossum <guido@python.org>
parents: 5564
diff changeset
13 struct _ts; /* Forward */
5da18e002b1a Mass checkin (more to follow for other directories).
Guido van Rossum <guido@python.org>
parents: 5564
diff changeset
14 struct _is; /* Forward */
5da18e002b1a Mass checkin (more to follow for other directories).
Guido van Rossum <guido@python.org>
parents: 5564
diff changeset
15
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
16 #ifdef Py_LIMITED_API
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
17 typedef struct _is PyInterpreterState;
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
18 #else
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 typedef struct _is {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20
13443
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
21 struct _is *next;
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
22 struct _ts *tstate_head;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
13443
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
24 PyObject *modules;
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 42013
diff changeset
25 PyObject *modules_by_index;
13443
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
26 PyObject *sysdict;
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
27 PyObject *builtins;
76303
2dd046be2c88 Issue #2377: Make importlib the implementation of __import__().
Brett Cannon <brett@python.org>
parents: 71770
diff changeset
28 PyObject *importlib;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
28325
850626d47574 Fixed SF bug #663074. The codec system was using global static
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 27978
diff changeset
30 PyObject *codec_search_path;
850626d47574 Fixed SF bug #663074. The codec system was using global static
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 27978
diff changeset
31 PyObject *codec_search_cache;
850626d47574 Fixed SF bug #663074. The codec system was using global static
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 27978
diff changeset
32 PyObject *codec_error_registry;
49613
efef5fc45a9a Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents: 47580
diff changeset
33 int codecs_initialized;
69708
2caf82aee7a4 Issue #10914: Initialize correctly the filesystem codec when creating a new
Victor Stinner <victor.stinner@haypocalc.com>
parents: 69637
diff changeset
34 int fscodec_initialized;
28325
850626d47574 Fixed SF bug #663074. The codec system was using global static
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 27978
diff changeset
35
76303
2dd046be2c88 Issue #2377: Make importlib the implementation of __import__().
Brett Cannon <brett@python.org>
parents: 71770
diff changeset
36
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18374
diff changeset
37 #ifdef HAVE_DLOPEN
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18374
diff changeset
38 int dlopenflags;
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18374
diff changeset
39 #endif
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31836
diff changeset
40 #ifdef WITH_TSC
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31836
diff changeset
41 int tscdump;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31836
diff changeset
42 #endif
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
43
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 } PyInterpreterState;
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
45 #endif
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 /* State unique per thread */
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 struct _frame; /* Avoid including frameobject.h */
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
52 #ifndef Py_LIMITED_API
18325
fb35b3a22604 Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 16139
diff changeset
53 /* Py_tracefunc return -1 when raising an exception, or 0 for success. */
fb35b3a22604 Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 16139
diff changeset
54 typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *);
fb35b3a22604 Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 16139
diff changeset
55
fb35b3a22604 Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 16139
diff changeset
56 /* The following values are used for 'what' for tracefunc functions: */
fb35b3a22604 Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 16139
diff changeset
57 #define PyTrace_CALL 0
fb35b3a22604 Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 16139
diff changeset
58 #define PyTrace_EXCEPTION 1
fb35b3a22604 Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 16139
diff changeset
59 #define PyTrace_LINE 2
fb35b3a22604 Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 16139
diff changeset
60 #define PyTrace_RETURN 3
31796
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31654
diff changeset
61 #define PyTrace_C_CALL 4
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31654
diff changeset
62 #define PyTrace_C_EXCEPTION 5
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31654
diff changeset
63 #define PyTrace_C_RETURN 6
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
64 #endif
18325
fb35b3a22604 Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 16139
diff changeset
65
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
66 #ifdef Py_LIMITED_API
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
67 typedef struct _ts PyThreadState;
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
68 #else
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 typedef struct _ts {
35125
cdec978b916c Add comments about PyThreadState and the usage of its fields.
Brett Cannon <bcannon@gmail.com>
parents: 32301
diff changeset
70 /* See Python/ceval.c for comments explaining most fields */
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
71
13443
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
72 struct _ts *next;
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
73 PyInterpreterState *interp;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
74
13443
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
75 struct _frame *frame;
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
76 int recursion_depth;
42013
cd125fe83051 Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents: 41554
diff changeset
77 char overflowed; /* The stack has overflowed. Allow 50 more calls
69584
75503c26a17f PyGILState_Ensure(), PyGILState_Release(), PyGILState_GetThisThreadState() are
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
78 to handle the runtime error. */
75503c26a17f PyGILState_Ensure(), PyGILState_Release(), PyGILState_GetThisThreadState() are
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
79 char recursion_critical; /* The current calls must not cause
75503c26a17f PyGILState_Ensure(), PyGILState_Release(), PyGILState_GetThisThreadState() are
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
80 a stack overflow. */
35125
cdec978b916c Add comments about PyThreadState and the usage of its fields.
Brett Cannon <bcannon@gmail.com>
parents: 32301
diff changeset
81 /* 'tracing' keeps track of the execution depth when tracing/profiling.
cdec978b916c Add comments about PyThreadState and the usage of its fields.
Brett Cannon <bcannon@gmail.com>
parents: 32301
diff changeset
82 This is to prevent the actual trace/profile code from being recorded in
cdec978b916c Add comments about PyThreadState and the usage of its fields.
Brett Cannon <bcannon@gmail.com>
parents: 32301
diff changeset
83 the trace/profile. */
13443
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
84 int tracing;
18374
3b295ce2705f This change adjusts the profiling/tracing support so that the common
Fred Drake <fdrake@acm.org>
parents: 18325
diff changeset
85 int use_tracing;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
18325
fb35b3a22604 Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 16139
diff changeset
87 Py_tracefunc c_profilefunc;
fb35b3a22604 Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 16139
diff changeset
88 Py_tracefunc c_tracefunc;
fb35b3a22604 Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 16139
diff changeset
89 PyObject *c_profileobj;
fb35b3a22604 Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 16139
diff changeset
90 PyObject *c_traceobj;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
91
13443
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
92 PyObject *curexc_type;
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
93 PyObject *curexc_value;
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
94 PyObject *curexc_traceback;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
95
13443
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
96 PyObject *exc_type;
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
97 PyObject *exc_value;
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
98 PyObject *exc_traceback;
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
99
35125
cdec978b916c Add comments about PyThreadState and the usage of its fields.
Brett Cannon <bcannon@gmail.com>
parents: 32301
diff changeset
100 PyObject *dict; /* Stores per-thread state */
8043
b8e8ace79cf0 Move 'dict' struct member to end of struct. This ensures binary
Guido van Rossum <guido@python.org>
parents: 7971
diff changeset
101
57175
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 49613
diff changeset
102 /* XXX doesn't mean anything anymore (the comment below is obsolete)
fdd6484f1210 Merge in the new GIL.
Antoine Pitrou <solipsis@pitrou.net>
parents: 49613
diff changeset
103 => deprecate or remove? */
31836
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
104 /* tick_counter is incremented whenever the check_interval ticker
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
105 * reaches zero. The purpose is to give a useful measure of the number
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
106 * of interpreted bytecode instructions in a given thread. This
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
107 * extremely lightweight statistic collector may be of interest to
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
108 * profilers (like psyco.jit()), although nothing in the core uses it.
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
109 */
26109
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 25108
diff changeset
110 int tick_counter;
31836
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
111
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
112 int gilstate_counter;
26109
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 25108
diff changeset
113
29643
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 28694
diff changeset
114 PyObject *async_exc; /* Asynchronous exception to raise */
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 28694
diff changeset
115 long thread_id; /* Thread id where this tstate was created */
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 28694
diff changeset
116
78912
5aa1bc2f00ad Issue #13992: The trashcan mechanism is now thread-safe. This eliminates
Antoine Pitrou <solipsis@pitrou.net>
parents: 77564
diff changeset
117 int trash_delete_nesting;
5aa1bc2f00ad Issue #13992: The trashcan mechanism is now thread-safe. This eliminates
Antoine Pitrou <solipsis@pitrou.net>
parents: 77564
diff changeset
118 PyObject *trash_delete_later;
5aa1bc2f00ad Issue #13992: The trashcan mechanism is now thread-safe. This eliminates
Antoine Pitrou <solipsis@pitrou.net>
parents: 77564
diff changeset
119
13443
7e58c060d534 ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
120 /* XXX signal handlers should also be here */
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 } PyThreadState;
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
123 #endif
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
124
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
125
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 18733
diff changeset
126 PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 18733
diff changeset
127 PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 18733
diff changeset
128 PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *);
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 42013
diff changeset
129 PyAPI_FUNC(int) _PyState_AddModule(PyObject*, struct PyModuleDef*);
77564
55e8cba34b11 Issue #15042: Add PyState_AddModule and PyState_RemoveModule.
Martin v. Löwis <martin@v.loewis.de>
parents: 76640
diff changeset
130 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
55e8cba34b11 Issue #15042: Add PyState_AddModule and PyState_RemoveModule.
Martin v. Löwis <martin@v.loewis.de>
parents: 76640
diff changeset
131 /* New in 3.3 */
55e8cba34b11 Issue #15042: Add PyState_AddModule and PyState_RemoveModule.
Martin v. Löwis <martin@v.loewis.de>
parents: 76640
diff changeset
132 PyAPI_FUNC(int) PyState_AddModule(PyObject*, struct PyModuleDef*);
55e8cba34b11 Issue #15042: Add PyState_AddModule and PyState_RemoveModule.
Martin v. Löwis <martin@v.loewis.de>
parents: 76640
diff changeset
133 PyAPI_FUNC(int) PyState_RemoveModule(struct PyModuleDef*);
55e8cba34b11 Issue #15042: Add PyState_AddModule and PyState_RemoveModule.
Martin v. Löwis <martin@v.loewis.de>
parents: 76640
diff changeset
134 #endif
47580
94f64f11fdd0 Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents: 42013
diff changeset
135 PyAPI_FUNC(PyObject*) PyState_FindModule(struct PyModuleDef*);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
136
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 18733
diff changeset
137 PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);
59317
d7a62c16505b Merged revisions 78639 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 49613
diff changeset
138 PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *);
d7a62c16505b Merged revisions 78639 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents: 49613
diff changeset
139 PyAPI_FUNC(void) _PyThreadState_Init(PyThreadState *);
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 18733
diff changeset
140 PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 18733
diff changeset
141 PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *);
16139
d96ce9708c00 Add a new API, PyThreadState_DeleteCurrent() that combines
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
142 #ifdef WITH_THREAD
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 18733
diff changeset
143 PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
69637
7b7ad9a88451 Issue #10517: After fork(), reinitialize the TLS used by the PyGILState_*
Antoine Pitrou <solipsis@pitrou.net>
parents: 68257
diff changeset
144 PyAPI_FUNC(void) _PyGILState_Reinit(void);
16139
d96ce9708c00 Add a new API, PyThreadState_DeleteCurrent() that combines
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
145 #endif
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
146
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 18733
diff changeset
147 PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 18733
diff changeset
148 PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 18733
diff changeset
149 PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void);
29643
fa97293533a9 Add PyThreadState_SetAsyncExc(long, PyObject *).
Guido van Rossum <guido@python.org>
parents: 28694
diff changeset
150 PyAPI_FUNC(int) PyThreadState_SetAsyncExc(long, PyObject *);
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
151
9668
40858ab23568 Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
152
40858ab23568 Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
153 /* Variable and macro for in-line access to current thread state */
40858ab23568 Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
154
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 59316
diff changeset
155 /* Assuming the current thread holds the GIL, this is the
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 59316
diff changeset
156 PyThreadState for the current thread. */
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
157 #ifndef Py_LIMITED_API
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 59316
diff changeset
158 PyAPI_DATA(_Py_atomic_address) _PyThreadState_Current;
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
159 #endif
9668
40858ab23568 Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
160
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
161 #if defined(Py_DEBUG) || defined(Py_LIMITED_API)
9668
40858ab23568 Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
162 #define PyThreadState_GET() PyThreadState_Get()
40858ab23568 Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
163 #else
61184
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 59316
diff changeset
164 #define PyThreadState_GET() \
4fd3ab5fa71d Make (most of) Python's tests pass under Thread Sanitizer.
Jeffrey Yasskin <jyasskin@gmail.com>
parents: 59316
diff changeset
165 ((PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current))
9668
40858ab23568 Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
166 #endif
40858ab23568 Add macro version of PyThreadState_GET(). This uses
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
167
31836
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
168 typedef
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
169 enum {PyGILState_LOCKED, PyGILState_UNLOCKED}
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
170 PyGILState_STATE;
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
171
69584
75503c26a17f PyGILState_Ensure(), PyGILState_Release(), PyGILState_GetThisThreadState() are
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
172 #ifdef WITH_THREAD
75503c26a17f PyGILState_Ensure(), PyGILState_Release(), PyGILState_GetThisThreadState() are
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
173
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
174 /* Ensure that the current thread is ready to call the Python
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
175 C API, regardless of the current state of Python, or of its
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
176 thread lock. This may be called as many times as desired
31836
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
177 by a thread so long as each call is matched with a call to
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
178 PyGILState_Release(). In general, other thread-state APIs may
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
179 be used between _Ensure() and _Release() calls, so long as the
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
180 thread-state is restored to its previous state before the Release().
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
181 For example, normal use of the Py_BEGIN_ALLOW_THREADS/
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
182 Py_END_ALLOW_THREADS macros are acceptable.
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
183
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
184 The return value is an opaque "handle" to the thread state when
31654
7fffdb94a172 SF patch #906501: Fix typos in pystate.h comments
Raymond Hettinger <python@rcn.com>
parents: 29643
diff changeset
185 PyGILState_Ensure() was called, and must be passed to
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
186 PyGILState_Release() to ensure Python is left in the same state. Even
31836
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
187 though recursive calls are allowed, these handles can *not* be shared -
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
188 each unique call to PyGILState_Ensure must save the handle for its
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
189 call to PyGILState_Release.
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
190
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
191 When the function returns, the current thread will hold the GIL.
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
192
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
193 Failure is a fatal error.
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
194 */
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
195 PyAPI_FUNC(PyGILState_STATE) PyGILState_Ensure(void);
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
196
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
197 /* Release any resources previously acquired. After this call, Python's
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
198 state will be the same as it was prior to the corresponding
31836
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
199 PyGILState_Ensure() call (but generally this state will be unknown to
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
200 the caller, hence the use of the GILState API.)
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
201
31836
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
202 Every call to PyGILState_Ensure must be matched by a call to
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
203 PyGILState_Release on the same thread.
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
204 */
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
205 PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE);
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
206
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
207 /* Helper/diagnostic function - get the current thread state for
31836
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
208 this thread. May return NULL if no GILState API has been used
71769
53b8260b9ea7 #10741: add documentation for PyGILState_GetThisThreadState()
Sandro Tosi <sandro.tosi@gmail.com>
parents: 69708
diff changeset
209 on the current thread. Note that the main thread always has such a
31836
e42cbaff8027 Added a comment about the unreferenced PyThreadState.tick_counter
Tim Peters <tim.peters@gmail.com>
parents: 31796
diff changeset
210 thread-state, even if no auto-thread-state call has been made
28694
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
211 on the main thread.
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
212 */
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
213 PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void);
a4154dd5939a New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents: 28325
diff changeset
214
69584
75503c26a17f PyGILState_Ensure(), PyGILState_Release(), PyGILState_GetThisThreadState() are
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
215 #endif /* #ifdef WITH_THREAD */
75503c26a17f PyGILState_Ensure(), PyGILState_Release(), PyGILState_GetThisThreadState() are
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
216
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 35125
diff changeset
217 /* The implementation of sys._current_frames() Returns a dict mapping
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 35125
diff changeset
218 thread id to that thread's current frame.
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 35125
diff changeset
219 */
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
220 #ifndef Py_LIMITED_API
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 35125
diff changeset
221 PyAPI_FUNC(PyObject *) _PyThread_CurrentFrames(void);
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
222 #endif
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 35125
diff changeset
223
18733
b0329649b8cf Add a low-level API to access interpreters, for David Beazley.
Guido van Rossum <guido@python.org>
parents: 18689
diff changeset
224 /* Routines for advanced debuggers, requested by David Beazley.
b0329649b8cf Add a low-level API to access interpreters, for David Beazley.
Guido van Rossum <guido@python.org>
parents: 18689
diff changeset
225 Don't use unless you know what you are doing! */
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
226 #ifndef Py_LIMITED_API
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 18733
diff changeset
227 PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 18733
diff changeset
228 PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 18733
diff changeset
229 PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 18733
diff changeset
230 PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *);
18733
b0329649b8cf Add a low-level API to access interpreters, for David Beazley.
Guido van Rossum <guido@python.org>
parents: 18689
diff changeset
231
27978
4b99a701defe - PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents: 26109
diff changeset
232 typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_);
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
233 #endif
27978
4b99a701defe - PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents: 26109
diff changeset
234
26109
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 25108
diff changeset
235 /* hook for PyEval_GetFrame(), requested for Psyco */
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
236 #ifndef Py_LIMITED_API
27978
4b99a701defe - PyEval_GetFrame() is now declared to return a PyFrameObject *
Guido van Rossum <guido@python.org>
parents: 26109
diff changeset
237 PyAPI_DATA(PyThreadFrameGetter) _PyThreadState_GetFrame;
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 61184
diff changeset
238 #endif
26109
e61b946474df Assorted patches from Armin Rigo:
Michael W. Hudson <mwh@python.net>
parents: 25108
diff changeset
239
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 #ifdef __cplusplus
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 #endif
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 #endif /* !Py_PYSTATE_H */