|
40 | 40 | #define DEFAULT_BLOCKS 8
|
41 | 41 | #define DEFAULT_CODE_SIZE 128
|
42 | 42 | #define DEFAULT_LNOTAB_SIZE 16
|
43 |
| -#define DEFAULT_CNOTAB_SIZE 0 |
| 43 | +#define DEFAULT_CNOTAB_SIZE 32 |
44 | 44 |
|
45 | 45 | #define COMP_GENEXP 0
|
46 | 46 | #define COMP_LISTCOMP 1
|
@@ -6587,6 +6587,7 @@ struct assembler {
|
6587 | 6587 | PyObject* a_cnotab; /* bytes containing cnotab */
|
6588 | 6588 | int a_lnotab_off; /* offset into lnotab */
|
6589 | 6589 | int a_enotab_off; /* offset into enotab */
|
| 6590 | + int a_cnotab_off; /* offset into cnotab */ |
6590 | 6591 | PyObject *a_except_table; /* bytes containing exception table */
|
6591 | 6592 | int a_except_table_off; /* offset into exception table */
|
6592 | 6593 | int a_prevlineno; /* lineno of last emitted line in line table */
|
@@ -6696,6 +6697,7 @@ assemble_init(struct assembler *a, int nblocks, int firstlineno)
|
6696 | 6697 | a->a_lnotab = NULL;
|
6697 | 6698 | a->a_enotab = NULL;
|
6698 | 6699 | a->a_cnotab = NULL;
|
| 6700 | + a->a_cnotab_off = 0; |
6699 | 6701 | a->a_except_table = NULL;
|
6700 | 6702 | a->a_bytecode = PyBytes_FromStringAndSize(NULL, DEFAULT_CODE_SIZE);
|
6701 | 6703 | if (a->a_bytecode == NULL) {
|
@@ -7106,14 +7108,16 @@ static int
|
7106 | 7108 | assemble_cnotab(struct assembler* a, struct instr* i, int instr_size)
|
7107 | 7109 | {
|
7108 | 7110 | Py_ssize_t len = PyBytes_GET_SIZE(a->a_cnotab);
|
7109 |
| - // TODO: Allocate more memory than just what we immediately need |
7110 |
| - // like a_lnotab does. |
7111 |
| - if (_PyBytes_Resize(&a->a_cnotab, len + (instr_size * 2)) < 0) { |
7112 |
| - return 0; |
| 7111 | + int difference = instr_size * 2; |
| 7112 | + if (a->a_cnotab_off + difference >= len) { |
| 7113 | + if (_PyBytes_Resize(&a->a_cnotab, difference + (len * 2)) < 0) { |
| 7114 | + return 0; |
| 7115 | + } |
7113 | 7116 | }
|
7114 | 7117 |
|
7115 | 7118 | unsigned char* cnotab = (unsigned char*)PyBytes_AS_STRING(a->a_cnotab);
|
7116 |
| - cnotab += len; |
| 7119 | + cnotab += a->a_cnotab_off; |
| 7120 | + a->a_cnotab_off += difference; |
7117 | 7121 |
|
7118 | 7122 | for (int j = 0; j < instr_size; j++) {
|
7119 | 7123 | if (i->i_col_offset > 255 || i->i_end_col_offset > 255) {
|
@@ -7855,6 +7859,9 @@ assemble(struct compiler *c, int addNone)
|
7855 | 7859 | if (!merge_const_one(c, &a.a_enotab)) {
|
7856 | 7860 | goto error;
|
7857 | 7861 | }
|
| 7862 | + if (_PyBytes_Resize(&a.a_cnotab, a.a_cnotab_off) < 0) { |
| 7863 | + goto error; |
| 7864 | + } |
7858 | 7865 | if (_PyBytes_Resize(&a.a_bytecode, a.a_offset * sizeof(_Py_CODEUNIT)) < 0) {
|
7859 | 7866 | goto error;
|
7860 | 7867 | }
|
|
0 commit comments