projects/guix·blob python-team · refs

30 lines · 1.1 KiB

1From 6c8ea7c1dacd42f3ba00440231ec0e6b1a38300d Mon Sep 17 00:00:00 2001
2From: Inada Naoki <[email protected]>
3Date: Sat, 14 Jul 2018 00:46:11 +0900
4Subject: [PATCH] Use FLAG_REF always for interned strings
5
6---
7 Python/marshal.c | 9 +++++++--
8 1 file changed, 7 insertions(+), 2 deletions(-)
9
10diff --git a/Python/marshal.c b/Python/marshal.c
11index 6d06266c6a8e2e..51db2e3b2e29a2 100644
12--- a/Python/marshal.c
13+++ b/Python/marshal.c
14@@ -275,9 +275,14 @@ w_ref(PyObject *v, char *flag, WFILE *p)
15 if (p->version < 3 || p->hashtable == NULL)
16 return 0; /* not writing object references */
17
18- /* if it has only one reference, it definitely isn't shared */
19- if (Py_REFCNT(v) == 1)
20+ /* If it has only one reference, it definitely isn't shared.
21+ * But we use TYPE_REF always for interned string, to PYC file stable
22+ * as possible.
23+ */
24+ if (Py_REFCNT(v) == 1 &&
25+ !(PyUnicode_CheckExact(v) && PyUnicode_CHECK_INTERNED(v))) {
26 return 0;
27+ }
28
29 entry = _Py_HASHTABLE_GET_ENTRY(p->hashtable, v);
30 if (entry != NULL) {