Issue #26590: Implement a safe finalizer for the _socket.socket type. It now
releases the GIL to close the socket. Use PyErr_ResourceWarning() to raise the
ResourceWarning to pass the socket object to the warning logger, to get the
traceback where the socket was created (allocated).
Issue #26567:
* Add a new function PyErr_ResourceWarning() function to pass the destroyed
object
* Add a source attribute to warnings.WarningMessage
* Add warnings._showwarnmsg() which uses tracemalloc to get the traceback where
source object was allocated.
Issue #26227: On Windows, getnameinfo(), gethostbyaddr() and gethostbyname_ex()
functions of the socket module now decode the hostname from the ANSI code page
rather than UTF-8.
PyUnicode_AsEncodedString() instead of calling the encode() method of the
host, to handle correctly custom string with an encode() method which doesn't
return a byte string. The encoder of the IDNA codec is now called directly
instead of calling the encode() method of the string.
Use _PyTime_FromSeconds() to initialize the default socket timeout to -1
second, instead of -1 nanosecond which causes rounding issues in
internal_select().
* Use the new _PyTime_FromSeconds() function to set the timeout to -1 second
for socket.settimeout(None). It avoids a special case in internal_select()
because of a rounding issue: -1 nanosecond is rounded to 0 millisecond which
means non-blocking, instead of blocking.
* Check if the interval the negative in sock_call_ex() instead of doing the
check in internal_select(). sock_call_ex() remembers if the socket has a
timeout or not, which avoids a race condition if the timeout is modified in a
different thread.
instead of raising InterruptedError if the connection is interrupted by
signals, signal handlers don't raise an exception and the socket is blocking or
has a timeout.
socket.socket.connect() still raise InterruptedError for non-blocking sockets.
The BEGIN_SELECT_LOOP and END_SELECT_LOOP macros of socketmodule.c don't handle
EINTR. Functions using these macros use an inner loop to handle EINTR, but they
don't recompute the timeout.
This changes replaces the two macros with a new sock_call() function which
takes a function as a parameter. sock_call() recomputes the timeout, handle
false positive and handle EINTR.
Call PyErr_CheckSignals() immediatly if connect() or select() fails with EINTR
in internal_connect().
Refactor also the code to limit indentaton and make it more readable.
The function now returns the error code instead of using the global errno
(POSIX) or WSAGetLastError() (Windows).
internal_connect() now returns errno if getsockopt() fails.