Skip to content

gh-99845: Use size_t type in __sizeof__() methods - #99846

Merged
vstinner merged 2 commits into
python:mainfrom
vstinner:sizeof
Nov 30, 2022
Merged

vstinner merged 2 commits into
python:mainfrom
vstinner:sizeof

Conversation

@vstinner

@vstinner vstinner commented Nov 28, 2022 •

Copy link
Copy Markdown
Member

The implementation of sizeof() methods using _PyObject_SIZE() now use unsigned size_t type to compute the size, rather than the signed Py_ssize_t type.

Cast explicitly signed (Py_ssize_t) values to unsigned type (Py_ssize_t).

The implementation of __sizeof__() methods using _PyObject_SIZE() now
use unsigned size_t type to compute the size, rather than the signed
Py_ssize_t type.

Cast explicitly signed (Py_ssize_t) values to unsigned type
(Py_ssize_t).
@vstinner
vstinner merged commit 85dd6cb into python:main Nov 30, 2022
@vstinner
vstinner deleted the sizeof branch November 30, 2022 16:22
Py_ssize_t blocks;

res = _PyObject_SIZE(Py_TYPE(deque));
size_t res = _PyObject_SIZE(Py_TYPE(deque));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doesn't it need an explicit cast to size_t?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I chose to limit this change only to prepare the code for _PyObject_SIZE() API change.

With commit 131801d, _PyObject_SIZE() return type is now well defined: it returns a size_t.

carljm added a commit to carljm/cpython that referenced this pull request Dec 1, 2022
* main: (112 commits)
  pythongh-99894: Ensure the local names don't collide with the test file in traceback suggestion error checking (python#99895)
  pythongh-99612: Fix PyUnicode_DecodeUTF8Stateful() for ASCII-only data (pythonGH-99613)
  Doc: Add summary line to isolation_level & autocommit sqlite3.connect params (python#99917)
  pythonGH-98906 ```re``` module: ```search() vs. match()``` section should mention ```fullmatch()``` (pythonGH-98916)
  pythongh-89189: More compact range iterator (pythonGH-27986)
  bpo-47220: Document the optional callback parameter of weakref.WeakMethod (pythonGH-25491)
  pythonGH-99905: Fix output of misses in summarize_stats.py execution counts (pythonGH-99906)
  pythongh-99845: PEP 670: Convert PyObject macros to functions (python#99850)
  pythongh-99845: Use size_t type in __sizeof__() methods (python#99846)
  pythonGH-99877)
  Fix typo in exception message in `multiprocessing.pool` (python#99900)
  pythongh-87092: move all localsplus preparation into separate function called from assembler stage (pythonGH-99869)
  pythongh-99891: Fix infinite recursion in the tokenizer when showing warnings (pythonGH-99893)
  pythongh-99824: Document that sqlite3.connect implicitly open a transaction if autocommit=False (python#99825)
  pythonGH-81057: remove static state from suggestions.c (python#99411)
  Improve zip64 limit error message (python#95892)
  pythongh-98253: Break potential reference cycles in external code worsened by typing.py lru_cache (python#98591)
  pythongh-99127: Allow some features of syslog to the main interpreter only (pythongh-99128)
  pythongh-82836: fix private network check (python#97733)
  Docs: improve accuracy of socketserver reference (python#24767)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants