STINNER Victor <vstin...@python.org> added the comment:

> New changeset ea251806b8dffff11b30d2182af1e589caf88acf by Victor Stinner in 
> branch 'master':
> bpo-40521: Per-interpreter interned strings (GH-20085)

I reopen the issue. This change caused a regression in attached 
interned_bug.py. Output:
---
$ ./python interned_bug.py 
Exception ignored deletion of interned string failed:
KeyError: 'out of memory'
python: Objects/unicodeobject.c:1946: unicode_dealloc: Assertion 
`Py_REFCNT(unicode) == 1' failed.
Abandon (core dumped)
---

Running "import xml.parsers.expat" in a subinterpreter causes two issues when 
the subinterpreter completes:

* pyexpat.errors and pyexpat.model dictionaries are cleared: all values set to 
None
* unicode_dealloc() logs an error on an interned string in the subinterpreter, 
because the string doesn't exist in the subinterpreter interned dictionary.

The interned string is created in the main interpreter and so stored in the 
main interpreter interned dictionary.

The string is stored in 2 dictionaries of pyexpat.errors dictionaries:

>>> pyexpat.errors.messages[1]
'out of memory'
>>> pyexpat.errors.codes['out of memory']
1

When the subinterpreter clears pyexpat.errors and pyexpat.model dictionaries, 
the interned string is deleted: unicode_dealloc() is called. But 
unicode_dealloc() fails to delete the interned string in the subinterpreter 
interned dictionary.

pyexpat.errors and pyexpat.model modules are cleared because they are stored as 
different names in sys.modules by Lib/xml/parsers/expat.py:

sys.modules['xml.parsers.expat.model'] = model
sys.modules['xml.parsers.expat.errors'] = errors

----------
resolution: fixed -> 
status: closed -> open
Added file: https://bugs.python.org/file49699/interned_bug.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40521>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to