aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Python/context.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/context.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/context.c')
-rw-r--r--contrib/tools/python3/src/Python/context.c78
1 files changed, 27 insertions, 51 deletions
diff --git a/contrib/tools/python3/src/Python/context.c b/contrib/tools/python3/src/Python/context.c
index ef9db6a9cd..1ffae9871b 100644
--- a/contrib/tools/python3/src/Python/context.c
+++ b/contrib/tools/python3/src/Python/context.c
@@ -124,8 +124,7 @@ _PyContext_Enter(PyThreadState *ts, PyObject *octx)
ctx->ctx_prev = (PyContext *)ts->context; /* borrow */
ctx->ctx_entered = 1;
- Py_INCREF(ctx);
- ts->context = (PyObject *)ctx;
+ ts->context = Py_NewRef(ctx);
ts->context_ver++;
return 0;
@@ -400,8 +399,7 @@ context_new_from_vars(PyHamtObject *vars)
return NULL;
}
- Py_INCREF(vars);
- ctx->ctx_vars = vars;
+ ctx->ctx_vars = (PyHamtObject*)Py_NewRef(vars);
_PyObject_GC_TRACK(ctx);
return ctx;
@@ -546,8 +544,7 @@ context_tp_subscript(PyContext *self, PyObject *key)
PyErr_SetObject(PyExc_KeyError, key);
return NULL;
}
- Py_INCREF(val);
- return val;
+ return Py_NewRef(val);
}
static int
@@ -588,11 +585,9 @@ _contextvars_Context_get_impl(PyContext *self, PyObject *key,
return NULL;
}
if (found == 0) {
- Py_INCREF(default_value);
- return default_value;
+ return Py_NewRef(default_value);
}
- Py_INCREF(val);
- return val;
+ return Py_NewRef(val);
}
@@ -831,11 +826,9 @@ contextvar_new(PyObject *name, PyObject *def)
return NULL;
}
- Py_INCREF(name);
- var->var_name = name;
+ var->var_name = Py_NewRef(name);
- Py_XINCREF(def);
- var->var_default = def;
+ var->var_default = Py_XNewRef(def);
var->var_cached = NULL;
var->var_cached_tsid = 0;
@@ -1176,8 +1169,7 @@ error:
static PyObject *
token_get_var(PyContextToken *self, void *Py_UNUSED(ignored))
{
- Py_INCREF(self->tok_var);
- return (PyObject *)self->tok_var;
+ return Py_NewRef(self->tok_var);;
}
static PyObject *
@@ -1187,8 +1179,7 @@ token_get_old_value(PyContextToken *self, void *Py_UNUSED(ignored))
return get_token_missing();
}
- Py_INCREF(self->tok_oldval);
- return self->tok_oldval;
+ return Py_NewRef(self->tok_oldval);
}
static PyGetSetDef PyContextTokenType_getsetlist[] = {
@@ -1228,14 +1219,11 @@ token_new(PyContext *ctx, PyContextVar *var, PyObject *val)
return NULL;
}
- Py_INCREF(ctx);
- tok->tok_ctx = ctx;
+ tok->tok_ctx = (PyContext*)Py_NewRef(ctx);
- Py_INCREF(var);
- tok->tok_var = var;
+ tok->tok_var = (PyContextVar*)Py_NewRef(var);
- Py_XINCREF(val);
- tok->tok_oldval = val;
+ tok->tok_oldval = Py_XNewRef(val);
tok->tok_used = 0;
@@ -1247,25 +1235,29 @@ token_new(PyContext *ctx, PyContextVar *var, PyObject *val)
/////////////////////////// Token.MISSING
-static PyObject *_token_missing;
-
-
-typedef struct {
- PyObject_HEAD
-} PyContextTokenMissing;
-
-
static PyObject *
context_token_missing_tp_repr(PyObject *self)
{
return PyUnicode_FromString("<Token.MISSING>");
}
+static void
+context_token_missing_tp_dealloc(_PyContextTokenMissing *Py_UNUSED(self))
+{
+#ifdef Py_DEBUG
+ /* The singleton is statically allocated. */
+ _Py_FatalRefcountError("deallocating the token missing singleton");
+#else
+ return;
+#endif
+}
+
PyTypeObject _PyContextTokenMissing_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"Token.MISSING",
- sizeof(PyContextTokenMissing),
+ sizeof(_PyContextTokenMissing),
+ .tp_dealloc = (destructor)context_token_missing_tp_dealloc,
.tp_getattro = PyObject_GenericGetAttr,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_repr = context_token_missing_tp_repr,
@@ -1275,19 +1267,7 @@ PyTypeObject _PyContextTokenMissing_Type = {
static PyObject *
get_token_missing(void)
{
- if (_token_missing != NULL) {
- Py_INCREF(_token_missing);
- return _token_missing;
- }
-
- _token_missing = (PyObject *)PyObject_New(
- PyContextTokenMissing, &_PyContextTokenMissing_Type);
- if (_token_missing == NULL) {
- return NULL;
- }
-
- Py_INCREF(_token_missing);
- return _token_missing;
+ return Py_NewRef(&_Py_SINGLETON(context_token_missing));
}
@@ -1312,15 +1292,11 @@ _PyContext_ClearFreeList(PyInterpreterState *interp)
void
_PyContext_Fini(PyInterpreterState *interp)
{
- if (_Py_IsMainInterpreter(interp)) {
- Py_CLEAR(_token_missing);
- }
_PyContext_ClearFreeList(interp);
#if defined(Py_DEBUG) && PyContext_MAXFREELIST > 0
struct _Py_context_state *state = &interp->context;
state->numfree = -1;
#endif
- _PyHamt_Fini(interp);
}
@@ -1333,7 +1309,7 @@ _PyContext_Init(PyInterpreterState *interp)
PyObject *missing = get_token_missing();
if (PyDict_SetItemString(
- PyContextToken_Type.tp_dict, "MISSING", missing))
+ _PyType_GetDict(&PyContextToken_Type), "MISSING", missing))
{
Py_DECREF(missing);
return _PyStatus_ERR("can't init context types");