@@ -505,21 +505,35 @@ dictbytype(PyObject *src, int scope_type, int flag, Py_ssize_t offset)
505
505
deterministic, then the generated bytecode is not deterministic.
506
506
*/
507
507
sorted_keys = PyDict_Keys (src );
508
- if (sorted_keys == NULL )
508
+ if (sorted_keys == NULL ) {
509
+ Py_DECREF (dest );
509
510
return NULL ;
511
+ }
510
512
if (PyList_Sort (sorted_keys ) != 0 ) {
511
513
Py_DECREF (sorted_keys );
514
+ Py_DECREF (dest );
512
515
return NULL ;
513
516
}
514
517
num_keys = PyList_GET_SIZE (sorted_keys );
515
518
516
519
for (key_i = 0 ; key_i < num_keys ; key_i ++ ) {
517
- /* XXX this should probably be a macro in symtable.h */
518
- long vi ;
519
520
k = PyList_GET_ITEM (sorted_keys , key_i );
520
521
v = PyDict_GetItemWithError (src , k );
521
- assert (v && PyLong_Check (v ));
522
- vi = PyLong_AS_LONG (v );
522
+ if (!v ) {
523
+ if (!PyErr_Occurred ()) {
524
+ PyErr_SetObject (PyExc_KeyError , k );
525
+ }
526
+ Py_DECREF (sorted_keys );
527
+ Py_DECREF (dest );
528
+ return NULL ;
529
+ }
530
+ long vi = PyLong_AsLong (v );
531
+ if (vi == -1 && PyErr_Occurred ()) {
532
+ Py_DECREF (sorted_keys );
533
+ Py_DECREF (dest );
534
+ return NULL ;
535
+ }
536
+ /* XXX this should probably be a macro in symtable.h */
523
537
scope = (vi >> SCOPE_OFFSET ) & SCOPE_MASK ;
524
538
525
539
if (scope == scope_type || vi & flag ) {
@@ -631,6 +645,7 @@ compiler_set_qualname(struct compiler *c)
631
645
632
646
scope = _PyST_GetScope (parent -> u_ste , mangled );
633
647
Py_DECREF (mangled );
648
+ RETURN_IF_ERROR (scope );
634
649
assert (scope != GLOBAL_IMPLICIT );
635
650
if (scope == GLOBAL_EXPLICIT )
636
651
force_global = 1 ;
@@ -1648,7 +1663,7 @@ dict_lookup_arg(PyObject *dict, PyObject *name)
1648
1663
if (v == NULL ) {
1649
1664
return ERROR ;
1650
1665
}
1651
- return PyLong_AS_LONG (v );
1666
+ return PyLong_AsLong (v );
1652
1667
}
1653
1668
1654
1669
static int
@@ -1671,7 +1686,7 @@ compiler_lookup_arg(struct compiler *c, PyCodeObject *co, PyObject *name)
1671
1686
else {
1672
1687
arg = dict_lookup_arg (c -> u -> u_metadata .u_freevars , name );
1673
1688
}
1674
- if (arg == -1 ) {
1689
+ if (arg == -1 && ! PyErr_Occurred () ) {
1675
1690
PyObject * freevars = _PyCode_GetFreevars (co );
1676
1691
if (freevars == NULL ) {
1677
1692
PyErr_Clear ();
@@ -4085,6 +4100,8 @@ compiler_nameop(struct compiler *c, location loc,
4085
4100
case GLOBAL_EXPLICIT :
4086
4101
optype = OP_GLOBAL ;
4087
4102
break ;
4103
+ case -1 :
4104
+ goto error ;
4088
4105
default :
4089
4106
/* scope can be 0 */
4090
4107
break ;
@@ -4638,6 +4655,7 @@ is_import_originated(struct compiler *c, expr_ty e)
4638
4655
}
4639
4656
4640
4657
long flags = _PyST_GetSymbol (SYMTABLE (c )-> st_top , e -> v .Name .id );
4658
+ RETURN_IF_ERROR (flags );
4641
4659
return flags & DEF_IMPORT ;
4642
4660
}
4643
4661
@@ -4657,10 +4675,12 @@ can_optimize_super_call(struct compiler *c, expr_ty attr)
4657
4675
PyObject * super_name = e -> v .Call .func -> v .Name .id ;
4658
4676
// detect statically-visible shadowing of 'super' name
4659
4677
int scope = _PyST_GetScope (SYMTABLE_ENTRY (c ), super_name );
4678
+ RETURN_IF_ERROR (scope );
4660
4679
if (scope != GLOBAL_IMPLICIT ) {
4661
4680
return 0 ;
4662
4681
}
4663
4682
scope = _PyST_GetScope (SYMTABLE (c )-> st_top , super_name );
4683
+ RETURN_IF_ERROR (scope );
4664
4684
if (scope != 0 ) {
4665
4685
return 0 ;
4666
4686
}
@@ -4767,7 +4787,9 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
4767
4787
}
4768
4788
4769
4789
/* Check that the base object is not something that is imported */
4770
- if (is_import_originated (c , meth -> v .Attribute .value )) {
4790
+ int ret = is_import_originated (c , meth -> v .Attribute .value );
4791
+ RETURN_IF_ERROR (ret );
4792
+ if (ret ) {
4771
4793
return 0 ;
4772
4794
}
4773
4795
@@ -4795,7 +4817,9 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
4795
4817
/* Alright, we can optimize the code. */
4796
4818
location loc = LOC (meth );
4797
4819
4798
- if (can_optimize_super_call (c , meth )) {
4820
+ ret = can_optimize_super_call (c , meth );
4821
+ RETURN_IF_ERROR (ret );
4822
+ if (ret ) {
4799
4823
RETURN_IF_ERROR (load_args_for_super (c , meth -> v .Attribute .value ));
4800
4824
int opcode = asdl_seq_LEN (meth -> v .Attribute .value -> v .Call .args ) ?
4801
4825
LOAD_SUPER_METHOD : LOAD_ZERO_SUPER_METHOD ;
@@ -5367,8 +5391,10 @@ push_inlined_comprehension_state(struct compiler *c, location loc,
5367
5391
PyObject * k , * v ;
5368
5392
Py_ssize_t pos = 0 ;
5369
5393
while (PyDict_Next (entry -> ste_symbols , & pos , & k , & v )) {
5370
- assert (PyLong_Check (v ));
5371
- long symbol = PyLong_AS_LONG (v );
5394
+ long symbol = PyLong_AsLong (v );
5395
+ if (symbol == -1 && PyErr_Occurred ()) {
5396
+ return ERROR ;
5397
+ }
5372
5398
long scope = (symbol >> SCOPE_OFFSET ) & SCOPE_MASK ;
5373
5399
PyObject * outv = PyDict_GetItemWithError (SYMTABLE_ENTRY (c )-> ste_symbols , k );
5374
5400
if (outv == NULL ) {
@@ -5377,8 +5403,11 @@ push_inlined_comprehension_state(struct compiler *c, location loc,
5377
5403
}
5378
5404
outv = _PyLong_GetZero ();
5379
5405
}
5380
- assert (PyLong_CheckExact (outv ));
5381
- long outsc = (PyLong_AS_LONG (outv ) >> SCOPE_OFFSET ) & SCOPE_MASK ;
5406
+ long outsymbol = PyLong_AsLong (outv );
5407
+ if (outsymbol == -1 && PyErr_Occurred ()) {
5408
+ return ERROR ;
5409
+ }
5410
+ long outsc = (outsymbol >> SCOPE_OFFSET ) & SCOPE_MASK ;
5382
5411
// If a name has different scope inside than outside the comprehension,
5383
5412
// we need to temporarily handle it with the right scope while
5384
5413
// compiling the comprehension. If it's free in the comprehension
@@ -6064,14 +6093,18 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
6064
6093
return compiler_formatted_value (c , e );
6065
6094
/* The following exprs can be assignment targets. */
6066
6095
case Attribute_kind :
6067
- if (e -> v .Attribute .ctx == Load && can_optimize_super_call (c , e )) {
6068
- RETURN_IF_ERROR (load_args_for_super (c , e -> v .Attribute .value ));
6069
- int opcode = asdl_seq_LEN (e -> v .Attribute .value -> v .Call .args ) ?
6070
- LOAD_SUPER_ATTR : LOAD_ZERO_SUPER_ATTR ;
6071
- ADDOP_NAME (c , loc , opcode , e -> v .Attribute .attr , names );
6072
- loc = update_start_location_to_match_attr (c , loc , e );
6073
- ADDOP (c , loc , NOP );
6074
- return SUCCESS ;
6096
+ if (e -> v .Attribute .ctx == Load ) {
6097
+ int ret = can_optimize_super_call (c , e );
6098
+ RETURN_IF_ERROR (ret );
6099
+ if (ret ) {
6100
+ RETURN_IF_ERROR (load_args_for_super (c , e -> v .Attribute .value ));
6101
+ int opcode = asdl_seq_LEN (e -> v .Attribute .value -> v .Call .args ) ?
6102
+ LOAD_SUPER_ATTR : LOAD_ZERO_SUPER_ATTR ;
6103
+ ADDOP_NAME (c , loc , opcode , e -> v .Attribute .attr , names );
6104
+ loc = update_start_location_to_match_attr (c , loc , e );
6105
+ ADDOP (c , loc , NOP );
6106
+ return SUCCESS ;
6107
+ }
6075
6108
}
6076
6109
RETURN_IF_ERROR (compiler_maybe_add_static_attribute_to_class (c , e ));
6077
6110
VISIT (c , expr , e -> v .Attribute .value );
@@ -7300,7 +7333,8 @@ consts_dict_keys_inorder(PyObject *dict)
7300
7333
if (consts == NULL )
7301
7334
return NULL ;
7302
7335
while (PyDict_Next (dict , & pos , & k , & v )) {
7303
- i = PyLong_AS_LONG (v );
7336
+ assert (PyLong_CheckExact (v ));
7337
+ i = PyLong_AsLong (v );
7304
7338
/* The keys of the dictionary can be tuples wrapping a constant.
7305
7339
* (see dict_add_o and _PyCode_ConstantKey). In that case
7306
7340
* the object we want is always second. */
0 commit comments