diff options
| author | Erlend E. Aasland <erlend@python.org> | 2024-01-29 23:04:34 (GMT) | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-29 23:04:34 (GMT) | 
| commit | 8612230c1cacab6d48bfbeb9e17d04ef5a9acf21 (patch) | |
| tree | bf514924f4e271505cfd154d14f9315931bfa199 /Python/compile.c | |
| parent | 3996cbdd33a479b7e59757b81489cbb3370f85e5 (diff) | |
| download | cpython-8612230c1cacab6d48bfbeb9e17d04ef5a9acf21.zip cpython-8612230c1cacab6d48bfbeb9e17d04ef5a9acf21.tar.gz cpython-8612230c1cacab6d48bfbeb9e17d04ef5a9acf21.tar.bz2  | |
gh-114569: Use PyMem_* APIs for non-PyObjects in compiler (#114587)
Diffstat (limited to 'Python/compile.c')
| -rw-r--r-- | Python/compile.c | 25 | 
1 files changed, 12 insertions, 13 deletions
diff --git a/Python/compile.c b/Python/compile.c index 7cf05dd..4c1d3bb 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -160,7 +160,7 @@ _PyCompile_EnsureArrayLargeEnough(int idx, void **array, int *alloc,          if (idx >= new_alloc) {              new_alloc = idx + default_alloc;          } -        arr = PyObject_Calloc(new_alloc, item_size); +        arr = PyMem_Calloc(new_alloc, item_size);          if (arr == NULL) {              PyErr_NoMemory();              return ERROR; @@ -181,7 +181,7 @@ _PyCompile_EnsureArrayLargeEnough(int idx, void **array, int *alloc,          }          assert(newsize > 0); -        void *tmp = PyObject_Realloc(arr, newsize); +        void *tmp = PyMem_Realloc(arr, newsize);          if (tmp == NULL) {              PyErr_NoMemory();              return ERROR; @@ -282,10 +282,10 @@ instr_sequence_insert_instruction(instr_sequence *seq, int pos,  static void  instr_sequence_fini(instr_sequence *seq) { -    PyObject_Free(seq->s_labelmap); +    PyMem_Free(seq->s_labelmap);      seq->s_labelmap = NULL; -    PyObject_Free(seq->s_instrs); +    PyMem_Free(seq->s_instrs);      seq->s_instrs = NULL;  } @@ -690,7 +690,7 @@ compiler_unit_free(struct compiler_unit *u)      Py_CLEAR(u->u_metadata.u_cellvars);      Py_CLEAR(u->u_metadata.u_fasthidden);      Py_CLEAR(u->u_private); -    PyObject_Free(u); +    PyMem_Free(u);  }  static int @@ -1262,8 +1262,7 @@ compiler_enter_scope(struct compiler *c, identifier name,      struct compiler_unit *u; -    u = (struct compiler_unit *)PyObject_Calloc(1, sizeof( -                                            struct compiler_unit)); +    u = (struct compiler_unit *)PyMem_Calloc(1, sizeof(struct compiler_unit));      if (!u) {          PyErr_NoMemory();          return ERROR; @@ -6657,7 +6656,7 @@ ensure_fail_pop(struct compiler *c, pattern_context *pc, Py_ssize_t n)          return SUCCESS;      }      Py_ssize_t needed = sizeof(jump_target_label) * size; -    jump_target_label *resized = PyObject_Realloc(pc->fail_pop, needed); +    jump_target_label *resized = PyMem_Realloc(pc->fail_pop, needed);      if (resized == NULL) {          PyErr_NoMemory();          return ERROR; @@ -6696,13 +6695,13 @@ emit_and_reset_fail_pop(struct compiler *c, location loc,          USE_LABEL(c, pc->fail_pop[pc->fail_pop_size]);          if (codegen_addop_noarg(INSTR_SEQUENCE(c), POP_TOP, loc) < 0) {              pc->fail_pop_size = 0; -            PyObject_Free(pc->fail_pop); +            PyMem_Free(pc->fail_pop);              pc->fail_pop = NULL;              return ERROR;          }      }      USE_LABEL(c, pc->fail_pop[0]); -    PyObject_Free(pc->fail_pop); +    PyMem_Free(pc->fail_pop);      pc->fail_pop = NULL;      return SUCCESS;  } @@ -7206,7 +7205,7 @@ compiler_pattern_or(struct compiler *c, pattern_ty p, pattern_context *pc)      Py_DECREF(pc->stores);      *pc = old_pc;      Py_INCREF(pc->stores); -    // Need to NULL this for the PyObject_Free call in the error block. +    // Need to NULL this for the PyMem_Free call in the error block.      old_pc.fail_pop = NULL;      // No match. Pop the remaining copy of the subject and fail:      if (codegen_addop_noarg(INSTR_SEQUENCE(c), POP_TOP, LOC(p)) < 0 || @@ -7252,7 +7251,7 @@ compiler_pattern_or(struct compiler *c, pattern_ty p, pattern_context *pc)  diff:      compiler_error(c, LOC(p), "alternative patterns bind different names");  error: -    PyObject_Free(old_pc.fail_pop); +    PyMem_Free(old_pc.fail_pop);      Py_DECREF(old_pc.stores);      Py_XDECREF(control);      return ERROR; @@ -7453,7 +7452,7 @@ compiler_match(struct compiler *c, stmt_ty s)      pattern_context pc;      pc.fail_pop = NULL;      int result = compiler_match_inner(c, s, &pc); -    PyObject_Free(pc.fail_pop); +    PyMem_Free(pc.fail_pop);      return result;  }  | 
