Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Include/internal/pycore_c_array.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef Py_INTERNAL_C_ARRAY_H
#define Py_INTERNAL_C_ARRAY_H
#ifdef __cplusplus
extern "C" {
#endif

#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif


/* Utility for a number of growing arrays
*
* idx: index we need to write to
* array: pointer to the array
* alloc: pointer to array capacity
* delta: array growth
* item_size: size of each array entry
*
* If *array is NULL, allocate default_alloc entries.
* Otherwise, grow the array by default_alloc entries.
*
* return 0 if successful and -1 (with exception set) otherwise.
*/
int _Py_EnsureArrayLargeEnough(
int idx,
void **array,
int *alloc,
int delta,
size_t item_size);


#ifdef __cplusplus
}
#endif
#endif /* !Py_INTERNAL_C_ARRAY_H */
9 changes: 1 addition & 8 deletions Include/internal/pycore_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern "C" {
#include <stdbool.h>

#include "pycore_ast.h" // mod_ty
#include "pycore_c_array.h" // _Py_EnsureArrayLargeEnough()
#include "pycore_symtable.h" // _Py_SourceLocation
#include "pycore_instruction_sequence.h"

Expand Down Expand Up @@ -174,14 +175,6 @@ int _PyCodegen_Expression(struct _PyCompiler *c, expr_ty e);
int _PyCodegen_Body(struct _PyCompiler *c, _Py_SourceLocation loc, asdl_stmt_seq *stmts,
bool is_interactive);

/* Utility for a number of growing arrays used in the compiler */
int _PyCompile_EnsureArrayLargeEnough(
int idx,
void **array,
int *alloc,
int default_alloc,
size_t item_size);

int _PyCompile_ConstCacheMergeOne(PyObject *const_cache, PyObject **obj);

PyCodeObject *_PyCompile_OptimizeAndAssemble(struct _PyCompiler *c, int addNone);
Expand Down
4 changes: 2 additions & 2 deletions Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ static const int compare_masks[] = {
*
*/
int
_PyCompile_EnsureArrayLargeEnough(int idx, void **array, int *alloc,
int default_alloc, size_t item_size)
_Py_EnsureArrayLargeEnough(int idx, void **array, int *alloc,
int default_alloc, size_t item_size)
{
void *arr = *array;
if (arr == NULL) {
Expand Down
3 changes: 2 additions & 1 deletion Python/flowgraph.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Python.h"
#include "opcode.h"
#include "pycore_c_array.h" // _Py_EnsureArrayLargeEnough
#include "pycore_flowgraph.h"
#include "pycore_compile.h"
#include "pycore_intrinsics.h"
Expand Down Expand Up @@ -142,7 +143,7 @@ basicblock_next_instr(basicblock *b)
{
assert(b != NULL);
RETURN_IF_ERROR(
_PyCompile_EnsureArrayLargeEnough(
_Py_EnsureArrayLargeEnough(
b->b_iused + 1,
(void**)&b->b_instr,
&b->b_ialloc,
Expand Down
23 changes: 12 additions & 11 deletions Python/instruction_sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

#include "Python.h"

#include "pycore_compile.h" // _PyCompile_EnsureArrayLargeEnough
#include "pycore_c_array.h" // _Py_EnsureArrayLargeEnough
#include "pycore_compile.h" // _PyInstruction
#include "pycore_opcode_utils.h"
#include "pycore_opcode_metadata.h" // OPCODE_HAS_ARG, etc

Expand Down Expand Up @@ -37,11 +38,11 @@ instr_sequence_next_inst(instr_sequence *seq) {
assert(seq->s_instrs != NULL || seq->s_used == 0);

RETURN_IF_ERROR(
_PyCompile_EnsureArrayLargeEnough(seq->s_used + 1,
(void**)&seq->s_instrs,
&seq->s_allocated,
INITIAL_INSTR_SEQUENCE_SIZE,
sizeof(instruction)));
_Py_EnsureArrayLargeEnough(seq->s_used + 1,
(void**)&seq->s_instrs,
&seq->s_allocated,
INITIAL_INSTR_SEQUENCE_SIZE,
sizeof(instruction)));
assert(seq->s_allocated >= 0);
assert(seq->s_used < seq->s_allocated);
return seq->s_used++;
Expand All @@ -59,11 +60,11 @@ _PyInstructionSequence_UseLabel(instr_sequence *seq, int lbl)
{
int old_size = seq->s_labelmap_size;
RETURN_IF_ERROR(
_PyCompile_EnsureArrayLargeEnough(lbl,
(void**)&seq->s_labelmap,
&seq->s_labelmap_size,
INITIAL_INSTR_SEQUENCE_LABELS_MAP_SIZE,
sizeof(int)));
_Py_EnsureArrayLargeEnough(lbl,
(void**)&seq->s_labelmap,
&seq->s_labelmap_size,
INITIAL_INSTR_SEQUENCE_LABELS_MAP_SIZE,
sizeof(int)));

for(int i = old_size; i < seq->s_labelmap_size; i++) {
seq->s_labelmap[i] = -111; /* something weird, for debugging */
Expand Down
Loading