aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-06-13 19:29:50 +0300
committershadchin <shadchin@yandex-team.com>2024-06-13 19:51:47 +0300
commit9051e2318afc1bfbd88a103f7392e622aa8c9527 (patch)
tree5c63ea23ebd5e7b7b9864903a9312aa853193ca5
parent224da250178b9250c7577a167d44f94f732d3627 (diff)
downloadydb-9051e2318afc1bfbd88a103f7392e622aa8c9527.tar.gz
Update Python from 2.7.16 to 2.7.18
2a151e9cf2ebdfa59d250c1bbb800e908703a6f0
-rw-r--r--contrib/tools/python/src/Include/code.h2
-rw-r--r--contrib/tools/python/src/Include/patchlevel.h4
-rw-r--r--contrib/tools/python/src/Include/pyport.h2
-rw-r--r--contrib/tools/python/src/Modules/_csv.c2
-rw-r--r--contrib/tools/python/src/Modules/_ctypes/_ctypes.c25
-rw-r--r--contrib/tools/python/src/Modules/_ctypes/callproc.c5
-rw-r--r--contrib/tools/python/src/Modules/_ctypes/cfield.c26
-rw-r--r--contrib/tools/python/src/Modules/_hashopenssl.c16
-rw-r--r--contrib/tools/python/src/Modules/_hotshot.c5
-rw-r--r--contrib/tools/python/src/Modules/_io/bufferedio.c1
-rw-r--r--contrib/tools/python/src/Modules/_json.c4
-rw-r--r--contrib/tools/python/src/Modules/_multiprocessing/multiprocessing.c2
-rw-r--r--contrib/tools/python/src/Modules/_sqlite/row.c12
-rw-r--r--contrib/tools/python/src/Modules/_ssl.c4
-rw-r--r--contrib/tools/python/src/Modules/cPickle.c13
-rw-r--r--contrib/tools/python/src/Modules/getpath.c2
-rw-r--r--contrib/tools/python/src/Modules/itertoolsmodule.c10
-rw-r--r--contrib/tools/python/src/Modules/mathmodule.c8
-rw-r--r--contrib/tools/python/src/Modules/mmapmodule.c3
-rw-r--r--contrib/tools/python/src/Modules/parsermodule.c11
-rw-r--r--contrib/tools/python/src/Modules/signalmodule.c6
-rw-r--r--contrib/tools/python/src/Modules/socketmodule.c29
-rw-r--r--contrib/tools/python/src/Modules/zipimport.c6
-rw-r--r--contrib/tools/python/src/Objects/bytearrayobject.c10
-rw-r--r--contrib/tools/python/src/Objects/exceptions.c4
-rw-r--r--contrib/tools/python/src/Objects/longobject.c2
-rw-r--r--contrib/tools/python/src/Objects/obmalloc.c1
-rw-r--r--contrib/tools/python/src/Objects/structseq.c9
-rw-r--r--contrib/tools/python/src/Objects/typeobject.c8
-rw-r--r--contrib/tools/python/src/PC/_winreg.c8
-rw-r--r--contrib/tools/python/src/PC/dl_nt.c15
-rw-r--r--contrib/tools/python/src/Parser/myreadline.c22
-rw-r--r--contrib/tools/python/src/Parser/tokenizer.c9
-rw-r--r--contrib/tools/python/src/Python/ast.c5
-rw-r--r--contrib/tools/python/src/Python/bltinmodule.c11
-rw-r--r--contrib/tools/python/src/Python/compile.c4
-rw-r--r--contrib/tools/python/src/Python/dtoa.c78
-rw-r--r--contrib/tools/python/src/Python/getargs.c14
-rw-r--r--contrib/tools/python/src/Python/getcopyright.c2
-rw-r--r--contrib/tools/python/src/Python/import.c6
-rw-r--r--contrib/tools/python/src/Python/pythonrun.c2
-rw-r--r--contrib/tools/python/src/Python/thread_pthread.h15
42 files changed, 237 insertions, 186 deletions
diff --git a/contrib/tools/python/src/Include/code.h b/contrib/tools/python/src/Include/code.h
index 16aee701e0..ac6b81dc99 100644
--- a/contrib/tools/python/src/Include/code.h
+++ b/contrib/tools/python/src/Include/code.h
@@ -104,7 +104,7 @@ PyAPI_FUNC(int) _PyCode_CheckLineNumber(PyCodeObject* co,
*
* Return (type(obj), obj, ...): a tuple with variable size (at least 2 items)
* depending on the type and the value. The type is the first item to not
- * compare bytes and str which can raise a BytesWarning exception. */
+ * compare bytes and unicode which can raise a BytesWarning exception. */
PyAPI_FUNC(PyObject*) _PyCode_ConstantKey(PyObject *obj);
PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts,
diff --git a/contrib/tools/python/src/Include/patchlevel.h b/contrib/tools/python/src/Include/patchlevel.h
index b12d901685..0ce6313fa9 100644
--- a/contrib/tools/python/src/Include/patchlevel.h
+++ b/contrib/tools/python/src/Include/patchlevel.h
@@ -22,12 +22,12 @@
/*--start constants--*/
#define PY_MAJOR_VERSION 2
#define PY_MINOR_VERSION 7
-#define PY_MICRO_VERSION 16
+#define PY_MICRO_VERSION 18
#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_FINAL
#define PY_RELEASE_SERIAL 0
/* Version as a string */
-#define PY_VERSION "2.7.16"
+#define PY_VERSION "2.7.18"
/*--end constants--*/
/* Subversion Revision number of this file (not of the repository). Empty
diff --git a/contrib/tools/python/src/Include/pyport.h b/contrib/tools/python/src/Include/pyport.h
index ad2ff5929a..f58b8d2d99 100644
--- a/contrib/tools/python/src/Include/pyport.h
+++ b/contrib/tools/python/src/Include/pyport.h
@@ -481,7 +481,7 @@ extern "C" {
} \
} while(0)
-/* Py_SET_ERANGE_ON_OVERFLOW(x)
+/* Py_SET_ERANGE_IF_OVERFLOW(x)
* An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility.
*/
#define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X)
diff --git a/contrib/tools/python/src/Modules/_csv.c b/contrib/tools/python/src/Modules/_csv.c
index 88e3e90658..a54e74ecc3 100644
--- a/contrib/tools/python/src/Modules/_csv.c
+++ b/contrib/tools/python/src/Modules/_csv.c
@@ -818,7 +818,7 @@ Reader_iternext(ReaderObj *self)
if (c == '\0') {
Py_DECREF(lineobj);
PyErr_Format(error_obj,
- "line contains NULL byte");
+ "line contains NUL");
goto err;
}
if (parse_process_char(self, c) < 0) {
diff --git a/contrib/tools/python/src/Modules/_ctypes/_ctypes.c b/contrib/tools/python/src/Modules/_ctypes/_ctypes.c
index 8abcd30753..bef251ef04 100644
--- a/contrib/tools/python/src/Modules/_ctypes/_ctypes.c
+++ b/contrib/tools/python/src/Modules/_ctypes/_ctypes.c
@@ -1534,9 +1534,10 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
itemsize = itemdict->size;
- if (length * itemsize < 0) {
+ if (itemsize != 0 && length > PY_SSIZE_T_MAX / itemsize) {
PyErr_SetString(PyExc_OverflowError,
"array too large");
+ Py_DECREF(stgdict);
return NULL;
}
@@ -1559,8 +1560,10 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
/* create the new instance (which is a class,
since we are a metatype!) */
result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds);
- if (result == NULL)
+ if (result == NULL) {
+ Py_DECREF(stgdict);
return NULL;
+ }
/* replace the class dict by our updated spam dict */
if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) {
@@ -1574,12 +1577,16 @@ PyCArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
A permanent annoyance: char arrays are also strings!
*/
if (itemdict->getfunc == _ctypes_get_fielddesc("c")->getfunc) {
- if (-1 == add_getset(result, CharArray_getsets))
+ if (-1 == add_getset(result, CharArray_getsets)) {
+ Py_DECREF(result);
return NULL;
+ }
#ifdef CTYPES_UNICODE
} else if (itemdict->getfunc == _ctypes_get_fielddesc("u")->getfunc) {
- if (-1 == add_getset(result, WCharArray_getsets))
+ if (-1 == add_getset(result, WCharArray_getsets)) {
+ Py_DECREF(result);
return NULL;
+ }
#endif
}
@@ -2788,16 +2795,18 @@ static PyObject *
PyCData_reduce(PyObject *_self, PyObject *args)
{
CDataObject *self = (CDataObject *)_self;
+ PyObject *dict;
if (PyObject_stgdict(_self)->flags & (TYPEFLAG_ISPOINTER|TYPEFLAG_HASPOINTER)) {
PyErr_SetString(PyExc_ValueError,
"ctypes objects containing pointers cannot be pickled");
return NULL;
}
- return Py_BuildValue("O(O(NN))",
- _unpickle,
- Py_TYPE(_self),
- PyObject_GetAttrString(_self, "__dict__"),
+ dict = PyObject_GetAttrString(_self, "__dict__");
+ if (dict == NULL) {
+ return NULL;
+ }
+ return Py_BuildValue("O(O(NN))", _unpickle, Py_TYPE(_self), dict,
PyString_FromStringAndSize(self->b_ptr, self->b_size));
}
diff --git a/contrib/tools/python/src/Modules/_ctypes/callproc.c b/contrib/tools/python/src/Modules/_ctypes/callproc.c
index e7bff9cae1..661271a3a6 100644
--- a/contrib/tools/python/src/Modules/_ctypes/callproc.c
+++ b/contrib/tools/python/src/Modules/_ctypes/callproc.c
@@ -242,7 +242,9 @@ static TCHAR *FormatError(DWORD code)
{
TCHAR *lpMsgBuf;
DWORD n;
- n = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+ n = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
@@ -1846,6 +1848,7 @@ POINTER(PyObject *self, PyObject *cls)
"s(O){}",
buf,
&PyCPointer_Type);
+ PyMem_Free(buf);
if (result == NULL)
return result;
key = PyLong_FromVoidPtr(result);
diff --git a/contrib/tools/python/src/Modules/_ctypes/cfield.c b/contrib/tools/python/src/Modules/_ctypes/cfield.c
index 8088da13c2..2dc0198cf1 100644
--- a/contrib/tools/python/src/Modules/_ctypes/cfield.c
+++ b/contrib/tools/python/src/Modules/_ctypes/cfield.c
@@ -1291,24 +1291,16 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
static PyObject *
s_get(void *ptr, Py_ssize_t size)
{
- PyObject *result;
- size_t slen;
+ Py_ssize_t i;
+ char *p;
- result = PyString_FromString((char *)ptr);
- if (!result)
- return NULL;
- /* chop off at the first NUL character, if any.
- * On error, result will be deallocated and set to NULL.
- */
- slen = strlen(PyString_AS_STRING(result));
- size = min(size, (Py_ssize_t)slen);
- if (result->ob_refcnt == 1) {
- /* shorten the result */
- _PyString_Resize(&result, size);
- return result;
- } else
- /* cannot shorten the result */
- return PyString_FromStringAndSize(ptr, size);
+ p = (char *)ptr;
+ for (i = 0; i < size; ++i) {
+ if (*p++ == '\0')
+ break;
+ }
+
+ return PyBytes_FromStringAndSize((char *)ptr, (Py_ssize_t)i);
}
static PyObject *
diff --git a/contrib/tools/python/src/Modules/_hashopenssl.c b/contrib/tools/python/src/Modules/_hashopenssl.c
index de69f6fcd0..5df08e54b2 100644
--- a/contrib/tools/python/src/Modules/_hashopenssl.c
+++ b/contrib/tools/python/src/Modules/_hashopenssl.c
@@ -133,12 +133,6 @@ newEVPobject(PyObject *name)
if (retval == NULL)
return NULL;
- retval->ctx = EVP_MD_CTX_new();
- if (retval->ctx == NULL) {
- PyErr_NoMemory();
- return NULL;
- }
-
/* save the name for .name to return */
Py_INCREF(name);
retval->name = name;
@@ -146,6 +140,13 @@ newEVPobject(PyObject *name)
retval->lock = NULL;
#endif
+ retval->ctx = EVP_MD_CTX_new();
+ if (retval->ctx == NULL) {
+ Py_DECREF(retval);
+ PyErr_NoMemory();
+ return NULL;
+ }
+
return retval;
}
@@ -205,6 +206,7 @@ EVP_copy(EVPobject *self, PyObject *unused)
return NULL;
if (!locked_EVP_MD_CTX_copy(newobj->ctx, self)) {
+ Py_DECREF(newobj);
return _setException(PyExc_ValueError);
}
return (PyObject *)newobj;
@@ -899,7 +901,7 @@ init_hashlib(void)
{
PyObject *m, *openssl_md_meth_names;
-#ifndef OPENSSL_VERSION_1_1
+#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER)
/* Load all digest algorithms and initialize cpuid */
OPENSSL_add_all_algorithms_noconf();
ERR_load_crypto_strings();
diff --git a/contrib/tools/python/src/Modules/_hotshot.c b/contrib/tools/python/src/Modules/_hotshot.c
index 33cd38da2f..4fc5cee479 100644
--- a/contrib/tools/python/src/Modules/_hotshot.c
+++ b/contrib/tools/python/src/Modules/_hotshot.c
@@ -482,8 +482,11 @@ restart:
}
else if (!err) {
result = PyTuple_New(4);
- if (result == NULL)
+ if (result == NULL) {
+ Py_XDECREF(s1);
+ Py_XDECREF(s2);
return NULL;
+ }
PyTuple_SET_ITEM(result, 0, PyInt_FromLong(what));
PyTuple_SET_ITEM(result, 2, PyInt_FromLong(fileno));
if (s1 == NULL)
diff --git a/contrib/tools/python/src/Modules/_io/bufferedio.c b/contrib/tools/python/src/Modules/_io/bufferedio.c
index b8c98a4d0d..d68f7d85b0 100644
--- a/contrib/tools/python/src/Modules/_io/bufferedio.c
+++ b/contrib/tools/python/src/Modules/_io/bufferedio.c
@@ -1363,6 +1363,7 @@ _bufferedreader_read_all(buffered *self)
res = buffered_flush_and_rewind_unlocked(self);
if (res == NULL) {
Py_DECREF(chunks);
+ Py_XDECREF(data);
return NULL;
}
Py_CLEAR(res);
diff --git a/contrib/tools/python/src/Modules/_json.c b/contrib/tools/python/src/Modules/_json.c
index 3a88882f0c..050d37daa4 100644
--- a/contrib/tools/python/src/Modules/_json.c
+++ b/contrib/tools/python/src/Modules/_json.c
@@ -1375,8 +1375,10 @@ _match_number_str(PyScannerObject *s, PyObject *pystr, Py_ssize_t start, Py_ssiz
else {
double d = PyOS_string_to_double(PyString_AS_STRING(numstr),
NULL, NULL);
- if (d == -1.0 && PyErr_Occurred())
+ if (d == -1.0 && PyErr_Occurred()) {
+ Py_DECREF(numstr);
return NULL;
+ }
rval = PyFloat_FromDouble(d);
}
}
diff --git a/contrib/tools/python/src/Modules/_multiprocessing/multiprocessing.c b/contrib/tools/python/src/Modules/_multiprocessing/multiprocessing.c
index d192a074ba..eecace887e 100644
--- a/contrib/tools/python/src/Modules/_multiprocessing/multiprocessing.c
+++ b/contrib/tools/python/src/Modules/_multiprocessing/multiprocessing.c
@@ -167,7 +167,7 @@ multiprocessing_recvfd(PyObject *self, PyObject *args)
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
- cmsg->cmsg_len = CMSG_LEN(sizeof(int));
+ cmsg->cmsg_len = CMSG_SPACE(sizeof(int));
msg.msg_controllen = cmsg->cmsg_len;
Py_BEGIN_ALLOW_THREADS
diff --git a/contrib/tools/python/src/Modules/_sqlite/row.c b/contrib/tools/python/src/Modules/_sqlite/row.c
index 9ebe7b7b81..c0da329c13 100644
--- a/contrib/tools/python/src/Modules/_sqlite/row.c
+++ b/contrib/tools/python/src/Modules/_sqlite/row.c
@@ -199,14 +199,16 @@ static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other,
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
- if (PyType_IsSubtype(Py_TYPE(_other), &pysqlite_RowType)) {
+ if (PyObject_TypeCheck(_other, &pysqlite_RowType)) {
pysqlite_Row *other = (pysqlite_Row *)_other;
- PyObject *res = PyObject_RichCompare(self->description, other->description, opid);
- if ((opid == Py_EQ && res == Py_True)
- || (opid == Py_NE && res == Py_False)) {
- Py_DECREF(res);
+ int eq = PyObject_RichCompareBool(self->description, other->description, Py_EQ);
+ if (eq < 0) {
+ return NULL;
+ }
+ if (eq) {
return PyObject_RichCompare(self->data, other->data, opid);
}
+ return PyBool_FromLong(opid != Py_EQ);
}
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
diff --git a/contrib/tools/python/src/Modules/_ssl.c b/contrib/tools/python/src/Modules/_ssl.c
index dc3c3dfcba..b5e88eba5a 100644
--- a/contrib/tools/python/src/Modules/_ssl.c
+++ b/contrib/tools/python/src/Modules/_ssl.c
@@ -1589,7 +1589,7 @@ static PyObject *PySSL_version(PySSLSocket *self)
return PyUnicode_FromString(version);
}
-#if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG)
+#if HAVE_NPN
static PyObject *PySSL_selected_npn_protocol(PySSLSocket *self) {
const unsigned char *out;
unsigned int outlen;
@@ -2117,7 +2117,7 @@ static PyMethodDef PySSLMethods[] = {
PySSL_peercert_doc},
{"cipher", (PyCFunction)PySSL_cipher, METH_NOARGS},
{"version", (PyCFunction)PySSL_version, METH_NOARGS},
-#ifdef OPENSSL_NPN_NEGOTIATED
+#if HAVE_NPN
{"selected_npn_protocol", (PyCFunction)PySSL_selected_npn_protocol, METH_NOARGS},
#endif
#if HAVE_ALPN
diff --git a/contrib/tools/python/src/Modules/cPickle.c b/contrib/tools/python/src/Modules/cPickle.c
index 914ebb3eeb..f7c6feccaf 100644
--- a/contrib/tools/python/src/Modules/cPickle.c
+++ b/contrib/tools/python/src/Modules/cPickle.c
@@ -586,12 +586,15 @@ readline_file(Unpicklerobject *self, char **s)
while (1) {
Py_ssize_t bigger;
char *newbuf;
- for (; i < (self->buf_size - 1); i++) {
- if (feof(self->fp) ||
- (self->buf[i] = getc(self->fp)) == '\n') {
- self->buf[i + 1] = '\0';
+ while (i < (self->buf_size - 1)) {
+ int newchar = getc(self->fp);
+ if (newchar != EOF) {
+ self->buf[i++] = newchar;
+ }
+ if (newchar == EOF || newchar == '\n') {
+ self->buf[i] = '\0';
*s = self->buf;
- return i + 1;
+ return i;
}
}
if (self->buf_size > (PY_SSIZE_T_MAX >> 1)) {
diff --git a/contrib/tools/python/src/Modules/getpath.c b/contrib/tools/python/src/Modules/getpath.c
index 83ce2da9b8..9506821e29 100644
--- a/contrib/tools/python/src/Modules/getpath.c
+++ b/contrib/tools/python/src/Modules/getpath.c
@@ -496,7 +496,7 @@ calculate_path(void)
if (tmpbuffer[0] == SEP)
/* tmpbuffer should never be longer than MAXPATHLEN,
but extra check does not hurt */
- strncpy(argv0_path, tmpbuffer, MAXPATHLEN);
+ strncpy(argv0_path, tmpbuffer, MAXPATHLEN + 1);
else {
/* Interpret relative to progpath */
reduce(argv0_path);
diff --git a/contrib/tools/python/src/Modules/itertoolsmodule.c b/contrib/tools/python/src/Modules/itertoolsmodule.c
index 47db7affb0..edd21be337 100644
--- a/contrib/tools/python/src/Modules/itertoolsmodule.c
+++ b/contrib/tools/python/src/Modules/itertoolsmodule.c
@@ -314,6 +314,7 @@ typedef struct {
PyObject_HEAD
PyObject *it;
int numread;
+ int running;
PyObject *nextlink;
PyObject *(values[LINKCELLS]);
} teedataobject;
@@ -336,6 +337,7 @@ teedataobject_new(PyObject *it)
if (tdo == NULL)
return NULL;
+ tdo->running = 0;
tdo->numread = 0;
tdo->nextlink = NULL;
Py_INCREF(it);
@@ -364,7 +366,14 @@ teedataobject_getitem(teedataobject *tdo, int i)
else {
/* this is the lead iterator, so fetch more data */
assert(i == tdo->numread);
+ if (tdo->running) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "cannot re-enter the tee iterator");
+ return NULL;
+ }
+ tdo->running = 1;
value = PyIter_Next(tdo->it);
+ tdo->running = 0;
if (value == NULL)
return NULL;
tdo->numread++;
@@ -3321,6 +3330,7 @@ count_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
lz = (countobject *)type->tp_alloc(type, 0);
if (lz == NULL) {
Py_XDECREF(long_cnt);
+ Py_DECREF(long_step);
return NULL;
}
lz->cnt = cnt;
diff --git a/contrib/tools/python/src/Modules/mathmodule.c b/contrib/tools/python/src/Modules/mathmodule.c
index 67354a7594..e2ad281e12 100644
--- a/contrib/tools/python/src/Modules/mathmodule.c
+++ b/contrib/tools/python/src/Modules/mathmodule.c
@@ -71,7 +71,7 @@ static const double pi = 3.141592653589793238462643383279502884197;
static const double sqrtpi = 1.772453850905516027298167483341145182798;
static double
-sinpi(double x)
+m_sinpi(double x)
{
double y, r;
int n;
@@ -270,7 +270,7 @@ m_tgamma(double x)
integer. */
if (absx > 200.0) {
if (x < 0.0) {
- return 0.0/sinpi(x);
+ return 0.0/m_sinpi(x);
}
else {
errno = ERANGE;
@@ -294,7 +294,7 @@ m_tgamma(double x)
}
z = z * lanczos_g / y;
if (x < 0.0) {
- r = -pi / sinpi(absx) / absx * exp(y) / lanczos_sum(absx);
+ r = -pi / m_sinpi(absx) / absx * exp(y) / lanczos_sum(absx);
r -= z * r;
if (absx < 140.0) {
r /= pow(y, absx - 0.5);
@@ -366,7 +366,7 @@ m_lgamma(double x)
(x-0.5)*(log(x+lanczos_g-0.5)-1);
}
else {
- r = log(pi) - log(fabs(sinpi(absx))) - log(absx) -
+ r = log(pi) - log(fabs(m_sinpi(absx))) - log(absx) -
(log(lanczos_sum(absx)) - lanczos_g +
(absx-0.5)*(log(absx+lanczos_g-0.5)-1));
}
diff --git a/contrib/tools/python/src/Modules/mmapmodule.c b/contrib/tools/python/src/Modules/mmapmodule.c
index 02b31ca438..57cc40c53f 100644
--- a/contrib/tools/python/src/Modules/mmapmodule.c
+++ b/contrib/tools/python/src/Modules/mmapmodule.c
@@ -1436,7 +1436,8 @@ static void
setint(PyObject *d, const char *name, long value)
{
PyObject *o = PyInt_FromLong(value);
- if (o && PyDict_SetItemString(d, name, o) == 0) {
+ if (o) {
+ PyDict_SetItemString(d, name, o);
Py_DECREF(o);
}
}
diff --git a/contrib/tools/python/src/Modules/parsermodule.c b/contrib/tools/python/src/Modules/parsermodule.c
index fcc618d5d9..759f0ff4f6 100644
--- a/contrib/tools/python/src/Modules/parsermodule.c
+++ b/contrib/tools/python/src/Modules/parsermodule.c
@@ -1055,14 +1055,15 @@ validate_numnodes(node *n, int num, const char *const name)
static int
validate_terminal(node *terminal, int type, char *string)
{
- int res = (validate_ntype(terminal, type)
- && ((string == 0) || (strcmp(string, STR(terminal)) == 0)));
-
- if (!res && !PyErr_Occurred()) {
+ if (!validate_ntype(terminal, type)) {
+ return 0;
+ }
+ if (string != NULL && strcmp(string, STR(terminal)) != 0) {
PyErr_Format(parser_error,
"Illegal terminal: expected \"%s\"", string);
+ return 0;
}
- return (res);
+ return 1;
}
diff --git a/contrib/tools/python/src/Modules/signalmodule.c b/contrib/tools/python/src/Modules/signalmodule.c
index 8628f7a800..88b4711932 100644
--- a/contrib/tools/python/src/Modules/signalmodule.c
+++ b/contrib/tools/python/src/Modules/signalmodule.c
@@ -173,8 +173,10 @@ trip_signal(int sig_num)
cleared in PyErr_CheckSignals() before .tripped. */
is_tripped = 1;
Py_AddPendingCall(checksignals_witharg, NULL);
- if (wakeup_fd != -1)
- write(wakeup_fd, "\0", 1);
+ if (wakeup_fd != -1) {
+ int rc = write(wakeup_fd, "\0", 1);
+ (void)rc;
+ }
}
static void
diff --git a/contrib/tools/python/src/Modules/socketmodule.c b/contrib/tools/python/src/Modules/socketmodule.c
index 4ab05d97b3..ea7876157d 100644
--- a/contrib/tools/python/src/Modules/socketmodule.c
+++ b/contrib/tools/python/src/Modules/socketmodule.c
@@ -625,16 +625,16 @@ set_gaierror(int error)
#ifdef __VMS
/* Function to send in segments */
-static int
-sendsegmented(int sock_fd, char *buf, int len, int flags)
+static Py_ssize_t
+sendsegmented(int sock_fd, char *buf, Py_ssize_t len, int flags)
{
int n = 0;
- int remaining = len;
+ Py_ssize_t remaining = len;
while (remaining > 0) {
unsigned int segment;
- segment = (remaining >= SEGMENT_SIZE ? SEGMENT_SIZE : remaining);
+ segment = ((size_t)remaining >= SEGMENT_SIZE ? SEGMENT_SIZE : (unsigned int) remaining);
n = send(sock_fd, buf, segment, flags);
if (n < 0) {
return n;
@@ -2797,7 +2797,8 @@ static PyObject *
sock_send(PySocketSockObject *s, PyObject *args)
{
char *buf;
- int len, n = -1, flags = 0, timeout;
+ int flags = 0, timeout;
+ Py_ssize_t len, n = -1;
Py_buffer pbuf;
if (!PyArg_ParseTuple(args, "s*|i:send", &pbuf, &flags))
@@ -2813,12 +2814,18 @@ sock_send(PySocketSockObject *s, PyObject *args)
BEGIN_SELECT_LOOP(s)
Py_BEGIN_ALLOW_THREADS
timeout = internal_select_ex(s, 1, interval);
- if (!timeout)
+ if (!timeout) {
#ifdef __VMS
n = sendsegmented(s->sock_fd, buf, len, flags);
+#elif defined(MS_WINDOWS)
+ if (len > INT_MAX) {
+ len = INT_MAX;
+ }
+ n = send(s->sock_fd, buf, (int)len, flags);
#else
n = send(s->sock_fd, buf, len, flags);
#endif
+ }
Py_END_ALLOW_THREADS
if (timeout == 1) {
PyBuffer_Release(&pbuf);
@@ -2830,7 +2837,7 @@ sock_send(PySocketSockObject *s, PyObject *args)
PyBuffer_Release(&pbuf);
if (n < 0)
return s->errorhandler();
- return PyInt_FromLong((long)n);
+ return PyInt_FromSsize_t(n);
}
PyDoc_STRVAR(send_doc,
@@ -2847,7 +2854,8 @@ static PyObject *
sock_sendall(PySocketSockObject *s, PyObject *args)
{
char *buf;
- int len, n = -1, flags = 0, timeout, saved_errno;
+ int flags = 0, timeout, saved_errno;
+ Py_ssize_t len, n = -1;
Py_buffer pbuf;
if (!PyArg_ParseTuple(args, "s*|i:sendall", &pbuf, &flags))
@@ -2868,6 +2876,11 @@ sock_sendall(PySocketSockObject *s, PyObject *args)
if (!timeout) {
#ifdef __VMS
n = sendsegmented(s->sock_fd, buf, len, flags);
+#elif defined(MS_WINDOWS)
+ if (len > INT_MAX) {
+ len = INT_MAX;
+ }
+ n = send(s->sock_fd, buf, (int)len, flags);
#else
n = send(s->sock_fd, buf, len, flags);
#endif
diff --git a/contrib/tools/python/src/Modules/zipimport.c b/contrib/tools/python/src/Modules/zipimport.c
index 1691773ec1..8ec2475571 100644
--- a/contrib/tools/python/src/Modules/zipimport.c
+++ b/contrib/tools/python/src/Modules/zipimport.c
@@ -714,8 +714,8 @@ read_directory(const char *archive)
unsigned int count, i;
unsigned char buffer[46];
size_t length;
- char path[MAXPATHLEN + 5];
- char name[MAXPATHLEN + 5];
+ char name[MAXPATHLEN + 1];
+ char path[2*MAXPATHLEN + 2]; /* archive + SEP + name + '\0' */
const char *errmsg = NULL;
if (strlen(archive) > MAXPATHLEN) {
@@ -838,7 +838,7 @@ read_directory(const char *archive)
}
}
- strncpy(path + length + 1, name, MAXPATHLEN - length - 1);
+ memcpy(path + length + 1, name, name_size + 1);
t = Py_BuildValue("sHIIkHHI", path, compress, data_size,
file_size, file_offset, time, date, crc);
diff --git a/contrib/tools/python/src/Objects/bytearrayobject.c b/contrib/tools/python/src/Objects/bytearrayobject.c
index a96d6d981d..5824832477 100644
--- a/contrib/tools/python/src/Objects/bytearrayobject.c
+++ b/contrib/tools/python/src/Objects/bytearrayobject.c
@@ -1027,14 +1027,6 @@ bytearray_repr(PyByteArrayObject *self)
static PyObject *
bytearray_str(PyObject *op)
{
-#if 0
- if (Py_BytesWarningFlag) {
- if (PyErr_WarnEx(PyExc_BytesWarning,
- "str() on a bytearray instance", 1))
- return NULL;
- }
- return bytearray_repr((PyByteArrayObject*)op);
-#endif
return PyBytes_FromStringAndSize(((PyByteArrayObject*)op)->ob_bytes, Py_SIZE(op));
}
@@ -1059,7 +1051,7 @@ bytearray_richcompare(PyObject *self, PyObject *other, int op)
if (rc) {
if (Py_BytesWarningFlag && op == Py_EQ) {
if (PyErr_WarnEx(PyExc_BytesWarning,
- "Comparison between bytearray and string", 1))
+ "Comparison between bytearray and unicode", 1))
return NULL;
}
diff --git a/contrib/tools/python/src/Objects/exceptions.c b/contrib/tools/python/src/Objects/exceptions.c
index a62a19d659..dbd941a357 100644
--- a/contrib/tools/python/src/Objects/exceptions.c
+++ b/contrib/tools/python/src/Objects/exceptions.c
@@ -2026,8 +2026,8 @@ SimpleExtendsException(PyExc_Warning, UnicodeWarning,
* BytesWarning extends Warning
*/
SimpleExtendsException(PyExc_Warning, BytesWarning,
- "Base class for warnings about bytes and buffer related problems, mostly\n"
- "related to conversion from str or comparing to str.");
+ "Base class for warnings about bytes and bytearray related problems, \n"
+ "mostly related to comparing to str.");
/* Pre-computed MemoryError instance. Best to create this as early as
* possible and not wait until a MemoryError is actually raised!
diff --git a/contrib/tools/python/src/Objects/longobject.c b/contrib/tools/python/src/Objects/longobject.c
index f40ad7ab1b..c05f67c36c 100644
--- a/contrib/tools/python/src/Objects/longobject.c
+++ b/contrib/tools/python/src/Objects/longobject.c
@@ -1022,7 +1022,7 @@ PyLong_AsUnsignedLongLongMask(PyObject *vv)
if (vv == NULL || !PyLong_Check(vv)) {
PyErr_BadInternalCall();
- return (unsigned long) -1;
+ return (unsigned PY_LONG_LONG) -1;
}
v = (PyLongObject *)vv;
i = Py_SIZE(v);
diff --git a/contrib/tools/python/src/Objects/obmalloc.c b/contrib/tools/python/src/Objects/obmalloc.c
index 78e974a4c7..6aad6a913f 100644
--- a/contrib/tools/python/src/Objects/obmalloc.c
+++ b/contrib/tools/python/src/Objects/obmalloc.c
@@ -439,6 +439,7 @@ static int running_on_valgrind = -1;
*
* You shouldn't change this unless you know what you are doing.
*/
+
#if SIZEOF_VOID_P > 4
#define ALIGNMENT 16 /* must be 2^N */
#define ALIGNMENT_SHIFT 4
diff --git a/contrib/tools/python/src/Objects/structseq.c b/contrib/tools/python/src/Objects/structseq.c
index 3e45840fb7..82df926f28 100644
--- a/contrib/tools/python/src/Objects/structseq.c
+++ b/contrib/tools/python/src/Objects/structseq.c
@@ -252,9 +252,11 @@ structseq_repr(PyStructSequence *obj)
}
/* "typename(", limited to TYPE_MAXSIZE */
- len = strlen(typ->tp_name) > TYPE_MAXSIZE ? TYPE_MAXSIZE :
- strlen(typ->tp_name);
- strncpy(pbuf, typ->tp_name, len);
+ len = strlen(typ->tp_name);
+ if (len > TYPE_MAXSIZE) {
+ len = TYPE_MAXSIZE;
+ }
+ pbuf = memcpy(pbuf, typ->tp_name, len);
pbuf += len;
*pbuf++ = '(';
@@ -266,6 +268,7 @@ structseq_repr(PyStructSequence *obj)
val = PyTuple_GetItem(tup, i);
if (cname == NULL || val == NULL) {
+ Py_DECREF(tup);
return NULL;
}
repr = PyObject_Repr(val);
diff --git a/contrib/tools/python/src/Objects/typeobject.c b/contrib/tools/python/src/Objects/typeobject.c
index 844fb00749..1c8958c49a 100644
--- a/contrib/tools/python/src/Objects/typeobject.c
+++ b/contrib/tools/python/src/Objects/typeobject.c
@@ -210,11 +210,11 @@ assign_version_tag(PyTypeObject *type)
static PyMemberDef type_members[] = {
{"__basicsize__", T_PYSSIZET, offsetof(PyTypeObject,tp_basicsize),READONLY},
{"__itemsize__", T_PYSSIZET, offsetof(PyTypeObject, tp_itemsize), READONLY},
- {"__flags__", T_LONG, offsetof(PyTypeObject, tp_flags), READONLY},
- {"__weakrefoffset__", T_LONG,
+ {"__flags__", T_ULONG, offsetof(PyTypeObject, tp_flags), READONLY},
+ {"__weakrefoffset__", T_PYSSIZET,
offsetof(PyTypeObject, tp_weaklistoffset), READONLY},
{"__base__", T_OBJECT, offsetof(PyTypeObject, tp_base), READONLY},
- {"__dictoffset__", T_LONG,
+ {"__dictoffset__", T_PYSSIZET,
offsetof(PyTypeObject, tp_dictoffset), READONLY},
{"__mro__", T_OBJECT, offsetof(PyTypeObject, tp_mro), READONLY},
{0}
@@ -4398,7 +4398,7 @@ wrap_lenfunc(PyObject *self, PyObject *args, void *wrapped)
res = (*func)(self);
if (res == -1 && PyErr_Occurred())
return NULL;
- return PyInt_FromLong((long)res);
+ return PyInt_FromSsize_t(res);
}
static PyObject *
diff --git a/contrib/tools/python/src/PC/_winreg.c b/contrib/tools/python/src/PC/_winreg.c
index 720f7988d3..0e4e816618 100644
--- a/contrib/tools/python/src/PC/_winreg.c
+++ b/contrib/tools/python/src/PC/_winreg.c
@@ -322,19 +322,19 @@ PyDoc_STRVAR(SetValueEx_doc,
PyDoc_STRVAR(DisableReflectionKey_doc,
"Disables registry reflection for 32-bit processes running on a 64-bit\n"
-"Operating System. Will generally raise NotImplemented if executed on\n"
+"Operating System. Will generally raise NotImplementedError if executed on\n"
"a 32-bit Operating System.\n"
"If the key is not on the reflection list, the function succeeds but has no effect.\n"
"Disabling reflection for a key does not affect reflection of any subkeys.");
PyDoc_STRVAR(EnableReflectionKey_doc,
"Restores registry reflection for the specified disabled key.\n"
-"Will generally raise NotImplemented if executed on a 32-bit Operating System.\n"
+"Will generally raise NotImplementedError if executed on a 32-bit Operating System.\n"
"Restoring reflection for a key does not affect reflection of any subkeys.");
PyDoc_STRVAR(QueryReflectionKey_doc,
"bool = QueryReflectionKey(hkey) - Determines the reflection state for the specified key.\n"
-"Will generally raise NotImplemented if executed on a 32-bit Operating System.\n");
+"Will generally raise NotImplementedError if executed on a 32-bit Operating System.\n");
/* PyHKEY docstrings */
PyDoc_STRVAR(PyHKEY_doc,
@@ -727,7 +727,7 @@ fixupMultiSZ(char **str, char *data, int len)
Q = data + len;
for (P = data, i = 0; P < Q && *P != '\0'; P++, i++) {
str[i] = P;
- for(; *P != '\0'; P++)
+ for (; P < Q && *P != '\0'; P++)
;
}
}
diff --git a/contrib/tools/python/src/PC/dl_nt.c b/contrib/tools/python/src/PC/dl_nt.c
index ef1ce0934c..3e58bacb55 100644
--- a/contrib/tools/python/src/PC/dl_nt.c
+++ b/contrib/tools/python/src/PC/dl_nt.c
@@ -33,8 +33,8 @@ const char *PyWin_DLLVersionString = dllVersionBuffer;
typedef BOOL (WINAPI * PFN_GETCURRENTACTCTX)(HANDLE *);
typedef BOOL (WINAPI * PFN_ACTIVATEACTCTX)(HANDLE, ULONG_PTR *);
typedef BOOL (WINAPI * PFN_DEACTIVATEACTCTX)(DWORD, ULONG_PTR);
-typedef BOOL (WINAPI * PFN_ADDREFACTCTX)(HANDLE);
-typedef BOOL (WINAPI * PFN_RELEASEACTCTX)(HANDLE);
+typedef void (WINAPI * PFN_ADDREFACTCTX)(HANDLE);
+typedef void (WINAPI * PFN_RELEASEACTCTX)(HANDLE);
// locals and function pointers for this activation context magic.
static HANDLE PyWin_DLLhActivationContext = NULL; // one day it might be public
@@ -90,9 +90,14 @@ BOOL WINAPI DllMain (HANDLE hInst,
// and capture our activation context for use when loading extensions.
_LoadActCtxPointers();
if (pfnGetCurrentActCtx && pfnAddRefActCtx)
- if ((*pfnGetCurrentActCtx)(&PyWin_DLLhActivationContext))
- if (!(*pfnAddRefActCtx)(PyWin_DLLhActivationContext))
- OutputDebugString("Python failed to load the default activation context\n");
+ if ((*pfnGetCurrentActCtx)(&PyWin_DLLhActivationContext)) {
+ (*pfnAddRefActCtx)(PyWin_DLLhActivationContext);
+ }
+ else {
+ OutputDebugString("Python failed to load the default "
+ "activation context\n");
+ return FALSE;
+ }
break;
case DLL_PROCESS_DETACH:
diff --git a/contrib/tools/python/src/Parser/myreadline.c b/contrib/tools/python/src/Parser/myreadline.c
index 59db41ab16..537621402b 100644
--- a/contrib/tools/python/src/Parser/myreadline.c
+++ b/contrib/tools/python/src/Parser/myreadline.c
@@ -108,7 +108,7 @@ char *
PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)
{
size_t n;
- char *p;
+ char *p, *pr;
n = 100;
if ((p = (char *)PyMem_MALLOC(n)) == NULL)
return NULL;
@@ -140,17 +140,29 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, char *prompt)
n = strlen(p);
while (n > 0 && p[n-1] != '\n') {
size_t incr = n+2;
- p = (char *)PyMem_REALLOC(p, n + incr);
- if (p == NULL)
- return NULL;
if (incr > INT_MAX) {
+ PyMem_FREE(p);
PyErr_SetString(PyExc_OverflowError, "input line too long");
+ return NULL;
+ }
+ pr = (char *)PyMem_REALLOC(p, n + incr);
+ if (pr == NULL) {
+ PyMem_FREE(p);
+ PyErr_NoMemory();
+ return NULL;
}
+ p = pr;
if (my_fgets(p+n, (int)incr, sys_stdin) != 0)
break;
n += strlen(p+n);
}
- return (char *)PyMem_REALLOC(p, n+1);
+ pr = (char *)PyMem_REALLOC(p, n+1);
+ if (pr == NULL) {
+ PyMem_FREE(p);
+ PyErr_NoMemory();
+ return NULL;
+ }
+ return pr;
}
diff --git a/contrib/tools/python/src/Parser/tokenizer.c b/contrib/tools/python/src/Parser/tokenizer.c
index c6e61df533..8966661194 100644
--- a/contrib/tools/python/src/Parser/tokenizer.c
+++ b/contrib/tools/python/src/Parser/tokenizer.c
@@ -656,9 +656,14 @@ translate_newlines(const char *s, int exec_input, struct tok_state *tok) {
}
*current = '\0';
final_length = current - buf + 1;
- if (final_length < needed_length && final_length)
+ if (final_length < needed_length && final_length) {
/* should never fail */
- buf = PyMem_REALLOC(buf, final_length);
+ char* result = PyMem_REALLOC(buf, final_length);
+ if (result == NULL) {
+ PyMem_FREE(buf);
+ }
+ buf = result;
+ }
return buf;
}
diff --git a/contrib/tools/python/src/Python/ast.c b/contrib/tools/python/src/Python/ast.c
index 946032589f..10571a3ec2 100644
--- a/contrib/tools/python/src/Python/ast.c
+++ b/contrib/tools/python/src/Python/ast.c
@@ -852,8 +852,9 @@ ast_for_decorator(struct compiling *c, const node *n)
name_expr = NULL;
}
else if (NCH(n) == 5) { /* Call with no arguments */
- d = Call(name_expr, NULL, NULL, NULL, NULL, LINENO(n),
- n->n_col_offset, c->c_arena);
+ d = Call(name_expr, NULL, NULL, NULL, NULL,
+ name_expr->lineno, name_expr->col_offset,
+ c->c_arena);
if (!d)
return NULL;
name_expr = NULL;
diff --git a/contrib/tools/python/src/Python/bltinmodule.c b/contrib/tools/python/src/Python/bltinmodule.c
index 4b819da8b3..6d47de1fb2 100644
--- a/contrib/tools/python/src/Python/bltinmodule.c
+++ b/contrib/tools/python/src/Python/bltinmodule.c
@@ -351,11 +351,12 @@ Fail_arg:
}
PyDoc_STRVAR(filter_doc,
-"filter(function or None, sequence) -> list, tuple, or string\n"
-"\n"
-"Return those items of sequence for which function(item) is true. If\n"
-"function is None, return the items that are true. If sequence is a tuple\n"
-"or string, return the same type, else return a list.");
+"filter(function or None, iterable) -> list, string or tuple\n\
+\n\
+Return a sequence yielding those items of iterable for which function(item)\n\
+is true. If function is None, return the items that are true.\n\
+If iterable is a string or a tuple, the result also has that type; otherwise\n\
+it is always a list.");
static PyObject *
builtin_format(PyObject *self, PyObject *args)
diff --git a/contrib/tools/python/src/Python/compile.c b/contrib/tools/python/src/Python/compile.c
index 7f8babc12b..92b2c39b91 100644
--- a/contrib/tools/python/src/Python/compile.c
+++ b/contrib/tools/python/src/Python/compile.c
@@ -221,7 +221,7 @@ _Py_Mangle(PyObject *privateobj, PyObject *ident)
}
plen = strlen(p);
- if (plen + nlen >= PY_SSIZE_T_MAX - 1) {
+ if (nlen >= PY_SSIZE_T_MAX - 1 - plen) {
PyErr_SetString(PyExc_OverflowError,
"private identifier too large to be mangled");
return NULL;
@@ -233,7 +233,7 @@ _Py_Mangle(PyObject *privateobj, PyObject *ident)
/* ident = "_" + p[:plen] + name # i.e. 1+plen+nlen bytes */
buffer = PyString_AS_STRING(ident);
buffer[0] = '_';
- strncpy(buffer+1, p, plen);
+ memcpy(buffer+1, p, plen);
strcpy(buffer+1+plen, name);
return ident;
}
diff --git a/contrib/tools/python/src/Python/dtoa.c b/contrib/tools/python/src/Python/dtoa.c
index 73e23af010..25eb9a72d0 100644
--- a/contrib/tools/python/src/Python/dtoa.c
+++ b/contrib/tools/python/src/Python/dtoa.c
@@ -1514,8 +1514,9 @@ _Py_dg_strtod(const char *s00, char **se)
ULong y, z, abs_exp;
Long L;
BCinfo bc;
- Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
+ Bigint *bb = NULL, *bd = NULL, *bd0 = NULL, *bs = NULL, *delta = NULL;
size_t ndigits, fraclen;
+ double result;
dval(&rv) = 0.;
@@ -1707,7 +1708,6 @@ _Py_dg_strtod(const char *s00, char **se)
if (k > 9) {
dval(&rv) = tens[k - 9] * dval(&rv) + z;
}
- bd0 = 0;
if (nd <= DBL_DIG
&& Flt_Rounds == 1
) {
@@ -1877,14 +1877,11 @@ _Py_dg_strtod(const char *s00, char **se)
bd = Balloc(bd0->k);
if (bd == NULL) {
- Bfree(bd0);
goto failed_malloc;
}
Bcopy(bd, bd0);
bb = sd2b(&rv, bc.scale, &bbe); /* srv = bb * 2^bbe */
if (bb == NULL) {
- Bfree(bd);
- Bfree(bd0);
goto failed_malloc;
}
/* Record whether lsb of bb is odd, in case we need this
@@ -1894,9 +1891,6 @@ _Py_dg_strtod(const char *s00, char **se)
/* tdv = bd * 10**e; srv = bb * 2**bbe */
bs = i2b(1);
if (bs == NULL) {
- Bfree(bb);
- Bfree(bd);
- Bfree(bd0);
goto failed_malloc;
}
@@ -1945,56 +1939,39 @@ _Py_dg_strtod(const char *s00, char **se)
/* Scale bb, bd, bs by the appropriate powers of 2 and 5. */
if (bb5 > 0) {
+ Bigint *bb1;
bs = pow5mult(bs, bb5);
if (bs == NULL) {
- Bfree(bb);
- Bfree(bd);
- Bfree(bd0);
goto failed_malloc;
}
bb1 = mult(bs, bb);
Bfree(bb);
bb = bb1;
if (bb == NULL) {
- Bfree(bs);
- Bfree(bd);
- Bfree(bd0);
goto failed_malloc;
}
}
if (bb2 > 0) {
bb = lshift(bb, bb2);
if (bb == NULL) {
- Bfree(bs);
- Bfree(bd);
- Bfree(bd0);
goto failed_malloc;
}
}
if (bd5 > 0) {
bd = pow5mult(bd, bd5);
if (bd == NULL) {
- Bfree(bb);
- Bfree(bs);
- Bfree(bd0);
goto failed_malloc;
}
}
if (bd2 > 0) {
bd = lshift(bd, bd2);
if (bd == NULL) {
- Bfree(bb);
- Bfree(bs);
- Bfree(bd0);
goto failed_malloc;
}
}
if (bs2 > 0) {
bs = lshift(bs, bs2);
if (bs == NULL) {
- Bfree(bb);
- Bfree(bd);
- Bfree(bd0);
goto failed_malloc;
}
}
@@ -2005,10 +1982,6 @@ _Py_dg_strtod(const char *s00, char **se)
delta = diff(bb, bd);
if (delta == NULL) {
- Bfree(bb);
- Bfree(bs);
- Bfree(bd);
- Bfree(bd0);
goto failed_malloc;
}
dsign = delta->sign;
@@ -2062,10 +2035,6 @@ _Py_dg_strtod(const char *s00, char **se)
}
delta = lshift(delta,Log2P);
if (delta == NULL) {
- Bfree(bb);
- Bfree(bs);
- Bfree(bd);
- Bfree(bd0);
goto failed_malloc;
}
if (cmp(delta, bs) > 0)
@@ -2167,11 +2136,6 @@ _Py_dg_strtod(const char *s00, char **se)
if ((word0(&rv) & Exp_mask) >=
Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
if (word0(&rv0) == Big0 && word1(&rv0) == Big1) {
- Bfree(bb);
- Bfree(bd);
- Bfree(bs);
- Bfree(bd0);
- Bfree(delta);
goto ovfl;
}
word0(&rv) = Big0;
@@ -2213,16 +2177,11 @@ _Py_dg_strtod(const char *s00, char **se)
}
}
cont:
- Bfree(bb);
- Bfree(bd);
- Bfree(bs);
- Bfree(delta);
+ Bfree(bb); bb = NULL;
+ Bfree(bd); bd = NULL;
+ Bfree(bs); bs = NULL;
+ Bfree(delta); delta = NULL;
}
- Bfree(bb);
- Bfree(bd);
- Bfree(bs);
- Bfree(bd0);
- Bfree(delta);
if (bc.nd > nd) {
error = bigcomp(&rv, s0, &bc);
if (error)
@@ -2236,24 +2195,37 @@ _Py_dg_strtod(const char *s00, char **se)
}
ret:
- return sign ? -dval(&rv) : dval(&rv);
+ result = sign ? -dval(&rv) : dval(&rv);
+ goto done;
parse_error:
- return 0.0;
+ result = 0.0;
+ goto done;
failed_malloc:
errno = ENOMEM;
- return -1.0;
+ result = -1.0;
+ goto done;
undfl:
- return sign ? -0.0 : 0.0;
+ result = sign ? -0.0 : 0.0;
+ goto done;
ovfl:
errno = ERANGE;
/* Can't trust HUGE_VAL */
word0(&rv) = Exp_mask;
word1(&rv) = 0;
- return sign ? -dval(&rv) : dval(&rv);
+ result = sign ? -dval(&rv) : dval(&rv);
+ goto done;
+
+ done:
+ Bfree(bb);
+ Bfree(bd);
+ Bfree(bs);
+ Bfree(bd0);
+ Bfree(delta);
+ return result;
}
diff --git a/contrib/tools/python/src/Python/getargs.c b/contrib/tools/python/src/Python/getargs.c
index cc1ddde977..12ee248637 100644
--- a/contrib/tools/python/src/Python/getargs.c
+++ b/contrib/tools/python/src/Python/getargs.c
@@ -1156,7 +1156,19 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
memcpy(*buffer,
PyString_AS_STRING(s),
size + 1);
- STORE_SIZE(size);
+
+ if (flags & FLAG_SIZE_T) {
+ *q2 = size;
+ }
+ else {
+ if (INT_MAX < size) {
+ Py_DECREF(s);
+ PyErr_SetString(PyExc_OverflowError,
+ "size does not fit in an int");
+ return converterr("", arg, msgbuf, bufsize);
+ }
+ *q = (int)size;
+ }
} else {
/* Using a 0-terminated buffer:
diff --git a/contrib/tools/python/src/Python/getcopyright.c b/contrib/tools/python/src/Python/getcopyright.c
index 0ef16d0923..3362ed5984 100644
--- a/contrib/tools/python/src/Python/getcopyright.c
+++ b/contrib/tools/python/src/Python/getcopyright.c
@@ -4,7 +4,7 @@
static char cprt[] =
"\
-Copyright (c) 2001-2019 Python Software Foundation.\n\
+Copyright (c) 2001-2020 Python Software Foundation.\n\
All Rights Reserved.\n\
\n\
Copyright (c) 2000 BeOpen.com.\n\
diff --git a/contrib/tools/python/src/Python/import.c b/contrib/tools/python/src/Python/import.c
index d59c1549bf..0bc0c65bfe 100644
--- a/contrib/tools/python/src/Python/import.c
+++ b/contrib/tools/python/src/Python/import.c
@@ -2465,7 +2465,7 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
"Module name too long");
return NULL;
}
- strncpy(buf, start, len);
+ memcpy(buf, start, len);
buf[len] = '\0';
pkgname = PyString_FromString(buf);
if (pkgname == NULL) {
@@ -2563,7 +2563,7 @@ load_next(PyObject *mod, PyObject *altmod, char **p_name, char *buf,
"Module name too long");
return NULL;
}
- strncpy(p, name, len);
+ memcpy(p, name, len);
p[len] = '\0';
*p_buflen = p+len-buf;
@@ -2577,7 +2577,7 @@ load_next(PyObject *mod, PyObject *altmod, char **p_name, char *buf,
Py_DECREF(result);
return NULL;
}
- strncpy(buf, name, len);
+ memcpy(buf, name, len);
buf[len] = '\0';
*p_buflen = len;
}
diff --git a/contrib/tools/python/src/Python/pythonrun.c b/contrib/tools/python/src/Python/pythonrun.c
index 44574d795a..345d95c619 100644
--- a/contrib/tools/python/src/Python/pythonrun.c
+++ b/contrib/tools/python/src/Python/pythonrun.c
@@ -70,7 +70,7 @@ int Py_VerboseFlag; /* Needed by import.c */
int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
int Py_InspectFlag; /* Needed to determine whether to exit at SystemExit */
int Py_NoSiteFlag; /* Suppress 'import site' */
-int Py_BytesWarningFlag; /* Warn on str(bytes) and str(buffer) */
+int Py_BytesWarningFlag; /* Warn on comparison between bytearray and unicode */
int Py_DontWriteBytecodeFlag; /* Suppress writing bytecode files (*.py[co]) */
int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */
int Py_FrozenFlag = 1; /* Needed by getpath.c */
diff --git a/contrib/tools/python/src/Python/thread_pthread.h b/contrib/tools/python/src/Python/thread_pthread.h
index 6d4b3b389f..4d792a123a 100644
--- a/contrib/tools/python/src/Python/thread_pthread.h
+++ b/contrib/tools/python/src/Python/thread_pthread.h
@@ -430,12 +430,15 @@ PyThread_free_lock(PyThread_type_lock lock)
(void) error; /* silence unused-but-set-variable warning */
dprintf(("PyThread_free_lock(%p) called\n", lock));
- status = pthread_mutex_destroy( &thelock->mut );
- CHECK_STATUS("pthread_mutex_destroy");
-
+ /* some pthread-like implementations tie the mutex to the cond
+ * and must have the cond destroyed first.
+ */
status = pthread_cond_destroy( &thelock->lock_released );
CHECK_STATUS("pthread_cond_destroy");
+ status = pthread_mutex_destroy( &thelock->mut );
+ CHECK_STATUS("pthread_mutex_destroy");
+
free((void *)thelock);
}
@@ -497,12 +500,12 @@ PyThread_release_lock(PyThread_type_lock lock)
thelock->locked = 0;
- status = pthread_mutex_unlock( &thelock->mut );
- CHECK_STATUS("pthread_mutex_unlock[3]");
-
/* wake up someone (anyone, if any) waiting on the lock */
status = pthread_cond_signal( &thelock->lock_released );
CHECK_STATUS("pthread_cond_signal");
+
+ status = pthread_mutex_unlock( &thelock->mut );
+ CHECK_STATUS("pthread_mutex_unlock[3]");
}
#endif /* USE_SEMAPHORES */