MCPcopy Index your code
hub / github.com/python/cpython / escaping_call_in_simple_stmt

Function escaping_call_in_simple_stmt

Tools/cases_generator/analyzer.py:754–795  ·  view source on GitHub ↗
(stmt: SimpleStmt, result: dict[SimpleStmt, EscapingCall])

Source from the content-addressed store, hash-verified

752 raise analysis_error(f"Escaping call '{error.text} in condition", error)
753
754def escaping_call_in_simple_stmt(stmt: SimpleStmt, result: dict[SimpleStmt, EscapingCall]) -> None:
755 tokens = stmt.contents
756 for idx, tkn in enumerate(tokens):
757 try:
758 next_tkn = tokens[idx+1]
759 except IndexError:
760 break
761 if next_tkn.kind != lexer.LPAREN:
762 continue
763 if tkn.kind == lexer.IDENTIFIER:
764 if tkn.text.upper() == tkn.text:
765 # simple macro
766 continue
767 #if not tkn.text.startswith(("Py", "_Py", "monitor")):
768 # continue
769 if tkn.text.startswith(("sym_", "optimize_", "PyJitRef")):
770 # Optimize functions
771 continue
772 if tkn.text.endswith("Check"):
773 continue
774 if tkn.text.startswith("Py_Is"):
775 continue
776 if tkn.text.endswith("CheckExact"):
777 continue
778 if tkn.text in NON_ESCAPING_FUNCTIONS:
779 continue
780 elif tkn.kind == "RPAREN":
781 prev = tokens[idx-1]
782 if prev.text.endswith("_t") or prev.text == "*" or prev.text == "int":
783 #cast
784 continue
785 elif tkn.kind != "RBRACKET":
786 continue
787 if tkn.text in ("PyStackRef_CLOSE", "PyStackRef_XCLOSE"):
788 if len(tokens) <= idx+2:
789 raise analysis_error("Unexpected end of file", next_tkn)
790 kills = tokens[idx+2]
791 if kills.kind != "IDENTIFIER":
792 raise analysis_error(f"Expected identifier, got '{kills.text}'", kills)
793 else:
794 kills = None
795 result[stmt] = EscapingCall(stmt, tkn, kills)
796
797
798def find_escaping_api_calls(instr: parser.CodeDef) -> dict[SimpleStmt, EscapingCall]:

Callers 2

visitFunction · 0.85
stmt_escapesFunction · 0.85

Calls 6

enumerateFunction · 0.85
analysis_errorFunction · 0.85
EscapingCallClass · 0.85
upperMethod · 0.45
startswithMethod · 0.45
endswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…