-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-43916: Add _PyType_DisabledNew to prevent new heap types from being created uninitialised #25653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the state->typeobject->tp_new
approach. It looks like a hack. Does this work?
keyobject_type_slots[] = {
{Py_tp_null, NULL},
...
}
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 don't like it either, but that's how it has been fixed earlier.
Unfortunately, no. Also, How about this:
Feels less like a hack, and will be easily greppable. |
Yes, that would be my preferred solution. We have |
I like it, but I think we should add it as cc. @pablogsal |
Doesn't this change require a news entry? |
@tiran @pablogsal: Disabling the constructor is commonly used in Python, so I would not be surprised if this feature would be needed outside CPython code base. I'm fine with adding directly a public function. I understand that @tiran is ok with that, what about you @pablogsal? |
I am still -1, this can be done manually and I prefer to stop growing the C-API when possible unless is very clear that is needed, like with the GC functions. |
@pablogsal: Sorry, I missed your earlier comment "Can we move this to the inernal API maybe? @vstinner what do you think?". Ok, let's keep it internal for now. We can revisit that later. |
All right. I need help landing this PR; see my questions regarding Perhaps it would be easier if I split it up in three:
It up to the reviewers :) |
This time the error is FSCTL_SET_REPARSE_POINT not found |
Try |
Looks like |
The fix is similar to the issue in Lines 15 to 24 in 1e7b858
There's a conflict between pycore_condvar.h and windows.h . The former is implicitly included via pycore_object.h . The solution is to reorder the includes.
If a missing Windows include was the problem, the Windows build would have been broken all over. |
@pablogsal, @vstinner: I've marked this as ready for review. Test coverage is not complete, but I'm not sure how much time we should put into extracting all the implementation specific types; they are normally hidden from the APIs anyway, and one really has to put an effort into snatching the type and then trying to create it uninitialised. Consenting adults and so on. I refer to Pablos's comment regarding my problems with declaring @tiran will take care of his stuff, presumably in a separate PR. I still think the PR is too large, but that's up to you two to decide :) BTW, |
Urks, |
I can use |
I have opened PR GH-25713 to address the problem. I'll rebase my PR after you have landed your PR. Let's land your PR first. |
Thank you, Christian! |
Thanks for reviewing, @tiran. I have made the requested changes; please review again. |
Thanks for making the requested changes! @tiran: please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, good work!
@pablogsal @vstinner Do you want to double check the PR or should I merge it? |
Thanks! Actually, you should add attribution to yourself; I've based the core solution off of your work :) |
@@ -58,6 +58,13 @@ def tearDown(self): | |||
os_helper.unlink(teardown_file) | |||
self._warnings_manager.__exit__(None, None, None) | |||
|
|||
@support.cpython_only | |||
def test_uninitialised_new(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is already tested in test_os
.
I propose a different solution: PR #25721 adds Py_TPFLAGS_DISABLE_NEW type flag. |
Closing in favour of #25721 |
TODO
missing multibytecodec tests: suggesting to drop thismissing _functools._lru_list_elem test: suggesting to drop thismissing _thread._localdummy test: suggesting to drop thiswhat's newUPDATE: Draft NEWS entry addedextern
iso.PyAPI_FUNC
: bpo-43916: Add _PyType_DisabledNew to prevent new heap types from being created uninitialised #25653 (comment)Py_BUILD_CORE
is not set on Travishttps://bugs.python.org/issue43916