classification
Title: Modules are not deallocated correctly if m_size = -1
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: loewis Nosy List: Arfrever, jak, loewis, pitrou
Priority: normal Keywords:

Created on 2009-07-14 12:03 by jak, last changed 2014-02-03 19:22 by Arfrever.

Files
File name Uploaded Description Edit
test.c jak, 2009-07-14 12:03 Test case.
Messages (5)
msg90514 - (view) Author: Julian Andres Klode (jak) Date: 2009-07-14 12:03
The documentation states that m_size should be -1 if no additional
memory is needed. But this causes the objects inside the module to not
be deallocated at all.

The attached module (test) stores an object of a type 'Test', which
prints "Deallocation is happening" in it's tp_dealloc. If m_size in the
TestModule is set to -1, this is never reached. If it is 0, it is reached.
msg90535 - (view) Author: Julian Andres Klode (jak) Date: 2009-07-15 11:26
I believe this may be related to Python/import.c (l. 592):

   def->m_base.m_copy = PyDict_Copy(dict);

It creates a copy of the module dictionary, but the reference count of
this copy is not decreased when the module object is deallocated, thus
causing the objects contained therein to be not allocated as well.
msg103700 - (view) Author: Julian Andres Klode (jak) Date: 2010-04-20 12:42
This bug still exists in Python 3.1.2.
msg104161 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-04-25 20:54
Well, in 2.x you didn't even have the choice. The dict of an extension module was always copied, becoming essentially immortal. In 3.x you can use an m_size>=0 so as to disable this behaviour.
msg190085 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2013-05-26 12:51
Please correct me if I'm wrong but I believe this applies to all Python 3 versions.
History
Date User Action Args
2014-02-03 19:22:30Arfreversetnosy: + Arfrever
2014-02-03 17:12:08BreamoreBoysetnosy: - BreamoreBoy
2013-05-26 12:51:43BreamoreBoysetnosy: + BreamoreBoy

messages: + msg190085
versions: + Python 3.3, Python 3.4
2010-04-25 20:54:52pitrousetnosy: + pitrou

messages: + msg104161
versions: + Python 3.2
2010-04-20 12:42:02jaksetmessages: + msg103700
2009-07-15 11:26:49jaksetmessages: + msg90535
2009-07-14 14:08:13benjamin.petersonsetassignee: loewis

nosy: + loewis
2009-07-14 12:03:53jakcreate