bpo-33132: Fix reference counting issues in the compiler. (GH-6209) · python/cpython@a95d986 (original) (raw)
`@@ -2909,9 +2909,7 @@ static int
`
2909
2909
`compiler_from_import(struct compiler *c, stmt_ty s)
`
2910
2910
`{
`
2911
2911
`Py_ssize_t i, n = asdl_seq_LEN(s->v.ImportFrom.names);
`
2912
``
-
2913
``
`-
PyObject *names = PyTuple_New(n);
`
2914
``
`-
PyObject *level;
`
``
2912
`+
PyObject *level, *names;
`
2915
2913
`static PyObject *empty_string;
`
2916
2914
``
2917
2915
`if (!empty_string) {
`
`@@ -2920,14 +2918,15 @@ compiler_from_import(struct compiler *c, stmt_ty s)
`
2920
2918
`return 0;
`
2921
2919
` }
`
2922
2920
``
2923
``
`-
if (!names)
`
2924
``
`-
return 0;
`
2925
``
-
2926
2921
`level = PyLong_FromLong(s->v.ImportFrom.level);
`
2927
2922
`if (!level) {
`
2928
``
`-
Py_DECREF(names);
`
2929
2923
`return 0;
`
2930
2924
` }
`
``
2925
`+
ADDOP_N(c, LOAD_CONST, level, consts);
`
``
2926
+
``
2927
`+
names = PyTuple_New(n);
`
``
2928
`+
if (!names)
`
``
2929
`+
return 0;
`
2931
2930
``
2932
2931
`/* build up the names */
`
2933
2932
`for (i = 0; i < n; i++) {
`
`@@ -2938,16 +2937,12 @@ compiler_from_import(struct compiler *c, stmt_ty s)
`
2938
2937
``
2939
2938
`if (s->lineno > c->c_future->ff_lineno && s->v.ImportFrom.module &&
`
2940
2939
`_PyUnicode_EqualToASCIIString(s->v.ImportFrom.module, "future")) {
`
2941
``
`-
Py_DECREF(level);
`
2942
2940
`Py_DECREF(names);
`
2943
2941
`return compiler_error(c, "from future imports must occur "
`
2944
2942
`"at the beginning of the file");
`
2945
2943
` }
`
``
2944
`+
ADDOP_N(c, LOAD_CONST, names, consts);
`
2946
2945
``
2947
``
`-
ADDOP_O(c, LOAD_CONST, level, consts);
`
2948
``
`-
Py_DECREF(level);
`
2949
``
`-
ADDOP_O(c, LOAD_CONST, names, consts);
`
2950
``
`-
Py_DECREF(names);
`
2951
2946
`if (s->v.ImportFrom.module) {
`
2952
2947
`ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names);
`
2953
2948
` }
`
`@@ -2970,7 +2965,6 @@ compiler_from_import(struct compiler *c, stmt_ty s)
`
2970
2965
`store_name = alias->asname;
`
2971
2966
``
2972
2967
`if (!compiler_nameop(c, store_name, Store)) {
`
2973
``
`-
Py_DECREF(names);
`
2974
2968
`return 0;
`
2975
2969
` }
`
2976
2970
` }
`
`@@ -4739,19 +4733,18 @@ compiler_annassign(struct compiler *c, stmt_ty s)
`
4739
4733
`if (s->v.AnnAssign.simple &&
`
4740
4734
` (c->u->u_scope_type == COMPILER_SCOPE_MODULE ||
`
4741
4735
`c->u->u_scope_type == COMPILER_SCOPE_CLASS)) {
`
4742
``
`-
mangled = _Py_Mangle(c->u->u_private, targ->v.Name.id);
`
4743
``
`-
if (!mangled) {
`
4744
``
`-
return 0;
`
4745
``
`-
}
`
4746
4736
`if (c->c_future->ff_features & CO_FUTURE_ANNOTATIONS) {
`
4747
4737
`VISIT(c, annexpr, s->v.AnnAssign.annotation)
`
4748
4738
` }
`
4749
4739
`else {
`
4750
4740
`VISIT(c, expr, s->v.AnnAssign.annotation);
`
4751
4741
` }
`
4752
4742
`ADDOP_NAME(c, LOAD_NAME, annotations, names);
`
4753
``
`-
ADDOP_O(c, LOAD_CONST, mangled, consts);
`
4754
``
`-
Py_DECREF(mangled);
`
``
4743
`+
mangled = _Py_Mangle(c->u->u_private, targ->v.Name.id);
`
``
4744
`+
if (!mangled) {
`
``
4745
`+
return 0;
`
``
4746
`+
}
`
``
4747
`+
ADDOP_N(c, LOAD_CONST, mangled, consts);
`
4755
4748
`ADDOP(c, STORE_SUBSCR);
`
4756
4749
` }
`
4757
4750
`break;
`