-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-37732: Fix GCC warning in _PyObject_Malloc() #15333
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
pymalloc_alloc() now returns directly the pointer, return NULL on memory allocation error. allocate_from_new_pool() already uses NULL as marker for "allocation failed".
PR #15309 proposes a different fix: always initialize ptr to NULL. This change is only needed to make GCC warning quiet, whereas ptr is always initialized. My change rewrites the code to avoid the warning without adding an useless initialization. Note: I wrote the
|
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, but one check is redundant now.
if (LIKELY(pool != pool->nextpool)) { | ||
/* | ||
* There is a used pool for this size class. | ||
* Pick up the head block of its free list. | ||
*/ | ||
++pool->ref.count; | ||
bp = pool->freeblock; | ||
assert(bp != NULL); | ||
|
||
if (UNLIKELY((pool->freeblock = *(block **)bp) == NULL)) { | ||
// Reached the end of the free list, try to extend it. |
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's better to use comment style "/* */" instead of "//" here,to ensure consistent context.
// Reached the end of the free list, try to extend it. | |
/* Reached the end of the free list, try to extend it. | |
*/ |
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.
This code was likely written before PEP 7 was updated to allow a subset of C99. My PR doesn't add these comments ;-)
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
Sorry, @vstinner, I could not cleanly backport this to |
Sorry @vstinner, I had trouble checking out the |
👍 |
GH-15342 is a backport of this pull request to the 3.8 branch. |
pymalloc_alloc() now returns directly the pointer, return NULL on memory allocation error. allocate_from_new_pool() already uses NULL as marker for "allocation failed".
pymalloc_alloc() now returns directly the pointer, return NULL on memory allocation error. allocate_from_new_pool() already uses NULL as marker for "allocation failed".
pymalloc_alloc() now returns directly the pointer, return NULL on memory allocation error. allocate_from_new_pool() already uses NULL as marker for "allocation failed".
pymalloc_alloc() now returns directly the pointer, return NULL on
memory allocation error.
allocate_from_new_pool() already uses NULL as marker for "allocation
failed".
https://bugs.python.org/issue37732