diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py index 57ee6c37f0ce7e9..8c689f7aaa32768 100644 --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -6,8 +6,6 @@ from test import test_support as support from test.script_helper import assert_python_ok import asyncore -# import unittest.mock -from mock import Mock from test import support import re import socket @@ -3577,8 +3575,8 @@ def test_keylog_filename(self): "test is not compatible with ignore_environment") def test_keylog_env(self): self.addCleanup(support.unlink, support.TESTFN) - with mock.patch.dict(os.environ): - os.environ['SSLKEYLOGFILE'] = support.TESTFN + with support.EnvironmentVarGuard() as env: + env['SSLKEYLOGFILE'] = support.TESTFN self.assertEqual(os.environ['SSLKEYLOGFILE'], support.TESTFN) ctx = ssl.SSLContext(ssl.PROTOCOL_TLS) diff --git a/Modules/_ssl.c b/Modules/_ssl.c index c8f07f92b2622e3..232fff61af61e63 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -3472,7 +3472,9 @@ _servername_callback(SSL *s, int *al, void *args) Py_INCREF(sni_cb); if (ssl->ssl_sock == NULL) { + /* The error path below releases ssl_socket. */ ssl_socket = Py_None; + Py_INCREF(ssl_socket); } else { ssl_socket = PyWeakref_GetObject(ssl->ssl_sock); Py_INCREF(ssl_socket); diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index b26e87b99b107ec..4ad7de27c6206ec 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -278,11 +278,14 @@ extern int lstat(const char *, struct stat *); #include #include #include /* for ShellExecute() */ -#include /* for ConvertStringSecurityDescriptorToSecurityDescriptorW() */ #define popen _popen #define pclose _pclose #endif /* _MSC_VER */ +#ifdef MS_WINDOWS +#include /* for ConvertStringSecurityDescriptorToSecurityDescriptorW() */ +#endif + #if defined(PYCC_VACPP) && defined(PYOS_OS2) #include #endif /* OS2 */ diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index b145daf5c88b6df..69472cf2d95e9c4 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -1836,47 +1836,6 @@ PyDoc_STRVAR(getblocking_doc, Returns True if socket is in blocking mode, or False if it\n\ is in non-blocking mode."); -static int -socket_parse_timeout(_PyTime_t *timeout, PyObject *timeout_obj) -{ -#ifdef MS_WINDOWS - struct timeval tv; -#endif -#ifndef HAVE_POLL - _PyTime_t ms; -#endif - int overflow = 0; - - if (timeout_obj == Py_None) { - *timeout = _PyTime_FromSeconds(-1); - return 0; - } - - if (_PyTime_FromSecondsObject(timeout, - timeout_obj, _PyTime_ROUND_TIMEOUT) < 0) - return -1; - - if (*timeout < 0) { - PyErr_SetString(PyExc_ValueError, "Timeout value out of range"); - return -1; - } - -#ifdef MS_WINDOWS - overflow |= (_PyTime_AsTimeval(*timeout, &tv, _PyTime_ROUND_TIMEOUT) < 0); -#endif -#ifndef HAVE_POLL - ms = _PyTime_AsMilliseconds(*timeout, _PyTime_ROUND_TIMEOUT); - overflow |= (ms > INT_MAX); -#endif - if (overflow) { - PyErr_SetString(PyExc_OverflowError, - "timeout doesn't fit into C timeval"); - return -1; - } - - return 0; -} - /* s.settimeout(timeout) method. Argument: None -- no timeout, blocking mode; same as setblocking(True) 0.0 -- non-blocking mode; same as setblocking(False)