Skip to content

Commit 6c8ea7c

Browse files
committed
Use FLAG_REF always for interned strings
1 parent cafaf04 commit 6c8ea7c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Python/marshal.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,14 @@ w_ref(PyObject *v, char *flag, WFILE *p)
275275
if (p->version < 3 || p->hashtable == NULL)
276276
return 0; /* not writing object references */
277277

278-
/* if it has only one reference, it definitely isn't shared */
279-
if (Py_REFCNT(v) == 1)
278+
/* If it has only one reference, it definitely isn't shared.
279+
* But we use TYPE_REF always for interned string, to PYC file stable
280+
* as possible.
281+
*/
282+
if (Py_REFCNT(v) == 1 &&
283+
!(PyUnicode_CheckExact(v) && PyUnicode_CHECK_INTERNED(v))) {
280284
return 0;
285+
}
281286

282287
entry = _Py_HASHTABLE_GET_ENTRY(p->hashtable, v);
283288
if (entry != NULL) {

0 commit comments

Comments
 (0)