Skip to content

Commit cbd7254

Browse files
committed
Use the new names for the API.
1 parent 23ea059 commit cbd7254

File tree

5 files changed

+109
-109
lines changed

5 files changed

+109
-109
lines changed

Include/cpython/pystate.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -284,43 +284,43 @@ PyAPI_FUNC(void) _PyInterpreterState_SetEvalFrameFunc(
284284

285285
/* Strong interpreter references */
286286

287-
typedef uintptr_t PyInterpreterRef;
287+
typedef uintptr_t PyInterpreterLock;
288288

289-
PyAPI_FUNC(int) PyInterpreterRef_FromCurrent(PyInterpreterRef *ref);
290-
PyAPI_FUNC(PyInterpreterRef) PyInterpreterRef_Dup(PyInterpreterRef ref);
291-
PyAPI_FUNC(int) PyUnstable_GetDefaultInterpreterRef(PyInterpreterRef *ref);
292-
PyAPI_FUNC(void) PyInterpreterRef_Close(PyInterpreterRef ref);
293-
PyAPI_FUNC(PyInterpreterState *) PyInterpreterRef_GetInterpreter(PyInterpreterRef ref);
289+
PyAPI_FUNC(int) PyInterpreterLock_FromCurrent(PyInterpreterLock *ref);
290+
PyAPI_FUNC(PyInterpreterLock) PyInterpreterLock_Copy(PyInterpreterLock ref);
291+
PyAPI_FUNC(int) PyUnstable_InterpreterView_FromDefault(PyInterpreterLock *ref);
292+
PyAPI_FUNC(void) PyInterpreterLock_Release(PyInterpreterLock ref);
293+
PyAPI_FUNC(PyInterpreterState *) PyInterpreterLock_GetInterpreter(PyInterpreterLock ref);
294294

295-
#define PyInterpreterRef_Close(ref) do { \
296-
PyInterpreterRef_Close(ref); \
295+
#define PyInterpreterLock_Release(ref) do { \
296+
PyInterpreterLock_Release(ref); \
297297
ref = 0; \
298298
} while (0)
299299

300300
/* Weak interpreter references */
301301

302-
typedef struct _PyInterpreterWeakRef {
302+
typedef struct _PyInterpreterView {
303303
int64_t id;
304304
Py_ssize_t refcount;
305-
} _PyInterpreterWeakRef;
305+
} _PyInterpreterView;
306306

307-
typedef _PyInterpreterWeakRef *PyInterpreterWeakRef;
307+
typedef _PyInterpreterView *PyInterpreterView;
308308

309-
PyAPI_FUNC(int) PyInterpreterWeakRef_FromCurrent(PyInterpreterWeakRef *ptr);
310-
PyAPI_FUNC(PyInterpreterWeakRef) PyInterpreterWeakRef_Dup(PyInterpreterWeakRef wref);
311-
PyAPI_FUNC(int) PyInterpreterWeakRef_Promote(PyInterpreterWeakRef wref, PyInterpreterRef *strong_ptr);
312-
PyAPI_FUNC(void) PyInterpreterWeakRef_Close(PyInterpreterWeakRef wref);
309+
PyAPI_FUNC(int) PyInterpreterView_FromCurrent(PyInterpreterView *ptr);
310+
PyAPI_FUNC(PyInterpreterView) PyInterpreterView_Copy(PyInterpreterView wref);
311+
PyAPI_FUNC(int) PyInterpreterLock_FromView(PyInterpreterView wref, PyInterpreterLock *strong_ptr);
312+
PyAPI_FUNC(void) PyInterpreterView_Close(PyInterpreterView wref);
313313

314-
#define PyInterpreterWeakRef_Close(ref) do { \
315-
PyInterpreterWeakRef_Close(ref); \
314+
#define PyInterpreterView_Close(ref) do { \
315+
PyInterpreterView_Close(ref); \
316316
ref = 0; \
317317
} while (0)
318318

