|
1 | 1 | #ifndef Py_BUILD_CORE_MODULE |
2 | 2 | # define Py_BUILD_CORE_MODULE |
| 3 | +#include "pystate.h" |
3 | 4 | #endif |
4 | 5 |
|
5 | 6 | /* Always enable assertion (even in release mode) */ |
@@ -2341,6 +2342,27 @@ test_get_incomplete_frame(void) |
2341 | 2342 | return result; |
2342 | 2343 | } |
2343 | 2344 |
|
| 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 | +} |
2344 | 2366 |
|
2345 | 2367 | /* ********************************************************* |
2346 | 2368 | * List of test cases and the function that implements it. |
@@ -2431,7 +2453,7 @@ static struct TestCase TestCases[] = { |
2431 | 2453 | {"test_frozenmain", test_frozenmain}, |
2432 | 2454 | #endif |
2433 | 2455 | {"test_get_incomplete_frame", test_get_incomplete_frame}, |
2434 | | - |
| 2456 | + {"test_gilstate_after_finalization", test_gilstate_after_finalization}, |
2435 | 2457 | {NULL, NULL} |
2436 | 2458 | }; |
2437 | 2459 |
|
|
0 commit comments