-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
[WIP] bpo-17870: Add support for C intmax_t type #857
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
Conversation
* Add new conversions functions for PyLong: - PyLong_FromIntMax() - PyLong_FromUIntMax() - PyLong_AsIntMax() - PyLong_AsIntMaxAndOverflow() - PyLong_AsUIntMax() * getargs: add 'm' format * New _testcapi constants: INTMAX_MAX, INTMAX_MIN, UINTMAX_MAX, SIZEOF_INTMAX_T * Add _testcapi.getargs_m() and _testcapi.test_long_intmax_api() * PyLong_FromVoidPtr() uses PyLong_FromUIntMax() * Use intmax_t in various modules array, struct, ctypes and memoryview are not modified yet to support intmax_t.
@@ -275,6 +275,11 @@ Numbers | |||
``n`` (:class:`int`) [Py_ssize_t] | |||
Convert a Python integer to a C :c:type:`Py_ssize_t`. | |||
|
|||
``m`` (:class:`int`) [intmax_t] | |||
Convert a Python integer to a C :c:type:`intmax_t`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about uintmax_t
?
@@ -1442,9 +1442,9 @@ static PyModuleDef _lzmamodule = { | |||
/* Some of our constants are more than 32 bits wide, so PyModule_AddIntConstant | |||
would not work correctly on platforms with 32-bit longs. */ | |||
static int | |||
module_add_int_constant(PyObject *m, const char *name, long long value) | |||
module_add_int_constant(PyObject *m, const char *name, intmax_t value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure 64 bit is enough for all LZMA constants.
@@ -432,7 +432,7 @@ mmap_size_method(mmap_object *self, | |||
#ifdef MS_WINDOWS | |||
if (self->file_handle != INVALID_HANDLE_VALUE) { | |||
DWORD low,high; | |||
long long size; | |||
intmax_t size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size
is a 64-bit number. long long
is enough.
@@ -1182,8 +1182,9 @@ fromWideIntObj(PyObject* tkapp, Tcl_Obj *value) | |||
{ | |||
Tcl_WideInt wideValue; | |||
if (Tcl_GetWideIntFromObj(Tkapp_Interp(tkapp), value, &wideValue) == TCL_OK) { | |||
if (sizeof(wideValue) <= SIZEOF_LONG_LONG) | |||
return PyLong_FromLongLong(wideValue); | |||
if (sizeof(wideValue) <= SIZEOF_INTMAX_T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this condition is always true. I think that it is always true even for long long
. I added this check only because the support of long long
was optional.
@@ -11414,11 +11387,7 @@ os_DirEntry_inode_impl(DirEntry *self) | |||
Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(self->win32_file_index)); | |||
return PyLong_FromUnsignedLongLong(self->win32_file_index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be used PyLong_FromUIntMax
?
#else | ||
return PyLong_FromLong((long)self->d_ino); | ||
#endif | ||
return PyLong_FromUIntMax((long)self->d_ino); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(long)
?
Can d_ino
be negative?
Rejected for the reasons explained in the bpo: http://bugs.python.org/issue17870 |
Add new conversions functions for PyLong:
getargs: add 'm' format
New _testcapi constants: INTMAX_MAX, INTMAX_MIN, UINTMAX_MAX, SIZEOF_INTMAX_T
Add _testcapi.getargs_m() and _testcapi.test_long_intmax_api()
PyLong_FromVoidPtr() uses PyLong_FromUIntMax()
Use intmax_t in various modules
array, struct, ctypes and memoryview are not modified yet to support
intmax_t.