@@ -113,13 +113,17 @@ static const uint8_t INSTRUMENTED_OPCODES[256] = {
113113};
114114
115115static 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+ );
119122}
120123
121124static inline bool
122- is_instrumented (int opcode ) {
125+ is_instrumented (int opcode )
126+ {
123127 assert (opcode != 0 );
124128 assert (opcode != RESERVED );
125129 return opcode >= MIN_INSTRUMENTED_OPCODE ;
@@ -339,7 +343,8 @@ dump_monitors(const char *prefix, _Py_Monitors monitors, FILE*out)
339343/* Like _Py_GetBaseOpcode but without asserts.
340344 * Does its best to give the right answer, but won't abort
341345 * 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 )
343348{
344349 int opcode = _Py_OPCODE (_PyCode_CODE (code )[offset ]);
345350 if (INSTRUMENTED_OPCODES [opcode ] != opcode ) {
@@ -418,13 +423,15 @@ dump_instrumentation_data(PyCodeObject *code, int star, FILE*out)
418423 assert(test); \
419424} while (0)
420425
421- bool valid_opcode (int opcode ) {
426+ static bool
427+ valid_opcode (int opcode )
428+ {
422429 if (opcode > 0 &&
423430 opcode != RESERVED &&
424431 opcode < 255 &&
425432 _PyOpcode_OpName [opcode ] &&
426- _PyOpcode_OpName [opcode ][0 ] != '<'
427- ) {
433+ _PyOpcode_OpName [opcode ][0 ] != '<' )
434+ {
428435 return true;
429436 }
430437 return false;
@@ -550,11 +557,11 @@ de_instrument(PyCodeObject *code, int i, int event)
550557 opcode_ptr = & code -> _co_monitoring -> lines [i ].original_opcode ;
551558 opcode = * opcode_ptr ;
552559 }
553- if (opcode == INSTRUMENTED_INSTRUCTION ) {
560+ if (opcode == INSTRUMENTED_INSTRUCTION ) {
554561 opcode_ptr = & code -> _co_monitoring -> per_instruction_opcodes [i ];
555562 opcode = * opcode_ptr ;
556563 }
557- int deinstrumented = DE_INSTRUMENT [opcode ];
564+ int deinstrumented = DE_INSTRUMENT [opcode ];
558565 if (deinstrumented == 0 ) {
559566 return ;
560567 }
@@ -781,8 +788,7 @@ add_line_tools(PyCodeObject * code, int offset, int tools)
781788{
782789 assert (tools_is_subset_for_event (code , PY_MONITORING_EVENT_LINE , tools ));
783790 assert (code -> _co_monitoring );
784- if (code -> _co_monitoring -> line_tools
785- ) {
791+ if (code -> _co_monitoring -> line_tools ) {
786792 code -> _co_monitoring -> line_tools [offset ] |= tools ;
787793 }
788794 else {
@@ -798,8 +804,7 @@ add_per_instruction_tools(PyCodeObject * code, int offset, int tools)
798804{
799805 assert (tools_is_subset_for_event (code , PY_MONITORING_EVENT_INSTRUCTION , tools ));
800806 assert (code -> _co_monitoring );
801- if (code -> _co_monitoring -> per_instruction_tools
802- ) {
807+ if (code -> _co_monitoring -> per_instruction_tools ) {
803808 code -> _co_monitoring -> per_instruction_tools [offset ] |= tools ;
804809 }
805810 else {
@@ -814,11 +819,10 @@ static void
814819remove_per_instruction_tools (PyCodeObject * code , int offset , int tools )
815820{
816821 assert (code -> _co_monitoring );
817- if (code -> _co_monitoring -> per_instruction_tools )
818- {
822+ if (code -> _co_monitoring -> per_instruction_tools ) {
819823 uint8_t * toolsptr = & code -> _co_monitoring -> per_instruction_tools [offset ];
820824 * toolsptr &= ~tools ;
821- if (* toolsptr == 0 ) {
825+ if (* toolsptr == 0 ) {
822826 de_instrument_per_instruction (code , offset );
823827 }
824828 }
@@ -843,7 +847,7 @@ call_one_instrument(
843847 assert (tstate -> tracing == 0 );
844848 PyObject * instrument = interp -> monitoring_callables [tool ][event ];
845849 if (instrument == NULL ) {
846- return 0 ;
850+ return 0 ;
847851 }
848852 int old_what = tstate -> what_event ;
849853 tstate -> what_event = event ;
@@ -865,16 +869,15 @@ static const int8_t MOST_SIGNIFICANT_BITS[16] = {
865869 3 , 3 , 3 , 3 ,
866870};
867871
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. */
870875static inline int most_significant_bit (uint8_t bits ) {
871876 assert (bits != 0 );
872877 if (bits > 15 ) {
873878 return MOST_SIGNIFICANT_BITS [bits >>4 ]+ 4 ;
874879 }
875- else {
876- return MOST_SIGNIFICANT_BITS [bits ];
877- }
880+ return MOST_SIGNIFICANT_BITS [bits ];
878881}
879882
880883static bool
@@ -1002,8 +1005,8 @@ _Py_call_instrumentation_2args(
10021005int
10031006_Py_call_instrumentation_jump (
10041007 PyThreadState * tstate , int event ,
1005- _PyInterpreterFrame * frame , _Py_CODEUNIT * instr , _Py_CODEUNIT * target
1006- ) {
1008+ _PyInterpreterFrame * frame , _Py_CODEUNIT * instr , _Py_CODEUNIT * target )
1009+ {
10071010 assert (event == PY_MONITORING_EVENT_JUMP ||
10081011 event == PY_MONITORING_EVENT_BRANCH );
10091012 assert (frame -> prev_instr == instr );
@@ -1309,8 +1312,8 @@ initialize_line_tools(PyCodeObject *code, _Py_Monitors *all_events)
13091312 }
13101313}
13111314
1312- static
1313- int allocate_instrumentation_data (PyCodeObject * code )
1315+ static int
1316+ allocate_instrumentation_data (PyCodeObject * code )
13141317{
13151318
13161319 if (code -> _co_monitoring == NULL ) {
@@ -1404,7 +1407,7 @@ static const uint8_t super_instructions[256] = {
14041407
14051408/* Should use instruction metadata for this */
14061409static bool
1407- is_super_instruction (int opcode ) {
1410+ is_super_instruction (uint8_t opcode ) {
14081411 return super_instructions [opcode ] != 0 ;
14091412}
14101413
@@ -1516,7 +1519,7 @@ _Py_Instrument(PyCodeObject *code, PyInterpreterState *interp)
15161519
15171520#define C_RETURN_EVENTS \
15181521 ((1 << PY_MONITORING_EVENT_C_RETURN) | \
1519- (1 << PY_MONITORING_EVENT_C_RAISE))
1522+ (1 << PY_MONITORING_EVENT_C_RAISE))
15201523
15211524#define C_CALL_EVENTS \
15221525 (C_RETURN_EVENTS | (1 << PY_MONITORING_EVENT_CALL))
@@ -1561,8 +1564,8 @@ static int
15611564check_tool (PyInterpreterState * interp , int tool_id )
15621565{
15631566 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+ {
15661569 PyErr_Format (PyExc_ValueError , "tool %d is not in use" , tool_id );
15671570 return -1 ;
15681571 }
0 commit comments