319319

320320
/* Thread references */
321321

322-
typedef uintptr_t PyThreadRef;
322+
typedef uintptr_t PyThreadView;
323323

324-
PyAPI_FUNC(int) PyThreadState_Ensure(PyInterpreterRef interp_ref, PyThreadRef *thread_ref);
324+
PyAPI_FUNC(int) PyThreadState_Ensure(PyInterpreterLock interp_ref, PyThreadView *thread_ref);
325325

326-
PyAPI_FUNC(void) PyThreadState_Release(PyThreadRef thread_ref);
326+
PyAPI_FUNC(void) PyThreadState_Release(PyThreadView thread_ref);

Modules/_testcapimodule.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,11 +2562,11 @@ toggle_reftrace_printer(PyObject *ob, PyObject *arg)
25622562
Py_RETURN_NONE;
25632563
}
25642564

2565-
static PyInterpreterRef
2565+
static PyInterpreterLock
25662566
get_strong_ref(void)
25672567
{
2568-
PyInterpreterRef ref;
2569-
if (PyInterpreterRef_FromCurrent(&ref) < 0) {
2568+
PyInterpreterLock ref;
2569+
if (PyInterpreterLock_FromCurrent(&ref) < 0) {
25702570
Py_FatalError("strong reference should not have failed");
25712571
}
25722572
return ref;
@@ -2576,15 +2576,15 @@ static void
25762576
test_interp_ref_common(void)
25772577
{
25782578
PyInterpreterState *interp = PyInterpreterState_Get();
2579-
PyInterpreterRef ref = get_strong_ref();
2580-
assert(PyInterpreterRef_GetInterpreter(ref) == interp);
2579+
PyInterpreterLock ref = get_strong_ref();
2580+
assert(PyInterpreterLock_GetInterpreter(ref) == interp);
25812581

2582-
PyInterpreterRef ref_2 = PyInterpreterRef_Dup(ref);
2583-
assert(PyInterpreterRef_GetInterpreter(ref_2) == interp);
2582+
PyInterpreterLock ref_2 = PyInterpreterLock_Copy(ref);
2583+
assert(PyInterpreterLock_GetInterpreter(ref_2) == interp);
25842584

25852585
// We can close the references in any order
2586-
PyInterpreterRef_Close(ref);
2587-
PyInterpreterRef_Close(ref_2);
2586+
PyInterpreterLock_Release(ref);
2587+
PyInterpreterLock_Release(ref_2);
25882588
}
25892589

25902590
static PyObject *
@@ -2621,15 +2621,15 @@ test_interpreter_refs(PyObject *self, PyObject *unused)
26212621
static PyObject *
26222622
test_thread_state_ensure_nested(PyObject *self, PyObject *unused)
26232623
{
2624-
PyInterpreterRef ref = get_strong_ref();
2624+
PyInterpreterLock ref = get_strong_ref();
26252625
PyThreadState *save_tstate = PyThreadState_Swap(NULL);
26262626
assert(PyGILState_GetThisThreadState() == save_tstate);
2627-
PyThreadRef refs[10];
2627+
PyThreadView refs[10];
26282628

26292629
for (int i = 0; i < 10; ++i) {
26302630
// Test reactivation of the detached tstate.
26312631
if (PyThreadState_Ensure(ref, &refs[i]) < 0) {
2632-
PyInterpreterRef_Close(ref);
2632+
PyInterpreterLock_Release(ref);
26332633
return PyErr_NoMemory();
26342634
}
26352635

@@ -2647,7 +2647,7 @@ test_thread_state_ensure_nested(PyObject *self, PyObject *unused)
26472647
if (PyThreadState_Ensure(ref, &refs[i]) < 0) {
26482648
// This will technically leak other thread states, but it doesn't
26492649
// matter because this is a test.
2650-
PyInterpreterRef_Close(ref);
2650+
PyInterpreterLock_Release(ref);
26512651
return PyErr_NoMemory();
26522652
}
26532653

@@ -2660,19 +2660,19 @@ test_thread_state_ensure_nested(PyObject *self, PyObject *unused)
26602660
}
26612661

26622662
assert(PyThreadState_GetUnchecked() == NULL);
2663-
PyInterpreterRef_Close(ref);
2663+
PyInterpreterLock_Release(ref);
26642664
PyThreadState_Swap(save_tstate);
26652665
Py_RETURN_NONE;
26662666
}
26672667

26682668
static PyObject *
26692669
test_thread_state_ensure_crossinterp(PyObject *self, PyObject *unused)
26702670
{
2671-
PyInterpreterRef ref = get_strong_ref();
2671+
PyInterpreterLock ref = get_strong_ref();
26722672
PyThreadState *save_tstate = PyThreadState_Swap(NULL);
26732673
PyThreadState *interp_tstate = Py_NewInterpreter();
26742674
if (interp_tstate == NULL) {
2675-
PyInterpreterRef_Close(ref);
2675+
PyInterpreterLock_Release(ref);
26762676
return PyErr_NoMemory();
26772677
}
26782678

@@ -2689,21 +2689,21 @@ test_thread_state_ensure_crossinterp(PyObject *self, PyObject *unused)
26892689
interp = interpreters.create()
26902690
interp.exec(some_func)
26912691
*/
2692-
PyThreadRef thread_ref;
2693-
PyThreadRef other_thread_ref;
2692+
PyThreadView thread_ref;
2693+
PyThreadView other_thread_ref;
26942694
if (PyThreadState_Ensure(ref, &thread_ref) < 0) {
2695-
PyInterpreterRef_Close(ref);
2695+
PyInterpreterLock_Release(ref);
26962696
return PyErr_NoMemory();
26972697
}
26982698

26992699
PyThreadState *ensured_tstate = PyThreadState_Get();
27002700
assert(ensured_tstate != save_tstate);
2701-
assert(PyInterpreterState_Get() == PyInterpreterRef_GetInterpreter(ref));
2701+
assert(PyInterpreterState_Get() == PyInterpreterLock_GetInterpreter(ref));
27022702
assert(PyGILState_GetThisThreadState() == ensured_tstate);
27032703

27042704
// Now though, we should reactivate the thread state
27052705
if (PyThreadState_Ensure(ref, &other_thread_ref) < 0) {
2706-
PyInterpreterRef_Close(ref);
2706+
PyInterpreterLock_Release(ref);
27072707
return PyErr_NoMemory();
27082708
}
27092709

@@ -2718,7 +2718,7 @@ test_thread_state_ensure_crossinterp(PyObject *self, PyObject *unused)
27182718
PyThreadState_Swap(interp_tstate);
27192719
Py_EndInterpreter(interp_tstate);
27202720

2721-
PyInterpreterRef_Close(ref);
2721+
PyInterpreterLock_Release(ref);
27222722
PyThreadState_Swap(save_tstate);
27232723
Py_RETURN_NONE;
27242724
}
@@ -2727,26 +2727,26 @@ static PyObject *
27272727
test_weak_interpreter_ref_after_shutdown(PyObject *self, PyObject *unused)
27282728
{
27292729
PyThreadState *save_tstate = PyThreadState_Swap(NULL);
2730-
PyInterpreterWeakRef wref;
2730+
PyInterpreterView wref;
27312731
PyThreadState *interp_tstate = Py_NewInterpreter();
27322732
if (interp_tstate == NULL) {
27332733
return PyErr_NoMemory();
27342734
}
27352735

2736-
int res = PyInterpreterWeakRef_FromCurrent(&wref);
2736+
int res = PyInterpreterView_FromCurrent(&wref);
27372737
(void)res;
27382738
assert(res == 0);
27392739

27402740
// As a sanity check, ensure that the weakref actually works
2741-
PyInterpreterRef ref;
2742-
res = PyInterpreterWeakRef_Promote(wref, &ref);
2741+
PyInterpreterLock ref;
2742+
res = PyInterpreterLock_FromView(wref, &ref);
27432743
assert(res == 0);
2744-
PyInterpreterRef_Close(ref);
2744+
PyInterpreterLock_Release(ref);
27452745

27462746
// Now, destroy the interpreter and try to acquire a weak reference.
27472747
// It should fail.
27482748
Py_EndInterpreter(interp_tstate);
2749-
res = PyInterpreterWeakRef_Promote(wref, &ref);
2749+
res = PyInterpreterLock_FromView(wref, &ref);
27502750
assert(res == -1);
27512751

27522752
PyThreadState_Swap(save_tstate);
@@ -2756,9 +2756,9 @@ test_weak_interpreter_ref_after_shutdown(PyObject *self, PyObject *unused)
27562756
static PyObject *
27572757
foo(PyObject *self, PyObject *foo)
27582758
{
2759-
PyInterpreterRef ref;
2760-
PyInterpreterRef_FromCurrent(&ref);
2761-
PyInterpreterRef_Close(ref);
2759+
PyInterpreterLock ref;
2760+
PyInterpreterLock_FromCurrent(&ref);
2761+
PyInterpreterLock_Release(ref);
27622762
Py_RETURN_NONE;
27632763
}
27642764

Modules/_testinternalcapi.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,16 +2425,16 @@ test_interp_refcount(PyObject *self, PyObject *unused)
24252425
{
24262426
PyInterpreterState *interp = PyInterpreterState_Get();
24272427
assert(_PyInterpreterState_Refcount(interp) == 0);
2428-
PyInterpreterRef refs[NUM_REFS];
2428+
PyInterpreterLock refs[NUM_REFS];
24292429
for (int i = 0; i < NUM_REFS; ++i) {
2430-
int res = PyInterpreterRef_FromCurrent(&refs[i]);
2430+
int res = PyInterpreterLock_FromCurrent(&refs[i]);
24312431
(void)res;
24322432
assert(res == 0);
24332433
assert(_PyInterpreterState_Refcount(interp) == i + 1);
24342434
}
24352435

24362436
for (int i = 0; i < NUM_REFS; ++i) {
2437-
PyInterpreterRef_Close(refs[i]);
2437+
PyInterpreterLock_Release(refs[i]);
24382438
assert(_PyInterpreterState_Refcount(interp) == (NUM_REFS - i - 1));
24392439
}
24402440

@@ -2445,28 +2445,28 @@ static PyObject *
24452445
test_interp_weakref_incref(PyObject *self, PyObject *unused)
24462446
{
24472447
PyInterpreterState *interp = PyInterpreterState_Get();
2448-
PyInterpreterWeakRef wref;
2449-
if (PyInterpreterWeakRef_FromCurrent(&wref) < 0) {
2448+
PyInterpreterView wref;
2449+
if (PyInterpreterView_FromCurrent(&wref) < 0) {
24502450
return NULL;
24512451
}
24522452
assert(_PyInterpreterState_Refcount(interp) == 0);
24532453

2454-
PyInterpreterRef refs[NUM_REFS];
2454+
PyInterpreterLock refs[NUM_REFS];
24552455

24562456
for (int i = 0; i < NUM_REFS; ++i) {
2457-
int res = PyInterpreterWeakRef_Promote(wref, &refs[i]);
2457+
int res = PyInterpreterLock_FromView(wref, &refs[i]);
24582458
(void)res;
24592459
assert(res == 0);
2460-
assert(PyInterpreterRef_GetInterpreter(refs[i]) == interp);
2460+
assert(PyInterpreterLock_GetInterpreter(refs[i]) == interp);
24612461
assert(_PyInterpreterState_Refcount(interp) == i + 1);
24622462
}
24632463

24642464
for (int i = 0; i < NUM_REFS; ++i) {
2465-
PyInterpreterRef_Close(refs[i]);
2465+
PyInterpreterLock_Release(refs[i]);
24662466
assert(_PyInterpreterState_Refcount(interp) == (NUM_REFS - i - 1));
24672467
}
24682468

2469-
PyInterpreterWeakRef_Close(wref);
2469+
PyInterpreterView_Close(wref);
24702470
Py_RETURN_NONE;
24712471
}
24722472

Programs/_testembed.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,15 +2291,15 @@ const char *THREAD_CODE = \
22912291
"fib(10)";
22922292

22932293
typedef struct {
2294-
PyInterpreterRef ref;
2294+
PyInterpreterLock ref;
22952295
int done;
22962296
} ThreadData;
22972297

22982298
static void
22992299
do_tstate_ensure(void *arg)
23002300
{
23012301
ThreadData *data = (ThreadData *)arg;
2302-
PyThreadRef refs[4];
2302+
PyThreadView refs[4];
23032303
int res = PyThreadState_Ensure(data->ref, &refs[0]);
23042304
assert(res == 0);
23052305
PyThreadState_Ensure(data->ref, &refs[1]);
@@ -2313,7 +2313,7 @@ do_tstate_ensure(void *arg)
23132313
PyThreadState_Release(refs[1]);
23142314
assert(res == 0);
23152315
PyThreadState_Release(refs[0]);
2316-
PyInterpreterRef_Close(data->ref);
2316+
PyInterpreterLock_Release(data->ref);
23172317
data->done = 1;
23182318
}
23192319

@@ -2323,14 +2323,14 @@ test_thread_state_ensure(void)
23232323
_testembed_initialize();
23242324
PyThread_handle_t handle;
23252325
PyThread_ident_t ident;
2326-
PyInterpreterRef ref;
2327-
if (PyInterpreterRef_FromCurrent(&ref) < 0) {
2326+
PyInterpreterLock ref;
2327+
if (PyInterpreterLock_FromCurrent(&ref) < 0) {
23282328
return -1;
23292329
};
23302330
ThreadData data = { ref };
23312331
if (PyThread_start_joinable_thread(do_tstate_ensure, &data,
23322332
&ident, &handle) < 0) {
2333-
PyInterpreterRef_Close(ref);
2333+
PyInterpreterLock_Release(ref);
23342334
return -1;
23352335
}
23362336
// We hold a strong interpreter reference, so we don't
@@ -2372,23 +2372,23 @@ static int
23722372
test_main_interpreter_ref(void)
23732373
{
23742374
// It should not work before the runtime has started.
2375-
PyInterpreterRef ref;
2376-
int res = PyUnstable_GetDefaultInterpreterRef(&ref);
2375+
PyInterpreterLock ref;
2376+
int res = PyUnstable_InterpreterView_FromDefault(&ref);
23772377
(void)res;
23782378
assert(res == -1);
23792379

23802380
_testembed_initialize();
23812381

23822382
// Main interpreter is initialized and ready.
2383-
res = PyUnstable_GetDefaultInterpreterRef(&ref);
2383+
res = PyUnstable_InterpreterView_FromDefault(&ref);
23842384
assert(res == 0);
2385-
assert(PyInterpreterRef_GetInterpreter(ref) == PyInterpreterState_Main());
2386-
PyInterpreterRef_Close(ref);
2385+
assert(PyInterpreterLock_GetInterpreter(ref) == PyInterpreterState_Main());
2386+
PyInterpreterLock_Release(ref);
23872387

23882388
Py_Finalize();
23892389

23902390
// Main interpreter is dead, we can no longer acquire references to it.
2391-
res = PyUnstable_GetDefaultInterpreterRef(&ref);
2391+
res = PyUnstable_InterpreterView_FromDefault(&ref);
23922392
assert(res == -1);
23932393
return 0;
23942394
}

0 commit comments

Comments
 (0)