Skip to content

Commit ba4c00e

Browse files
committed
Add a test case.
1 parent 0e93b03 commit ba4c00e

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Programs/_testembed.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#ifndef Py_BUILD_CORE_MODULE
22
# define Py_BUILD_CORE_MODULE
3+
#include "pystate.h"
34
#endif
45

56
/* Always enable assertion (even in release mode) */
@@ -2341,6 +2342,27 @@ test_get_incomplete_frame(void)
23412342
return result;
23422343
}
23432344

2345+
static void do_gilstate_ensure(void *unused)
2346+
{
2347+
for (int i = 0; i < 50; ++i) {
2348+
PyGILState_STATE gstate = PyGILState_Ensure();
2349+
assert(PyGILState_Check()); // Yuck
2350+
PyGILState_Release(gstate);
2351+
}
2352+
}
2353+
2354+
static int
2355+
test_gilstate_after_finalization(void)
2356+
{
2357+
PyThread_handle_t handle;
2358+
PyThread_ident_t ident;
2359+
_testembed_Py_Initialize();
2360+
if (PyThread_start_joinable_thread(&do_gilstate_ensure, NULL, &ident, &handle) < 0) {
2361+
return -1;
2362+
}
2363+
Py_Finalize();
2364+
return PyThread_join_thread(handle);
2365+
}
23442366

23452367
/* *********************************************************
23462368
* List of test cases and the function that implements it.
@@ -2431,7 +2453,7 @@ static struct TestCase TestCases[] = {
24312453
{"test_frozenmain", test_frozenmain},
24322454
#endif
24332455
{"test_get_incomplete_frame", test_get_incomplete_frame},
2434-
2456+
{"test_gilstate_after_finalization", test_gilstate_after_finalization},
24352457
{NULL, NULL}
24362458
};
24372459

0 commit comments

Comments
 (0)