@@ -113,13 +113,17 @@ static const uint8_t INSTRUMENTED_OPCODES[256] = {
113
113
};
114
114
115
115
static inline bool
116
- opcode_has_event (int opcode ) {
117
- return opcode < INSTRUMENTED_LINE &&
118
- INSTRUMENTED_OPCODES [opcode ] > 0 ;
116
+ opcode_has_event (int opcode )
117
+ {
118
+ return (
119
+ opcode < INSTRUMENTED_LINE &&
120
+ INSTRUMENTED_OPCODES [opcode ] > 0
121
+ );
119
122
}
120
123
121
124
static inline bool
122
- is_instrumented (int opcode ) {
125
+ is_instrumented (int opcode )
126
+ {
123
127
assert (opcode != 0 );
124
128
assert (opcode != RESERVED );
125
129
return opcode >= MIN_INSTRUMENTED_OPCODE ;
@@ -339,7 +343,8 @@ dump_monitors(const char *prefix, _Py_Monitors monitors, FILE*out)
339
343
/* Like _Py_GetBaseOpcode but without asserts.
340
344
* Does its best to give the right answer, but won't abort
341
345
* if something is wrong */
342
- int get_base_opcode_best_attempt (PyCodeObject * code , int offset )
346
+ static int
347
+ get_base_opcode_best_attempt (PyCodeObject * code , int offset )
343
348
{
344
349
int opcode = _Py_OPCODE (_PyCode_CODE (code )[offset ]);
345
350
if (INSTRUMENTED_OPCODES [opcode ] != opcode ) {
@@ -418,13 +423,15 @@ dump_instrumentation_data(PyCodeObject *code, int star, FILE*out)
418
423
assert(test); \
419
424
} while (0)
420
425
421
- bool valid_opcode (int opcode ) {
426
+ static bool
427
+ valid_opcode (int opcode )
428
+ {
422
429
if (opcode > 0 &&
423
430
opcode != RESERVED &&
424
431
opcode < 255 &&
425
432
_PyOpcode_OpName [opcode ] &&
426
- _PyOpcode_OpName [opcode ][0 ] != '<'
427
- ) {
433
+ _PyOpcode_OpName [opcode ][0 ] != '<' )
434
+ {
428
435
return true;
429
436
}
430
437
return false;
@@ -550,11 +557,11 @@ de_instrument(PyCodeObject *code, int i, int event)
550
557
opcode_ptr = & code -> _co_monitoring -> lines [i ].original_opcode ;
551
558
opcode = * opcode_ptr ;
552
559
}
553
- if (opcode == INSTRUMENTED_INSTRUCTION ) {
560
+ if (opcode == INSTRUMENTED_INSTRUCTION ) {
554
561
opcode_ptr = & code -> _co_monitoring -> per_instruction_opcodes [i ];
555
562
opcode = * opcode_ptr ;
556
563
}
557
- int deinstrumented = DE_INSTRUMENT [opcode ];
564
+ int deinstrumented = DE_INSTRUMENT [opcode ];
558
565
if (deinstrumented == 0 ) {
559
566
return ;
560
567
}
@@ -781,8 +788,7 @@ add_line_tools(PyCodeObject * code, int offset, int tools)
781
788
{
782
789
assert (tools_is_subset_for_event (code , PY_MONITORING_EVENT_LINE , tools ));
783
790
assert (code -> _co_monitoring );
784
- if (code -> _co_monitoring -> line_tools
785
- ) {
791
+ if (code -> _co_monitoring -> line_tools ) {
786
792
code -> _co_monitoring -> line_tools [offset ] |= tools ;
787
793
}
788
794
else {
@@ -798,8 +804,7 @@ add_per_instruction_tools(PyCodeObject * code, int offset, int tools)
798
804
{
799
805
assert (tools_is_subset_for_event (code , PY_MONITORING_EVENT_INSTRUCTION , tools ));
800
806
assert (code -> _co_monitoring );
801
- if (code -> _co_monitoring -> per_instruction_tools
802
- ) {
807
+ if (code -> _co_monitoring -> per_instruction_tools ) {
803
808
code -> _co_monitoring -> per_instruction_tools [offset ] |= tools ;
804
809
}
805
810
else {
@@ -814,11 +819,10 @@ static void
814
819
remove_per_instruction_tools (PyCodeObject * code , int offset , int tools )
815
820
{
816
821
assert (code -> _co_monitoring );
817
- if (code -> _co_monitoring -> per_instruction_tools )
818
- {
822
+ if (code -> _co_monitoring -> per_instruction_tools ) {
819
823
uint8_t * toolsptr = & code -> _co_monitoring -> per_instruction_tools [offset ];
820
824
* toolsptr &= ~tools ;
821
- if (* toolsptr == 0 ) {
825
+ if (* toolsptr == 0 ) {
822
826
de_instrument_per_instruction (code , offset );
823
827
}
824
828
}
@@ -843,7 +847,7 @@ call_one_instrument(
843
847
assert (tstate -> tracing == 0 );
844
848
PyObject * instrument = interp -> monitoring_callables [tool ][event ];
845
849
if (instrument == NULL ) {
846
- return 0 ;
850
+ return 0 ;
847
851
}
848
852
int old_what = tstate -> what_event ;
849
853
tstate -> what_event = event ;
@@ -865,16 +869,15 @@ static const int8_t MOST_SIGNIFICANT_BITS[16] = {
865
869
3 , 3 , 3 , 3 ,
866
870
};
867
871
868
- /* We could use _Py_bit_length here, but that is designed for larger (32/64) bit ints,
869
- and can perform relatively poorly on platforms without the necessary intrinsics. */
872
+ /* We could use _Py_bit_length here, but that is designed for larger (32/64)
873
+ * bit ints, and can perform relatively poorly on platforms without the
874
+ * necessary intrinsics. */
870
875
static inline int most_significant_bit (uint8_t bits ) {
871
876
assert (bits != 0 );
872
877
if (bits > 15 ) {
873
878
return MOST_SIGNIFICANT_BITS [bits >>4 ]+ 4 ;
874
879
}
875
- else {
876
- return MOST_SIGNIFICANT_BITS [bits ];
877
- }
880
+ return MOST_SIGNIFICANT_BITS [bits ];
878
881
}
879
882
880
883
static bool
@@ -1002,8 +1005,8 @@ _Py_call_instrumentation_2args(
1002
1005
int
1003
1006
_Py_call_instrumentation_jump (
1004
1007
PyThreadState * tstate , int event ,
1005
- _PyInterpreterFrame * frame , _Py_CODEUNIT * instr , _Py_CODEUNIT * target
1006
- ) {
1008
+ _PyInterpreterFrame * frame , _Py_CODEUNIT * instr , _Py_CODEUNIT * target )
1009
+ {
1007
1010
assert (event == PY_MONITORING_EVENT_JUMP ||
1008
1011
event == PY_MONITORING_EVENT_BRANCH );
1009
1012
assert (frame -> prev_instr == instr );
@@ -1309,8 +1312,8 @@ initialize_line_tools(PyCodeObject *code, _Py_Monitors *all_events)
1309
1312
}
1310
1313
}
1311
1314
1312
- static
1313
- int allocate_instrumentation_data (PyCodeObject * code )
1315
+ static int
1316
+ allocate_instrumentation_data (PyCodeObject * code )
1314
1317
{
1315
1318
1316
1319
if (code -> _co_monitoring == NULL ) {
@@ -1404,7 +1407,7 @@ static const uint8_t super_instructions[256] = {
1404
1407
1405
1408
/* Should use instruction metadata for this */
1406
1409
static bool
1407
- is_super_instruction (int opcode ) {
1410
+ is_super_instruction (uint8_t opcode ) {
1408
1411
return super_instructions [opcode ] != 0 ;
1409
1412
}
1410
1413
@@ -1516,7 +1519,7 @@ _Py_Instrument(PyCodeObject *code, PyInterpreterState *interp)
1516
1519
1517
1520
#define C_RETURN_EVENTS \
1518
1521
((1 << PY_MONITORING_EVENT_C_RETURN) | \
1519
- (1 << PY_MONITORING_EVENT_C_RAISE))
1522
+ (1 << PY_MONITORING_EVENT_C_RAISE))
1520
1523
1521
1524
#define C_CALL_EVENTS \
1522
1525
(C_RETURN_EVENTS | (1 << PY_MONITORING_EVENT_CALL))
@@ -1561,8 +1564,8 @@ static int
1561
1564
check_tool (PyInterpreterState * interp , int tool_id )
1562
1565
{
1563
1566
if (tool_id < PY_MONITORING_SYS_PROFILE_ID &&
1564
- interp -> monitoring_tool_names [tool_id ] == NULL
1565
- ) {
1567
+ interp -> monitoring_tool_names [tool_id ] == NULL )
1568
+ {
1566
1569
PyErr_Format (PyExc_ValueError , "tool %d is not in use" , tool_id );
1567
1570
return -1 ;
1568
1571
}
0 commit comments