Skip to content

Commit 3994c3a

Browse files
committed
make _PyCfgInstruction and _PyCfgExceptStack opaque
1 parent 0197e0b commit 3994c3a

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

Include/internal/pycore_flowgraph.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,11 @@ extern "C" {
1212
#include "pycore_compile.h"
1313

1414

15-
typedef struct {
16-
int i_opcode;
17-
int i_oparg;
18-
_PyCompilerSrcLocation i_loc;
19-
struct _PyCfgBasicblock_ *i_target; /* target block (if jump instruction) */
20-
struct _PyCfgBasicblock_ *i_except; /* target block when exception is raised */
21-
} _PyCfgInstruction;
22-
2315
typedef struct {
2416
int id;
2517
} _PyCfgJumpTargetLabel;
2618

27-
28-
typedef struct {
29-
struct _PyCfgBasicblock_ *handlers[CO_MAXBLOCKS+1];
30-
int depth;
31-
} _PyCfgExceptStack;
19+
struct _PyCfgExceptStack;
3220

3321
typedef struct _PyCfgBasicblock_ {
3422
/* Each basicblock in a compilation unit is linked via b_list in the
@@ -39,9 +27,9 @@ typedef struct _PyCfgBasicblock_ {
3927
/* The label of this block if it is a jump target, -1 otherwise */
4028
_PyCfgJumpTargetLabel b_label;
4129
/* Exception stack at start of block, used by assembler to create the exception handling table */
42-
_PyCfgExceptStack *b_exceptstack;
30+
struct PyCfgExceptStack *b_exceptstack;
4331
/* pointer to an array of instructions, initially NULL */
44-
_PyCfgInstruction *b_instr;
32+
struct _PyCfgInstruction *b_instr;
4533
/* If b_next is non-NULL, it is a pointer to the next
4634
block reached by normal control flow. */
4735
struct _PyCfgBasicblock_ *b_next;

Python/flowgraph.c

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ typedef _PyCompilerSrcLocation location;
2626
typedef _PyCfgJumpTargetLabel jump_target_label;
2727
typedef _PyCfgBasicblock basicblock;
2828
typedef _PyCfgBuilder cfg_builder;
29-
typedef _PyCfgInstruction cfg_instr;
29+
30+
typedef struct _PyCfgInstruction {
31+
int i_opcode;
32+
int i_oparg;
33+
_PyCompilerSrcLocation i_loc;
34+
struct _PyCfgBasicblock_ *i_target; /* target block (if jump instruction) */
35+
struct _PyCfgBasicblock_ *i_except; /* target block when exception is raised */
36+
} cfg_instr;
37+
3038

3139
static const jump_target_label NO_LABEL = {-1};
3240

@@ -52,7 +60,7 @@ is_jump(cfg_instr *i)
5260
#define INSTR_SET_OP1(I, OP, ARG) \
5361
do { \
5462
assert(OPCODE_HAS_ARG(OP)); \
55-
_PyCfgInstruction *_instr__ptr_ = (I); \
63+
struct _PyCfgInstruction *_instr__ptr_ = (I); \
5664
_instr__ptr_->i_opcode = (OP); \
5765
_instr__ptr_->i_oparg = (ARG); \
5866
} while (0);
@@ -61,7 +69,7 @@ is_jump(cfg_instr *i)
6169
#define INSTR_SET_OP0(I, OP) \
6270
do { \
6371
assert(!OPCODE_HAS_ARG(OP)); \
64-
_PyCfgInstruction *_instr__ptr_ = (I); \
72+
struct _PyCfgInstruction *_instr__ptr_ = (I); \
6573
_instr__ptr_->i_opcode = (OP); \
6674
_instr__ptr_->i_oparg = 0; \
6775
} while (0);
@@ -151,7 +159,7 @@ basicblock_last_instr(const basicblock *b) {
151159

152160
static inline int
153161
basicblock_nofallthrough(const _PyCfgBasicblock *b) {
154-
_PyCfgInstruction *last = basicblock_last_instr(b);
162+
struct _PyCfgInstruction *last = basicblock_last_instr(b);
155163
return (last &&
156164
(IS_SCOPE_EXIT_OPCODE(last->i_opcode) ||
157165
IS_UNCONDITIONAL_JUMP_OPCODE(last->i_opcode)));
@@ -581,10 +589,14 @@ mark_except_handlers(basicblock *entryblock) {
581589
}
582590

583591

584-
typedef _PyCfgExceptStack ExceptStack;
592+
struct _PyCfgExceptStack {
593+
struct _PyCfgBasicblock_ *handlers[CO_MAXBLOCKS+1];
594+
int depth;
595+
};
596+
585597

586598
static basicblock *
587-
push_except_block(ExceptStack *stack, cfg_instr *setup) {
599+
push_except_block(struct _PyCfgExceptStack *stack, cfg_instr *setup) {
588600
assert(is_block_push(setup));
589601
int opcode = setup->i_opcode;
590602
basicblock * target = setup->i_target;
@@ -596,19 +608,19 @@ push_except_block(ExceptStack *stack, cfg_instr *setup) {
596608
}
597609

598610
static basicblock *
599-
pop_except_block(ExceptStack *stack) {
611+
pop_except_block(struct _PyCfgExceptStack *stack) {
600612
assert(stack->depth > 0);
601613
return stack->handlers[--stack->depth];
602614
}
603615

604616
static basicblock *
605-
except_stack_top(ExceptStack *stack) {
617+
except_stack_top(struct _PyCfgExceptStack *stack) {
606618
return stack->handlers[stack->depth];
607619
}
608620

609-
static ExceptStack *
621+
static struct _PyCfgExceptStack *
610622
make_except_stack(void) {
611-
ExceptStack *new = PyMem_Malloc(sizeof(ExceptStack));
623+
struct _PyCfgExceptStack *new = PyMem_Malloc(sizeof(struct _PyCfgExceptStack));
612624
if (new == NULL) {
613625
PyErr_NoMemory();
614626
return NULL;
@@ -618,14 +630,14 @@ make_except_stack(void) {
618630
return new;
619631
}
620632

621-
static ExceptStack *
622-
copy_except_stack(ExceptStack *stack) {
623-
ExceptStack *copy = PyMem_Malloc(sizeof(ExceptStack));
633+
static struct _PyCfgExceptStack *
634+
copy_except_stack(struct _PyCfgExceptStack *stack) {
635+
struct _PyCfgExceptStack *copy = PyMem_Malloc(sizeof(struct _PyCfgExceptStack));
624636
if (copy == NULL) {
625637
PyErr_NoMemory();
626638
return NULL;
627639
}
628-
memcpy(copy, stack, sizeof(ExceptStack));
640+
memcpy(copy, stack, sizeof(struct _PyCfgExceptStack));
629641
return copy;
630642
}
631643

@@ -751,7 +763,7 @@ label_exception_targets(basicblock *entryblock) {
751763
if (todo_stack == NULL) {
752764
return ERROR;
753765
}
754-
ExceptStack *except_stack = make_except_stack();
766+
struct _PyCfgExceptStack *except_stack = make_except_stack();
755767
if (except_stack == NULL) {
756768
PyMem_Free(todo_stack);
757769
PyErr_NoMemory();
@@ -775,7 +787,7 @@ label_exception_targets(basicblock *entryblock) {
775787
cfg_instr *instr = &b->b_instr[i];
776788
if (is_block_push(instr)) {
777789
if (!instr->i_target->b_visited) {
778-
ExceptStack *copy = copy_except_stack(except_stack);
790+
struct _PyCfgExceptStack *copy = copy_except_stack(except_stack);
779791
if (copy == NULL) {
780792
goto error;
781793
}
@@ -794,7 +806,7 @@ label_exception_targets(basicblock *entryblock) {
794806
assert(i == b->b_iused -1);
795807
if (!instr->i_target->b_visited) {
796808
if (BB_HAS_FALLTHROUGH(b)) {
797-
ExceptStack *copy = copy_except_stack(except_stack);
809+
struct _PyCfgExceptStack *copy = copy_except_stack(except_stack);
798810
if (copy == NULL) {
799811
goto error;
800812
}

0 commit comments

Comments
 (0)