[issue44531] Add _PyType_AllocNoTrack() function: allocate without tracking in the GC

2021-09-21 Thread STINNER Victor


Change by STINNER Victor :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44531] Add _PyType_AllocNoTrack() function: allocate without tracking in the GC

2021-06-30 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 818628c2da99ba0376313971816d472c65c9a9fc by Victor Stinner in 
branch 'main':
bpo-44531: Add _PyType_AllocNoTrack() function (GH-26947)
https://github.com/python/cpython/commit/818628c2da99ba0376313971816d472c65c9a9fc


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44531] Add _PyType_AllocNoTrack() function: allocate without tracking in the GC

2021-06-29 Thread STINNER Victor


STINNER Victor  added the comment:

For the background of this issue, please see bpo-38392:
https://bugs.python.org/issue38392#msg354074

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44531] Add _PyType_AllocNoTrack() function: allocate without tracking in the GC

2021-06-29 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

> About subclasses, I'm not sure if it's safe to call the traverse function if 
> a subclass overrides it and visits its own member which are not in the 
> built-in type (like dict or tuple).

Technically the traverse should only call visit on the members, but in practice 
they can do whatever. I agree is not clear is a safe operation

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44531] Add _PyType_AllocNoTrack() function: allocate without tracking in the GC

2021-06-29 Thread STINNER Victor


STINNER Victor  added the comment:

> How is that going to help third party extensions and subclasses?

It doesn't solve bpo-40142 issue for third party extensions.

About subclasses, I'm not sure if it's safe to call the traverse function if a 
subclass overrides it and visits its own member which are not in the built-in 
type (like dict or tuple).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44531] Add _PyType_AllocNoTrack() function: allocate without tracking in the GC

2021-06-29 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 823460daa9fab3d0cf00ec553d1e35635ef73d40 by Victor Stinner in 
branch 'main':
bpo-44531: Fix type_repr() if tp_name is NULL (GH-26948)
https://github.com/python/cpython/commit/823460daa9fab3d0cf00ec553d1e35635ef73d40


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44531] Add _PyType_AllocNoTrack() function: allocate without tracking in the GC

2021-06-29 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

> Anyway, I propose to add a new _PyType_AllocNoTrack() function which 
> allocates memory without tracking the newly allocated object directly in the 
> GC.

How is that going to help third party extensions and subclasses?

--
nosy: +pablogsal

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44531] Add _PyType_AllocNoTrack() function: allocate without tracking in the GC

2021-06-28 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +25515
pull_request: https://github.com/python/cpython/pull/26948

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44531] Add _PyType_AllocNoTrack() function: allocate without tracking in the GC

2021-06-28 Thread STINNER Victor


STINNER Victor  added the comment:

In bpo-40142, I tried to modify _PyObject_GC_TRACK() to visit the object before 
tracking it, as done by PyObject_GC_Track().

Problem: PyType_GenericAlloc() cannot traverse the object since the object 
members are not initialized yet. For example, dict_traverse() can only be 
called at dict_new() exit.

Here I propose a different approach. First, fix built-in types to only track 
instances when they are fully initialized. Avoid PyType_GenericAlloc().

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44531] Add _PyType_AllocNoTrack() function: allocate without tracking in the GC

2021-06-28 Thread STINNER Victor


Change by STINNER Victor :


--
keywords: +patch
pull_requests: +25514
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26947

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44531] Add _PyType_AllocNoTrack() function: allocate without tracking in the GC

2021-06-28 Thread STINNER Victor


New submission from STINNER Victor :

The PyType_GenericAlloc() function tracks the newly created object in the 
garbage collector (GC) as soon as memory is initialized, but before all object 
members are initialized.

If a GC collection happens before the object is fully initialized, the traverse 
function of the newly created object can crash.

This case is hypothetical for built-in types since their constructor should not 
trigger a GC collection. It is more likely in third party extensions and 
subclasses.

Anyway, I propose to add a new _PyType_AllocNoTrack() function which allocates 
memory without tracking the newly allocated object directly in the GC.

This function can be used to only track explicitly the object in the GC once it 
is fully initialized.

--
components: C API
messages: 396695
nosy: vstinner
priority: normal
severity: normal
status: open
title: Add _PyType_AllocNoTrack() function: allocate without tracking in the GC
versions: Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com