bpo-37732: Fix GCC warning in _PyObject_Malloc()#15333
bpo-37732: Fix GCC warning in _PyObject_Malloc()#15333vstinner merged 2 commits intopython:masterfrom vstinner:pymalloc_alloc_warn
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 |
serhiy-storchaka
left a comment
There was a problem hiding this comment.
LGTM, but one check is redundant now.
| 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.
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.
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