bpo-30860: Fix a refleak. (#3506) · python/cpython@8728018 (original) (raw)

`@@ -36,12 +36,14 @@ extern const char *PyWin_DLLVersionString;

`

36

36

``

37

37

`Py_IDENTIFIER();

`

38

38

`_Py_IDENTIFIER(sizeof);

`

``

39

`+

_Py_IDENTIFIER(_xoptions);

`

39

40

`_Py_IDENTIFIER(buffer);

`

40

41

`_Py_IDENTIFIER(builtins);

`

41

42

`_Py_IDENTIFIER(encoding);

`

42

43

`_Py_IDENTIFIER(path);

`

43

44

`_Py_IDENTIFIER(stdout);

`

44

45

`_Py_IDENTIFIER(stderr);

`

``

46

`+

_Py_IDENTIFIER(warnoptions);

`

45

47

`_Py_IDENTIFIER(write);

`

46

48

``

47

49

`PyObject *

`

`@@ -1479,21 +1481,25 @@ list_builtin_module_names(void)

`

1479

1481

`static PyObject *

`

1480

1482

`get_warnoptions(void)

`

1481

1483

`{

`

1482

``

`-

PyObject *warnoptions = PyThreadState_GET()->interp->warnoptions;

`

``

1484

`+

PyObject *warnoptions = _PySys_GetObjectId(&PyId_warnoptions);

`

1483

1485

`if (warnoptions == NULL || !PyList_Check(warnoptions)) {

`

1484

1486

`Py_XDECREF(warnoptions);

`

1485

1487

`warnoptions = PyList_New(0);

`

1486

1488

`if (warnoptions == NULL)

`

1487

1489

`return NULL;

`

1488

``

`-

PyThreadState_GET()->interp->warnoptions = warnoptions;

`

``

1490

`+

if (_PySys_SetObjectId(&PyId_warnoptions, warnoptions)) {

`

``

1491

`+

Py_DECREF(warnoptions);

`

``

1492

`+

return NULL;

`

``

1493

`+

}

`

``

1494

`+

Py_DECREF(warnoptions);

`

1489

1495

` }

`

1490

1496

`return warnoptions;

`

1491

1497

`}

`

1492

1498

``

1493

1499

`void

`

1494

1500

`PySys_ResetWarnOptions(void)

`

1495

1501

`{

`

1496

``

`-

PyObject *warnoptions = PyThreadState_GET()->interp->warnoptions;

`

``

1502

`+

PyObject *warnoptions = _PySys_GetObjectId(&PyId_warnoptions);

`

1497

1503

`if (warnoptions == NULL || !PyList_Check(warnoptions))

`

1498

1504

`return;

`

1499

1505

`PyList_SetSlice(warnoptions, 0, PyList_GET_SIZE(warnoptions), NULL);

`

`@@ -1522,20 +1528,24 @@ PySys_AddWarnOption(const wchar_t *s)

`

1522

1528

`int

`

1523

1529

`PySys_HasWarnOptions(void)

`

1524

1530

`{

`

1525

``

`-

PyObject *warnoptions = PyThreadState_GET()->interp->warnoptions;

`

``

1531

`+

PyObject *warnoptions = _PySys_GetObjectId(&PyId_warnoptions);

`

1526

1532

`return (warnoptions != NULL && (PyList_Size(warnoptions) > 0)) ? 1 : 0;

`

1527

1533

`}

`

1528

1534

``

1529

1535

`static PyObject *

`

1530

1536

`get_xoptions(void)

`

1531

1537

`{

`

1532

``

`-

PyObject *xoptions = PyThreadState_GET()->interp->xoptions;

`

``

1538

`+

PyObject *xoptions = _PySys_GetObjectId(&PyId__xoptions);

`

1533

1539

`if (xoptions == NULL || !PyDict_Check(xoptions)) {

`

1534

1540

`Py_XDECREF(xoptions);

`

1535

1541

`xoptions = PyDict_New();

`

1536

1542

`if (xoptions == NULL)

`

1537

1543

`return NULL;

`

1538

``

`-

PyThreadState_GET()->interp->xoptions = xoptions;

`

``

1544

`+

if (_PySys_SetObjectId(&PyId__xoptions, xoptions)) {

`

``

1545

`+

Py_DECREF(xoptions);

`

``

1546

`+

return NULL;

`

``

1547

`+

}

`

``

1548

`+

Py_DECREF(xoptions);

`

1539

1549

` }

`

1540

1550

`return xoptions;

`

1541

1551

`}

`

`@@ -2084,16 +2094,6 @@ _PySys_BeginInit(void)

`

2084

2094

`#undef SET_SYS_FROM_STRING_BORROW

`

2085

2095

``

2086

2096

`/* Updating the sys namespace, returning integer error codes */

`

2087

``

`-

#define SET_SYS_FROM_STRING_BORROW_INT_RESULT(key, value) \

`

2088

``

`-

do { \

`

2089

``

`-

PyObject *v = (value); \

`

2090

``

`-

if (v == NULL) \

`

2091

``

`-

return -1; \

`

2092

``

`-

res = PyDict_SetItemString(sysdict, key, v); \

`

2093

``

`-

if (res < 0) { \

`

2094

``

`-

return res; \

`

2095

``

`-

} \

`

2096

``

`-

} while (0)

`

2097

2097

`#define SET_SYS_FROM_STRING_INT_RESULT(key, value) \

`

2098

2098

` do { \

`

2099

2099

` PyObject *v = (value); \

`

`@@ -2138,23 +2138,18 @@ _PySys_EndInit(PyObject *sysdict)

`

2138

2138

`SET_SYS_FROM_STRING_INT_RESULT("base_exec_prefix",

`

2139

2139

`PyUnicode_FromWideChar(Py_GetExecPrefix(), -1));

`

2140

2140

``

2141

``

`-

PyObject *warnoptions = get_warnoptions();

`

2142

``

`-

if (warnoptions == NULL)

`

``

2141

`+

if (get_warnoptions() == NULL)

`

2143

2142

`return -1;

`

2144

``

`-

SET_SYS_FROM_STRING_BORROW_INT_RESULT("warnoptions", warnoptions);

`

2145

2143

``

2146

``

`-

PyObject *xoptions = get_xoptions();

`

2147

``

`-

if (xoptions == NULL)

`

``

2144

`+

if (get_xoptions() == NULL)

`

2148

2145

`return -1;

`

2149

``

`-

SET_SYS_FROM_STRING_BORROW_INT_RESULT("_xoptions", xoptions);

`

2150

2146

``

2151

2147

`if (PyErr_Occurred())

`

2152

2148

`return -1;

`

2153

2149

`return 0;

`

2154

2150

`}

`

2155

2151

``

2156

2152

`#undef SET_SYS_FROM_STRING_INT_RESULT

`

2157

``

`-

#undef SET_SYS_FROM_STRING_BORROW_INT_RESULT

`

2158

2153

``

2159

2154

`static PyObject *

`

2160

2155

`makepathobject(const wchar_t *path, wchar_t delim)

`