Skip to content

Commit a4058ab

Browse files
committed
pythonGH-103082: Rename PY_MONITORING_EVENTS to _PY_MONITORING_EVENTS (python#107069)
Rename private C API constants: * Rename PY_MONITORING_UNGROUPED_EVENTS to _PY_MONITORING_UNGROUPED_EVENTS * Rename PY_MONITORING_EVENTS to _PY_MONITORING_EVENTS (cherry picked from commit 0927a2b)
1 parent bd907dc commit a4058ab

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

Include/cpython/code.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ extern "C" {
1010

1111

1212
/* Count of all "real" monitoring events (not derived from other events) */
13-
#define PY_MONITORING_UNGROUPED_EVENTS 14
13+
#define _PY_MONITORING_UNGROUPED_EVENTS 14
1414
/* Count of all monitoring events */
15-
#define PY_MONITORING_EVENTS 16
15+
#define _PY_MONITORING_EVENTS 16
1616

1717
/* Table of which tools are active for each monitored event. */
1818
typedef struct _Py_Monitors {
19-
uint8_t tools[PY_MONITORING_UNGROUPED_EVENTS];
19+
uint8_t tools[_PY_MONITORING_UNGROUPED_EVENTS];
2020
} _Py_Monitors;
2121

2222
/* Each instruction in a code object is a fixed-width value,

Include/internal/pycore_interp.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern "C" {
2525
#include "pycore_gc.h" // struct _gc_runtime_state
2626
#include "pycore_global_objects.h" // struct _Py_interp_static_objects
2727
#include "pycore_import.h" // struct _import_state
28-
#include "pycore_instruments.h" // PY_MONITORING_EVENTS
28+
#include "pycore_instruments.h" // _PY_MONITORING_EVENTS
2929
#include "pycore_list.h" // struct _Py_list_state
3030
#include "pycore_object_state.h" // struct _py_object_state
3131
#include "pycore_obmalloc.h" // struct obmalloc_state
@@ -188,7 +188,7 @@ struct _is {
188188
bool sys_trace_initialized;
189189
Py_ssize_t sys_profiling_threads; /* Count of threads with c_profilefunc set */
190190
Py_ssize_t sys_tracing_threads; /* Count of threads with c_tracefunc set */
191-
PyObject *monitoring_callables[PY_MONITORING_TOOL_IDS][PY_MONITORING_EVENTS];
191+
PyObject *monitoring_callables[PY_MONITORING_TOOL_IDS][_PY_MONITORING_EVENTS];
192192
PyObject *monitoring_tool_names[PY_MONITORING_TOOL_IDS];
193193

194194
struct _Py_interp_cached_objects cached_objects;

Python/ceval.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,7 @@ static int
19971997
do_monitor_exc(PyThreadState *tstate, _PyInterpreterFrame *frame,
19981998
_Py_CODEUNIT *instr, int event)
19991999
{
2000-
assert(event < PY_MONITORING_UNGROUPED_EVENTS);
2000+
assert(event < _PY_MONITORING_UNGROUPED_EVENTS);
20012001
PyObject *exc = PyErr_GetRaisedException();
20022002
assert(exc != NULL);
20032003
int err = _Py_call_instrumentation_arg(tstate, event, frame, instr, exc);

Python/instrumentation.c

+19-19
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ is_instrumented(int opcode)
138138
static inline bool
139139
monitors_equals(_Py_Monitors a, _Py_Monitors b)
140140
{
141-
for (int i = 0; i < PY_MONITORING_UNGROUPED_EVENTS; i++) {
141+
for (int i = 0; i < _PY_MONITORING_UNGROUPED_EVENTS; i++) {
142142
if (a.tools[i] != b.tools[i]) {
143143
return false;
144144
}
@@ -151,7 +151,7 @@ static inline _Py_Monitors
151151
monitors_sub(_Py_Monitors a, _Py_Monitors b)
152152
{
153153
_Py_Monitors res;
154-
for (int i = 0; i < PY_MONITORING_UNGROUPED_EVENTS; i++) {
154+
for (int i = 0; i < _PY_MONITORING_UNGROUPED_EVENTS; i++) {
155155
res.tools[i] = a.tools[i] & ~b.tools[i];
156156
}
157157
return res;
@@ -162,7 +162,7 @@ static inline _Py_Monitors
162162
monitors_and(_Py_Monitors a, _Py_Monitors b)
163163
{
164164
_Py_Monitors res;
165-
for (int i = 0; i < PY_MONITORING_UNGROUPED_EVENTS; i++) {
165+
for (int i = 0; i < _PY_MONITORING_UNGROUPED_EVENTS; i++) {
166166
res.tools[i] = a.tools[i] & b.tools[i];
167167
}
168168
return res;
@@ -173,7 +173,7 @@ static inline _Py_Monitors
173173
monitors_or(_Py_Monitors a, _Py_Monitors b)
174174
{
175175
_Py_Monitors res;
176-
for (int i = 0; i < PY_MONITORING_UNGROUPED_EVENTS; i++) {
176+
for (int i = 0; i < _PY_MONITORING_UNGROUPED_EVENTS; i++) {
177177
res.tools[i] = a.tools[i] | b.tools[i];
178178
}
179179
return res;
@@ -182,7 +182,7 @@ monitors_or(_Py_Monitors a, _Py_Monitors b)
182182
static inline bool
183183
monitors_are_empty(_Py_Monitors m)
184184
{
185-
for (int i = 0; i < PY_MONITORING_UNGROUPED_EVENTS; i++) {
185+
for (int i = 0; i < _PY_MONITORING_UNGROUPED_EVENTS; i++) {
186186
if (m.tools[i]) {
187187
return false;
188188
}
@@ -193,7 +193,7 @@ monitors_are_empty(_Py_Monitors m)
193193
static inline bool
194194
multiple_tools(_Py_Monitors *m)
195195
{
196-
for (int i = 0; i < PY_MONITORING_UNGROUPED_EVENTS; i++) {
196+
for (int i = 0; i < _PY_MONITORING_UNGROUPED_EVENTS; i++) {
197197
if (_Py_popcount32(m->tools[i]) > 1) {
198198
return true;
199199
}
@@ -205,7 +205,7 @@ static inline _PyMonitoringEventSet
205205
get_events(_Py_Monitors *m, int tool_id)
206206
{
207207
_PyMonitoringEventSet result = 0;
208-
for (int e = 0; e < PY_MONITORING_UNGROUPED_EVENTS; e++) {
208+
for (int e = 0; e < _PY_MONITORING_UNGROUPED_EVENTS; e++) {
209209
if ((m->tools[e] >> tool_id) & 1) {
210210
result |= (1 << e);
211211
}
@@ -340,7 +340,7 @@ static void
340340
dump_monitors(const char *prefix, _Py_Monitors monitors, FILE*out)
341341
{
342342
fprintf(out, "%s monitors:\n", prefix);
343-
for (int event = 0; event < PY_MONITORING_UNGROUPED_EVENTS; event++) {
343+
for (int event = 0; event < _PY_MONITORING_UNGROUPED_EVENTS; event++) {
344344
fprintf(out, " Event %d: Tools %x\n", event, monitors.tools[event]);
345345
}
346346
}
@@ -910,7 +910,7 @@ get_tools_for_instruction(PyCodeObject * code, int i, int event)
910910
assert(event != PY_MONITORING_EVENT_INSTRUCTION);
911911
assert(instrumentation_cross_checks(PyThreadState_GET()->interp, code));
912912
_PyCoMonitoringData *monitoring = code->_co_monitoring;
913-
if (event >= PY_MONITORING_UNGROUPED_EVENTS) {
913+
if (event >= _PY_MONITORING_UNGROUPED_EVENTS) {
914914
assert(event == PY_MONITORING_EVENT_C_RAISE ||
915915
event == PY_MONITORING_EVENT_C_RETURN);
916916
event = PY_MONITORING_EVENT_CALL;
@@ -1216,7 +1216,7 @@ _PyMonitoring_RegisterCallback(int tool_id, int event_id, PyObject *obj)
12161216
{
12171217
PyInterpreterState *is = _PyInterpreterState_Get();
12181218
assert(0 <= tool_id && tool_id < PY_MONITORING_TOOL_IDS);
1219-
assert(0 <= event_id && event_id < PY_MONITORING_EVENTS);
1219+
assert(0 <= event_id && event_id < _PY_MONITORING_EVENTS);
12201220
PyObject *callback = is->monitoring_callables[tool_id][event_id];
12211221
is->monitoring_callables[tool_id][event_id] = Py_XNewRef(obj);
12221222
return callback;
@@ -1667,7 +1667,7 @@ static void
16671667
set_events(_Py_Monitors *m, int tool_id, _PyMonitoringEventSet events)
16681668
{
16691669
assert(0 <= tool_id && tool_id < PY_MONITORING_TOOL_IDS);
1670-
for (int e = 0; e < PY_MONITORING_UNGROUPED_EVENTS; e++) {
1670+
for (int e = 0; e < _PY_MONITORING_UNGROUPED_EVENTS; e++) {
16711671
uint8_t *tools = &m->tools[e];
16721672
int val = (events >> e) & 1;
16731673
*tools &= ~(1 << tool_id);
@@ -1692,7 +1692,7 @@ _PyMonitoring_SetEvents(int tool_id, _PyMonitoringEventSet events)
16921692
{
16931693
assert(0 <= tool_id && tool_id < PY_MONITORING_TOOL_IDS);
16941694
PyInterpreterState *interp = _PyInterpreterState_Get();
1695-
assert(events < (1 << PY_MONITORING_UNGROUPED_EVENTS));
1695+
assert(events < (1 << _PY_MONITORING_UNGROUPED_EVENTS));
16961696
if (check_tool(interp, tool_id)) {
16971697
return -1;
16981698
}
@@ -1710,7 +1710,7 @@ _PyMonitoring_SetLocalEvents(PyCodeObject *code, int tool_id, _PyMonitoringEvent
17101710
{
17111711
assert(0 <= tool_id && tool_id < PY_MONITORING_TOOL_IDS);
17121712
PyInterpreterState *interp = _PyInterpreterState_Get();
1713-
assert(events < (1 << PY_MONITORING_UNGROUPED_EVENTS));
1713+
assert(events < (1 << _PY_MONITORING_UNGROUPED_EVENTS));
17141714
if (check_tool(interp, tool_id)) {
17151715
return -1;
17161716
}
@@ -1849,7 +1849,7 @@ monitoring_register_callback_impl(PyObject *module, int tool_id, int event,
18491849
return NULL;
18501850
}
18511851
int event_id = _Py_bit_length(event)-1;
1852-
if (event_id < 0 || event_id >= PY_MONITORING_EVENTS) {
1852+
if (event_id < 0 || event_id >= _PY_MONITORING_EVENTS) {
18531853
PyErr_Format(PyExc_ValueError, "invalid event %d", event);
18541854
return NULL;
18551855
}
@@ -1899,7 +1899,7 @@ monitoring_set_events_impl(PyObject *module, int tool_id, int event_set)
18991899
if (check_valid_tool(tool_id)) {
19001900
return NULL;
19011901
}
1902-
if (event_set < 0 || event_set >= (1 << PY_MONITORING_EVENTS)) {
1902+
if (event_set < 0 || event_set >= (1 << _PY_MONITORING_EVENTS)) {
19031903
PyErr_Format(PyExc_ValueError, "invalid event set 0x%x", event_set);
19041904
return NULL;
19051905
}
@@ -1941,7 +1941,7 @@ monitoring_get_local_events_impl(PyObject *module, int tool_id,
19411941
_PyMonitoringEventSet event_set = 0;
19421942
_PyCoMonitoringData *data = ((PyCodeObject *)code)->_co_monitoring;
19431943
if (data != NULL) {
1944-
for (int e = 0; e < PY_MONITORING_UNGROUPED_EVENTS; e++) {
1944+
for (int e = 0; e < _PY_MONITORING_UNGROUPED_EVENTS; e++) {
19451945
if ((data->local_monitors.tools[e] >> tool_id) & 1) {
19461946
event_set |= (1 << e);
19471947
}
@@ -1975,7 +1975,7 @@ monitoring_set_local_events_impl(PyObject *module, int tool_id,
19751975
if (check_valid_tool(tool_id)) {
19761976
return NULL;
19771977
}
1978-
if (event_set < 0 || event_set >= (1 << PY_MONITORING_EVENTS)) {
1978+
if (event_set < 0 || event_set >= (1 << _PY_MONITORING_EVENTS)) {
19791979
PyErr_Format(PyExc_ValueError, "invalid event set 0x%x", event_set);
19801980
return NULL;
19811981
}
@@ -2056,7 +2056,7 @@ monitoring__all_events_impl(PyObject *module)
20562056
if (res == NULL) {
20572057
return NULL;
20582058
}
2059-
for (int e = 0; e < PY_MONITORING_UNGROUPED_EVENTS; e++) {
2059+
for (int e = 0; e < _PY_MONITORING_UNGROUPED_EVENTS; e++) {
20602060
uint8_t tools = interp->monitors.tools[e];
20612061
if (tools == 0) {
20622062
continue;
@@ -2115,7 +2115,7 @@ PyObject *_Py_CreateMonitoringObject(void)
21152115
if (err) {
21162116
goto error;
21172117
}
2118-
for (int i = 0; i < PY_MONITORING_EVENTS; i++) {
2118+
for (int i = 0; i < _PY_MONITORING_EVENTS; i++) {
21192119
if (add_power2_constant(events, event_names[i], i)) {
21202120
goto error;
21212121
}

Python/pystate.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -678,11 +678,11 @@ init_interpreter(PyInterpreterState *interp,
678678
_PyGC_InitState(&interp->gc);
679679
PyConfig_InitPythonConfig(&interp->config);
680680
_PyType_InitCache(interp);
681-
for (int i = 0; i < PY_MONITORING_UNGROUPED_EVENTS; i++) {
681+
for (int i = 0; i < _PY_MONITORING_UNGROUPED_EVENTS; i++) {
682682
interp->monitors.tools[i] = 0;
683683
}
684684
for (int t = 0; t < PY_MONITORING_TOOL_IDS; t++) {
685-
for (int e = 0; e < PY_MONITORING_EVENTS; e++) {
685+
for (int e = 0; e < _PY_MONITORING_EVENTS; e++) {
686686
interp->monitoring_callables[t][e] = NULL;
687687

688688
}
@@ -832,11 +832,11 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
832832

833833
Py_CLEAR(interp->audit_hooks);
834834

835-
for (int i = 0; i < PY_MONITORING_UNGROUPED_EVENTS; i++) {
835+
for (int i = 0; i < _PY_MONITORING_UNGROUPED_EVENTS; i++) {
836836
interp->monitors.tools[i] = 0;
837837
}
838838
for (int t = 0; t < PY_MONITORING_TOOL_IDS; t++) {
839-
for (int e = 0; e < PY_MONITORING_EVENTS; e++) {
839+
for (int e = 0; e < _PY_MONITORING_EVENTS; e++) {
840840
Py_CLEAR(interp->monitoring_callables[t][e]);
841841
}
842842
}

0 commit comments

Comments
 (0)