@@ -7268,12 +7268,12 @@ assemble_init(struct assembler *a, int firstlineno)
7268
7268
if (a -> a_except_table == NULL ) {
7269
7269
goto error ;
7270
7270
}
7271
- return 1 ;
7271
+ return 0 ;
7272
7272
error :
7273
7273
Py_XDECREF (a -> a_bytecode );
7274
7274
Py_XDECREF (a -> a_linetable );
7275
7275
Py_XDECREF (a -> a_except_table );
7276
- return 0 ;
7276
+ return -1 ;
7277
7277
}
7278
7278
7279
7279
static void
@@ -7667,8 +7667,9 @@ assemble_emit_exception_table_entry(struct assembler *a, int start, int end, bas
7667
7667
{
7668
7668
Py_ssize_t len = PyBytes_GET_SIZE (a -> a_except_table );
7669
7669
if (a -> a_except_table_off + MAX_SIZE_OF_ENTRY >= len ) {
7670
- if (_PyBytes_Resize (& a -> a_except_table , len * 2 ) < 0 )
7671
- return 0 ;
7670
+ if (_PyBytes_Resize (& a -> a_except_table , len * 2 ) < 0 ) {
7671
+ return -1 ;
7672
+ }
7672
7673
}
7673
7674
int size = end - start ;
7674
7675
assert (end > start );
@@ -7683,7 +7684,7 @@ assemble_emit_exception_table_entry(struct assembler *a, int start, int end, bas
7683
7684
assemble_emit_exception_table_item (a , size , 0 );
7684
7685
assemble_emit_exception_table_item (a , target , 0 );
7685
7686
assemble_emit_exception_table_item (a , depth_lasti , 0 );
7686
- return 1 ;
7687
+ return 0 ;
7687
7688
}
7688
7689
7689
7690
static int
@@ -7699,7 +7700,9 @@ assemble_exception_table(struct assembler *a, basicblock *entryblock)
7699
7700
struct instr * instr = & b -> b_instr [i ];
7700
7701
if (instr -> i_except != handler ) {
7701
7702
if (handler != NULL ) {
7702
- RETURN_IF_FALSE (assemble_emit_exception_table_entry (a , start , ioffset , handler ));
7703
+ if (assemble_emit_exception_table_entry (a , start , ioffset , handler ) < 0 ) {
7704
+ return -1 ;
7705
+ }
7703
7706
}
7704
7707
start = ioffset ;
7705
7708
handler = instr -> i_except ;
@@ -7708,9 +7711,11 @@ assemble_exception_table(struct assembler *a, basicblock *entryblock)
7708
7711
}
7709
7712
}
7710
7713
if (handler != NULL ) {
7711
- RETURN_IF_FALSE (assemble_emit_exception_table_entry (a , start , ioffset , handler ));
7714
+ if (assemble_emit_exception_table_entry (a , start , ioffset , handler ) < 0 ) {
7715
+ return -1 ;
7716
+ }
7712
7717
}
7713
- return 1 ;
7718
+ return 0 ;
7714
7719
}
7715
7720
7716
7721
/* Code location emitting code. See locations.md for a description of the format. */
@@ -7813,12 +7818,12 @@ write_location_info_entry(struct assembler* a, struct instr* i, int isize)
7813
7818
if (a -> a_location_off + THEORETICAL_MAX_ENTRY_SIZE >= len ) {
7814
7819
assert (len > THEORETICAL_MAX_ENTRY_SIZE );
7815
7820
if (_PyBytes_Resize (& a -> a_linetable , len * 2 ) < 0 ) {
7816
- return 0 ;
7821
+ return -1 ;
7817
7822
}
7818
7823
}
7819
7824
if (i -> i_loc .lineno < 0 ) {
7820
7825
write_location_info_none (a , isize );
7821
- return 1 ;
7826
+ return 0 ;
7822
7827
}
7823
7828
int line_delta = i -> i_loc .lineno - a -> a_lineno ;
7824
7829
int column = i -> i_loc .col_offset ;
@@ -7829,32 +7834,32 @@ write_location_info_entry(struct assembler* a, struct instr* i, int isize)
7829
7834
if (i -> i_loc .end_lineno == i -> i_loc .lineno || i -> i_loc .end_lineno == -1 ) {
7830
7835
write_location_info_no_column (a , isize , line_delta );
7831
7836
a -> a_lineno = i -> i_loc .lineno ;
7832
- return 1 ;
7837
+ return 0 ;
7833
7838
}
7834
7839
}
7835
7840
else if (i -> i_loc .end_lineno == i -> i_loc .lineno ) {
7836
7841
if (line_delta == 0 && column < 80 && end_column - column < 16 && end_column >= column ) {
7837
7842
write_location_info_short_form (a , isize , column , end_column );
7838
- return 1 ;
7843
+ return 0 ;
7839
7844
}
7840
7845
if (line_delta >= 0 && line_delta < 3 && column < 128 && end_column < 128 ) {
7841
7846
write_location_info_oneline_form (a , isize , line_delta , column , end_column );
7842
7847
a -> a_lineno = i -> i_loc .lineno ;
7843
- return 1 ;
7848
+ return 0 ;
7844
7849
}
7845
7850
}
7846
7851
write_location_info_long_form (a , i , isize );
7847
7852
a -> a_lineno = i -> i_loc .lineno ;
7848
- return 1 ;
7853
+ return 0 ;
7849
7854
}
7850
7855
7851
7856
static int
7852
7857
assemble_emit_location (struct assembler * a , struct instr * i )
7853
7858
{
7854
7859
int isize = instr_size (i );
7855
7860
while (isize > 8 ) {
7856
- if (! write_location_info_entry (a , i , 8 )) {
7857
- return 0 ;
7861
+ if (write_location_info_entry (a , i , 8 ) < 0 ) {
7862
+ return -1 ;
7858
7863
}
7859
7864
isize -= 8 ;
7860
7865
}
@@ -7874,15 +7879,17 @@ assemble_emit(struct assembler *a, struct instr *i)
7874
7879
7875
7880
int size = instr_size (i );
7876
7881
if (a -> a_offset + size >= len / (int )sizeof (_Py_CODEUNIT )) {
7877
- if (len > PY_SSIZE_T_MAX / 2 )
7878
- return 0 ;
7879
- if (_PyBytes_Resize (& a -> a_bytecode , len * 2 ) < 0 )
7880
- return 0 ;
7882
+ if (len > PY_SSIZE_T_MAX / 2 ) {
7883
+ return -1 ;
7884
+ }
7885
+ if (_PyBytes_Resize (& a -> a_bytecode , len * 2 ) < 0 ) {
7886
+ return -1 ;
7887
+ }
7881
7888
}
7882
7889
code = (_Py_CODEUNIT * )PyBytes_AS_STRING (a -> a_bytecode ) + a -> a_offset ;
7883
7890
a -> a_offset += size ;
7884
7891
write_instr (code , i , size );
7885
- return 1 ;
7892
+ return 0 ;
7886
7893
}
7887
7894
7888
7895
static int
@@ -8282,17 +8289,17 @@ merge_const_one(PyObject *const_cache, PyObject **obj)
8282
8289
PyDict_CheckExact (const_cache );
8283
8290
PyObject * key = _PyCode_ConstantKey (* obj );
8284
8291
if (key == NULL ) {
8285
- return 0 ;
8292
+ return -1 ;
8286
8293
}
8287
8294
8288
8295
// t is borrowed reference
8289
8296
PyObject * t = PyDict_SetDefault (const_cache , key , key );
8290
8297
Py_DECREF (key );
8291
8298
if (t == NULL ) {
8292
- return 0 ;
8299
+ return -1 ;
8293
8300
}
8294
8301
if (t == key ) { // obj is new constant.
8295
- return 1 ;
8302
+ return 0 ;
8296
8303
}
8297
8304
8298
8305
if (PyTuple_CheckExact (t )) {
@@ -8301,7 +8308,7 @@ merge_const_one(PyObject *const_cache, PyObject **obj)
8301
8308
}
8302
8309
8303
8310
Py_SETREF (* obj , Py_NewRef (t ));
8304
- return 1 ;
8311
+ return 0 ;
8305
8312
}
8306
8313
8307
8314
// This is in codeobject.c.
@@ -8367,15 +8374,15 @@ makecode(struct compiler *c, struct assembler *a, PyObject *constslist,
8367
8374
if (!names ) {
8368
8375
goto error ;
8369
8376
}
8370
- if (! merge_const_one (c -> c_const_cache , & names )) {
8377
+ if (merge_const_one (c -> c_const_cache , & names ) < 0 ) {
8371
8378
goto error ;
8372
8379
}
8373
8380
8374
8381
consts = PyList_AsTuple (constslist ); /* PyCode_New requires a tuple */
8375
8382
if (consts == NULL ) {
8376
8383
goto error ;
8377
8384
}
8378
- if (! merge_const_one (c -> c_const_cache , & consts )) {
8385
+ if (merge_const_one (c -> c_const_cache , & consts ) < 0 ) {
8379
8386
goto error ;
8380
8387
}
8381
8388
@@ -8426,7 +8433,7 @@ makecode(struct compiler *c, struct assembler *a, PyObject *constslist,
8426
8433
goto error ;
8427
8434
}
8428
8435
8429
- if (! merge_const_one (c -> c_const_cache , & localsplusnames )) {
8436
+ if (merge_const_one (c -> c_const_cache , & localsplusnames ) < 0 ) {
8430
8437
goto error ;
8431
8438
}
8432
8439
con .localsplusnames = localsplusnames ;
@@ -8892,45 +8899,50 @@ assemble(struct compiler *c, int addNone)
8892
8899
assemble_jump_offsets (g -> g_entryblock );
8893
8900
8894
8901
/* Create assembler */
8895
- if (! assemble_init (& a , c -> u -> u_firstlineno ))
8902
+ if (assemble_init (& a , c -> u -> u_firstlineno ) < 0 ) {
8896
8903
goto error ;
8904
+ }
8897
8905
8898
8906
/* Emit code. */
8899
8907
for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
8900
- for (int j = 0 ; j < b -> b_iused ; j ++ )
8901
- if (! assemble_emit (& a , & b -> b_instr [j ]))
8908
+ for (int j = 0 ; j < b -> b_iused ; j ++ ) {
8909
+ if (assemble_emit (& a , & b -> b_instr [j ]) < 0 ) {
8902
8910
goto error ;
8911
+ }
8912
+ }
8903
8913
}
8904
8914
8905
8915
/* Emit location info */
8906
8916
a .a_lineno = c -> u -> u_firstlineno ;
8907
8917
for (basicblock * b = g -> g_entryblock ; b != NULL ; b = b -> b_next ) {
8908
- for (int j = 0 ; j < b -> b_iused ; j ++ )
8909
- if (! assemble_emit_location (& a , & b -> b_instr [j ]))
8918
+ for (int j = 0 ; j < b -> b_iused ; j ++ ) {
8919
+ if (assemble_emit_location (& a , & b -> b_instr [j ]) < 0 ) {
8910
8920
goto error ;
8921
+ }
8922
+ }
8911
8923
}
8912
8924
8913
- if (! assemble_exception_table (& a , g -> g_entryblock )) {
8925
+ if (assemble_exception_table (& a , g -> g_entryblock ) < 0 ) {
8914
8926
goto error ;
8915
8927
}
8916
8928
if (_PyBytes_Resize (& a .a_except_table , a .a_except_table_off ) < 0 ) {
8917
8929
goto error ;
8918
8930
}
8919
- if (! merge_const_one (c -> c_const_cache , & a .a_except_table )) {
8931
+ if (merge_const_one (c -> c_const_cache , & a .a_except_table ) < 0 ) {
8920
8932
goto error ;
8921
8933
}
8922
8934
8923
8935
if (_PyBytes_Resize (& a .a_linetable , a .a_location_off ) < 0 ) {
8924
8936
goto error ;
8925
8937
}
8926
- if (! merge_const_one (c -> c_const_cache , & a .a_linetable )) {
8938
+ if (merge_const_one (c -> c_const_cache , & a .a_linetable ) < 0 ) {
8927
8939
goto error ;
8928
8940
}
8929
8941
8930
8942
if (_PyBytes_Resize (& a .a_bytecode , a .a_offset * sizeof (_Py_CODEUNIT )) < 0 ) {
8931
8943
goto error ;
8932
8944
}
8933
- if (! merge_const_one (c -> c_const_cache , & a .a_bytecode )) {
8945
+ if (merge_const_one (c -> c_const_cache , & a .a_bytecode ) < 0 ) {
8934
8946
goto error ;
8935
8947
}
8936
8948
@@ -8995,7 +9007,7 @@ fold_tuple_on_constants(PyObject *const_cache,
8995
9007
}
8996
9008
PyTuple_SET_ITEM (newconst , i , constant );
8997
9009
}
8998
- if (merge_const_one (const_cache , & newconst ) == 0 ) {
9010
+ if (merge_const_one (const_cache , & newconst ) < 0 ) {
8999
9011
Py_DECREF (newconst );
9000
9012
return -1 ;
9001
9013
}
@@ -9849,17 +9861,17 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
9849
9861
return err ;
9850
9862
}
9851
9863
9852
- static inline int
9864
+ static inline bool
9853
9865
is_exit_without_lineno (basicblock * b ) {
9854
9866
if (!basicblock_exits_scope (b )) {
9855
- return 0 ;
9867
+ return false ;
9856
9868
}
9857
9869
for (int i = 0 ; i < b -> b_iused ; i ++ ) {
9858
9870
if (b -> b_instr [i ].i_loc .lineno >= 0 ) {
9859
- return 0 ;
9871
+ return false ;
9860
9872
}
9861
9873
}
9862
- return 1 ;
9874
+ return true ;
9863
9875
}
9864
9876
9865
9877
/* PEP 626 mandates that the f_lineno of a frame is correct
0 commit comments