text
stringlengths
79
3.72M
<vulnerable_code> cmp_op = ('<', '<=', '==', '!=', '>', '>=') ENABLE_SPECIALIZATION = True def is_pseudo(op): return op >= MIN_PSEUDO_OPCODE and op <= MAX_PSEUDO_OPCODE <commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I found in PR gh-106798 (issue gh-106...
<vulnerable_code>import contextlib import functools import getpass import opcode import os import re import stat def requires_specialization(test): return unittest.skipUnless( opcode.ENABLE_SPECIALIZATION, "requires specialization")(test) def _filter_suite(suite, pred): """Recursively filter test case...
<vulnerable_code> {NULL, NULL, 0, NULL} }; static PyModuleDef_Slot module_slots[] = { {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, {0, NULL} };<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I found in PR gh-106798 (issue gh...
<vulnerable_code> opname = opcode['opname'] is_pseudo = opcode['is_pseudo'] ENABLE_SPECIALIZATION = opcode["ENABLE_SPECIALIZATION"] MIN_PSEUDO_OPCODE = opcode["MIN_PSEUDO_OPCODE"] MAX_PSEUDO_OPCODE = opcode["MAX_PSEUDO_OPCODE"] MIN_INSTRUMENTED_OPCODE = opcode["MIN_INSTRUMENTED_OPCODE"] ...
<vulnerable_code>#! /usr/bin/env python """Generate C code for the jump table of the threaded code interpreter (for compilers supporting computed gotos or "labels-as-values", such as gcc). """ import os import sys # 2023-04-27(warsaw): Pre-Python 3.12, this would catch ImportErrors and try to # import imp, and then ...
<vulnerable_code>def main(opcode_py, _opcode_metadata_py='Lib/_opcode_metadata.py', outfile='Include/opcode.h', internaloutfile='Include/internal/pycore_opcode.h'): _opcode_metadata = get_python_module_dict(_opcode_metadata_py) fobj.write(footer) iobj.write(internal_foote...
<vulnerable_code> [clinic start generated code]*/ """) msg = ( "Stepped on a land mine, trying to access attribute 'noaccess':\n" "Don't access members of self.function inside converter_init!" ) self.assertIn(msg, out) <commit_title>[PATCH 016/395] Smal...
<vulnerable_code>) from types import FunctionType, NoneType from typing import ( Any, Final, Literal, return f'"argument {i}"' @dc.dataclass class LandMine: # try to access any __message__: str def __getattribute__(self, name: str) -> Any: if name in ('__repr__', '__messag...
<vulnerable_code> NamedTuple, NoReturn, Protocol, TypeGuard, TypeVar, cast, overload, return line[indent:] StateKeeper = Callable[[str | None], None] ConverterArgs = dict[str, Any] class ParamState(enum.IntEnum): fail('Tab characters are illegal in the Clinic DSL.\n...
<vulnerable_code> Path to be examined """) def test_explicit_parameters_in_docstring(self): function = self.parse_function(dedent(""" module foo<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I found in PR gh-1067...
<vulnerable_code> fail("'preserve' only works for blocks that don't produce any output!") block.output = self.saved_output @staticmethod def valid_line(line: str) -> bool: # ignore comment-only lines if line.lstrip().startswith('#'): return False ...
<vulnerable_code> parsearg = p.converter.parse_arg(argname, displayname) if parsearg is None: #print('Cannot convert %s %r for %s' % (p.converter.__class__.__name__, p.converter.format_unit, p.converter.name), file=sys.stderr) parser_code = None ...
<vulnerable_code>import dataclasses as dc import re import sys from collections.abc import Callable from typing import NoReturn <commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I found in PR gh-106798 (issue gh-106797) and in PR gh-106716 (issue gh-106706).<fix...
<vulnerable_code> actual = stdout.getvalue() self.assertEqual(actual, expected) class ClinicExternalTest(TestCase): maxDiff = None<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I found in PR gh-106798 (issue gh-106797) and in PR gh-106716 ...
<vulnerable_code> self, f: Function ) -> str: if re.search(r'[^\x00-\x7F]', f.docstring): warn("Non-ascii character appear in docstring.") text, add, output = _text_accumulator() # turn docstring into a properly quoted C string for line in f.docstr...
<vulnerable_code>"\n" "Only this docstring should be outputted to test1."); /*[clinic end generated code: output=9cac703f51d90e84 input=090db8df4945576d]*/<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I found in PR gh-106798 (issue gh-106797) and in PR gh-106...
<vulnerable_code>from textwrap import dedent from unittest import TestCase import collections import inspect import os.path import sys ) self.assertIn(msg, out) class ClinicGroupPermuterTest(TestCase): def _test(self, l, m, r, output): class ClinicParserTest(_ParserBase): def checkDocstring(...
<vulnerable_code> cmp_op = ('<', '<=', '==', '!=', '>', '>=') def is_pseudo(op): return op >= MIN_PSEUDO_OPCODE and op <= MAX_PSEUDO_OPCODE opmap = {} # pseudo opcodes (used in the compiler) mapped to the values # they can become in the actual code. _pseudo_ops = {} def def_op(name, op): opmap[name] = op d...
<vulnerable_code> opcode = get_python_module_dict(opcode_py) opmap = opcode['opmap'] opname = opcode['opname'] is_pseudo = opcode['is_pseudo'] MIN_PSEUDO_OPCODE = opcode["MIN_PSEUDO_OPCODE"] MAX_PSEUDO_OPCODE = opcode["MAX_PSEUDO_OPCODE"] MIN_INSTRUMENTED_OPCODE = opcode["MIN_INSTRUMENTED_OP...
<vulnerable_code> gen->gi_frame_state = FRAME_CLEARED; frame->previous = NULL; _PyFrame_ClearExceptCode(frame); } if (_PyGen_GetCode(gen)->co_flags & CO_COROUTINE) { Py_CLEAR(((PyCoroObject *)gen)->cr_origin_or_finalizer); } Py_DECREF(_PyGen_GetCode(gen)); Py_CLEAR(gen...
<vulnerable_code> tstate->c_recursion_remaining--; assert(frame->frame_obj == NULL || frame->frame_obj->f_frame == frame); _PyFrame_ClearExceptCode(frame); tstate->c_recursion_remaining++; frame->previous = NULL; }<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_descriptio...
<vulnerable_code> def test_extended_arg(self): "Check EXTENDED_ARG handling in superblock creation" def many_vars(): # 260 vars, so z9 should have index 259 a0 = a1 = a2 = a3 = a4 = a5 = a6 = a7 = a8 = a9 = 42 b0 = b1 = b2 = b3 = b4 = b5 = b6 = b7 = b8 = b9 = 42 ...
<vulnerable_code> stop_line = "[{dsl_name} start generated code]*/" checksum_line = "/*[{dsl_name} end generated code: {arguments}]*/" def __init__(self, filename: str) -> None: super().__init__(filename) self.cpp = cpp.Monitor(filename) # methoddef_ifndef return_value_d...
<vulnerable_code> def restore__testsinglephase(*, _orig=_testsinglephase): # We started with the module imported and want to restore # it to its nominal state. _orig._clear_globals() _testinternalcapi.clear_extension('_testsinglephase', _orig.__file__) import _testsinglephase ...
<vulnerable_code> However, this decref would be problematic if the module def were dynamically allocated, it were the last ref, and this function were called with an interpreter other than the def's owner. */ entry->value = NULL; finally:<commit_title>[PATCH 016/395] Small fixes to code generat...
<vulnerable_code>import contextlib import inspect import os.path import sys import unittest from clinic import DSLParser class _ParserBase(TestCase): maxDiff = None def expect_parser_failure(self, parser, _input): with support.captured_stdout() as stdout: with self.assertRaises(Syste...
<vulnerable_code>import string import sys import textwrap import traceback from collections.abc import ( Callable, text, append, output = _text_accumulator() return TextAccumulator(append, output) @overload def warn_or_fail( *args: object, line_number: int | None = None, ) -> None: joined = " ...
<vulnerable_code>import unittest from ctypes import (CDLL, Structure, Array, CFUNCTYPE, byref, POINTER, pointer, ArgumentError, c_char, c_wchar, c_byte, c_char_p, c_short, c_int, c_long, c_longlong, c_float, c_double, c_longdouble) from _ct...
<vulnerable_code> Py_DECREF(as_parameter); return value; } /* XXX better message */ PyErr_SetString(PyExc_TypeError, "wrong type"); return NULL; } Py_DECREF(as_parameter); return value; } /* XXX better message */ PyErr_SetString(PyExc_TypeE...
<vulnerable_code> # cleanly the logging module. @import_helper.mock_register_at_fork def test_sundry(self, mock_os): old_modules = import_helper.modules_setup() try: for fn in os.listdir(scriptsdir): if not fn.endswith('.py'): continue ...
<vulnerable_code> const char *key, Py_ssize_t key_length) /*[clinic end generated code: output=4fda8a7f2547137c input=fc72ef4b4cfafabc]*/<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits...
<vulnerable_code> """ self.expect_failure(block, err) class ClinicGroupPermuterTest(TestCase): def _test(self, l, m, r, output): p = function.parameters['follow_symlinks'] self.assertEqual(True, p.default) def test_param_default_expression(self): function = self.parse_f...
<vulnerable_code> errstr = "Some I/O error occurred"; } } else { p = PY_SSL_ERROR_SYSCALL; } break;<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I found in PR gh-106798 (is...
<vulnerable_code> class B(typing.Generic[T]): pass class C(B[int]): pass class D(B[str], float): pass self.assertEqual(types.get_original_bases(A), (object,)) self.assertEqual(types.get_original_bases(B), (typing.Generic[T],)) self.assertEqual(types.get_original_bases(C), ...
<vulnerable_code> assert get_original_bases(int) == (object,) """ try: return cls.__orig_bases__ except AttributeError: try: return cls.__bases__ except AttributeError: raise TypeError( f'Expected an instance of type, not {type(cls).__na...
<vulnerable_code> with DirsOnSysPath(tempdir): import inspect_actual self.assertIn("correct", inspect.getsource(inspect_actual.A)) @unittest.skipIf( support.is_emscripten or support.is_wasi,<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<comm...
<vulnerable_code> } if (dump_refs) { _Py_PrintReferences(stderr); } if (dump_refs_fp != NULL) { _Py_PrintReferences(dump_refs_fp); } #endif /* Py_TRACE_REFS */ */ if (dump_refs) { _Py_PrintReferenceAddresses(stderr); } if (dump_refs_fp != NULL) { ...
<vulnerable_code> def expect_success(self, *args): out, err, code = self.run_clinic(*args) self.assertEqual(code, 0, f"Unexpected failure: {args=}") self.assertEqual(err, "") return out <commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These rep...
<vulnerable_code> return tuple(version) def version_comparitor(version1: str, version2: str) -> Literal[-1, 0, 1]: iterator = itertools.zip_longest(version_splitter(version1), version_splitter(version2), fillvalue=0) for i, (a, b) in enumerate(iterator): if a < b: return -1 if a ...
<vulnerable_code> print(" ", ' '.join(str(x) for x in a)) sys.exit(-1) def close(self) -> None: if self.stack: self.fail("Ended file while still in a preprocessor conditional block!") def write(self, s: str) -> None: for line in s.split("\n"): self.writ...
<vulnerable_code> """ self.expect_failure(block, err, lineno=8) class ClinicGroupPermuterTest(TestCase): def _test(self, l, m, r, output):<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I found in PR gh-106798 (issue gh-106797) and in PR gh...
<vulnerable_code>} /*[clinic input] module _testcapi class _testcapi.VectorCallClass "PyObject *" "&PyType_Type" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=8423a8e919f2f0df]*/ /*[clinic input] _testcapi.VectorCallClass.set_vectorcall<commit_title>[PATCH 016/395] Small ...
<vulnerable_code> if cls: fail("Can't nest a module inside a class!") if name in module.classes: fail("Already defined module " + repr(name) + "!") m = Module(name, module)<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repa...
<vulnerable_code> class ClinicWholeFileTest(TestCase): def expect_failure(self, raw, errmsg, *, filename=None, lineno=None): _expect_failure(self, self.clinic.parse, raw, errmsg, """ self.expect_failure(block, err, lineno=3) class ClinicGroupPermuterTest(TestCase): def _test(self, l,...
<vulnerable_code>from functools import cmp_to_key from test import seq_tests from test.support import ALWAYS_EQ, NEVER_EQ class CommonTest(seq_tests.CommonTest): def test_repr_deep(self): a = self.type2test([]) for i in range(sys.getrecursionlimit() + 100): a = self.type2test([a]) ...
<vulnerable_code>import unittest import collections import sys class BasicTestMappingProtocol(unittest.TestCase): def test_repr_deep(self): d = self._empty_mapping() for i in range(sys.getrecursionlimit() + 100): d0 = d d = self._empty_mapping() d[1] = d0<commi...
<vulnerable_code> "run_with_tz", "PGO", "missing_compiler_executable", "ALWAYS_EQ", "NEVER_EQ", "LARGEST", "SMALLEST", "LOOPBACK_TIMEOUT", "INTERNET_TIMEOUT", "SHORT_TIMEOUT", "LONG_TIMEOUT", "Py_DEBUG", "EXCEEDS_RECURSION_LIMIT", ] #For recursion tests, easily exceeds default recursion limit EXCE...
<vulnerable_code> return self enum._test_simple_enum(_Precedence, ast._Precedence) @support.cpython_only def test_ast_recursion_limit(self): fail_depth = support.EXCEEDS_RECURSION_LIMIT<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>Th...
<vulnerable_code>import unittest from test.support import cpython_only, requires_limited_api try: import _testcapi except ImportError: @cpython_only class TestRecursion(unittest.TestCase): def test_super_deep(self): def recurse(n):<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<c...
<vulnerable_code>import warnings from test import support from test.support import (script_helper, requires_debug_ranges, requires_specialization) from test.support.os_helper import FakePath class TestSpecifics(unittest.TestCase): def compile_single(self, source): @unittest.skipIf(...
<vulnerable_code>import unittest import weakref from test import support from test.support import import_helper class DictTest(unittest.TestCase): def test_repr_deep(self): d = {} for i in range(sys.getrecursionlimit() + 100): d = {1: d} self.assertRaises(RecursionError, repr,...
<vulnerable_code>import pickle import sys import unittest class DictSetTest(unittest.TestCase): def test_deeply_nested_repr(self): d = {} for i in range(sys.getrecursionlimit() + 100): d = {42: d.values()} self.assertRaises(RecursionError, repr, d) <commit_title>[PATCH 016/395...
<vulnerable_code>import collections.abc import types import unittest class TestExceptionGroupTypeHierarchy(unittest.TestCase): def test_exception_group_types(self): class DeepRecursionInSplitAndSubgroup(unittest.TestCase): def make_deep_eg(self): e = TypeError(1) for i in range(2000): ...
<vulnerable_code>import pickle import random import sys from test.support import bigmemtest, _1G, _4G zlib = import_helper.import_module('zlib') # zlib.decompress(func1(data)) == zlib.decompress(func2(data)) == data # # Make the assumption that s390x always has an accelerator to simplify the skip # condition. Windo...
<vulnerable_code> int starting_recursion_depth; /* Be careful here to prevent overflow. */ int COMPILER_STACK_FRAME_SCALE = 3; PyThreadState *tstate = _PyThreadState_GET(); if (!tstate) { return 0;<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These ...
<vulnerable_code> /* See comments in symtable.c. */ #define COMPILER_STACK_FRAME_SCALE 3 int _PyAST_Validate(mod_ty mod)<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I found in PR gh-106798 (issue gh-106797) and in PR gh-106716 (issue gh-106706).<fixed_code...
<vulnerable_code>#undef CALL_SEQ /* See comments in symtable.c. */ #define COMPILER_STACK_FRAME_SCALE 3 int _PyAST_Optimize(mod_ty mod, PyArena *arena, int optimize, int ff_features)<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I found in PR gh-106798 (issu...
<vulnerable_code> tstate->cframe = cframe.previous; assert(tstate->cframe->current_frame == frame->previous); assert(!_PyErr_Occurred(tstate)); _Py_LeaveRecursiveCallTstate(tstate); return retval; } <commit_title>[PATCH 016/395] Small fixes to code gene...
<vulnerable_code># pragma warning(disable:4102) #endif PyObject* _Py_HOT_FUNCTION _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag) { frame->previous = &entry_frame; cframe.current_frame = frame; if (_Py_EnterRecursiveCallTstate(tstate, "")) { tstate->c_re...
<vulnerable_code> return NULL; } /* When compiling the use of C stack is probably going to be a lot lighter than when executing Python code but still can overflow and causing a Python crash if not checked (e.g. eval("()"*300000)). Using the current recursion limit for the compiler seems too restrictive ...
<vulnerable_code>static int visit_decref(PyObject *op, void *parent) { _PyObject_ASSERT(_PyObject_CAST(parent), !_PyObject_IsFreed(op)); if (_PyObject_IS_GC(op)) { static int visit_reachable(PyObject *op, PyGC_Head *reachable) { if (!_PyObject_IS_GC(op)) { return 0; } static int visit_move(PyOb...
<vulnerable_code> */ #ifdef Py_STATS PyStats _py_stats_struct = { 0 }; PyStats *_py_stats = NULL; #define ADD_STAT_TO_DICT(res, field) \ fprintf(out, "Optimization uops executed: %" PRIu64 "\n", stats->optimization_uops_executed); } static void print_stats(FILE *out, PyStats *stats) { print_spec_stats(out, s...
<vulnerable_code> rows.append((label, value, ratio)) return rows def emit_object_stats(stats): with Section("Object stats", summary="allocations, frees and dict materializatons"): rows = calculate_object_stats(stats) head_rows = calculate_object_stats(head_stats) emit_table((...
<vulnerable_code> [clinic start generated code]*/ /*[clinic end generated code: output=0123456789abcdef input=fedcba9876543210]*/ """ err = ( 'Checksum mismatch!\n' 'Expected: 0123456789abcdef\n' 'Computed: da39a3ee5e6b4b0d\n' ) ...
<vulnerable_code> continue if trailing: fail("Text found after {" + name + "} block marker! It must be on a line by itself.") if indent.strip(): fail("Non-whitespace characters found before {" + name + "} block marker! It must be on a line by itself.") valu...
<vulnerable_code> converters = [p.converter for p in parameters] has_option_groups = parameters and (parameters[0].group or parameters[-1].group) default_return_converter = (not f.return_converter or f.return_converter.type == 'PyObject *') new_or_init = f.kind.new_or_init ...
<vulnerable_code> found on the start line of the block between the square brackets. signatures is either list or None. If it's a list, it may only contain clinic.Module, clinic.Class, and clinic.Function objects. At the moment it should contain at most one of each. output is either str or...
<vulnerable_code> test_tools.skip_if_missing('cases_generator') with test_tools.imports_under_tool('cases_generator'): import analysis import formatting import generate_cases from parsing import StackEffect (2, "(oparg<<1)"), ) self.assertEqual( formatting.stri...
<vulnerable_code> MacroParts, OverriddenInstructionPlaceHolder, PseudoInstruction, StackEffectMapping, ) import parsing from parsing import StackEffect input_filenames: list[str] errors: int = 0 def __init__(self, input_filenames: list[str]): self.input_filenames = input_filenames ...
<vulnerable_code> if value: setattr(self, name, value) def names(self, value=None): if value is None: return dataclasses.asdict(self).keys() return [n for n, v in dataclasses.asdict(self).items() if v == value] def bitmap(self) -> int:<commit_title>[PATCH...
<vulnerable_code>import re import typing from parsing import StackEffect UNUSED = "unused" nominal_filename: str def __init__( self, stream: typing.TextIO, indent: int, emit_line_directives: bool = False, comment: str = "//", ) -> None: self.stream = stream ...
<vulnerable_code>""" import argparse import contextlib import os import posixpath import sys import typing from analysis import Analyzer from formatting import Formatter, list_effect_size, maybe_parenthesize from flags import InstructionFlags, variable_used from instructions import ( AnyInstruction, ...
<vulnerable_code>import re import typing from flags import InstructionFlags, variable_used_unspecialized from formatting import ( Formatter, UNUSED, string_effect_size, list_effect_size, maybe_parenthesize, ) import lexer as lx import parsing from parsing import StackEffect BITS_PER_CODE_UNIT = 16...
<vulnerable_code> @dataclass class StackEffect(Node): name: str type: str = "" # Optional `:type` cond: str = "" # Optional `if (cond)` size: str = "" # Optional `[size]` # Note: size cannot be combined with type or cond @dataclass class Expression(Node): size: str # Variable giving the ca...
<vulnerable_code>import lexer as lx Token = lx.Token tkn = self.next() if tkn is not None and tkn.kind == kind: return tkn raise self.make_syntax_error(f"Expected {kind!r} but got {tkn and tkn.text!r}", tkn) def extract_line(self, lineno: int) -> str: # Return source l...
<vulnerable_code><commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I found in PR gh-106798 (issue gh-106797) and in PR gh-106716 (issue gh-106706).<fixed_code> import dataclasses import typing from formatting import ( Formatter, UNUSED, maybe_parenth...
<vulnerable_code> # Only used by the 'O!' format unit (and the "object" converter). subclass_of: str | None = None # Do we want an adjacent '_length' variable for this variable? # Only used by format units ending with '#'. length = False s = ("&" if self.impl_by_reference else "") + name ...
<vulnerable_code> Okay, we're done here. """) def test_parser_regression_special_character_in_parameter_column_of_docstring_first_line(self): function = self.parse_function(dedent(""" module os<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_descri...
<vulnerable_code> # this line is permitted to start with whitespace. # we'll call this number of spaces F (for "function"). if not self.valid_line(line): return self.indent.infer(line) # are we cloning?<commit_title>[PATCH 016/395] Small fixes to code generator (#10...
<vulnerable_code> pattern_parts.append('') if pattern_parts[-1] == '**': # GH-70303: '**' only matches directories. Add trailing slash. pattern_parts.append('') if case_sensitive is None:<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_desc...
<vulnerable_code> "dirC/dirD", "dirC/dirD/fileD"]) _check(p.rglob("file*"), ["dirC/fileC", "dirC/dirD/fileD"]) _check(p.rglob("**/file*"), ["dirC/fileC", "dirC/dirD/fileD"]) _check(p.rglob("dir*/**"), ["dirC/dirD"]) _check(p.rglob("*/*"), ["dirC/dirD/fileD"])...
<vulnerable_code> default: assert (0); } return Py_XNewRef(ret); } static PyObject *<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I found in PR gh-106798 (issue gh-106797) and in PR gh-106716 (issue gh-106706).<fixed_code> default: ...
<vulnerable_code>{ if (errors == NULL) { errors = Py_NewRef(&_Py_ID(strict)); } else { errors = Py_NewRef(errors); if (encoding == NULL && _PyRuntime.preconfig.utf8_mode) { _Py_DECLARE_STR(utf_8, "utf-8"); self->encoding = Py_NewRef(&_Py_STR(utf_8)); } else if (...
<vulnerable_code>{ /* Return the JSON string representation of None, True, False */ if (obj == Py_None) { return Py_NewRef(&_Py_ID(null)); } else if (obj == Py_True) { return Py_NewRef(&_Py_ID(true)); } else if (obj == Py_False) { return Py_NewRef(&_Py_ID(false)); } ...
<vulnerable_code> } /* If no module is found, use __main__. */ module_name = &_Py_ID(__main__); return Py_NewRef(module_name); } /* fast_save_enter() and fast_save_leave() are guards against recursive<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair n...
<vulnerable_code>static PyObject * bool_repr(PyObject *self) { PyObject *res = self == Py_True ? &_Py_ID(True) : &_Py_ID(False); return Py_NewRef(res); } /* Function to return a bool from a C long */<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I fou...
<vulnerable_code>#define EMPTY (&_Py_SINGLETON(bytes_empty)) // Return a borrowed reference to the empty bytes string singleton. static inline PyObject* bytes_get_empty(void) { return &EMPTY->ob_base.ob_base; } // Return a strong reference to the empty bytes string singleton. static inline PyObject* bytes_new_e...
<vulnerable_code> // However, name and qualname could be str subclasses, so they // could have reference cycles. The solution is to replace them // with a genuinely immutable string. Py_SETREF(op->func_name, Py_NewRef(&_Py_STR(empty))); Py_SETREF(op->func_qualname, Py_NewRef(&_Py_STR(empty))); re...
<vulnerable_code>{ assert(digit_count >= 0); if (digit_count == 0) { return (PyLongObject *)Py_NewRef(_PyLong_GetZero()); } PyLongObject *result = _PyLong_New(digit_count); if (result == NULL) { if (*prem == NULL) { return -1; } PyObject *zero = _PyLong_Ge...
<vulnerable_code> if (!stop) { return NULL; } start = Py_NewRef(_PyLong_GetZero()); step = Py_NewRef(_PyLong_GetOne()); break; case 0: PyErr_SetString(PyExc_TypeError,<commit_title>[PATCH 016/395] Small fixes to code generato...
<vulnerable_code> /* Convert step to an integer; raise for zero step. */ if (self->step == Py_None) { step = Py_NewRef(_PyLong_GetOne()); step_is_negative = 0; } else { goto error; } else { lower = Py_NewRef(_PyLong_GetZero()); upper = Py_NewRef(length...
<vulnerable_code>static inline PyObject * tuple_get_empty(void) { return Py_NewRef(&_Py_SINGLETON(tuple_empty)); } PyObject *<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I found in PR gh-106798 (issue gh-106797) and in PR gh-106716 (issue gh-106706).<fi...
<vulnerable_code> PyUnicode_InternInPlace(&mod); } else { mod = Py_NewRef(&_Py_ID(builtins)); } } return mod;<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I found in PR gh-106798 (issue gh-106797) and...
<vulnerable_code>#endif // Return a borrowed reference to the empty string singleton. static inline PyObject* unicode_get_empty(void) { _Py_DECLARE_STR(empty, ""); return &_Py_STR(empty); } // Return a strong reference to the empty string singleton. static inline PyObject* unicode_new_empty(void) { PyOb...
<vulnerable_code> if (co->co_flags & CO_VARARGS) { PyObject *u = NULL; if (argcount == n) { u = Py_NewRef(&_Py_SINGLETON(tuple_empty)); } else { assert(args != NULL);<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These ...
<vulnerable_code>static PyObject * get_token_missing(void) { return Py_NewRef(&_Py_SINGLETON(context_token_missing)); } <commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I found in PR gh-106798 (issue gh-106797) and in PR gh-106716 (issue gh-106706).<fixed_c...
<vulnerable_code>#else if (_PyRuntime.preconfig.utf8_mode) { _Py_DECLARE_STR(utf_8, "utf-8"); return Py_NewRef(&_Py_STR(utf_8)); } return _Py_GetLocaleEncodingObject(); #endif<commit_title>[PATCH 016/395] Small fixes to code generator (#106845)<commit_description>These repair nits I found in...
<vulnerable_code> /* Since bitmap nodes are immutable, we can cache the instance for size=0 and reuse it whenever we need an empty bitmap node. */ return (PyHamtNode *)Py_NewRef(&_Py_SINGLETON(hamt_bitmap_node_empty)); } assert(size >= 0);<commit_title>[PATCH 016/395] Small fi...
<vulnerable_code>static Py_ssize_t uop_len(_PyUOpExecutorObject *self) { int count = 0; for (; count < _Py_UOP_MAX_TRACE_LENGTH; count++) { if (self->trace[count].opcode == 0) { break; } } return count; } static PyObject * static PyTypeObject UOpExecutor_Type = { PyVarOb...
<vulnerable_code> def get_var_names(instr: Instruction) -> dict[str, StackEffect]: vars: dict[str, StackEffect] = {} for eff in instr.input_effects + instr.output_effects: if eff.name in vars: if vars[eff.name] != eff: self.error...