aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python/src/Python
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 /contrib/tools/python/src/Python
parent224da250178b9250c7577a167d44f94f732d3627 (diff)
downloadydb-9051e2318afc1bfbd88a103f7392e622aa8c9527.tar.gz
Update Python from 2.7.16 to 2.7.18
2a151e9cf2ebdfa59d250c1bbb800e908703a6f0
Diffstat (limited to 'contrib/tools/python/src/Python')
-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
9 files changed, 63 insertions, 74 deletions
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 */