| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e266e42 commit ef8ace3
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,8 +19,8 @@ extern "C" { | |||
| 19 | 19 | typedef struct _node { | |
| 20 | 20 | short n_type; | |
| 21 | 21 | char *n_str; | |
| 22 | - short n_lineno; | ||
| 23 | - short n_nchildren; | ||
| 22 | + int n_lineno; | ||
| 23 | + int n_nchildren; | ||
| 24 | 24 | struct _node *n_child; | |
| 25 | 25 | } node; | |
| 26 | 26 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -130,6 +130,9 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. | |||
| 130 | 130 | #define CALL_FUNCTION_KW 141 /* #args + (#kwargs<<8) */ | |
| 131 | 131 | #define CALL_FUNCTION_VAR_KW 142 /* #args + (#kwargs<<8) */ | |
| 132 | 132 | ||
| 133 | + /* Support for opargs more than 16 bits long */ | ||
| 134 | + #define EXTENDED_ARG 143 | ||
| 135 | + | ||
| 133 | 136 | /* Comparison operator codes (argument to COMPARE_OP) */ | |
| 134 | 137 | enum cmp_op {LT, LE, EQ, NE, GT, GE, IN, NOT_IN, IS, IS_NOT, EXC_MATCH, BAD}; | |
| 135 | 138 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,6 +56,7 @@ def disassemble(co, lasti=-1): | |||
| 56 | 56 | labels = findlabels(code) | |
| 57 | 57 | n = len(code) | |
| 58 | 58 | i = 0 | |
| 59 | + extended_arg = 0 | ||
| 59 | 60 | while i < n: | |
| 60 | 61 | c = code[i] | |
| 61 | 62 | op = ord(c) | |
@@ -68,8 +69,11 @@ def disassemble(co, lasti=-1): | |||
| 68 | 69 | print string.ljust(opname[op], 20), | |
| 69 | 70 | i = i+1 | |
| 70 | 71 | if op >= HAVE_ARGUMENT: | |
| 71 | - oparg = ord(code[i]) + ord(code[i+1])*256 | ||
| 72 | + oparg = ord(code[i]) + ord(code[i+1])*256 + extended_arg | ||
| 73 | + extended_arg = 0 | ||
| 72 | 74 | i = i+2 | |
| 75 | + if op == EXTENDED_ARG: | ||
| 76 | + extended_arg = oparg*65536L | ||
| 73 | 77 | print string.rjust(`oparg`, 5), | |
| 74 | 78 | if op in hasconst: | |
| 75 | 79 | print '(' + `co.co_consts[oparg]` + ')', | |
@@ -258,6 +262,8 @@ def jabs_op(name, op): | |||
| 258 | 262 | def_op('CALL_FUNCTION_KW', 141) # #args + (#kwargs << 8) | |
| 259 | 263 | def_op('CALL_FUNCTION_VAR_KW', 142) # #args + (#kwargs << 8) | |
| 260 | 264 | ||
| 265 | + def_op('EXTENDED_ARG', 143) | ||
| 266 | + EXTENDED_ARG = 143 | ||
| 261 | 267 | ||
| 262 | 268 | def _test(): | |
| 263 | 269 | """Simple test program to disassemble a file.""" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,12 @@ See the file "Misc/COPYRIGHT" for information on usage and | |||
| 8 | 8 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. | |
| 9 | 9 | ******************************************************************/ | |
| 10 | 10 | ||
| 11 | + #ifdef HAVE_LIMITS_H | ||
| 11 | 12 | #include <limits.h> | |
| 13 | + #endif | ||
| 14 | + #ifndef INT_MAX | ||
| 15 | + #define INT_MAX 2147483647 | ||
| 16 | + #endif | ||
| 12 | 17 | ||
| 13 | 18 | /* Parse tree node implementation */ | |
| 14 | 19 | ||
@@ -39,7 +44,7 @@ PyNode_AddChild(register node *n1, int type, char *str, int lineno) | |||
| 39 | 44 | register int nch = n1->n_nchildren; | |
| 40 | 45 | register int nch1 = nch+1; | |
| 41 | 46 | register node *n; | |
| 42 | - if (nch == SHRT_MAX || nch < 0) | ||
| 47 | + if (nch == INT_MAX || nch < 0) | ||
| 43 | 48 | return E_OVERFLOW; | |
| 44 | 49 | if (XXXROUNDUP(nch) < nch1) { | |
| 45 | 50 | n = n1->n_child; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -613,6 +613,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals, | |||
| 613 | 613 | opcode = NEXTOP(); | |
| 614 | 614 | if (HAS_ARG(opcode)) | |
| 615 | 615 | oparg = NEXTARG(); | |
| 616 | + dispatch_opcode: | ||
| 616 | 617 | #ifdef DYNAMIC_EXECUTION_PROFILE | |
| 617 | 618 | #ifdef DXPAIRS | |
| 618 | 619 | dxpairs[lastopcode][opcode]++; | |
@@ -1750,6 +1751,11 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals, | |||
| 1750 | 1751 | if (x != NULL) continue; | |
| 1751 | 1752 | break; | |
| 1752 | 1753 | ||
| 1754 | + case EXTENDED_ARG: | ||
| 1755 | + opcode = NEXTOP(); | ||
| 1756 | + oparg = oparg<<16 | NEXTARG(); | ||
| 1757 | + goto dispatch_opcode; | ||
| 1758 | + break; | ||
| 1753 | 1759 | ||
| 1754 | 1760 | default: | |
| 1755 | 1761 | fprintf(stderr, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,6 +36,9 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. | |||
| 36 | 36 | #ifdef HAVE_LIMITS_H | |
| 37 | 37 | #include <limits.h> | |
| 38 | 38 | #endif | |
| 39 | + #ifndef INT_MAX | ||
| 40 | + #define INT_MAX 2147483647 | ||
| 41 | + #endif | ||
| 39 | 42 | ||
| 40 | 43 | /* Three symbols from graminit.h are also defined in Python.h, with | |
| 41 | 44 | Py_ prefixes to their names. Python.h can't include graminit.h | |
@@ -572,11 +575,17 @@ com_set_lineno(struct compiling *c, int lineno) | |||
| 572 | 575 | static void | |
| 573 | 576 | com_addoparg(struct compiling *c, int op, int arg) | |
| 574 | 577 | { | |
| 578 | + int extended_arg = arg >> 16; | ||
| 575 | 579 | if (op == SET_LINENO) { | |
| 576 | 580 | com_set_lineno(c, arg); | |
| 577 | 581 | if (Py_OptimizeFlag) | |
| 578 | 582 | return; | |
| 579 | 583 | } | |
| 584 | + if (extended_arg){ | ||
| 585 | + com_addbyte(c, EXTENDED_ARG); | ||
| 586 | + com_addint(c, extended_arg); | ||
| 587 | + arg &= 0xffff; | ||
| 588 | + } | ||
| 580 | 589 | com_addbyte(c, op); | |
| 581 | 590 | com_addint(c, arg); | |
| 582 | 591 | } | |
@@ -606,7 +615,14 @@ com_backpatch(struct compiling *c, int anchor) | |||
| 606 | 615 | prev = code[anchor] + (code[anchor+1] << 8); | |
| 607 | 616 | dist = target - (anchor+2); | |
| 608 | 617 | code[anchor] = dist & 0xff; | |
| 609 | - code[anchor+1] = dist >> 8; | ||
| 618 | + dist >>= 8; | ||
| 619 | + code[anchor+1] = dist; | ||
| 620 | + dist >>= 8; | ||
| 621 | + if (dist) { | ||
| 622 | + com_error(c, PyExc_SystemError, | ||
| 623 | + "com_backpatch: offset too large"); | ||
| 624 | + break; | ||
| 625 | + } | ||
| 610 | 626 | if (!prev) | |
| 611 | 627 | break; | |
| 612 | 628 | anchor -= prev; | |
@@ -3364,6 +3380,7 @@ optimize(struct compiling *c) | |||
| 3364 | 3380 | break; | |
| 3365 | 3381 | if (HAS_ARG(opcode)) | |
| 3366 | 3382 | oparg = NEXTARG(); | |
| 3383 | + dispatch_opcode1: | ||
| 3367 | 3384 | switch (opcode) { | |
| 3368 | 3385 | case STORE_NAME: | |
| 3369 | 3386 | case DELETE_NAME: | |
@@ -3374,6 +3391,11 @@ optimize(struct compiling *c) | |||
| 3374 | 3391 | case EXEC_STMT: | |
| 3375 | 3392 | c->c_flags &= ~CO_OPTIMIZED; | |
| 3376 | 3393 | break; | |
| 3394 | + case EXTENDED_ARG: | ||
| 3395 | + opcode = NEXTOP(); | ||
| 3396 | + oparg = oparg<<16 | NEXTARG(); | ||
| 3397 | + goto dispatch_opcode1; | ||
| 3398 | + break; | ||
| 3377 | 3399 | } | |
| 3378 | 3400 | } | |
| 3379 | 3401 | ||
@@ -3389,6 +3411,7 @@ optimize(struct compiling *c) | |||
| 3389 | 3411 | break; | |
| 3390 | 3412 | if (HAS_ARG(opcode)) | |
| 3391 | 3413 | oparg = NEXTARG(); | |
| 3414 | + dispatch_opcode2: | ||
| 3392 | 3415 | if (opcode == LOAD_NAME || | |
| 3393 | 3416 | opcode == STORE_NAME || | |
| 3394 | 3417 | opcode == DELETE_NAME) { | |
@@ -3403,13 +3426,20 @@ optimize(struct compiling *c) | |||
| 3403 | 3426 | continue; | |
| 3404 | 3427 | } | |
| 3405 | 3428 | i = PyInt_AsLong(v); | |
| 3429 | + if (i >> 16) /* too big for 2 bytes */ | ||
| 3430 | + continue; | ||
| 3406 | 3431 | switch (opcode) { | |
| 3407 | 3432 | case LOAD_NAME: cur_instr[0] = LOAD_FAST; break; | |
| 3408 | 3433 | case STORE_NAME: cur_instr[0] = STORE_FAST; break; | |
| 3409 | 3434 | case DELETE_NAME: cur_instr[0] = DELETE_FAST; break; | |
| 3410 | 3435 | } | |
| 3411 | 3436 | cur_instr[1] = i & 0xff; | |
| 3412 | - cur_instr[2] = (i>>8) & 0xff; | ||
| 3437 | + cur_instr[2] = i >> 8; | ||
| 3438 | + } | ||
| 3439 | + if (opcode == EXTENDED_ARG) { | ||
| 3440 | + opcode = NEXTOP(); | ||
| 3441 | + oparg = oparg<<16 | NEXTARG(); | ||
| 3442 | + goto dispatch_opcode2; | ||
| 3413 | 3443 | } | |
| 3414 | 3444 | } | |
| 3415 | 3445 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments