classification
Title: inconsistent garbage collector behavior across platforms when using ctypes data-structures
Type: behavior Stage: resolved
Components: ctypes Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, belopolsky, iritkatriel, martin.panter, meador.inge, pitrou, unsec treedee
Priority: normal Keywords:

Created on 2016-04-20 16:04 by unsec treedee, last changed 2021-04-25 17:49 by iritkatriel. This issue is now closed.

Files
File name Uploaded Description Edit
gc_snippet_report_pybug.py unsec treedee, 2016-04-20 16:04 example re-write of python code that exhibits garbage collector inconsistency
Messages (3)
msg263846 - (view) Author: unsec treedee (unsec treedee) Date: 2016-04-20 16:04
The garbage collector is not behaving consistently across platforms for python 2.7.11.

I realize that the example code and style is not proper :-)

On the Mac OSX platform this code runs without the garbage collector "cleaning house" and there is no resulting crash from a NULL pointer.  On the Linux platform the garbage collector decides to "clean house" (deallocates the object) resulting in a NULL pointer which is not handled correctly by the c-function code (some legacy stuff) and causes a segmentation fault.

Temporarily disabling the garbage collector and enabling it later on allows a workaround (valid or not) that is consistent on all platforms.

Improper coding and style aside... the issue I am reporting is the inconsistent behaviour of the garbage collector.  I am looking for consistency across platforms (same result on all platforms).  :-)
msg263863 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-04-20 23:27
You should write your program so that it does not release objects until they are no longer needed, then it can handle the garbage collector running at any time. But it is not clear to me what your offending null pointer is. Your code has lots of pointers that could be null.

Can you provide a complete demonstration, perhaps using a standard function such as libc.printf, rather than your arbitrary function?
msg391863 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-04-25 17:49
I don't think GC is even guaranteed to do exactly the same thing in two different runs on the same platform. If objects are hashed by id (memory address) and then traversed then couldn't the order in which unrelated objects are deleted be non-deterministic?

In any case, 2.7 is no longer maintained. If you can provide a simple repro script for 3.9+, a GC expert may look at it. Open a new issue if you do that.
History
Date User Action Args
2021-04-25 17:49:00iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg391863

resolution: not a bug
stage: test needed -> resolved
2016-04-20 23:27:40martin.pantersetnosy: + martin.panter

messages: + msg263863
stage: test needed
2016-04-20 16:13:38SilentGhostsetnosy: + amaury.forgeotdarc, belopolsky, pitrou, meador.inge
2016-04-20 16:04:28unsec treedeecreate