Skip to content

Commit cc8873c

Browse files
committed
PyContext_CopyCurrent() & PyContext_Copy() (sync with the PEP)
1 parent 7070cca commit cc8873c

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

Include/context.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ typedef struct _pycontexttokenobject PyContextToken;
2323

2424

2525
PyAPI_FUNC(PyContext *) PyContext_New(void);
26-
PyAPI_FUNC(PyContext *) PyContext_Copy(void);
26+
PyAPI_FUNC(PyContext *) PyContext_Copy(PyContext *);
27+
PyAPI_FUNC(PyContext *) PyContext_CopyCurrent(void);
2728

2829
PyAPI_FUNC(int) PyContext_Enter(PyContext *);
2930
PyAPI_FUNC(int) PyContext_Exit(PyContext *);

Modules/_contextvarsmodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static PyObject *
1616
_contextvars_copy_context_impl(PyObject *module)
1717
/*[clinic end generated code: output=1fcd5da7225c4fa9 input=89bb9ae485888440]*/
1818
{
19-
return (PyObject *)PyContext_Copy();
19+
return (PyObject *)PyContext_CopyCurrent();
2020
}
2121

2222

Python/context.c

+14-16
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ context_new_from_vars(PyHamtObject *vars);
3030
static inline PyContext *
3131
context_get(void);
3232

33-
static inline PyContext *
34-
context_copy(void);
35-
3633
static PyContextToken *
3734
token_new(PyContext *ctx, PyContextVar *var, PyObject *val);
3835

@@ -61,9 +58,21 @@ PyContext_New(void)
6158

6259

6360
PyContext *
64-
PyContext_Copy(void)
61+
PyContext_Copy(PyContext * ctx)
62+
{
63+
return context_new_from_vars(ctx->ctx_vars);
64+
}
65+
66+
67+
PyContext *
68+
PyContext_CopyCurrent(void)
6569
{
66-
return context_copy();
70+
PyContext *ctx = context_get();
71+
if (ctx == NULL) {
72+
return NULL;
73+
}
74+
75+
return context_new_from_vars(ctx->ctx_vars);
6776
}
6877

6978

@@ -341,17 +350,6 @@ context_get(void)
341350
return current_ctx;
342351
}
343352

344-
static inline PyContext *
345-
context_copy(void)
346-
{
347-
PyContext *ctx = context_get();
348-
if (ctx == NULL) {
349-
return NULL;
350-
}
351-
352-
return context_new_from_vars(ctx->ctx_vars);
353-
}
354-
355353
static int
356354
context_check_key_type(PyObject *key)
357355
{

0 commit comments

Comments
 (0)