aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Python/structmember.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-04-28 21:17:44 +0300
committershadchin <shadchin@yandex-team.com>2024-04-28 21:25:54 +0300
commita55d99a3eb72f90355bc146baeda18aa7eb97352 (patch)
treeb17cfed786effe8b81bba022239d6729f716fbeb /contrib/tools/python3/Python/structmember.c
parent67bf49d08acf1277eff4c336021ac22d964bb4c4 (diff)
downloadydb-a55d99a3eb72f90355bc146baeda18aa7eb97352.tar.gz
Update Python 3 to 3.12.3
7d09de7d8b99ea2be554ef0fc61276942ca9c2e1
Diffstat (limited to 'contrib/tools/python3/Python/structmember.c')
-rw-r--r--contrib/tools/python3/Python/structmember.c82
1 files changed, 45 insertions, 37 deletions
diff --git a/contrib/tools/python3/Python/structmember.c b/contrib/tools/python3/Python/structmember.c
index ebebaa0a03..f4de0cb9ea 100644
--- a/contrib/tools/python3/Python/structmember.c
+++ b/contrib/tools/python3/Python/structmember.c
@@ -3,6 +3,9 @@
#include "Python.h"
#include "structmember.h" // PyMemberDef
+#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_long.h" // _PyLong_IsNegative()
+
PyObject *
PyMember_GetOne(const char *obj_addr, PyMemberDef *l)
@@ -200,27 +203,22 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
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");
+ v = _PyNumber_Index(v);
+ if (v == NULL) {
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");
+ if (_PyLong_IsNegative((PyLongObject *)v)) {
+ long long_val = PyLong_AsLong(v);
+ Py_DECREF(v);
+ if (long_val == -1 && PyErr_Occurred()) {
+ return -1;
}
+ *(unsigned int *)addr = (unsigned int)(unsigned long)long_val;
+ WARN("Writing negative value into unsigned field");
}
else {
unsigned long ulong_val = PyLong_AsUnsignedLong(v);
+ Py_DECREF(v);
if (ulong_val == (unsigned long)-1 && PyErr_Occurred()) {
return -1;
}
@@ -240,24 +238,22 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
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");
+ v = _PyNumber_Index(v);
+ if (v == NULL) {
return -1;
}
- else if (!overflow) {
- *(unsigned long *)addr = (unsigned long)long_val;
- if (long_val < 0) {
- WARN("Writing negative value into unsigned field");
+ if (_PyLong_IsNegative((PyLongObject *)v)) {
+ long long_val = PyLong_AsLong(v);
+ Py_DECREF(v);
+ if (long_val == -1 && PyErr_Occurred()) {
+ return -1;
}
+ *(unsigned long *)addr = (unsigned long)long_val;
+ WARN("Writing negative value into unsigned field");
}
else {
unsigned long ulong_val = PyLong_AsUnsignedLong(v);
+ Py_DECREF(v);
if (ulong_val == (unsigned long)-1 && PyErr_Occurred()) {
return -1;
}
@@ -313,18 +309,30 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
return -1;
break;
}
- case T_ULONGLONG:{
- unsigned long long value;
- /* ??? PyLong_AsLongLong accepts an int, but PyLong_AsUnsignedLongLong
- doesn't ??? */
- if (PyLong_Check(v))
- *(unsigned long long*)addr = value = PyLong_AsUnsignedLongLong(v);
- else
- *(unsigned long long*)addr = value = PyLong_AsLong(v);
- if ((value == (unsigned long long)-1) && PyErr_Occurred())
+ case Py_T_ULONGLONG: {
+ v = _PyNumber_Index(v);
+ if (v == NULL) {
return -1;
- break;
}
+ if (_PyLong_IsNegative((PyLongObject *)v)) {
+ long long_val = PyLong_AsLong(v);
+ Py_DECREF(v);
+ if (long_val == -1 && PyErr_Occurred()) {
+ return -1;
+ }
+ *(unsigned long long *)addr = (unsigned long long)(long long)long_val;
+ WARN("Writing negative value into unsigned field");
+ }
+ else {
+ unsigned long long ulonglong_val = PyLong_AsUnsignedLongLong(v);
+ Py_DECREF(v);
+ if (ulonglong_val == (unsigned long long)-1 && PyErr_Occurred()) {
+ return -1;
+ }
+ *(unsigned long long*)addr = ulonglong_val;
+ }
+ break;
+ }
default:
PyErr_Format(PyExc_SystemError,
"bad memberdescr type for %s", l->name);