Skip to content

Setters of members with unsigned integer type and __index__() #115011

Closed
@serhiy-storchaka

Description

@serhiy-storchaka

Yet one strange thing about member setters with unsigned integer type is that they support different ranges for int and int-like objects (objects with the __index__() method).

For Py_T_ULONG the range for int is LONG_MIN-ULONG_MAX, but for indexes it is smaller: LONG_MIN-LONG_MAX.

The same is for Py_T_UINT, except that the maximal hard limit for index LONG_MAX can be larger than the maximal safe limit UINT_MAX, depending on platform, so on some platforms it may be lesser issue.

Py_T_ULLONG is even more limited. The range for int is 0-ULLONG_MAX (negatives not allowed!), and the range for indexes is LONG_MIN-LONG_MAX, which includes negatives, bat has much lesser upper limit. It is a remnant of dark old times, when Python had two not yet completely compatible integer types.

Py_T_PYSSIZET does not support __index__() at all. It is because PyLong_AsSsize_t() does not support them.

Linked PRs

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions