bpo-31286, bpo-30024: Fixed stack usage in absolute imports with (#3217) · python/cpython@265fcc5 (original) (raw)

`@@ -2673,28 +2673,34 @@ compiler_import_as(struct compiler *c, identifier name, identifier asname)

`

2673

2673

` If there is a dot in name, we need to split it and emit a

`

2674

2674

` IMPORT_FROM for each name.

`

2675

2675

` */

`

2676

``

`-

Py_ssize_t dot = PyUnicode_FindChar(name, '.', 0,

`

2677

``

`-

PyUnicode_GET_LENGTH(name), 1);

`

``

2676

`+

Py_ssize_t len = PyUnicode_GET_LENGTH(name);

`

``

2677

`+

Py_ssize_t dot = PyUnicode_FindChar(name, '.', 0, len, 1);

`

2678

2678

`if (dot == -2)

`

2679

2679

`return 0;

`

2680

2680

`if (dot != -1) {

`

2681

2681

`/* Consume the base module name to get the first attribute */

`

2682

``

`-

Py_ssize_t pos = dot + 1;

`

2683

``

`-

while (dot != -1) {

`

``

2682

`+

while (1) {

`

``

2683

`+

Py_ssize_t pos = dot + 1;

`

2684

2684

`PyObject *attr;

`

2685

``

`-

dot = PyUnicode_FindChar(name, '.', pos,

`

2686

``

`-

PyUnicode_GET_LENGTH(name), 1);

`

``

2685

`+

dot = PyUnicode_FindChar(name, '.', pos, len, 1);

`

2687

2686

`if (dot == -2)

`

2688

2687

`return 0;

`

2689

``

`-

attr = PyUnicode_Substring(name, pos,

`

2690

``

`-

(dot != -1) ? dot :

`

2691

``

`-

PyUnicode_GET_LENGTH(name));

`

``

2688

`+

attr = PyUnicode_Substring(name, pos, (dot != -1) ? dot : len);

`

2692

2689

`if (!attr)

`

2693

2690

`return 0;

`

2694

2691

`ADDOP_O(c, IMPORT_FROM, attr, names);

`

2695

2692

`Py_DECREF(attr);

`

2696

``

`-

pos = dot + 1;

`

``

2693

`+

if (dot == -1) {

`

``

2694

`+

break;

`

``

2695

`+

}

`

``

2696

`+

ADDOP(c, ROT_TWO);

`

``

2697

`+

ADDOP(c, POP_TOP);

`

2697

2698

` }

`

``

2699

`+

if (!compiler_nameop(c, asname, Store)) {

`

``

2700

`+

return 0;

`

``

2701

`+

}

`

``

2702

`+

ADDOP(c, POP_TOP);

`

``

2703

`+

return 1;

`

2698

2704

` }

`

2699

2705

`return compiler_nameop(c, asname, Store);

`

2700

2706

`}

`