aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Python/marshal.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-02-12 07:53:52 +0300
committershadchin <shadchin@yandex-team.com>2024-02-12 08:07:36 +0300
commitce1b7ca3171f9158180640c6a02a74b4afffedea (patch)
treee47c1e8391b1b0128262c1e9b1e6ed4c8fff2348 /contrib/tools/python3/src/Python/marshal.c
parent57350d96f030db90f220ce50ee591d5c5d403df7 (diff)
downloadydb-ce1b7ca3171f9158180640c6a02a74b4afffedea.tar.gz
Update Python from 3.11.8 to 3.12.2
Diffstat (limited to 'contrib/tools/python3/src/Python/marshal.c')
-rw-r--r--contrib/tools/python3/src/Python/marshal.c57
1 files changed, 24 insertions, 33 deletions
diff --git a/contrib/tools/python3/src/Python/marshal.c b/contrib/tools/python3/src/Python/marshal.c
index 29f3bab60a..90953cbb72 100644
--- a/contrib/tools/python3/src/Python/marshal.c
+++ b/contrib/tools/python3/src/Python/marshal.c
@@ -11,6 +11,7 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_code.h" // _PyCode_New()
+#include "pycore_long.h" // _PyLong_DigitCount
#include "pycore_hashtable.h" // _Py_hashtable_t
#include "marshal.h" // Py_MARSHAL_VERSION
@@ -232,15 +233,15 @@ w_PyLong(const PyLongObject *ob, char flag, WFILE *p)
digit d;
W_TYPE(TYPE_LONG, p);
- if (Py_SIZE(ob) == 0) {
+ if (_PyLong_IsZero(ob)) {
w_long((long)0, p);
return;
}
/* set l to number of base PyLong_MARSHAL_BASE digits */
- n = Py_ABS(Py_SIZE(ob));
+ n = _PyLong_DigitCount(ob);
l = (n-1) * PyLong_MARSHAL_RATIO;
- d = ob->ob_digit[n-1];
+ d = ob->long_value.ob_digit[n-1];
assert(d != 0); /* a PyLong is always normalized */
do {
d >>= PyLong_MARSHAL_SHIFT;
@@ -251,17 +252,17 @@ w_PyLong(const PyLongObject *ob, char flag, WFILE *p)
p->error = WFERR_UNMARSHALLABLE;
return;
}
- w_long((long)(Py_SIZE(ob) > 0 ? l : -l), p);
+ w_long((long)(_PyLong_IsNegative(ob) ? -l : l), p);
for (i=0; i < n-1; i++) {
- d = ob->ob_digit[i];
+ d = ob->long_value.ob_digit[i];
for (j=0; j < PyLong_MARSHAL_RATIO; j++) {
w_short(d & PyLong_MARSHAL_MASK, p);
d >>= PyLong_MARSHAL_SHIFT;
}
assert (d == 0);
}
- d = ob->ob_digit[n-1];
+ d = ob->long_value.ob_digit[n-1];
do {
w_short(d & PyLong_MARSHAL_MASK, p);
d >>= PyLong_MARSHAL_SHIFT;
@@ -326,8 +327,8 @@ w_ref(PyObject *v, char *flag, WFILE *p)
goto err;
}
w = (int)s;
- Py_INCREF(v);
- if (_Py_hashtable_set(p->hashtable, v, (void *)(uintptr_t)w) < 0) {
+ if (_Py_hashtable_set(p->hashtable, Py_NewRef(v),
+ (void *)(uintptr_t)w) < 0) {
Py_DECREF(v);
goto err;
}
@@ -849,7 +850,7 @@ r_PyLong(RFILE *p)
if (ob == NULL)
return NULL;
- Py_SET_SIZE(ob, n > 0 ? size : -size);
+ _PyLong_SetSignAndDigitCount(ob, n < 0 ? -1 : 1, size);
for (i = 0; i < size-1; i++) {
d = 0;
@@ -859,7 +860,7 @@ r_PyLong(RFILE *p)
goto bad_digit;
d += (digit)md << j*PyLong_MARSHAL_SHIFT;
}
- ob->ob_digit[i] = d;
+ ob->long_value.ob_digit[i] = d;
}
d = 0;
@@ -879,7 +880,7 @@ r_PyLong(RFILE *p)
assert(!PyErr_Occurred());
/* top digit should be nonzero, else the resulting PyLong won't be
normalized */
- ob->ob_digit[size-1] = d;
+ ob->long_value.ob_digit[size-1] = d;
return (PyObject *)ob;
bad_digit:
Py_DECREF(ob);
@@ -950,8 +951,7 @@ r_ref_insert(PyObject *o, Py_ssize_t idx, int flag, RFILE *p)
{
if (o != NULL && flag) { /* currently only FLAG_REF is defined */
PyObject *tmp = PyList_GET_ITEM(p->refs, idx);
- Py_INCREF(o);
- PyList_SET_ITEM(p->refs, idx, o);
+ PyList_SET_ITEM(p->refs, idx, Py_NewRef(o));
Py_DECREF(tmp);
}
return o;
@@ -1016,28 +1016,23 @@ r_object(RFILE *p)
break;
case TYPE_NONE:
- Py_INCREF(Py_None);
- retval = Py_None;
+ retval = Py_NewRef(Py_None);
break;
case TYPE_STOPITER:
- Py_INCREF(PyExc_StopIteration);
- retval = PyExc_StopIteration;
+ retval = Py_NewRef(PyExc_StopIteration);
break;
case TYPE_ELLIPSIS:
- Py_INCREF(Py_Ellipsis);
- retval = Py_Ellipsis;
+ retval = Py_NewRef(Py_Ellipsis);
break;
case TYPE_FALSE:
- Py_INCREF(Py_False);
- retval = Py_False;
+ retval = Py_NewRef(Py_False);
break;
case TYPE_TRUE:
- Py_INCREF(Py_True);
- retval = Py_True;
+ retval = Py_NewRef(Py_True);
break;
case TYPE_INT:
@@ -1230,8 +1225,7 @@ r_object(RFILE *p)
if (!PyErr_Occurred())
PyErr_SetString(PyExc_TypeError,
"NULL object in marshal data for tuple");
- Py_DECREF(v);
- v = NULL;
+ Py_SETREF(v, NULL);
break;
}
PyTuple_SET_ITEM(v, i, v2);
@@ -1258,8 +1252,7 @@ r_object(RFILE *p)
if (!PyErr_Occurred())
PyErr_SetString(PyExc_TypeError,
"NULL object in marshal data for list");
- Py_DECREF(v);
- v = NULL;
+ Py_SETREF(v, NULL);
break;
}
PyList_SET_ITEM(v, i, v2);
@@ -1291,8 +1284,7 @@ r_object(RFILE *p)
Py_DECREF(val);
}
if (PyErr_Occurred()) {
- Py_DECREF(v);
- v = NULL;
+ Py_SETREF(v, NULL);
}
retval = v;
break;
@@ -1337,8 +1329,7 @@ r_object(RFILE *p)
if (!PyErr_Occurred())
PyErr_SetString(PyExc_TypeError,
"NULL object in marshal data for set");
- Py_DECREF(v);
- v = NULL;
+ Py_SETREF(v, NULL);
break;
}
if (PySet_Add(v, v2) == -1) {
@@ -1500,8 +1491,7 @@ r_object(RFILE *p)
PyErr_SetString(PyExc_ValueError, "bad marshal data (invalid reference)");
break;
}
- Py_INCREF(v);
- retval = v;
+ retval = Py_NewRef(v);
break;
default:
@@ -1894,6 +1884,7 @@ marshal_module_exec(PyObject *mod)
static PyModuleDef_Slot marshalmodule_slots[] = {
{Py_mod_exec, marshal_module_exec},
+ {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
{0, NULL}
};