Skip to content

GH-131296: fix clang-cl warning in tracemalloc.c #131374

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Python/tracemalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ typedef struct tracemalloc_traceback traceback_t;
/* The maximum number of frames is either:
- The maximum number of frames we can store in `traceback_t.nframe`
- The maximum memory size_t we can allocate */
static const unsigned long MAX_NFRAME = Py_MIN(UINT16_MAX, ((SIZE_MAX - sizeof(traceback_t)) / sizeof(frame_t) + 1));
static const unsigned long MAX_NFRAME = (unsigned long)Py_MIN(
Copy link
Member Author

Choose a reason for hiding this comment

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

Fix warning implicit conversion from 'unsigned long long' to 'const unsigned long' changes value from 1537228672809129300 to 1431655764 [-Wconstant-conversion]

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure that this change is needed. It should return UINT16_MAX which fits into unsigned long. IMO this code is too complicated, it's not worth it. I wrote a simpler but different fix: #131514 (note: I'm the author of this code ;-)).

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, much simpler. Didn't dare to do it, since there might be some weird targets where unsigned long is only 16 bit, but those are most probably not existing these days anymore :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Closing in favor of #131514, because

  • simple is better than complex
  • I can't imagine there are platforms out there where SIZE_MAX (maximum value of size_t) is so small that we'd get something smaller than UINT16_MAX

Copy link
Member

Choose a reason for hiding this comment

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

Right, I merged my PR. Thanks anyway!

UINT16_MAX, ((SIZE_MAX - sizeof(traceback_t)) / sizeof(frame_t) + 1));


#define tracemalloc_empty_traceback _PyRuntime.tracemalloc.empty_traceback
Expand Down
Loading