@@ -8730,6 +8730,41 @@ remove_redundant_jumps(cfg_builder *g) {
8730
8730
return 0 ;
8731
8731
}
8732
8732
8733
+ static int
8734
+ prepare_localsplus (struct compiler * c , int code_flags )
8735
+ {
8736
+ assert (PyDict_GET_SIZE (c -> u -> u_varnames ) < INT_MAX );
8737
+ assert (PyDict_GET_SIZE (c -> u -> u_cellvars ) < INT_MAX );
8738
+ assert (PyDict_GET_SIZE (c -> u -> u_freevars ) < INT_MAX );
8739
+ int nlocals = (int )PyDict_GET_SIZE (c -> u -> u_varnames );
8740
+ int ncellvars = (int )PyDict_GET_SIZE (c -> u -> u_cellvars );
8741
+ int nfreevars = (int )PyDict_GET_SIZE (c -> u -> u_freevars );
8742
+ assert (INT_MAX - nlocals - ncellvars > 0 );
8743
+ assert (INT_MAX - nlocals - ncellvars - nfreevars > 0 );
8744
+ int nlocalsplus = nlocals + ncellvars + nfreevars ;
8745
+ int * cellfixedoffsets = build_cellfixedoffsets (c );
8746
+ if (cellfixedoffsets == NULL ) {
8747
+ return -1 ;
8748
+ }
8749
+
8750
+ cfg_builder * g = CFG_BUILDER (c );
8751
+
8752
+ // This must be called before fix_cell_offsets().
8753
+ if (insert_prefix_instructions (c , g -> g_entryblock , cellfixedoffsets , nfreevars , code_flags )) {
8754
+ PyMem_Free (cellfixedoffsets );
8755
+ return -1 ;
8756
+ }
8757
+
8758
+ int numdropped = fix_cell_offsets (c , g -> g_entryblock , cellfixedoffsets );
8759
+ PyMem_Free (cellfixedoffsets ); // At this point we're done with it.
8760
+ cellfixedoffsets = NULL ;
8761
+ if (numdropped < 0 ) {
8762
+ return -1 ;
8763
+ }
8764
+ nlocalsplus -= numdropped ;
8765
+ return nlocalsplus ;
8766
+ }
8767
+
8733
8768
static PyCodeObject *
8734
8769
assemble (struct compiler * c , int addNone )
8735
8770
{
@@ -8751,20 +8786,6 @@ assemble(struct compiler *c, int addNone)
8751
8786
ADDOP (c , NO_LOCATION , RETURN_VALUE );
8752
8787
}
8753
8788
8754
- assert (PyDict_GET_SIZE (c -> u -> u_varnames ) < INT_MAX );
8755
- assert (PyDict_GET_SIZE (c -> u -> u_cellvars ) < INT_MAX );
8756
- assert (PyDict_GET_SIZE (c -> u -> u_freevars ) < INT_MAX );
8757
- int nlocals = (int )PyDict_GET_SIZE (c -> u -> u_varnames );
8758
- int ncellvars = (int )PyDict_GET_SIZE (c -> u -> u_cellvars );
8759
- int nfreevars = (int )PyDict_GET_SIZE (c -> u -> u_freevars );
8760
- assert (INT_MAX - nlocals - ncellvars > 0 );
8761
- assert (INT_MAX - nlocals - ncellvars - nfreevars > 0 );
8762
- int nlocalsplus = nlocals + ncellvars + nfreevars ;
8763
- int * cellfixedoffsets = build_cellfixedoffsets (c );
8764
- if (cellfixedoffsets == NULL ) {
8765
- goto error ;
8766
- }
8767
-
8768
8789
int nblocks = 0 ;
8769
8790
for (basicblock * b = CFG_BUILDER (c )-> g_block_list ; b != NULL ; b = b -> b_list ) {
8770
8791
nblocks ++ ;
@@ -8787,19 +8808,6 @@ assemble(struct compiler *c, int addNone)
8787
8808
}
8788
8809
}
8789
8810
8790
- // This must be called before fix_cell_offsets().
8791
- if (insert_prefix_instructions (c , g -> g_entryblock , cellfixedoffsets , nfreevars , code_flags )) {
8792
- goto error ;
8793
- }
8794
-
8795
- int numdropped = fix_cell_offsets (c , g -> g_entryblock , cellfixedoffsets );
8796
- PyMem_Free (cellfixedoffsets ); // At this point we're done with it.
8797
- cellfixedoffsets = NULL ;
8798
- if (numdropped < 0 ) {
8799
- goto error ;
8800
- }
8801
- nlocalsplus -= numdropped ;
8802
-
8803
8811
/** Preprocessing **/
8804
8812
/* Map labels to targets and mark exception handlers */
8805
8813
if (translate_jump_labels_to_targets (g -> g_entryblock )) {
@@ -8839,6 +8847,12 @@ assemble(struct compiler *c, int addNone)
8839
8847
}
8840
8848
8841
8849
/** Assembly **/
8850
+
8851
+ int nlocalsplus = prepare_localsplus (c , code_flags );
8852
+ if (nlocalsplus < 0 ) {
8853
+ goto error ;
8854
+ }
8855
+
8842
8856
int maxdepth = stackdepth (g -> g_entryblock , code_flags );
8843
8857
if (maxdepth < 0 ) {
8844
8858
goto error ;
@@ -8904,9 +8918,6 @@ assemble(struct compiler *c, int addNone)
8904
8918
error :
8905
8919
Py_XDECREF (consts );
8906
8920
assemble_free (& a );
8907
- if (cellfixedoffsets != NULL ) {
8908
- PyMem_Free (cellfixedoffsets );
8909
- }
8910
8921
return co ;
8911
8922
}
8912
8923
0 commit comments