[3.6] bpo-33132: Fix reference counting issues in the compiler. (GH-6… · python/cpython@25c869e (original) (raw)

`@@ -2599,8 +2599,7 @@ compiler_import_as(struct compiler *c, identifier name, identifier asname)

`

2599

2599

`PyUnicode_GET_LENGTH(name));

`

2600

2600

`if (!attr)

`

2601

2601

`return 0;

`

2602

``

`-

ADDOP_O(c, LOAD_ATTR, attr, names);

`

2603

``

`-

Py_DECREF(attr);

`

``

2602

`+

ADDOP_N(c, LOAD_ATTR, attr, names);

`

2604

2603

`pos = dot + 1;

`

2605

2604

` }

`

2606

2605

` }

`

`@@ -2628,8 +2627,7 @@ compiler_import(struct compiler *c, stmt_ty s)

`

2628

2627

`if (level == NULL)

`

2629

2628

`return 0;

`

2630

2629

``

2631

``

`-

ADDOP_O(c, LOAD_CONST, level, consts);

`

2632

``

`-

Py_DECREF(level);

`

``

2630

`+

ADDOP_N(c, LOAD_CONST, level, consts);

`

2633

2631

`ADDOP_O(c, LOAD_CONST, Py_None, consts);

`

2634

2632

`ADDOP_NAME(c, IMPORT_NAME, alias->name, names);

`

2635

2633

``

`@@ -2662,9 +2660,7 @@ static int

`

2662

2660

`compiler_from_import(struct compiler *c, stmt_ty s)

`

2663

2661

`{

`

2664

2662

`Py_ssize_t i, n = asdl_seq_LEN(s->v.ImportFrom.names);

`

2665

``

-

2666

``

`-

PyObject *names = PyTuple_New(n);

`

2667

``

`-

PyObject *level;

`

``

2663

`+

PyObject *level, *names;

`

2668

2664

`static PyObject *empty_string;

`

2669

2665

``

2670

2666

`if (!empty_string) {

`

`@@ -2673,14 +2669,15 @@ compiler_from_import(struct compiler *c, stmt_ty s)

`

2673

2669

`return 0;

`

2674

2670

` }

`

2675

2671

``

2676

``

`-

if (!names)

`

2677

``

`-

return 0;

`

2678

``

-

2679

2672

`level = PyLong_FromLong(s->v.ImportFrom.level);

`

2680

2673

`if (!level) {

`

2681

``

`-

Py_DECREF(names);

`

2682

2674

`return 0;

`

2683

2675

` }

`

``

2676

`+

ADDOP_N(c, LOAD_CONST, level, consts);

`

``

2677

+

``

2678

`+

names = PyTuple_New(n);

`

``

2679

`+

if (!names)

`

``

2680

`+

return 0;

`

2684

2681

``

2685

2682

`/* build up the names */

`

2686

2683

`for (i = 0; i < n; i++) {

`

`@@ -2691,16 +2688,12 @@ compiler_from_import(struct compiler *c, stmt_ty s)

`

2691

2688

``

2692

2689

`if (s->lineno > c->c_future->ff_lineno && s->v.ImportFrom.module &&

`

2693

2690

`_PyUnicode_EqualToASCIIString(s->v.ImportFrom.module, "future")) {

`

2694

``

`-

Py_DECREF(level);

`

2695

2691

`Py_DECREF(names);

`

2696

2692

`return compiler_error(c, "from future imports must occur "

`

2697

2693

`"at the beginning of the file");

`

2698

2694

` }

`

``

2695

`+

ADDOP_N(c, LOAD_CONST, names, consts);

`

2699

2696

``

2700

``

`-

ADDOP_O(c, LOAD_CONST, level, consts);

`

2701

``

`-

Py_DECREF(level);

`

2702

``

`-

ADDOP_O(c, LOAD_CONST, names, consts);

`

2703

``

`-

Py_DECREF(names);

`

2704

2697

`if (s->v.ImportFrom.module) {

`

2705

2698

`ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names);

`

2706

2699

` }

`

`@@ -2723,7 +2716,6 @@ compiler_from_import(struct compiler *c, stmt_ty s)

`

2723

2716

`store_name = alias->asname;

`

2724

2717

``

2725

2718

`if (!compiler_nameop(c, store_name, Store)) {

`

2726

``

`-

Py_DECREF(names);

`

2727

2719

`return 0;

`

2728

2720

` }

`

2729

2721

` }

`

`@@ -3101,8 +3093,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)

`

3101

3093

`"param invalid for local variable");

`

3102

3094

`return 0;

`

3103

3095

` }

`

3104

``

`-

ADDOP_O(c, op, mangled, varnames);

`

3105

``

`-

Py_DECREF(mangled);

`

``

3096

`+

ADDOP_N(c, op, mangled, varnames);

`

3106

3097

`return 1;

`

3107

3098

`case OP_GLOBAL:

`

3108

3099

`switch (ctx) {

`

`@@ -4552,11 +4543,11 @@ compiler_annassign(struct compiler *c, stmt_ty s)

`

4552

4543

`if (s->v.AnnAssign.simple &&

`

4553

4544

` (c->u->u_scope_type == COMPILER_SCOPE_MODULE ||

`

4554

4545

`c->u->u_scope_type == COMPILER_SCOPE_CLASS)) {

`

``

4546

`+

VISIT(c, expr, s->v.AnnAssign.annotation);

`

4555

4547

`mangled = _Py_Mangle(c->u->u_private, targ->v.Name.id);

`

4556

4548

`if (!mangled) {

`

4557

4549

`return 0;

`

4558

4550

` }

`

4559

``

`-

VISIT(c, expr, s->v.AnnAssign.annotation);

`

4560

4551

`/* ADDOP_N decrefs its argument */

`

4561

4552

`ADDOP_N(c, STORE_ANNOTATION, mangled, names);

`

4562

4553

` }

`