classification
Title: PyObject_GC_Resize() doesn't relink GCHead
Type: behavior Stage: resolved
Components: Documentation, Interpreter Core Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, inada.naoki, miss-islington, pitrou, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2018-05-20 07:42 by inada.naoki, last changed 2018-05-22 05:33 by inada.naoki. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 7021 merged inada.naoki, 2018-05-21 00:12
PR 7026 merged miss-islington, 2018-05-21 09:36
PR 7027 merged miss-islington, 2018-05-21 09:37
PR 7028 merged miss-islington, 2018-05-21 09:38
Messages (7)
msg317158 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2018-05-20 07:42
https://github.com/python/cpython/blob/master/Modules/gcmodule.c#L1750-L1763

PyObject_GC_Resize() calls PyObject_REALLOC(), which can change object's address.
But it doesn't relinking:

 g->gc.gc_prev->gc.gc_next = g
 g->gc.gc_next->gc.gc_prev = g

So this API can't be used for tracked object.
In CPython code, all callers use this API for non tracked objects.

But if some extension module author used this API for tracked objects, it will cause hard to debug behavior.

Which should we do?

1. Add relinking to PyObject_GC_Resize()
2. Add note in the document

If 1, should we backport it to 3.7 and 3.6?
msg317159 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2018-05-20 09:03
I think we can simply document it.  I don't think anyone has silently buggy code, since it would probably cause a crash as soon as the chain of objects is walked.

If we want to fix PyObject_GC_Resize(), we should check that benchmarks are unaffected.
msg317163 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-05-20 10:42
We can add a check that the object is not tracked and raise a SystemError otherwise. Maybe only in the debug build if it affects performance.
msg317225 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2018-05-21 09:35
New changeset 1179f4b40f375af5c59cd4b6be9cc313fa0e1a37 by INADA Naoki in branch 'master':
bpo-33583: Add note in PyObject_GC_Resize() doc (GH-7021)
https://github.com/python/cpython/commit/1179f4b40f375af5c59cd4b6be9cc313fa0e1a37
msg317234 - (view) Author: miss-islington (miss-islington) Date: 2018-05-21 14:10
New changeset 3ccc31386da5f35f83756a265429831d650db731 by Miss Islington (bot) in branch '2.7':
bpo-33583: Add note in PyObject_GC_Resize() doc (GH-7021)
https://github.com/python/cpython/commit/3ccc31386da5f35f83756a265429831d650db731
msg317239 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2018-05-21 14:51
New changeset 2b4ed5da1d599190c3be0084ee235b0a8f0a75ea by INADA Naoki (Miss Islington (bot)) in branch '3.7':
bpo-33583: Add note in PyObject_GC_Resize() doc (GH-7021)
https://github.com/python/cpython/commit/2b4ed5da1d599190c3be0084ee235b0a8f0a75ea
msg317257 - (view) Author: miss-islington (miss-islington) Date: 2018-05-22 02:18
New changeset 0c1e7d8122808d42f9fdb7019061dc2e78a78efa by Miss Islington (bot) in branch '3.6':
bpo-33583: Add note in PyObject_GC_Resize() doc (GH-7021)
https://github.com/python/cpython/commit/0c1e7d8122808d42f9fdb7019061dc2e78a78efa
History
Date User Action Args
2018-05-22 05:33:08inada.naokisetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-05-22 02:18:49miss-islingtonsetmessages: + msg317257
2018-05-21 14:51:02inada.naokisetmessages: + msg317239
2018-05-21 14:10:30miss-islingtonsetnosy: + miss-islington
messages: + msg317234
2018-05-21 09:38:50miss-islingtonsetpull_requests: + pull_request6676
2018-05-21 09:37:52miss-islingtonsetpull_requests: + pull_request6675
2018-05-21 09:36:50miss-islingtonsetpull_requests: + pull_request6674
2018-05-21 09:35:50inada.naokisetmessages: + msg317225
2018-05-21 00:17:53inada.naokisetassignee: docs@python

nosy: + docs@python
components: + Documentation
versions: + Python 2.7, Python 3.6, Python 3.7, Python 3.8
2018-05-21 00:12:08inada.naokisetkeywords: + patch
stage: patch review
pull_requests: + pull_request6670
2018-05-20 10:42:34serhiy.storchakasetmessages: + msg317163
2018-05-20 09:03:11pitrousetnosy: + serhiy.storchaka, pitrou
messages: + msg317159
2018-05-20 07:42:31inada.naokicreate