-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
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
Changes from 5 commits
dc8f650
344888d
bb76ef3
469a42a
4ae9d0e
122dbf1
93d018c
f717563
ce12085
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #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 */ | ||
|
|
||
| typedef struct { | ||
| void **array; /* pointer to the array */ | ||
| int *allocated_entries; /* pointer to the capacity of the array */ | ||
| size_t item_size; /* size of each element */ | ||
| int initial_num_entries; /* initial allocation size */ | ||
| } _Py_c_array_t; | ||
|
|
||
| /* If idx is out of bouds: | ||
| * If arr->array is NULL, allocate arr->initial_num_entries slots. | ||
| * Otherwise, double its size. | ||
| * | ||
| * Return 0 if successful and -1 (with exception set) otherwise. | ||
| */ | ||
| int _Py_c_array_EnsureCapacity(_Py_c_array_t *c_array, int idx); | ||
|
|
||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* !Py_INTERNAL_C_ARRAY_H */ | ||
| 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_c_array_EnsureCapacity | ||
| #include "pycore_flowgraph.h" | ||
| #include "pycore_compile.h" | ||
| #include "pycore_intrinsics.h" | ||
|
|
@@ -141,13 +142,14 @@ static int | |
| basicblock_next_instr(basicblock *b) | ||
| { | ||
| assert(b != NULL); | ||
| RETURN_IF_ERROR( | ||
| _PyCompile_EnsureArrayLargeEnough( | ||
| b->b_iused + 1, | ||
| (void**)&b->b_instr, | ||
| &b->b_ialloc, | ||
| DEFAULT_BLOCK_SIZE, | ||
| sizeof(cfg_instr))); | ||
| _Py_c_array_t array = { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having to manually initialize a struct, just to pass it to a function seems clunky. The previous API was probably better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just to make the transition now. If we were defining basic block from scratch we would have put this struct field in it. But I think now that's a transformation for another PR. |
||
| .array = (void**)&b->b_instr, | ||
| .allocated_entries = &b->b_ialloc, | ||
| .item_size = sizeof(cfg_instr), | ||
| .initial_num_entries = DEFAULT_BLOCK_SIZE, | ||
| }; | ||
|
|
||
| RETURN_IF_ERROR(_Py_c_array_EnsureCapacity(&array, b->b_iused + 1)); | ||
| return b->b_iused++; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we assume idx is n int or maybe a uint32_t or just a size_t? any possibility of unsafe downcasting?