aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Python/structmember.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-02-07 09:25:06 +0300
committershadchin <shadchin@yandex-team.com>2024-02-07 09:40:03 +0300
commit3139d9ab6df2a7014d19b87582466d17b4f496e2 (patch)
tree7fcb26a72dac212aa26beaaa7cd769fb1e396b5e /contrib/tools/python3/src/Python/structmember.c
parent4c04a8d1e278e6ca7ff16c11b74b2f16fc144253 (diff)
downloadydb-3139d9ab6df2a7014d19b87582466d17b4f496e2.tar.gz
Update Python 3 to 3.11.8
Diffstat (limited to 'contrib/tools/python3/src/Python/structmember.c')
-rw-r--r--contrib/tools/python3/src/Python/structmember.c85
1 files changed, 57 insertions, 28 deletions
diff --git a/contrib/tools/python3/src/Python/structmember.c b/contrib/tools/python3/src/Python/structmember.c
index c7e318811d..c790656978 100644
--- a/contrib/tools/python3/src/Python/structmember.c
+++ b/contrib/tools/python3/src/Python/structmember.c
@@ -187,45 +187,74 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
WARN("Truncation of value to int");
break;
}
- case T_UINT:{
- unsigned long ulong_val = PyLong_AsUnsignedLong(v);
- if ((ulong_val == (unsigned long)-1) && PyErr_Occurred()) {
- /* XXX: For compatibility, accept negative int values
- as well. */
- PyErr_Clear();
- ulong_val = PyLong_AsLong(v);
- if ((ulong_val == (unsigned long)-1) &&
- PyErr_Occurred())
+ case T_UINT: {
+ /* XXX: For compatibility, accept negative int values
+ as well. */
+ int overflow;
+ long long_val = PyLong_AsLongAndOverflow(v, &overflow);
+ if (long_val == -1 && PyErr_Occurred()) {
+ return -1;
+ }
+ if (overflow < 0) {
+ PyErr_SetString(PyExc_OverflowError,
+ "Python int too large to convert to C long");
+ return -1;
+ }
+ else if (!overflow) {
+ *(unsigned int *)addr = (unsigned int)(unsigned long)long_val;
+ if (long_val < 0) {
+ WARN("Writing negative value into unsigned field");
+ }
+ else if ((unsigned long)long_val > UINT_MAX) {
+ WARN("Truncation of value to unsigned short");
+ }
+ }
+ else {
+ unsigned long ulong_val = PyLong_AsUnsignedLong(v);
+ if (ulong_val == (unsigned long)-1 && PyErr_Occurred()) {
return -1;
- *(unsigned int *)addr = (unsigned int)ulong_val;
- WARN("Writing negative value into unsigned field");
- } else
- *(unsigned int *)addr = (unsigned int)ulong_val;
- if (ulong_val > UINT_MAX)
- WARN("Truncation of value to unsigned int");
- break;
+ }
+ *(unsigned int*)addr = (unsigned int)ulong_val;
+ if (ulong_val > UINT_MAX) {
+ WARN("Truncation of value to unsigned int");
+ }
}
+ break;
+ }
case T_LONG:{
*(long*)addr = PyLong_AsLong(v);
if ((*(long*)addr == -1) && PyErr_Occurred())
return -1;
break;
}
- case T_ULONG:{
- *(unsigned long*)addr = PyLong_AsUnsignedLong(v);
- if ((*(unsigned long*)addr == (unsigned long)-1)
- && PyErr_Occurred()) {
- /* XXX: For compatibility, accept negative int values
- as well. */
- PyErr_Clear();
- *(unsigned long*)addr = PyLong_AsLong(v);
- if ((*(unsigned long*)addr == (unsigned long)-1)
- && PyErr_Occurred())
+ case T_ULONG: {
+ /* XXX: For compatibility, accept negative int values
+ as well. */
+ int overflow;
+ long long_val = PyLong_AsLongAndOverflow(v, &overflow);
+ if (long_val == -1 && PyErr_Occurred()) {
+ return -1;
+ }
+ if (overflow < 0) {
+ PyErr_SetString(PyExc_OverflowError,
+ "Python int too large to convert to C long");
+ return -1;
+ }
+ else if (!overflow) {
+ *(unsigned long *)addr = (unsigned long)long_val;
+ if (long_val < 0) {
+ WARN("Writing negative value into unsigned field");
+ }
+ }
+ else {
+ unsigned long ulong_val = PyLong_AsUnsignedLong(v);
+ if (ulong_val == (unsigned long)-1 && PyErr_Occurred()) {
return -1;
- WARN("Writing negative value into unsigned field");
+ }
+ *(unsigned long*)addr = ulong_val;
}
break;
- }
+ }
case T_PYSSIZET:{
*(Py_ssize_t*)addr = PyLong_AsSsize_t(v);
if ((*(Py_ssize_t*)addr == (Py_ssize_t)-1)