Skip to content

bpo-37732 : Fix unintialized pointer warning in Objects/obmalloc.c#15309

Closed
hansrajdas wants to merge 1 commit into
python:masterfrom
hansrajdas:initialize-ptr
Closed

bpo-37732 : Fix unintialized pointer warning in Objects/obmalloc.c#15309
hansrajdas wants to merge 1 commit into
python:masterfrom
hansrajdas:initialize-ptr

Conversation

@hansrajdas

@hansrajdas hansrajdas commented Aug 15, 2019

Copy link
Copy Markdown
Contributor
  • Initialize ptr with NULL pointer while declaring

warning-2019-08-15 01-15-06

https://bugs.python.org/issue37732

* Initialize ptr with NULL pointer while declaring

@nanjekyejoannah nanjekyejoannah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had already opened a bpo issue here for this : https://bugs.python.org/issue37732 for someone to investigate. Please link to it in this PR title.
i.e

bpo-37732 : Fix unintialized pointer warning in Objects/obmalloc.c

@hansrajdas hansrajdas changed the title Fix unintialized pointer warning in Objects/obmalloc.c bpo-37732 : Fix unintialized pointer warning in Objects/obmalloc.c Aug 16, 2019
@hansrajdas

hansrajdas commented Aug 16, 2019

Copy link
Copy Markdown
Contributor Author

I had already opened a bpo issue here for this : https://bugs.python.org/issue37732 for someone to investigate. Please link to it in this PR title.
i.e

bpo-37732 : Fix unintialized pointer warning in Objects/obmalloc.c

Thanks @nanjekyejoannah, I will link this PR with opened bpo issue. And also move this PR from draft to open state.

@hansrajdas
hansrajdas marked this pull request as ready for review August 16, 2019 20:28
@methane

methane commented Aug 17, 2019

Copy link
Copy Markdown
Member

Why no warning in _PyObject_Calloc?

@hansrajdas

Copy link
Copy Markdown
Contributor Author

Why no warning in _PyObject_Calloc?

This is because in _PyObject_Calloc memory is initialized using memset but in case of _PyObject_Malloc memory is just allocated and returned(no initialization is done). If we remove memset statement from _PyObject_Calloc we will get the same pointer uninitialized warning for _PyObject_Calloc also. I have verified this.

This is another PR #15293 where Victor suggested that _PyObject_Malloc was intentionally designed to return uninitialized memory so we can't use memset here to fix this warning so I have just initialized ptr with NULL pointer to fix this warning. Please guide me if we can do anythig better to fix this warning.

@fusioncid

fusioncid commented Aug 18, 2019

Copy link
Copy Markdown
Contributor

It seems that warning was introduced by bpo-37543: optimize pymalloc (#14674

Why does this warning appear after using 'LIKELY'?

@fusioncid

Copy link
Copy Markdown
Contributor

And maybe we can resue _PyObject_Malloc in _PyObject_Calloc.

@vstinner

Copy link
Copy Markdown
Member

I dislike this change since it adds an useless initialization to NULL, ptr is already always initialized: GCC is just wrong. I wrote PR #15333 to fix the warning without adding an useless initialization.

_PyObject_Malloc() function is performance critical so I would prefer to not make it slower ;-)

@vstinner

Copy link
Copy Markdown
Member

Close: I merged my PR #15333 instead.

@vstinner vstinner closed this Aug 20, 2019
@vstinner

Copy link
Copy Markdown
Member

@hansrajdas: but thanks for your contribution anyway ;-)

@vstinner vstinner reopened this Aug 20, 2019
@vstinner vstinner closed this Aug 20, 2019
@hansrajdas

Copy link
Copy Markdown
Contributor Author

Thanks @vstinner for your guidance, It was good learning for me following your PR #15333 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants