Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4328dc6

Browse files
authored
gh-105927: finalize_modules_clear_weaklist() uses _PyWeakref_GET_REF() (#105971)
finalize_modules_clear_weaklist() now holds a strong reference to themodule longer than before: replace PyWeakref_GET_OBJECT() with_PyWeakref_GET_REF().
1 parentfc32522 commit4328dc6

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

‎Include/internal/pycore_moduleobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static inline PyObject* _PyModule_GetDict(PyObject *mod) {
3333
PyObject*dict= ((PyModuleObject*)mod)->md_dict;
3434
// _PyModule_GetDict(mod) must not be used after calling module_clear(mod)
3535
assert(dict!=NULL);
36-
returndict;
36+
returndict;// borrowed reference
3737
}
3838

3939
PyObject*_Py_module_getattro_impl(PyModuleObject*m,PyObject*name,intsuppress);

‎Objects/moduleobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ PyModule_GetDict(PyObject *m)
504504
PyErr_BadInternalCall();
505505
returnNULL;
506506
}
507-
return_PyModule_GetDict(m);
507+
return_PyModule_GetDict(m);// borrowed reference
508508
}
509509

510510
PyObject*

‎Python/pylifecycle.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include"pycore_typeobject.h"// _PyTypes_InitTypes()
2929
#include"pycore_typevarobject.h"// _Py_clear_generic_types()
3030
#include"pycore_unicodeobject.h"// _PyUnicode_InitTypes()
31+
#include"pycore_weakref.h"// _PyWeakref_GET_REF()
3132
#include"opcode.h"
3233

3334
#include<locale.h>// setlocale()
@@ -1464,16 +1465,16 @@ finalize_modules_clear_weaklist(PyInterpreterState *interp,
14641465
for (Py_ssize_ti=PyList_GET_SIZE(weaklist)-1;i >=0;i--) {
14651466
PyObject*tup=PyList_GET_ITEM(weaklist,i);
14661467
PyObject*name=PyTuple_GET_ITEM(tup,0);
1467-
PyObject*mod=PyWeakref_GET_OBJECT(PyTuple_GET_ITEM(tup,1));
1468-
if (mod==Py_None) {
1468+
PyObject*mod=_PyWeakref_GET_REF(PyTuple_GET_ITEM(tup,1));
1469+
if (mod==NULL) {
14691470
continue;
14701471
}
14711472
assert(PyModule_Check(mod));
1472-
PyObject*dict=PyModule_GetDict(mod);
1473+
PyObject*dict=_PyModule_GetDict(mod);// borrowed reference
14731474
if (dict==interp->builtins||dict==interp->sysdict) {
1475+
Py_DECREF(mod);
14741476
continue;
14751477
}
1476-
Py_INCREF(mod);
14771478
if (verbose&&PyUnicode_Check(name)) {
14781479
PySys_FormatStderr("# cleanup[3] wiping %U\n",name);
14791480
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp