Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-47172: Make virtual opcodes negative. Make is_jump detect only actual jumps, use is_block_push for the exception block setup opcodes. #32200

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 12 commits into from
Apr 1, 2022
Merged
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
added MIN_VIRTUAL_OPCODE/MAX_ALLOWED_OPCODE etc
  • Loading branch information
iritkatriel committed Apr 1, 2022
commit da4293169cb3ccb6dabfab9b25faea423d7eef4d
11 changes: 10 additions & 1 deletion 11 Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
#define POP_BLOCK -4
#define JUMP -5

iritkatriel marked this conversation as resolved.
Show resolved Hide resolved
#define MIN_VIRTUAL_OPCODE -5
#define MAX_ALLOWED_OPCODE 254

#define IS_WITHIN_OPCODE_RANGE(opcode) \
((opcode) >= MIN_VIRTUAL_OPCODE && (opcode) <= MAX_ALLOWED_OPCODE)

#define IS_VIRTUAL_OPCODE(opcode) ((opcode) < 0)

#define IS_TOP_LEVEL_AWAIT(c) ( \
Expand Down Expand Up @@ -117,7 +123,7 @@ is_bit_set_in_table(const uint32_t *table, int bitindex) {
* Word is indexed by (bitindex>>ln(size of int in bits)).
* Bit within word is the low bits of bitindex.
*/
if (bitindex >= 0) {
if (bitindex >= 0 && bitindex < 256) {
uint32_t word = table[bitindex >> LOG_BITS_PER_INT];
return (word >> (bitindex & MASK_LOW_LOG_BITS)) & 1;
}
Expand Down Expand Up @@ -1192,6 +1198,7 @@ static int
compiler_addop_line(struct compiler *c, int opcode, int line,
int end_line, int col_offset, int end_col_offset)
{
assert(IS_WITHIN_OPCODE_RANGE(opcode));
assert(!HAS_ARG(opcode) || IS_ARTIFICIAL(opcode));

if (compiler_use_new_implicit_block_if_needed(c) < 0) {
Expand Down Expand Up @@ -1434,6 +1441,7 @@ compiler_addop_i_line(struct compiler *c, int opcode, Py_ssize_t oparg,
The argument of a concrete bytecode instruction is limited to 8-bit.
EXTENDED_ARG is used for 16, 24, and 32-bit arguments. */

assert(IS_WITHIN_OPCODE_RANGE(opcode));
assert(HAS_ARG(opcode));
assert(0 <= oparg && oparg <= 2147483647);

Expand Down Expand Up @@ -1477,6 +1485,7 @@ static int add_jump_to_block(struct compiler *c, int opcode,
int col_offset, int end_col_offset,
basicblock *target)
{
assert(IS_WITHIN_OPCODE_RANGE(opcode));
assert(HAS_ARG(opcode) || IS_VIRTUAL_OPCODE(opcode));
assert(target != NULL);

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.