| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bdb847a commit ab87400
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,16 @@ | |||
| 7 | 7 | extern "C" { | |
| 8 | 8 | #endif | |
| 9 | 9 | ||
| 10 | + typedef uint16_t _Py_CODEUNIT; | ||
| 11 | + | ||
| 12 | + #ifdef WORDS_BIGENDIAN | ||
| 13 | + # define _Py_OPCODE(word) ((word) >> 8) | ||
| 14 | + # define _Py_OPARG(word) ((word) & 255) | ||
| 15 | + #else | ||
| 16 | + # define _Py_OPCODE(word) ((word) & 255) | ||
| 17 | + # define _Py_OPARG(word) ((word) >> 8) | ||
| 18 | + #endif | ||
| 19 | + | ||
| 10 | 20 | /* Bytecode object */ | |
| 11 | 21 | typedef struct { | |
| 12 | 22 | PyObject_HEAD | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -189,7 +189,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno) | |||
| 189 | 189 | memset(blockstack, '\0', sizeof(blockstack)); | |
| 190 | 190 | memset(in_finally, '\0', sizeof(in_finally)); | |
| 191 | 191 | blockstack_top = 0; | |
| 192 | - for (addr = 0; addr < code_len; addr += 2) { | ||
| 192 | + for (addr = 0; addr < code_len; addr += sizeof(_Py_CODEUNIT)) { | ||
| 193 | 193 | unsigned char op = code[addr]; | |
| 194 | 194 | switch (op) { | |
| 195 | 195 | case SETUP_LOOP: | |
@@ -273,7 +273,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno) | |||
| 273 | 273 | * can tell whether the jump goes into any blocks without coming out | |
| 274 | 274 | * again - in that case we raise an exception below. */ | |
| 275 | 275 | delta_iblock = 0; | |
| 276 | - for (addr = min_addr; addr < max_addr; addr += 2) { | ||
| 276 | + for (addr = min_addr; addr < max_addr; addr += sizeof(_Py_CODEUNIT)) { | ||
| 277 | 277 | unsigned char op = code[addr]; | |
| 278 | 278 | switch (op) { | |
| 279 | 279 | case SETUP_LOOP: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -390,7 +390,7 @@ _PyGen_yf(PyGenObject *gen) | |||
| 390 | 390 | PyObject *bytecode = f->f_code->co_code; | |
| 391 | 391 | unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode); | |
| 392 | 392 | ||
| 393 | - if (code[f->f_lasti + 2] != YIELD_FROM) | ||
| 393 | + if (code[f->f_lasti + sizeof(_Py_CODEUNIT)] != YIELD_FROM) | ||
| 394 | 394 | return NULL; | |
| 395 | 395 | yf = f->f_stacktop[-1]; | |
| 396 | 396 | Py_INCREF(yf); | |
@@ -498,7 +498,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, | |||
| 498 | 498 | assert(ret == yf); | |
| 499 | 499 | Py_DECREF(ret); | |
| 500 | 500 | /* Termination repetition of YIELD_FROM */ | |
| 501 | - gen->gi_frame->f_lasti += 2; | ||
| 501 | + gen->gi_frame->f_lasti += sizeof(_Py_CODEUNIT); | ||
| 502 | 502 | if (_PyGen_FetchStopIterationValue(&val) == 0) { | |
| 503 | 503 | ret = gen_send_ex(gen, val, 0, 0); | |
| 504 | 504 | Py_DECREF(val); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,7 +62,7 @@ static int import_all_from(PyObject *, PyObject *); | |||
| 62 | 62 | static void format_exc_check_arg(PyObject *, const char *, PyObject *); | |
| 63 | 63 | static void format_exc_unbound(PyCodeObject *co, int oparg); | |
| 64 | 64 | static PyObject * unicode_concatenate(PyObject *, PyObject *, | |
| 65 | - PyFrameObject *, const unsigned short *); | ||
| 65 | + PyFrameObject *, const _Py_CODEUNIT *); | ||
| 66 | 66 | static PyObject * special_lookup(PyObject *, _Py_Identifier *); | |
| 67 | 67 | ||
| 68 | 68 | #define NAME_ERROR_MSG \ | |
@@ -725,7 +725,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) | |||
| 725 | 725 | int lastopcode = 0; | |
| 726 | 726 | #endif | |
| 727 | 727 | PyObject **stack_pointer; /* Next free slot in value stack */ | |
| 728 | - const unsigned short *next_instr; | ||
| 728 | + const _Py_CODEUNIT *next_instr; | ||
| 729 | 729 | int opcode; /* Current opcode */ | |
| 730 | 730 | int oparg; /* Current opcode argument, if any */ | |
| 731 | 731 | enum why_code why; /* Reason for block stack unwind */ | |
@@ -743,7 +743,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) | |||
| 743 | 743 | time it is tested. */ | |
| 744 | 744 | int instr_ub = -1, instr_lb = 0, instr_prev = -1; | |
| 745 | 745 | ||
| 746 | - const unsigned short *first_instr; | ||
| 746 | + const _Py_CODEUNIT *first_instr; | ||
| 747 | 747 | PyObject *names; | |
| 748 | 748 | PyObject *consts; | |
| 749 | 749 | ||
@@ -864,23 +864,16 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) | |||
| 864 | 864 | ||
| 865 | 865 | /* Code access macros */ | |
| 866 | 866 | ||
| 867 | - #ifdef WORDS_BIGENDIAN | ||
| 868 | - #define OPCODE(word) ((word) >> 8) | ||
| 869 | - #define OPARG(word) ((word) & 255) | ||
| 870 | - #else | ||
| 871 | - #define OPCODE(word) ((word) & 255) | ||
| 872 | - #define OPARG(word) ((word) >> 8) | ||
| 873 | - #endif | ||
| 874 | 867 | /* The integer overflow is checked by an assertion below. */ | |
| 875 | - #define INSTR_OFFSET() (2*(int)(next_instr - first_instr)) | ||
| 868 | + #define INSTR_OFFSET() (sizeof(_Py_CODEUNIT) * (int)(next_instr - first_instr)) | ||
| 876 | 869 | #define NEXTOPARG() do { \ | |
| 877 | - unsigned short word = *next_instr; \ | ||
| 878 | - opcode = OPCODE(word); \ | ||
| 879 | - oparg = OPARG(word); \ | ||
| 870 | + _Py_CODEUNIT word = *next_instr; \ | ||
| 871 | + opcode = _Py_OPCODE(word); \ | ||
| 872 | + oparg = _Py_OPARG(word); \ | ||
| 880 | 873 | next_instr++; \ | |
| 881 | 874 | } while (0) | |
| 882 | - #define JUMPTO(x) (next_instr = first_instr + (x)/2) | ||
| 883 | - #define JUMPBY(x) (next_instr += (x)/2) | ||
| 875 | + #define JUMPTO(x) (next_instr = first_instr + (x) / sizeof(_Py_CODEUNIT)) | ||
| 876 | + #define JUMPBY(x) (next_instr += (x) / sizeof(_Py_CODEUNIT)) | ||
| 884 | 877 | ||
| 885 | 878 | /* OpCode prediction macros | |
| 886 | 879 | Some opcodes tend to come in pairs thus making it possible to | |
@@ -913,10 +906,10 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) | |||
| 913 | 906 | #else | |
| 914 | 907 | #define PREDICT(op) \ | |
| 915 | 908 | do{ \ | |
| 916 | - unsigned short word = *next_instr; \ | ||
| 917 | - opcode = OPCODE(word); \ | ||
| 909 | + _Py_CODEUNIT word = *next_instr; \ | ||
| 910 | + opcode = _Py_OPCODE(word); \ | ||
| 918 | 911 | if (opcode == op){ \ | |
| 919 | - oparg = OPARG(word); \ | ||
| 912 | + oparg = _Py_OPARG(word); \ | ||
| 920 | 913 | next_instr++; \ | |
| 921 | 914 | goto PRED_##op; \ | |
| 922 | 915 | } \ | |
@@ -1056,9 +1049,9 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) | |||
| 1056 | 1049 | freevars = f->f_localsplus + co->co_nlocals; | |
| 1057 | 1050 | assert(PyBytes_Check(co->co_code)); | |
| 1058 | 1051 | assert(PyBytes_GET_SIZE(co->co_code) <= INT_MAX); | |
| 1059 | - assert(PyBytes_GET_SIZE(co->co_code) % 2 == 0); | ||
| 1060 | - assert(_Py_IS_ALIGNED(PyBytes_AS_STRING(co->co_code), 2)); | ||
| 1061 | - first_instr = (unsigned short*) PyBytes_AS_STRING(co->co_code); | ||
| 1052 | + assert(PyBytes_GET_SIZE(co->co_code) % sizeof(_Py_CODEUNIT) == 0); | ||
| 1053 | + assert(_Py_IS_ALIGNED(PyBytes_AS_STRING(co->co_code), sizeof(_Py_CODEUNIT))); | ||
| 1054 | + first_instr = (_Py_CODEUNIT *) PyBytes_AS_STRING(co->co_code); | ||
| 1062 | 1055 | /* | |
| 1063 | 1056 | f->f_lasti refers to the index of the last instruction, | |
| 1064 | 1057 | unless it's -1 in which case next_instr should be first_instr. | |
@@ -1074,10 +1067,11 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) | |||
| 1074 | 1067 | FOR_ITER is effectively a single opcode and f->f_lasti will point | |
| 1075 | 1068 | to the beginning of the combined pair.) | |
| 1076 | 1069 | */ | |
| 1070 | + assert(f->f_lasti >= -1); | ||
| 1077 | 1071 | next_instr = first_instr; | |
| 1078 | 1072 | if (f->f_lasti >= 0) { | |
| 1079 | - assert(f->f_lasti % 2 == 0); | ||
| 1080 | - next_instr += f->f_lasti/2 + 1; | ||
| 1073 | + assert(f->f_lasti % sizeof(_Py_CODEUNIT) == 0); | ||
| 1074 | + next_instr += f->f_lasti / sizeof(_Py_CODEUNIT) + 1; | ||
| 1081 | 1075 | } | |
| 1082 | 1076 | stack_pointer = f->f_stacktop; | |
| 1083 | 1077 | assert(stack_pointer != NULL); | |
@@ -1125,7 +1119,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) | |||
| 1125 | 1119 | Py_MakePendingCalls() above. */ | |
| 1126 | 1120 | ||
| 1127 | 1121 | if (_Py_atomic_load_relaxed(&eval_breaker)) { | |
| 1128 | - if (OPCODE(*next_instr) == SETUP_FINALLY) { | ||
| 1122 | + if (_Py_OPCODE(*next_instr) == SETUP_FINALLY) { | ||
| 1129 | 1123 | /* Make the last opcode before | |
| 1130 | 1124 | a try: finally: block uninterruptible. */ | |
| 1131 | 1125 | goto fast_next_opcode; | |
@@ -2049,7 +2043,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) | |||
| 2049 | 2043 | f->f_stacktop = stack_pointer; | |
| 2050 | 2044 | why = WHY_YIELD; | |
| 2051 | 2045 | /* and repeat... */ | |
| 2052 | - f->f_lasti -= 2; | ||
| 2046 | + f->f_lasti -= sizeof(_Py_CODEUNIT); | ||
| 2053 | 2047 | goto fast_yield; | |
| 2054 | 2048 | } | |
| 2055 | 2049 | ||
@@ -5321,7 +5315,7 @@ format_exc_unbound(PyCodeObject *co, int oparg) | |||
| 5321 | 5315 | ||
| 5322 | 5316 | static PyObject * | |
| 5323 | 5317 | unicode_concatenate(PyObject *v, PyObject *w, | |
| 5324 | - PyFrameObject *f, const unsigned short *next_instr) | ||
| 5318 | + PyFrameObject *f, const _Py_CODEUNIT *next_instr) | ||
| 5325 | 5319 | { | |
| 5326 | 5320 | PyObject *res; | |
| 5327 | 5321 | if (Py_REFCNT(v) == 2) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4948,7 +4948,7 @@ assemble_lnotab(struct assembler *a, struct instr *i) | |||
| 4948 | 4948 | Py_ssize_t len; | |
| 4949 | 4949 | unsigned char *lnotab; | |
| 4950 | 4950 | ||
| 4951 | - d_bytecode = a->a_offset - a->a_lineno_off; | ||
| 4951 | + d_bytecode = (a->a_offset - a->a_lineno_off) * sizeof(_Py_CODEUNIT); | ||
| 4952 | 4952 | d_lineno = i->i_lineno - a->a_lineno; | |
| 4953 | 4953 | ||
| 4954 | 4954 | assert(d_bytecode >= 0); | |
@@ -5055,21 +5055,21 @@ assemble_emit(struct assembler *a, struct instr *i) | |||
| 5055 | 5055 | { | |
| 5056 | 5056 | int size, arg = 0; | |
| 5057 | 5057 | Py_ssize_t len = PyBytes_GET_SIZE(a->a_bytecode); | |
| 5058 | - char *code; | ||
| 5058 | + _Py_CODEUNIT *code; | ||
| 5059 | 5059 | ||
| 5060 | 5060 | arg = i->i_oparg; | |
| 5061 | 5061 | size = instrsize(arg); | |
| 5062 | 5062 | if (i->i_lineno && !assemble_lnotab(a, i)) | |
| 5063 | 5063 | return 0; | |
| 5064 | - if (a->a_offset + size >= len) { | ||
| 5064 | + if (a->a_offset + size >= len / (int)sizeof(_Py_CODEUNIT)) { | ||
| 5065 | 5065 | if (len > PY_SSIZE_T_MAX / 2) | |
| 5066 | 5066 | return 0; | |
| 5067 | 5067 | if (_PyBytes_Resize(&a->a_bytecode, len * 2) < 0) | |
| 5068 | 5068 | return 0; | |
| 5069 | 5069 | } | |
| 5070 | - code = PyBytes_AS_STRING(a->a_bytecode) + a->a_offset; | ||
| 5070 | + code = (_Py_CODEUNIT *)PyBytes_AS_STRING(a->a_bytecode) + a->a_offset; | ||
| 5071 | 5071 | a->a_offset += size; | |
| 5072 | - write_op_arg((unsigned char*)code, i->i_opcode, arg, size); | ||
| 5072 | + write_op_arg(code, i->i_opcode, arg, size); | ||
| 5073 | 5073 | return 1; | |
| 5074 | 5074 | } | |
| 5075 | 5075 | ||
@@ -5106,6 +5106,7 @@ assemble_jump_offsets(struct assembler *a, struct compiler *c) | |||
| 5106 | 5106 | if (instr->i_jrel) { | |
| 5107 | 5107 | instr->i_oparg -= bsize; | |
| 5108 | 5108 | } | |
| 5109 | + instr->i_oparg *= sizeof(_Py_CODEUNIT); | ||
| 5109 | 5110 | if (instrsize(instr->i_oparg) != isize) { | |
| 5110 | 5111 | extended_arg_recompile = 1; | |
| 5111 | 5112 | } | |
@@ -5351,7 +5352,7 @@ assemble(struct compiler *c, int addNone) | |||
| 5351 | 5352 | ||
| 5352 | 5353 | if (_PyBytes_Resize(&a.a_lnotab, a.a_lnotab_off) < 0) | |
| 5353 | 5354 | goto error; | |
| 5354 | - if (_PyBytes_Resize(&a.a_bytecode, a.a_offset) < 0) | ||
| 5355 | + if (_PyBytes_Resize(&a.a_bytecode, a.a_offset * sizeof(_Py_CODEUNIT)) < 0) | ||
| 5355 | 5356 | goto error; | |
| 5356 | 5357 | ||
| 5357 | 5358 | co = makecode(c, &a); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments