diff options
author | shadchin <[email protected]> | 2025-02-16 15:28:01 +0300 |
---|---|---|
committer | shadchin <[email protected]> | 2025-02-16 16:03:50 +0300 |
commit | a27b6a96fdc5ca444428ddef4823d0486dcdccb9 (patch) | |
tree | adde5c24d9ea37e1634e7972e27e682a820ab941 /contrib/tools/python3/Modules | |
parent | 7a3958c3c6de324baab9dba4bd4eb808c1b839a6 (diff) |
Update Python 3 to 3.12.9
commit_hash:c8651982d81e18f18e037fb247cc6ae53c4fa7f1
Diffstat (limited to 'contrib/tools/python3/Modules')
18 files changed, 193 insertions, 114 deletions
diff --git a/contrib/tools/python3/Modules/_csv.c b/contrib/tools/python3/Modules/_csv.c index 9a7b7d27c2e..df7207d0894 100644 --- a/contrib/tools/python3/Modules/_csv.c +++ b/contrib/tools/python3/Modules/_csv.c @@ -1074,7 +1074,7 @@ join_append_data(WriterObj *self, int field_kind, const void *field_data, int copy_phase) { DialectObj *dialect = self->dialect; - int i; + Py_ssize_t i; Py_ssize_t rec_len; #define INCLEN \ diff --git a/contrib/tools/python3/Modules/_ctypes/_ctypes.c b/contrib/tools/python3/Modules/_ctypes/_ctypes.c index b6d45e92647..96a05755496 100644 --- a/contrib/tools/python3/Modules/_ctypes/_ctypes.c +++ b/contrib/tools/python3/Modules/_ctypes/_ctypes.c @@ -125,6 +125,7 @@ bytes(cdata) #include "ctypes.h" #include "pycore_long.h" // _PyLong_GetZero() +#include "pycore_pyerrors.h" // _PyErr_SetLocaleString() ctypes_state global_state; @@ -778,31 +779,38 @@ CDataType_in_dll(PyObject *type, PyObject *args) return NULL; } +#undef USE_DLERROR #ifdef MS_WIN32 Py_BEGIN_ALLOW_THREADS address = (void *)GetProcAddress(handle, name); Py_END_ALLOW_THREADS - if (!address) { - PyErr_Format(PyExc_ValueError, - "symbol '%s' not found", - name); - return NULL; - } #else + #ifdef __CYGWIN__ + // dlerror() isn't very helpful on cygwin + #else + #define USE_DLERROR + /* dlerror() always returns the latest error. + * + * Clear the previous value before calling dlsym(), + * to ensure we can tell if our call resulted in an error. + */ + (void)dlerror(); + #endif address = (void *)dlsym(handle, name); - if (!address) { -#ifdef __CYGWIN__ -/* dlerror() isn't very helpful on cygwin */ - PyErr_Format(PyExc_ValueError, - "symbol '%s' not found", - name); -#else - PyErr_SetString(PyExc_ValueError, dlerror()); #endif + if (address) { + return PyCData_AtAddress(type, address); + } + #ifdef USE_DLERROR + const char *dlerr = dlerror(); + if (dlerr) { + _PyErr_SetLocaleString(PyExc_ValueError, dlerr); return NULL; } -#endif - return PyCData_AtAddress(type, address); + #endif +#undef USE_DLERROR + PyErr_Format(PyExc_ValueError, "symbol '%s' not found", name); + return NULL; } PyDoc_STRVAR(from_param_doc, @@ -847,8 +855,13 @@ CDataType_from_param(PyObject *type, PyObject *value) return NULL; } if (as_parameter) { + if (_Py_EnterRecursiveCall(" while processing _as_parameter_")) { + Py_DECREF(as_parameter); + return NULL; + } value = CDataType_from_param(type, as_parameter); Py_DECREF(as_parameter); + _Py_LeaveRecursiveCall(); return value; } PyErr_Format(PyExc_TypeError, @@ -1716,8 +1729,13 @@ c_wchar_p_from_param(PyObject *type, PyObject *value) return NULL; } if (as_parameter) { + if (_Py_EnterRecursiveCall(" while processing _as_parameter_")) { + Py_DECREF(as_parameter); + return NULL; + } value = c_wchar_p_from_param(type, as_parameter); Py_DECREF(as_parameter); + _Py_LeaveRecursiveCall(); return value; } /* XXX better message */ @@ -1780,8 +1798,13 @@ c_char_p_from_param(PyObject *type, PyObject *value) return NULL; } if (as_parameter) { + if (_Py_EnterRecursiveCall(" while processing _as_parameter_")) { + Py_DECREF(as_parameter); + return NULL; + } value = c_char_p_from_param(type, as_parameter); Py_DECREF(as_parameter); + _Py_LeaveRecursiveCall(); return value; } /* XXX better message */ @@ -1915,8 +1938,13 @@ c_void_p_from_param(PyObject *type, PyObject *value) return NULL; } if (as_parameter) { + if (_Py_EnterRecursiveCall(" while processing _as_parameter_")) { + Py_DECREF(as_parameter); + return NULL; + } value = c_void_p_from_param(type, as_parameter); Py_DECREF(as_parameter); + _Py_LeaveRecursiveCall(); return value; } /* XXX better message */ @@ -2275,9 +2303,9 @@ PyCSimpleType_from_param(PyObject *type, PyObject *value) return NULL; } value = PyCSimpleType_from_param(type, as_parameter); - _Py_LeaveRecursiveCall(); Py_DECREF(as_parameter); Py_XDECREF(exc); + _Py_LeaveRecursiveCall(); return value; } if (exc) { @@ -3583,6 +3611,7 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds) return NULL; } +#undef USE_DLERROR #ifdef MS_WIN32 address = FindAddress(handle, name, (PyObject *)type); if (!address) { @@ -3598,20 +3627,33 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds) return NULL; } #else + #ifdef __CYGWIN__ + //dlerror() isn't very helpful on cygwin */ + #else + #define USE_DLERROR + /* dlerror() always returns the latest error. + * + * Clear the previous value before calling dlsym(), + * to ensure we can tell if our call resulted in an error. + */ + (void)dlerror(); + #endif address = (PPROC)dlsym(handle, name); if (!address) { -#ifdef __CYGWIN__ -/* dlerror() isn't very helpful on cygwin */ - PyErr_Format(PyExc_AttributeError, - "function '%s' not found", - name); -#else - PyErr_SetString(PyExc_AttributeError, dlerror()); -#endif + #ifdef USE_DLERROR + const char *dlerr = dlerror(); + if (dlerr) { + _PyErr_SetLocaleString(PyExc_AttributeError, dlerr); + Py_DECREF(ftuple); + return NULL; + } + #endif + PyErr_Format(PyExc_AttributeError, "function '%s' not found", name); Py_DECREF(ftuple); return NULL; } #endif +#undef USE_DLERROR if (!_validate_paramflags(type, paramflags)) { Py_DECREF(ftuple); return NULL; diff --git a/contrib/tools/python3/Modules/_ctypes/callbacks.c b/contrib/tools/python3/Modules/_ctypes/callbacks.c index d71297f9c5c..65dfb980a39 100644 --- a/contrib/tools/python3/Modules/_ctypes/callbacks.c +++ b/contrib/tools/python3/Modules/_ctypes/callbacks.c @@ -82,22 +82,6 @@ PyType_Spec cthunk_spec = { /**************************************************************/ -static void -PrintError(const char *msg, ...) -{ - char buf[512]; - PyObject *f = PySys_GetObject("stderr"); - va_list marker; - - va_start(marker, msg); - PyOS_vsnprintf(buf, sizeof(buf), msg, marker); - va_end(marker); - if (f != NULL && f != Py_None) - PyFile_WriteString(buf, f); - PyErr_Print(); -} - - #ifdef MS_WIN32 /* * We must call AddRef() on non-NULL COM pointers we receive as arguments @@ -109,22 +93,19 @@ PrintError(const char *msg, ...) * after checking for PyObject_IsTrue(), but this would probably be somewhat * slower. */ -static void +static int TryAddRef(StgDictObject *dict, CDataObject *obj) { IUnknown *punk; int r = PyDict_Contains((PyObject *)dict, &_Py_ID(_needs_com_addref_)); if (r <= 0) { - if (r < 0) { - PrintError("getting _needs_com_addref_"); - } - return; + return r; } punk = *(IUnknown **)obj->b_ptr; if (punk) punk->lpVtbl->AddRef(punk); - return; + return 0; } #endif @@ -160,8 +141,7 @@ static void _CallPythonObject(void *mem, if (dict && dict->getfunc && !_ctypes_simple_instance(cnv)) { PyObject *v = dict->getfunc(*pArgs, dict->size); if (!v) { - PrintError("create argument %zd:\n", i); - goto Done; + goto Error; } args[i] = v; /* XXX XXX XX @@ -173,24 +153,25 @@ static void _CallPythonObject(void *mem, /* Hm, shouldn't we use PyCData_AtAddress() or something like that instead? */ CDataObject *obj = (CDataObject *)_PyObject_CallNoArgs(cnv); if (!obj) { - PrintError("create argument %zd:\n", i); - goto Done; + goto Error; } if (!CDataObject_Check(obj)) { + PyErr_Format(PyExc_TypeError, + "%R returned unexpected result of type %T", cnv, obj); Py_DECREF(obj); - PrintError("unexpected result of create argument %zd:\n", i); - goto Done; + goto Error; } memcpy(obj->b_ptr, *pArgs, dict->size); args[i] = (PyObject *)obj; #ifdef MS_WIN32 - TryAddRef(dict, obj); + if (TryAddRef(dict, obj) < 0) { + goto Error; + } #endif } else { - PyErr_SetString(PyExc_TypeError, - "cannot build parameter"); - PrintError("Parsing argument %zd\n", i); - goto Done; + PyErr_Format(PyExc_TypeError, + "cannot build parameter of type %R", cnv); + goto Error; } /* XXX error handling! */ pArgs++; @@ -198,8 +179,12 @@ static void _CallPythonObject(void *mem, if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) { error_object = _ctypes_get_errobj(&space); - if (error_object == NULL) + if (error_object == NULL) { + _PyErr_WriteUnraisableMsg("while setting error for " + "ctypes callback function", + callable); goto Done; + } if (flags & FUNCFLAG_USE_ERRNO) { int temp = space[0]; space[0] = errno; @@ -284,6 +269,13 @@ static void _CallPythonObject(void *mem, Py_DECREF(args[j]); } PyGILState_Release(state); + return; + + Error: + _PyErr_WriteUnraisableMsg("while creating argument for " + "ctypes callback function", + callable); + goto Done; } static void closure_fcn(ffi_cif *cif, diff --git a/contrib/tools/python3/Modules/_ctypes/callproc.c b/contrib/tools/python3/Modules/_ctypes/callproc.c index d2fe525dd4d..f98479ee85f 100644 --- a/contrib/tools/python3/Modules/_ctypes/callproc.c +++ b/contrib/tools/python3/Modules/_ctypes/callproc.c @@ -96,6 +96,7 @@ #define DONT_USE_SEH #endif +#include "pycore_pyerrors.h" // _PyErr_SetLocaleString() #include "pycore_runtime.h" // _PyRuntime #include "pycore_global_objects.h" // _Py_ID() @@ -1550,10 +1551,11 @@ static PyObject *py_dl_open(PyObject *self, PyObject *args) Py_XDECREF(name2); if (!handle) { const char *errmsg = dlerror(); - if (!errmsg) - errmsg = "dlopen() error"; - PyErr_SetString(PyExc_OSError, - errmsg); + if (errmsg) { + _PyErr_SetLocaleString(PyExc_OSError, errmsg); + return NULL; + } + PyErr_SetString(PyExc_OSError, "dlopen() error"); return NULL; } return PyLong_FromVoidPtr(handle); @@ -1566,8 +1568,12 @@ static PyObject *py_dl_close(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "O&:dlclose", &_parse_voidp, &handle)) return NULL; if (dlclose(handle)) { - PyErr_SetString(PyExc_OSError, - dlerror()); + const char *errmsg = dlerror(); + if (errmsg) { + _PyErr_SetLocaleString(PyExc_OSError, errmsg); + return NULL; + } + PyErr_SetString(PyExc_OSError, "dlclose() error"); return NULL; } Py_RETURN_NONE; @@ -1585,13 +1591,32 @@ static PyObject *py_dl_sym(PyObject *self, PyObject *args) if (PySys_Audit("ctypes.dlsym/handle", "O", args) < 0) { return NULL; } +#undef USE_DLERROR + #ifdef __CYGWIN__ + // dlerror() isn't very helpful on cygwin + #else + #define USE_DLERROR + /* dlerror() always returns the latest error. + * + * Clear the previous value before calling dlsym(), + * to ensure we can tell if our call resulted in an error. + */ + (void)dlerror(); + #endif ptr = dlsym((void*)handle, name); - if (!ptr) { - PyErr_SetString(PyExc_OSError, - dlerror()); + if (ptr) { + return PyLong_FromVoidPtr(ptr); + } + #ifdef USE_DLERROR + const char *errmsg = dlerror(); + if (errmsg) { + _PyErr_SetLocaleString(PyExc_OSError, errmsg); return NULL; } - return PyLong_FromVoidPtr(ptr); + #endif + #undef USE_DLERROR + PyErr_Format(PyExc_OSError, "symbol '%s' not found", name); + return NULL; } #endif diff --git a/contrib/tools/python3/Modules/_hashopenssl.c b/contrib/tools/python3/Modules/_hashopenssl.c index 2998820953b..3cc7d6f50e8 100644 --- a/contrib/tools/python3/Modules/_hashopenssl.c +++ b/contrib/tools/python3/Modules/_hashopenssl.c @@ -320,6 +320,7 @@ _setException(PyObject *exc, const char* altmsg, ...) va_end(vargs); ERR_clear_error(); + /* ERR_ERROR_STRING(3) ensures that the messages below are ASCII */ lib = ERR_lib_error_string(errcode); func = ERR_func_error_string(errcode); reason = ERR_reason_error_string(errcode); diff --git a/contrib/tools/python3/Modules/_multiprocessing/semaphore.c b/contrib/tools/python3/Modules/_multiprocessing/semaphore.c index c7df82dfe2d..bc718e273a8 100644 --- a/contrib/tools/python3/Modules/_multiprocessing/semaphore.c +++ b/contrib/tools/python3/Modules/_multiprocessing/semaphore.c @@ -23,6 +23,8 @@ typedef struct { char *name; } SemLockObject; +#define _SemLockObject_CAST(op) ((SemLockObject *)(op)) + /*[python input] class SEM_HANDLE_converter(CConverter): type = "SEM_HANDLE" @@ -567,8 +569,9 @@ _multiprocessing_SemLock__rebuild_impl(PyTypeObject *type, SEM_HANDLE handle, } static void -semlock_dealloc(SemLockObject* self) +semlock_dealloc(PyObject *op) { + SemLockObject *self = _SemLockObject_CAST(op); PyTypeObject *tp = Py_TYPE(self); PyObject_GC_UnTrack(self); if (self->handle != SEM_FAILED) @@ -706,7 +709,7 @@ _multiprocessing_SemLock___exit___impl(SemLockObject *self, } static int -semlock_traverse(SemLockObject *s, visitproc visit, void *arg) +semlock_traverse(PyObject *s, visitproc visit, void *arg) { Py_VISIT(Py_TYPE(s)); return 0; diff --git a/contrib/tools/python3/Modules/_sqlite/connection.c b/contrib/tools/python3/Modules/_sqlite/connection.c index 12e5c135aaf..1450037ca95 100644 --- a/contrib/tools/python3/Modules/_sqlite/connection.c +++ b/contrib/tools/python3/Modules/_sqlite/connection.c @@ -927,6 +927,11 @@ step_callback(sqlite3_context *context, int argc, sqlite3_value **params) assert(ctx != NULL); aggregate_instance = (PyObject**)sqlite3_aggregate_context(context, sizeof(PyObject*)); + if (aggregate_instance == NULL) { + (void)PyErr_NoMemory(); + set_sqlite_error(context, "unable to allocate SQLite aggregate context"); + goto error; + } if (*aggregate_instance == NULL) { *aggregate_instance = PyObject_CallNoArgs(ctx->callable); if (!*aggregate_instance) { diff --git a/contrib/tools/python3/Modules/_sqlite/util.c b/contrib/tools/python3/Modules/_sqlite/util.c index 2b3bbfefa3c..c521fc5ad6b 100644 --- a/contrib/tools/python3/Modules/_sqlite/util.c +++ b/contrib/tools/python3/Modules/_sqlite/util.c @@ -129,6 +129,7 @@ _pysqlite_seterror(pysqlite_state *state, sqlite3 *db) /* Create and set the exception. */ int extended_errcode = sqlite3_extended_errcode(db); + // sqlite3_errmsg() always returns an UTF-8 encoded message const char *errmsg = sqlite3_errmsg(db); raise_exception(exc_class, extended_errcode, errmsg); return extended_errcode; diff --git a/contrib/tools/python3/Modules/_sqlite/ya.make b/contrib/tools/python3/Modules/_sqlite/ya.make index bbafbaff858..7abcc1886ad 100644 --- a/contrib/tools/python3/Modules/_sqlite/ya.make +++ b/contrib/tools/python3/Modules/_sqlite/ya.make @@ -2,9 +2,9 @@ PY3_LIBRARY() -VERSION(3.12.8) +VERSION(3.12.9) -ORIGINAL_SOURCE(https://github.com/python/cpython/archive/v3.12.8.tar.gz) +ORIGINAL_SOURCE(https://github.com/python/cpython/archive/v3.12.9.tar.gz) LICENSE(Python-2.0) diff --git a/contrib/tools/python3/Modules/_ssl.c b/contrib/tools/python3/Modules/_ssl.c index dbb4e8da789..498c538c6b7 100644 --- a/contrib/tools/python3/Modules/_ssl.c +++ b/contrib/tools/python3/Modules/_ssl.c @@ -651,6 +651,11 @@ PySSL_SetError(PySSLSocket *sslsock, int ret, const char *filename, int lineno) ERR_GET_REASON(e) == SSL_R_CERTIFICATE_VERIFY_FAILED) { type = state->PySSLCertVerificationErrorObject; } + if (ERR_GET_LIB(e) == ERR_LIB_SYS) { + // A system error is being reported; reason is set to errno + errno = ERR_GET_REASON(e); + return PyErr_SetFromErrno(PyExc_OSError); + } p = PY_SSL_ERROR_SYSCALL; } break; @@ -676,6 +681,11 @@ PySSL_SetError(PySSLSocket *sslsock, int ret, const char *filename, int lineno) errstr = "EOF occurred in violation of protocol"; } #endif + if (ERR_GET_LIB(e) == ERR_LIB_SYS) { + // A system error is being reported; reason is set to errno + errno = ERR_GET_REASON(e); + return PyErr_SetFromErrno(PyExc_OSError); + } break; } default: diff --git a/contrib/tools/python3/Modules/_tracemalloc.c b/contrib/tools/python3/Modules/_tracemalloc.c index f3f4af9aba0..3a4092c9d08 100644 --- a/contrib/tools/python3/Modules/_tracemalloc.c +++ b/contrib/tools/python3/Modules/_tracemalloc.c @@ -219,10 +219,5 @@ PyInit__tracemalloc(void) if (m == NULL) return NULL; - if (_PyTraceMalloc_Init() < 0) { - Py_DECREF(m); - return NULL; - } - return m; } diff --git a/contrib/tools/python3/Modules/_winapi.c b/contrib/tools/python3/Modules/_winapi.c index 76f18c71a07..ac3ee113ffd 100644 --- a/contrib/tools/python3/Modules/_winapi.c +++ b/contrib/tools/python3/Modules/_winapi.c @@ -946,7 +946,7 @@ getenvironment(PyObject* environment) } normalized_environment = normalize_environment(environment); - if (normalize_environment == NULL) { + if (normalized_environment == NULL) { return NULL; } diff --git a/contrib/tools/python3/Modules/arraymodule.c b/contrib/tools/python3/Modules/arraymodule.c index d24c5989af3..090a7b841c9 100644 --- a/contrib/tools/python3/Modules/arraymodule.c +++ b/contrib/tools/python3/Modules/arraymodule.c @@ -2966,11 +2966,16 @@ array_arrayiterator___setstate__(arrayiterobject *self, PyObject *state) Py_ssize_t index = PyLong_AsSsize_t(state); if (index == -1 && PyErr_Occurred()) return NULL; - if (index < 0) - index = 0; - else if (index > Py_SIZE(self->ao)) - index = Py_SIZE(self->ao); /* iterator exhausted */ - self->index = index; + arrayobject *ao = self->ao; + if (ao != NULL) { + if (index < 0) { + index = 0; + } + else if (index > Py_SIZE(ao)) { + index = Py_SIZE(ao); /* iterator exhausted */ + } + self->index = index; + } Py_RETURN_NONE; } diff --git a/contrib/tools/python3/Modules/clinic/posixmodule.c.h b/contrib/tools/python3/Modules/clinic/posixmodule.c.h index a33461dc560..57121e1e890 100644 --- a/contrib/tools/python3/Modules/clinic/posixmodule.c.h +++ b/contrib/tools/python3/Modules/clinic/posixmodule.c.h @@ -304,7 +304,7 @@ exit: return return_value; } -#if defined(HAVE_TTYNAME) +#if defined(HAVE_TTYNAME_R) PyDoc_STRVAR(os_ttyname__doc__, "ttyname($module, fd, /)\n" @@ -337,7 +337,7 @@ exit: return return_value; } -#endif /* defined(HAVE_TTYNAME) */ +#endif /* defined(HAVE_TTYNAME_R) */ #if defined(HAVE_CTERMID) @@ -12032,4 +12032,4 @@ exit: #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=6d34c4564aca7725 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=efe45f93561db8d3 input=a9049054013a1b77]*/ diff --git a/contrib/tools/python3/Modules/main.c b/contrib/tools/python3/Modules/main.c index 5c608786263..7ed7c440e77 100644 --- a/contrib/tools/python3/Modules/main.c +++ b/contrib/tools/python3/Modules/main.c @@ -326,6 +326,7 @@ pymain_run_file_obj(PyObject *program_name, PyObject *filename, if (fp == NULL) { // Ignore the OSError PyErr_Clear(); + // TODO(picnixz): strerror() is locale dependent but not PySys_FormatStderr(). PySys_FormatStderr("%S: can't open file %R: [Errno %d] %s\n", program_name, filename, errno, strerror(errno)); return 2; diff --git a/contrib/tools/python3/Modules/posixmodule.c b/contrib/tools/python3/Modules/posixmodule.c index ce2c80e6daa..37075165506 100644 --- a/contrib/tools/python3/Modules/posixmodule.c +++ b/contrib/tools/python3/Modules/posixmodule.c @@ -49,10 +49,6 @@ # include "winreparse.h" #endif -#if !defined(EX_OK) && defined(EXIT_SUCCESS) -# define EX_OK EXIT_SUCCESS -#endif - /* On android API level 21, 'AT_EACCESS' is not declared although * HAVE_FACCESSAT is defined. */ #ifdef __ANDROID__ @@ -61,6 +57,9 @@ #include <stdio.h> // ctermid() #include <stdlib.h> // system() +#ifdef HAVE_SYS_PIDFD_H +# error #include <sys/pidfd.h> // PIDFD_NONBLOCK +#endif /* * A number of APIs are available on macOS from a certain macOS version. @@ -267,6 +266,10 @@ corresponding Unix manual entries for more information on calls."); # include <sysexits.h> #endif +#if !defined(EX_OK) && defined(EXIT_SUCCESS) +# define EX_OK EXIT_SUCCESS +#endif + #ifdef HAVE_SYS_LOADAVG_H # include <sys/loadavg.h> #endif @@ -3235,7 +3238,7 @@ os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd, #endif -#ifdef HAVE_TTYNAME +#ifdef HAVE_TTYNAME_R /*[clinic input] os.ttyname @@ -8982,42 +8985,33 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal) Py_RETURN_NONE; #else /* !MS_WINDOWS */ - PyObject *result; DWORD sig = (DWORD)signal; - DWORD err; - HANDLE handle; #ifdef HAVE_WINDOWS_CONSOLE_IO /* Console processes which share a common console can be sent CTRL+C or CTRL+BREAK events, provided they handle said events. */ if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT) { if (GenerateConsoleCtrlEvent(sig, (DWORD)pid) == 0) { - err = GetLastError(); - PyErr_SetFromWindowsErr(err); - } - else { - Py_RETURN_NONE; + return PyErr_SetFromWindowsErr(0); } + Py_RETURN_NONE; } #endif /* HAVE_WINDOWS_CONSOLE_IO */ /* If the signal is outside of what GenerateConsoleCtrlEvent can use, attempt to open and terminate the process. */ - handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid); + HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid); if (handle == NULL) { - err = GetLastError(); - return PyErr_SetFromWindowsErr(err); + return PyErr_SetFromWindowsErr(0); } - if (TerminateProcess(handle, sig) == 0) { - err = GetLastError(); - result = PyErr_SetFromWindowsErr(err); - } else { - result = Py_NewRef(Py_None); + BOOL res = TerminateProcess(handle, sig); + CloseHandle(handle); + if (res == 0) { + return PyErr_SetFromWindowsErr(0); } - CloseHandle(handle); - return result; + Py_RETURN_NONE; #endif /* !MS_WINDOWS */ } #endif /* HAVE_KILL */ diff --git a/contrib/tools/python3/Modules/pyexpat.c b/contrib/tools/python3/Modules/pyexpat.c index be31c637fcc..b354a86e7f9 100644 --- a/contrib/tools/python3/Modules/pyexpat.c +++ b/contrib/tools/python3/Modules/pyexpat.c @@ -1784,7 +1784,12 @@ add_error(PyObject *errors_module, PyObject *codes_dict, * with the other uses of the XML_ErrorString function * elsewhere within this file. pyexpat's copy of the messages * only acts as a fallback in case of outdated runtime libexpat, - * where it returns NULL. */ + * where it returns NULL. + * + * In addition, XML_ErrorString is assumed to return UTF-8 encoded + * strings (in conv_string_to_unicode, we decode them using 'strict' + * error handling). + */ const char *error_string = XML_ErrorString(error_code); if (error_string == NULL) { error_string = error_info_of[error_index].description; diff --git a/contrib/tools/python3/Modules/syslogmodule.c b/contrib/tools/python3/Modules/syslogmodule.c index 6db8de9c491..c925a42dc05 100644 --- a/contrib/tools/python3/Modules/syslogmodule.c +++ b/contrib/tools/python3/Modules/syslogmodule.c @@ -170,7 +170,7 @@ syslog_openlog_impl(PyObject *module, PyObject *ident, long logopt, } } if (PySys_Audit("syslog.openlog", "Oll", ident ? ident : Py_None, logopt, facility) < 0) { - Py_DECREF(ident); + Py_XDECREF(ident); return NULL; } @@ -250,7 +250,7 @@ syslog_closelog_impl(PyObject *module) // Since the sys.closelog changes the process level state of syslog library, // this operation is only allowed for the main interpreter. if (!is_main_interpreter()) { - PyErr_SetString(PyExc_RuntimeError, "sunbinterpreter can't use syslog.closelog()"); + PyErr_SetString(PyExc_RuntimeError, "subinterpreter can't use syslog.closelog()"); return NULL; } |