[issue28474] WinError(): Python int too large to convert to C long

2021-08-25 Thread Adam Meily
Change by Adam Meily : -- keywords: +patch pull_requests: +26407 stage: -> patch review pull_request: https://github.com/python/cpython/pull/27959 ___ Python tracker ___

[issue28474] WinError(): Python int too large to convert to C long

2021-08-23 Thread Adam Meily
Adam Meily added the comment: I can potentially take a stab at writing up a PR for this. I've also seen this affecting other locations that eventually call FormatMessage, including: - ctypes.format_error() - this original issue - os.strerror() - OSError(winerror=X) I will most likely look

[issue28474] WinError(): Python int too large to convert to C long

2021-02-26 Thread Eryk Sun
Eryk Sun added the comment: format_error() can use format "L" (long long) and then check for a value in the accepted range `value >= LONG_MIN && value <= ULONG_MAX`. If the value is out of range, raise OverflowError. Otherwise assign the value to DWORD `code`. -- versions: +Python

[issue28474] WinError(): Python int too large to convert to C long

2016-10-20 Thread Eryk Sun
Eryk Sun added the comment: Kelvin is calling WlanScan [1], which returns an error code that apparently can include HRESULT (signed) values cast as DWORD (unsigned) values, including 0x80342002 (ERROR_NDIS_DOT11_POWER_STATE_INVALID). ctypes.FormatError calls FormatMessage [2] with the flag

[issue28474] WinError(): Python int too large to convert to C long

2016-10-20 Thread Steve Dower
Steve Dower added the comment: All HRESULT values are, since the topmost bit indicates that it's an error, but all the others should be 16-bit positive integers IIRC. I don't think this function is meant to work with HRESULTs, but I could be wrong - fairly sure it's meant for Win32 error

[issue28474] WinError(): Python int too large to convert to C long

2016-10-19 Thread Kelvin You
Kelvin You added the comment: Here is the full list of windows error code: https://msdn.microsoft.com/en-us/library/cc231196.aspx You can see a lot of error codes is above 0x8000. -- ___ Python tracker

[issue28474] WinError(): Python int too large to convert to C long

2016-10-19 Thread Kelvin You
Kelvin You added the comment: I report this issue because the function WlanScan(https://msdn.microsoft.com/zh-cn/library/windows/desktop/ms706783(v=vs.85).aspx) returns a error code 0x80342002 when the WLAN is disabled on Windows 10. ctypes.WinError() raise an exception of 'Python int too

[issue28474] WinError(): Python int too large to convert to C long

2016-10-19 Thread Josh Rosenberg
Josh Rosenberg added the comment: You can't use I as a format code safely; it silently ignores/wraps overflow on the conversion, where i raises on overflow. The unsigned converters are basically useless for resilient code in 99% of cases. I *think* I remember some private utility functions

[issue28474] WinError(): Python int too large to convert to C long

2016-10-19 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- components: +Windows nosy: +amaury.forgeotdarc, belopolsky, meador.inge, paul.moore, steve.dower, tim.golden, zach.ware type: crash -> behavior versions: +Python 3.7 -Python 3.3, Python 3.4

[issue28474] WinError(): Python int too large to convert to C long

2016-10-19 Thread Kelvin You
New submission from Kelvin You: // callproc.c static PyObject *format_error(PyObject *self, PyObject *args) { PyObject *result; wchar_t *lpMsgBuf; DWORD code = 0; if (!PyArg_ParseTuple(args, "|i:FormatError", )) ^ Here the format string should