diff options
author | Inada Naoki <songofacandy@gmail.com> | 2022-05-04 01:01:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-04 01:01:15 (GMT) |
commit | 6dcfd6c5e3cb46543e82dc3f7234546adf4bb04a (patch) | |
tree | 6cf49503df92190b3ee66eca5b5af7a6f22c61f5 /Python | |
parent | dfb1b9da8a4becaeaed3d9cffcaac41bcaf746f4 (diff) | |
download | cpython-6dcfd6c5e3cb46543e82dc3f7234546adf4bb04a.zip cpython-6dcfd6c5e3cb46543e82dc3f7234546adf4bb04a.tar.gz cpython-6dcfd6c5e3cb46543e82dc3f7234546adf4bb04a.tar.bz2 |
gh-78214: marshal: Stabilize FLAG_REF usage (GH-8226)
Use FLAG_REF always for interned strings.
Refcounts of interned string is very unstable.
When compiling same source, refcounts of interned string in the output may be 1 or >1.
It makes FLAG_REF usage unstable.
To help reproducible build, use FLAG_REF for interned string even if refcnt(obj)==1.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/marshal.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Python/marshal.c b/Python/marshal.c index bbe67e3..90a4405 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -298,9 +298,14 @@ w_ref(PyObject *v, char *flag, WFILE *p) if (p->version < 3 || p->hashtable == NULL) return 0; /* not writing object references */ - /* if it has only one reference, it definitely isn't shared */ - if (Py_REFCNT(v) == 1) + /* If it has only one reference, it definitely isn't shared. + * But we use TYPE_REF always for interned string, to PYC file stable + * as possible. + */ + if (Py_REFCNT(v) == 1 && + !(PyUnicode_CheckExact(v) && PyUnicode_CHECK_INTERNED(v))) { return 0; + } entry = _Py_hashtable_get_entry(p->hashtable, v); if (entry != NULL) { |