@@ -24,7 +24,7 @@ interpreter. For example:
2424 static int
2525 thread_function(PyInterpreterView view)
2626 {
27- PyInterpreterLock lock = PyInterpreterLock_AcquireView (view);
27+ PyInterpreterLock lock = PyInterpreterLock_FromView (view);
2828 if (lock == 0) {
2929 return -1;
3030 }
@@ -300,7 +300,7 @@ Interpreter Locks
300300
301301 This type is guaranteed to be pointer-sized.
302302
303- .. c :function :: PyInterpreterLock PyInterpreterLock_AcquireCurrent (void)
303+ .. c :function :: PyInterpreterLock PyInterpreterLock_FromCurrent (void)
304304
305305 Acquire a lock for the current interpreter.
306306
@@ -310,7 +310,7 @@ Interpreter Locks
310310 The caller must hold an :term:`attached thread state`.
311311
312312
313- .. c:function:: PyInterpreterLock PyInterpreterLock_AcquireView (PyInterpreterView view)
313+ .. c:function:: PyInterpreterLock PyInterpreterLock_FromView (PyInterpreterView view)
314314
315315 Acquire a lock to an interpreter through a view.
316316
@@ -364,7 +364,7 @@ Interpreter Views
364364 Create a view to the current interpreter.
365365
366366 This function is generally meant to be used in tandem with
367- :c:func:`PyInterpreterLock_AcquireView `.
367+ :c:func:`PyInterpreterLock_FromView `.
368368
369369 On success, this function returns a view to the current
370370 interpreter, and returns ``0`` with an exception set on failure.
@@ -402,7 +402,7 @@ Interpreter Views
402402 The caller does not need to hold an :term:`attached thread state`.
403403
404404
405- Ensuring And Releasing Thread States
405+ Ensuring and Releasing Thread States
406406------------------------------------
407407
408408This proposal includes two new high-level threading APIs that intend to
@@ -508,7 +508,7 @@ With this PEP, you would implement it like this:
508508 PyObject *file,
509509 PyObject *text)
510510 {
511- PyInterpreterLock lock = PyInterpreterLock_AcquireView (view);
511+ PyInterpreterLock lock = PyInterpreterLock_FromView (view);
512512 if (lock == 0) {
513513 / * Python interpreter has shut down */
514514 return -1;
@@ -556,7 +556,7 @@ held. Any future finalizer that attempted to acquire the lock would be deadlocke
556556 my_critical_operation(PyObject *self, PyObject *Py_UNUSED(args))
557557 {
558558 assert(PyThreadState_GetUnchecked() != NULL);
559- PyInterpreterLock lock = PyInterpreterLock_AcquireCurrent ();
559+ PyInterpreterLock lock = PyInterpreterLock_FromCurrent ();
560560 if (lock == 0) {
561561 /* Python interpreter has shut down */
562562 return NULL;
@@ -639,7 +639,7 @@ This is the same code, rewritten to use the new functions:
639639 PyThread_handle_t handle;
640640 PyThead_indent_t indent;
641641
642- PyInterpreterLock lock = PyInterpreterLock_AcquireCurrent ();
642+ PyInterpreterLock lock = PyInterpreterLock_FromCurrent ();
643643 if (lock == 0) {
644644 return NULL;
645645 }
@@ -690,7 +690,7 @@ hang the current thread forever).
690690 PyThread_handle_t handle;
691691 PyThead_indent_t indent;
692692
693- PyInterpreterLock lock = PyInterpreterLock_AcquireCurrent ();
693+ PyInterpreterLock lock = PyInterpreterLock_FromCurrent ();
694694 if (lock == 0) {
695695 return NULL;
696696 }
@@ -716,7 +716,7 @@ Example: An Asynchronous Callback
716716 {
717717 ThreadData *tdata = (ThreadData *)arg;
718718 PyInterpreterView view = tdata->view;
719- PyInterpreterLock lock = PyInterpreterLock_AcquireView (view);
719+ PyInterpreterLock lock = PyInterpreterLock_FromView (view);
720720 if (lock == 0) {
721721 fputs("Python has shut down!\n", stderr);
722722 return -1;
@@ -771,7 +771,13 @@ interpreter through :c:func:`PyUnstable_InterpreterView_FromDefault`.
771771 static void
772772 call_python(void)
773773 {
774- PyInterpreterLock lock = PyUnstable_InterpreterView_FromDefault();
774+ PyInterpreterView view = PyUnstable_InterpreterView_FromDefault();
775+ if (lock == 0) {
776+ fputs("Python has shut down.", stderr);
777+ return;
778+ }
779+
780+ PyInterpreterLock lock = PyInterpreterLock_FromView(view);
775781 if (lock == 0) {
776782 fputs("Python has shut down.", stderr);
777783 return;
@@ -780,13 +786,15 @@ interpreter through :c:func:`PyUnstable_InterpreterView_FromDefault`.
780786 PyThreadView thread_view = PyThreadState_Ensure(lock);
781787 if (thread_view == 0) {
782788 PyInterpreterLock_Release(lock);
789+ PyInterpreterView_Close(view);
783790 return -1;
784791 }
785792 if (PyRun_SimpleString("print(42)") < 0) {
786793 PyErr_Print();
787794 }
788795 PyThreadState_Release(thread_view);
789796 PyInterpreterLock_Release(lock);
797+ PyInterpreterView_Close(view);
790798 return 0;
791799 }
792800
0 commit comments