gh-99845: Clean up _PyObject_VAR_SIZE() usage by vstinner · Pull Request #99847 · python/cpython
The dictoffset code was different in 2001 when the cast was added: commit 6d483d3
Change:
- dictoffset += size; + dictoffset += (long)size;
Code:
PyObject ** _PyObject_GetDictPtr(PyObject *obj) { long dictoffset; ... if (dictoffset < 0) { size_t size; _PyObject_VAR_SIZE(size, tp, ((PyVarObject *)obj)->ob_size); dictoffset += (long)size; assert(dictoffset > 0); assert(dictoffset % SIZEOF_VOID_P == 0); } ... }
The dictoffset type was changed in 2006 by commit 725507b without updating the cast, forgotten in the enhancement.
My change, replace (long) cast with (Py_ssize_t) only impact 64-bit Windows. On other platforms, long and Py_ssize_t should be the same type (either 32-bit or 64-bit signed integer, int32_t or int64_t).