Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-81057: Move contextvars-related Globals to _PyRuntimeState#99400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Move _token_missing to _PyRuntimeState.
  • Loading branch information
@ericsnowcurrently
ericsnowcurrently committedNov 11, 2022
commit902615318c3678e753ee9e0f39801fd528df0eb0
4 changes: 4 additions & 0 deletionsInclude/internal/pycore_context.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,6 +18,10 @@ void _PyContext_Fini(PyInterpreterState *);

/* other API */

typedef struct {
PyObject_HEAD
} _PyContextTokenMissing;

#ifndef WITH_FREELISTS
// without freelists
# define PyContext_MAXFREELIST 0
Expand Down
2 changes: 2 additions & 0 deletionsInclude/internal/pycore_global_objects.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,7 @@ extern "C" {
#include "pycore_gc.h" // PyGC_Head
#include "pycore_global_strings.h" // struct _Py_global_strings
#include "pycore_hamt.h" // PyHamtNode_Bitmap
#include "pycore_context.h" // _PyContextTokenMissing


// These would be in pycore_long.h if it weren't for an include cycle.
Expand DownExpand Up@@ -48,6 +49,7 @@ struct _Py_global_objects {

_PyGC_Head_UNUSED _hamt_bitmap_node_empty_gc_not_used;
PyHamtNode_Bitmap hamt_bitmap_node_empty;
_PyContextTokenMissing context_token_missing;
} singletons;

PyObject *interned;
Expand Down
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

3 changes: 3 additions & 0 deletionsInclude/internal/pycore_runtime_init.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,6 +45,9 @@ extern "C" {
.hamt_bitmap_node_empty = { \
.ob_base = _PyVarObject_IMMORTAL_INIT(&_PyHamt_BitmapNode_Type, 0) \
}, \
.context_token_missing = { \
.ob_base = _PyObject_IMMORTAL_INIT(&_PyContextTokenMissing_Type), \
}, \
}, \
}, \
._main_interpreter = _PyInterpreterState_INIT, \
Expand Down
37 changes: 14 additions & 23 deletionsPython/context.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1235,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,
Expand All@@ -1263,17 +1267,7 @@ PyTypeObject _PyContextTokenMissing_Type = {
static PyObject *
get_token_missing(void)
{
if (_token_missing != NULL) {
return Py_NewRef(_token_missing);
}

_token_missing = (PyObject *)PyObject_New(
PyContextTokenMissing, &_PyContextTokenMissing_Type);
if (_token_missing == NULL) {
return NULL;
}

return Py_NewRef(_token_missing);
return Py_NewRef(&_Py_SINGLETON(context_token_missing));
}


Expand All@@ -1298,9 +1292,6 @@ _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;
Expand Down
1 change: 1 addition & 0 deletionsTools/build/generate_global_objects.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -129,6 +129,7 @@
'(PyObject *)&_Py_SINGLETON(tuple_empty)',
'(PyObject *)&_Py_SINGLETON(hamt_bitmap_node_empty)',
'(PyObject *)&_Py_INTERP_SINGLETON(interp, hamt_empty)',
'(PyObject *)&_Py_SINGLETON(context_token_missing)',
]


Expand Down
3 changes: 0 additions & 3 deletionsTools/c-analyzer/cpython/globals-to-fix.tsv
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -310,9 +310,6 @@ Objects/typeobject.cobject___reduce_ex___implobjreduce-
#-----------------------
# other

# initialized once
Python/context.c-_token_missing-

# state
Objects/typeobject.cresolve_slotdupspname-

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp