8000 gh-130080: move _Py_EnsureArrayLargeEnough to a separate header so it can be used outside of the compiler by iritkatriel · Pull Request #130930 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-130080: move _Py_EnsureArrayLargeEnough to a separate header so it can be used outside of the compiler #130930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 13, 2025
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
Prev Previous commit
Next Next commit
implement review feedback and fix comment
  • Loading branch information
iritkatriel committed Mar 7, 2025
commit 344888d645456635d732d6a38a6f59295d79f7bb
16 changes: 9 additions & 7 deletions Include/internal/pycore_c_array.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef Py_INTERNAL_C_ARRAY_H
#define Py_INTERNAL_C_ARRAY_H

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -18,19 +19,20 @@ extern "C" {
* item_size: size of each array entry
*
* If *array is NULL, allocate default_alloc entries.
* Otherwise, grow the array by default_alloc entries.
* Otherwise, double the array size if idx is out of range.
*
* return 0 if successful and -1 (with exception set) otherwise.
* 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);
int idx,
void **array,
int *alloc,
int initial_size,
size_t item_size);


#ifdef __cplusplus
}
#endif

#endif /* !Py_INTERNAL_C_ARRAY_H */
1 change: 0 additions & 1 deletion Include/internal/pycore_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ 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
10 changes: 5 additions & 5 deletions Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,19 @@ static const int compare_masks[] = {
* idx: the index we want to access
* arr: pointer to the array
* alloc: pointer to the capacity of the array
* default_alloc: initial number of items
* initial_size: initial number of items
* item_size: size of each item
*
*/
int
_Py_EnsureArrayLargeEnough(int idx, void **array, int *alloc,
int default_alloc, size_t item_size)
int initial_size, size_t item_size)
{
void *arr = *array;
if (arr == NULL) {
int new_alloc = default_alloc;
int new_alloc = initial_size;
if (idx >= new_alloc) {
new_alloc = idx + default_alloc;
new_alloc = idx + initial_size;
}
arr = PyMem_Calloc(new_alloc, item_size);
if (arr == NULL) {
Expand All @@ -140,7 +140,7 @@ _Py_EnsureArrayLargeEnough(int idx, void **array, int *alloc,
size_t oldsize = *alloc * item_size;
int new_alloc = *alloc << 1;
if (idx >= new_alloc) {
new_alloc = idx + default_alloc;
new_alloc = idx + initial_size;
}
size_t newsize = new_alloc * item_size;

Expand Down
Loading
0