| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM
I'm not super familiar with the heap type machinery, but this lines up with other examples I've seen. Thanks for updating the argument clinic stuff.
Sorry, something went wrong.
There was a problem hiding this comment.
os.DirEntry() will crash. Prevent the crash and add a test. There should be similar issue with ScandirIteratorType.
See bpo-26979 and related issues for details.
Sorry, something went wrong.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request. |
Sorry, something went wrong.
|
I have made the requested changes; please review again cc @vstinner @ericsnowcurrently @serhiy-storchaka Hi Serihy. Thanks for pointing out the bug, I've updated the change with the appropriate fix.
ProblemMost of the issues in converting a PyType_Ready to a PyType_FromSpec come from implicit assumptions about how these types should behave. This results in missing signals which cause incorrect behavior. For example, uninstantiable types becoming instantiable, the runtime crashing, or refcnt leaks. To understand these issues I have broken down the scenarios that might arise: tp_new is defined and tp_dealloc is defined.Result: Refcnt Leak or Crash Instances are most likely instantiated in Python-land and it uses PyType_GenericAlloc to allocate the instance, increfing the type. However, under the assumption that the type is static, it is likely that tp_dealloc is not decrefing the type. This results in a net refcnt of +1 per object instantiation. tp_new is defined and tp_dealloc is undefined.Result: Correct Behavior Instances are most likely instantiated in Python-land and it uses PyType_GenericAlloc to allocate the instance, increfing the type. tp_dealloc is undefined and will inherit subtype_dealloc which will decref the type. This results in correct behavior. tp_new is undefined and tp_dealloc is defined. Result:Incorrect Behavior This is an uninstantiable type from Python-land. Therefore, instantiation comes directly from PyObject_New{Var}, which won't incref the type. Therefore, the defined tp_dealloc won't decref the type either. However, the side effect is that the signal produced by tp_new being NULL will be lost given that the type will inherit its base object's tp_new. This will now make the type both instantiable and pickable in Python-land. tp_new is undefined and tp_dealloc is unedefined.Result: Crash This is an uninstantiable type from Python-land. Therefore, instantiation comes directly from PyObject_New{Var}, which won't incref the type. However, the undefined tp_dealloc will inherit subtype_dealloc which will decref the type. This results in a net refcnt of -1 per object instantiation, causing a a segfault. SolutionIn order to solve these issues, we need to think of these types as participating in normal refcnting just like any other instance. The following provides a generic solution for all these different scenarios:
Closing BugsThe generic solution proposed here should be able to address all the issues and problems in the following bpos: https://bugs.python.org/issue14936 |
Sorry, something went wrong.
|
Thanks for making the requested changes! @ericsnowcurrently, @serhiy-storchaka: please review the changes made to this pull request. |
Sorry, something went wrong.
| return PyErr_NoMemory(); | ||
| /* Any changes should be reflected in PyObject_INIT (objimpl.h) */ | ||
| Py_TYPE(op) = tp; | ||
| if (PyType_GetFlags(tp) & Py_TPFLAGS_HEAPTYPE) { |
There was a problem hiding this comment.
I am not sure about this part. It will affect all other heap types. It is better to defer it to a separate issue.
Sorry, something went wrong.
There was a problem hiding this comment.
This is really needed for this change. PyTypeObjects should participate in reference counting. Without this change, instantiating a DirEntry or a ScandirIterator will not increase the type's refcount - which is incorrect (since they are now heap-allocated)
This ensures the correct behavior to the newly heap-allocated type. I added it in this place to ensure that any future migration from PyType_Ready to PyType_FromSpec won't have to worry about this anymore.
Sorry, something went wrong.
There was a problem hiding this comment.
To expand on this a bit more, this currently DOES NOT affect any other heap types but the ones changed here (with 1 exception).
There are only 3 ways to access PyObject_{Init,INIT} which are:
For each of these points:
Outside of the exception there should not be any problems with any other heap type.
Exception:
_tkinter.c. The incref was manually added after PyObject_New.
I have the following 3 proposals:
Sorry, something went wrong.
|
Thanks for the review @serhiy-storchaka ! I answered each of the points that you raised and marked the comments as resolved. Please feel free to raise it again if you still feel that I did not fully address either of your comments. |
Sorry, something went wrong.
|
I have made the requested changes; please review again |
Sorry, something went wrong.
|
Thanks for making the requested changes! @serhiy-storchaka, @ericsnowcurrently: please review the changes made to this pull request. |
Sorry, something went wrong.
| assert(op != NULL); | ||
| Py_TYPE(op) = typeobj; | ||
| if (PyType_GetFlags(typeobj) & Py_TPFLAGS_HEAPTYPE) { | ||
| Py_INCREF(typeobj); |
There was a problem hiding this comment.
I don't understand why "convert statically allocated types (DirEntryType & ScandirIteratorType) to heap-allocated types" needs to modify the very important _PyObject_INIT() function. If you want to modify it, would it be possible to do that in a first PR which only modify _PyObject_INIT() (with related changes)?
Sorry, something went wrong.
There was a problem hiding this comment.
Yeah, that makes sense! I just created:
https://bugs.python.org/issue35810
#11661
I will rebase this change once that PR is merged.
Sorry, something went wrong.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request. And if you don't make the requested changes, you will be poked with soft cushions! |
Sorry, something went wrong.
…ython#14568) * bpo-37459: importlib docs improperly reference get_resource_loader()
Fix multiprocessing.util.get_temp_dir() finalizer: clear also the 'tempdir' configuration of the current process, so next call to get_temp_dir() will create a new temporary directory, rather than reusing the removed temporary directory.
To get more info about this change.
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for your contribution, we look forward to reviewing it! |
Sorry, something went wrong.
|
Woops, this change got messed up in a rebase |
Sorry, something went wrong.
After #9665, this moves the remaining types in posixmodule to be heap-allocated to make it compatible with PEP384 as well as modifying all the type accessors to fully make the type opaque. The original PR that got messed up a rebase: #10854. All the issues in that commit have now been addressed since #11661 got committed. This change also removes any state from the data segment and onto the module state itself. https://bugs.python.org/issue35381 Automerge-Triggered-By: @encukou
After python#9665, this moves the remaining types in posixmodule to be heap-allocated to make it compatible with PEP384 as well as modifying all the type accessors to fully make the type opaque. The original PR that got messed up a rebase: python#10854. All the issues in that commit have now been addressed since python#11661 got committed. This change also removes any state from the data segment and onto the module state itself. https://bugs.python.org/issue35381 Automerge-Triggered-By: @encukou
After python#9665, this moves the remaining types in posixmodule to be heap-allocated to make it compatible with PEP384 as well as modifying all the type accessors to fully make the type opaque. The original PR that got messed up a rebase: python#10854. All the issues in that commit have now been addressed since python#11661 got committed. This change also removes any state from the data segment and onto the module state itself. https://bugs.python.org/issue35381 Automerge-Triggered-By: @encukou
| Back | FazBrowse Home | New Git URL |
After #9665, this moves the remaining types in posixmodule to be heap-allocated to make it compatible with PEP384
https://bugs.python.org/issue35381