Skip to content

Commit 867bd10

Browse files
committed
Merge branch 'main' into virtual-iterators
2 parents 5cd55c4 + ac06b53 commit 867bd10

17 files changed

+800
-430
lines changed

Include/internal/pycore_crossinterp.h

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -335,71 +335,29 @@ typedef struct _sharedexception {
335335
PyAPI_FUNC(PyObject *) _PyXI_ApplyError(_PyXI_error *err);
336336

337337

338-
typedef struct xi_session _PyXI_session;
339-
typedef struct _sharedns _PyXI_namespace;
340-
341-
PyAPI_FUNC(void) _PyXI_FreeNamespace(_PyXI_namespace *ns);
342-
PyAPI_FUNC(_PyXI_namespace *) _PyXI_NamespaceFromNames(PyObject *names);
343-
PyAPI_FUNC(int) _PyXI_FillNamespaceFromDict(
344-
_PyXI_namespace *ns,
345-
PyObject *nsobj,
346-
_PyXI_session *session);
347-
PyAPI_FUNC(int) _PyXI_ApplyNamespace(
348-
_PyXI_namespace *ns,
349-
PyObject *nsobj,
350-
PyObject *dflt);
351-
352-
353338
// A cross-interpreter session involves entering an interpreter
354-
// (_PyXI_Enter()), doing some work with it, and finally exiting
355-
// that interpreter (_PyXI_Exit()).
339+
// with _PyXI_Enter(), doing some work with it, and finally exiting
340+
// that interpreter with _PyXI_Exit().
356341
//
357342
// At the boundaries of the session, both entering and exiting,
358343
// data may be exchanged between the previous interpreter and the
359344
// target one in a thread-safe way that does not violate the
360345
// isolation between interpreters. This includes setting objects
361346
// in the target's __main__ module on the way in, and capturing
362347
// uncaught exceptions on the way out.
363-
struct xi_session {
364-
// Once a session has been entered, this is the tstate that was
365-
// current before the session. If it is different from cur_tstate
366-
// then we must have switched interpreters. Either way, this will
367-
// be the current tstate once we exit the session.
368-
PyThreadState *prev_tstate;
369-
// Once a session has been entered, this is the current tstate.
370-
// It must be current when the session exits.
371-
PyThreadState *init_tstate;
372-
// This is true if init_tstate needs cleanup during exit.
373-
int own_init_tstate;
374-
375-
// This is true if, while entering the session, init_thread took
376-
// "ownership" of the interpreter's __main__ module. This means
377-
// it is the only thread that is allowed to run code there.
378-
// (Caveat: for now, users may still run exec() against the
379-
// __main__ module's dict, though that isn't advisable.)
380-
int running;
381-
// This is a cached reference to the __dict__ of the entered
382-
// interpreter's __main__ module. It is looked up when at the
383-
// beginning of the session as a convenience.
384-
PyObject *main_ns;
385-
386-
// This is set if the interpreter is entered and raised an exception
387-
// that needs to be handled in some special way during exit.
388-
_PyXI_errcode *error_override;
389-
// This is set if exit captured an exception to propagate.
390-
_PyXI_error *error;
391-
392-
// -- pre-allocated memory --
393-
_PyXI_error _error;
394-
_PyXI_errcode _error_override;
395-
};
348+
typedef struct xi_session _PyXI_session;
349+
350+
PyAPI_FUNC(_PyXI_session *) _PyXI_NewSession(void);
351+
PyAPI_FUNC(void) _PyXI_FreeSession(_PyXI_session *);
396352

397353
PyAPI_FUNC(int) _PyXI_Enter(
398354
_PyXI_session *session,
399355
PyInterpreterState *interp,
400356
PyObject *nsupdates);
401357
PyAPI_FUNC(void) _PyXI_Exit(_PyXI_session *session);
402358

359+
PyAPI_FUNC(PyObject *) _PyXI_GetMainNamespace(_PyXI_session *);
360+
403361
PyAPI_FUNC(PyObject *) _PyXI_ApplyCapturedException(_PyXI_session *session);
404362
PyAPI_FUNC(int) _PyXI_HasCapturedException(_PyXI_session *session);
405363

Include/internal/pycore_uop_ids.h

Lines changed: 48 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 23 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/lock_tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,26 @@ class RLockTests(BaseLockTests):
337337
"""
338338
Tests for recursive locks.
339339
"""
340+
def test_repr_count(self):
341+
# see gh-134322: check that count values are correct:
342+
# when a rlock is just created,
343+
# in a second thread when rlock is acquired in the main thread.
344+
lock = self.locktype()
345+
self.assertIn("count=0", repr(lock))
346+
self.assertIn("<unlocked", repr(lock))
347+
lock.acquire()
348+
lock.acquire()
349+
self.assertIn("count=2", repr(lock))
350+
self.assertIn("<locked", repr(lock))
351+
352+
result = []
353+
def call_repr():
354+
result.append(repr(lock))
355+
with Bunch(call_repr, 1):
356+
pass
357+
self.assertIn("count=2", result[0])
358+
self.assertIn("<locked", result[0])
359+
340360
def test_reacquire(self):
341361
lock = self.locktype()
342362
lock.acquire()

Lib/test/test_capi/test_opt.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,10 @@ def testfunc(n):
20022002
self.assertNotIn("_CALL_ISINSTANCE", uops)
20032003
self.assertNotIn("_GUARD_THIRD_NULL", uops)
20042004
self.assertNotIn("_GUARD_CALLABLE_ISINSTANCE", uops)
2005-
self.assertIn("_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW", uops)
2005+
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
2006+
self.assertNotIn("_POP_CALL_LOAD_CONST_INLINE_BORROW", uops)
2007+
self.assertNotIn("_POP_CALL_ONE_LOAD_CONST_INLINE_BORROW", uops)
2008+
self.assertNotIn("_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW", uops)
20062009

20072010
def test_call_list_append(self):
20082011
def testfunc(n):
@@ -2035,7 +2038,10 @@ def testfunc(n):
20352038
self.assertNotIn("_CALL_ISINSTANCE", uops)
20362039
self.assertNotIn("_TO_BOOL_BOOL", uops)
20372040
self.assertNotIn("_GUARD_IS_TRUE_POP", uops)
2038-
self.assertIn("_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW", uops)
2041+
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
2042+
self.assertNotIn("_POP_CALL_LOAD_CONST_INLINE_BORROW", uops)
2043+
self.assertNotIn("_POP_CALL_ONE_LOAD_CONST_INLINE_BORROW", uops)
2044+
self.assertNotIn("_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW", uops)
20392045

20402046
def test_call_isinstance_is_false(self):
20412047
def testfunc(n):
@@ -2053,7 +2059,10 @@ def testfunc(n):
20532059
self.assertNotIn("_CALL_ISINSTANCE", uops)
20542060
self.assertNotIn("_TO_BOOL_BOOL", uops)
20552061
self.assertNotIn("_GUARD_IS_FALSE_POP", uops)
2056-
self.assertIn("_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW", uops)
2062+
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
2063+
self.assertNotIn("_POP_CALL_LOAD_CONST_INLINE_BORROW", uops)
2064+
self.assertNotIn("_POP_CALL_ONE_LOAD_CONST_INLINE_BORROW", uops)
2065+
self.assertNotIn("_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW", uops)
20572066

20582067
def test_call_isinstance_subclass(self):
20592068
def testfunc(n):
@@ -2071,7 +2080,10 @@ def testfunc(n):
20712080
self.assertNotIn("_CALL_ISINSTANCE", uops)
20722081
self.assertNotIn("_TO_BOOL_BOOL", uops)
20732082
self.assertNotIn("_GUARD_IS_TRUE_POP", uops)
2074-
self.assertIn("_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW", uops)
2083+
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
2084+
self.assertNotIn("_POP_CALL_LOAD_CONST_INLINE_BORROW", uops)
2085+
self.assertNotIn("_POP_CALL_ONE_LOAD_CONST_INLINE_BORROW", uops)
2086+
self.assertNotIn("_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW", uops)
20752087

20762088
def test_call_isinstance_unknown_object(self):
20772089
def testfunc(n):

Lib/test/test_importlib/test_locks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class ModuleLockAsRLockTests:
3434
# lock status in repr unsupported
3535
test_repr = None
3636
test_locked_repr = None
37+
test_repr_count = None
3738

3839
def tearDown(self):
3940
for splitinit in init.values():
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Optimize ``_POP_CALL_TWO_LOAD_CONST_INLINE_BORROW``.

Modules/_interpchannelsmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3443,7 +3443,7 @@ channelsmod_get_channel_defaults(PyObject *self, PyObject *args, PyObject *kwds)
34433443
}
34443444
int64_t cid = cid_data.cid;
34453445

3446-
struct _channeldefaults defaults;
3446+
struct _channeldefaults defaults = {0};
34473447
int err = channel_get_defaults(&_globals.channels, cid, &defaults);
34483448
if (handle_channel_error(err, self, cid)) {
34493449
return NULL;

Modules/_interpqueuesmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ queuesmod_get_queue_defaults(PyObject *self, PyObject *args, PyObject *kwds)
17721772
}
17731773
int64_t qid = qidarg.id;
17741774

1775-
struct _queuedefaults defaults;
1775+
struct _queuedefaults defaults = {0};
17761776
int err = queue_get_defaults(&_globals.queues, qid, &defaults);
17771777
if (handle_queue_error(err, self, qid)) {
17781778
return NULL;

0 commit comments

Comments
 (0)