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

Commit9e81a3b

Browse files
committed
gh-85283: Add PyInterpreterState_IsMain() function
This function can be used to convert the syslog extension to thelimited C API. The PyInterpreterState_Main() is not available in thelimited C API.
1 parent4116592 commit9e81a3b

File tree

7 files changed

+30
-1
lines changed

7 files changed

+30
-1
lines changed

‎Doc/c-api/init.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,15 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
11261126
11271127
.. versionadded:: 3.8
11281128
1129+
.. c:function:: int PyInterpreterState_IsMain(PyInterpreterState *interp)
1130+
1131+
Return true (non-zero) if the interpreter is the main interpreter.
1132+
Return false (zero) otherwise.
1133+
1134+
See also :c:func:`PyInterpreterState_Main`.
1135+
1136+
.. versionadded:: 3.13
1137+
11291138
.. c:type:: PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag)
11301139
11311140
Type of a frame evaluation function.

‎Doc/whatsnew/3.13.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,10 @@ New Features
886886
(with an underscore prefix).
887887
(Contributed by Victor Stinner in:gh:`108014`.)
888888

889+
* Add:c:func:`PyInterpreterState_IsMain` function to test if an interpreter
890+
is the main interpreter.
891+
(Contributed by Victor Stinner in:gh:`85283`.)
892+
889893
Porting to Python 3.13
890894
----------------------
891895

‎Include/pystate.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ PyAPI_FUNC(int64_t) PyInterpreterState_GetID(PyInterpreterState *);
3737
#endif
3838
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0 >=0x03030000
3939

40+
#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0 >=0x030d0000
41+
PyAPI_FUNC(int)PyInterpreterState_IsMain(PyInterpreterState*interp);
42+
#endif
43+
44+
4045
/* State unique per thread */
4146

4247
/* New in 3.3 */
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add:c:func:`PyInterpreterState_IsMain` function to test if an interpreter
2+
is the main interpreter. Patch by Victor Stinner.

‎Misc/stable_abi.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,3 +2452,5 @@
24522452
added ='3.13'
24532453
[function.PyLong_AsInt]
24542454
added ='3.13'
2455+
[function.PyInterpreterState_IsMain]
2456+
added ='3.13'

‎Modules/syslogmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ static char S_log_open = 0;
6969
staticinlineint
7070
is_main_interpreter(void)
7171
{
72-
return (PyInterpreterState_Get()==PyInterpreterState_Main());
72+
PyInterpreterState*interp=PyInterpreterState_Get();
73+
returnPyInterpreterState_IsMain(interp);
7374
}
7475

7576
staticPyObject*

‎Python/pystate.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,12 @@ _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime)
583583
// lifecycle
584584
//----------
585585

586+
int
587+
PyInterpreterState_IsMain(PyInterpreterState*interp)
588+
{
589+
return_Py_IsMainInterpreter(interp);
590+
}
591+
586592
/* Calling this indicates that the runtime is ready to create interpreters. */
587593

588594
PyStatus

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp