Skip to content

Commit c4b5152

Browse files
authored
Merge branch 'main' into hy/close_issue_140729
2 parents 285a66f + 058bc18 commit c4b5152

11 files changed

Lines changed: 92 additions & 48 deletions

File tree

Doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@
359359
'papersize': 'a4paper',
360360
# The font size ('10pt', '11pt' or '12pt').
361361
'pointsize': '10pt',
362+
'maxlistdepth': '8', # See https://github.com/python/cpython/issues/139588
362363
}
363364

364365
# Grouping the document tree into LaTeX files. List of tuples

Include/pyport.h

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -509,23 +509,18 @@ extern "C" {
509509
#endif
510510

511511
#ifdef WITH_THREAD
512-
# ifdef Py_BUILD_CORE
513-
# ifdef HAVE_THREAD_LOCAL
514-
# error "HAVE_THREAD_LOCAL is already defined"
515-
# endif
516-
# define HAVE_THREAD_LOCAL 1
517-
# ifdef thread_local
518-
# define _Py_thread_local thread_local
519-
# elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
520-
# define _Py_thread_local _Thread_local
521-
# elif defined(_MSC_VER) /* AKA NT_THREADS */
522-
# define _Py_thread_local __declspec(thread)
523-
# elif defined(__GNUC__) /* includes clang */
524-
# define _Py_thread_local __thread
525-
# else
526-
// fall back to the PyThread_tss_*() API, or ignore.
527-
# undef HAVE_THREAD_LOCAL
528-
# endif
512+
// HAVE_THREAD_LOCAL is just defined here for compatibility's sake
513+
# define HAVE_THREAD_LOCAL 1
514+
# ifdef thread_local
515+
# define _Py_thread_local thread_local
516+
# elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
517+
# define _Py_thread_local _Thread_local
518+
# elif defined(_MSC_VER) /* AKA NT_THREADS */
519+
# define _Py_thread_local __declspec(thread)
520+
# elif defined(__GNUC__) /* includes clang */
521+
# define _Py_thread_local __thread
522+
# else
523+
# error "no supported thread-local variable storage classifier"
529524
# endif
530525
#endif
531526

Lib/linecache.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,12 @@ def updatecache(filename, module_globals=None):
123123
if _source_unavailable(filename):
124124
return []
125125

126-
if filename.startswith('<frozen ') and module_globals is not None:
126+
if filename.startswith('<frozen '):
127127
# This is a frozen module, so we need to use the filename
128128
# from the module globals.
129+
if module_globals is None:
130+
return []
131+
129132
fullname = module_globals.get('__file__')
130133
if fullname is None:
131134
return []

Lib/pdb.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3577,7 +3577,13 @@ def main():
35773577
parser.error("argument -m: not allowed with argument --pid")
35783578
try:
35793579
attach(opts.pid, opts.commands)
3580-
except PermissionError as e:
3580+
except RuntimeError:
3581+
print(
3582+
f"Cannot attach to pid {opts.pid}, please make sure that the process exists "
3583+
"and is using the same Python version."
3584+
)
3585+
sys.exit(1)
3586+
except PermissionError:
35813587
exit_with_permission_help_text()
35823588
return
35833589
elif opts.module:

Lib/test/test_import/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3160,6 +3160,7 @@ def test_check_state_first(self):
31603160
# Also, we test with a single-phase module that has global state,
31613161
# which is shared by all interpreters.
31623162

3163+
@no_rerun(reason="module state is not cleared (see gh-140657)")
31633164
@requires_subinterpreters
31643165
def test_basic_multiple_interpreters_main_no_reset(self):
31653166
# without resetting; already loaded in main interpreter

Lib/test/test_remote_pdb.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,5 +1590,17 @@ def test_attach_to_process_with_colors(self):
15901590
self.assertNotIn("while x == 1", output["client"]["stdout"])
15911591
self.assertIn("while x == 1", re.sub("\x1b[^m]*m", "", output["client"]["stdout"]))
15921592

1593+
def test_attach_to_non_existent_process(self):
1594+
with force_color(False):
1595+
result = subprocess.run([sys.executable, "-m", "pdb", "-p", "999999"], text=True, capture_output=True)
1596+
self.assertNotEqual(result.returncode, 0)
1597+
if sys.platform == "darwin":
1598+
# On MacOS, attaching to a non-existent process gives PermissionError
1599+
error = "The specified process cannot be attached to due to insufficient permissions"
1600+
else:
1601+
error = "Cannot attach to pid 999999, please make sure that the process exists"
1602+
self.assertIn(error, result.stdout)
1603+
1604+
15931605
if __name__ == "__main__":
15941606
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Print clearer error message when using ``pdb`` to attach to a non-existing process.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Avoid making unnecessary filesystem calls for frozen modules in :mod:`linecache` when the global module cache is not present.

Python/import.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -782,42 +782,28 @@ _PyImport_ClearModulesByIndex(PyInterpreterState *interp)
782782
substitute this (if the name actually matches).
783783
*/
784784

785-
#ifdef HAVE_THREAD_LOCAL
786785
_Py_thread_local const char *pkgcontext = NULL;
787786
# undef PKGCONTEXT
788787
# define PKGCONTEXT pkgcontext
789-
#endif
790788

791789
const char *
792790
_PyImport_ResolveNameWithPackageContext(const char *name)
793791
{
794-
#ifndef HAVE_THREAD_LOCAL
795-
PyMutex_Lock(&EXTENSIONS.mutex);
796-
#endif
797792
if (PKGCONTEXT != NULL) {
798793
const char *p = strrchr(PKGCONTEXT, '.');
799794
if (p != NULL && strcmp(name, p+1) == 0) {
800795
name = PKGCONTEXT;
801796
PKGCONTEXT = NULL;
802797
}
803798
}
804-
#ifndef HAVE_THREAD_LOCAL
805-
PyMutex_Unlock(&EXTENSIONS.mutex);
806-
#endif
807799
return name;
808800
}
809801

810802
const char *
811803
_PyImport_SwapPackageContext(const char *newcontext)
812804
{
813-
#ifndef HAVE_THREAD_LOCAL
814-
PyMutex_Lock(&EXTENSIONS.mutex);
815-
#endif
816805
const char *oldcontext = PKGCONTEXT;
817806
PKGCONTEXT = newcontext;
818-
#ifndef HAVE_THREAD_LOCAL
819-
PyMutex_Unlock(&EXTENSIONS.mutex);
820-
#endif
821807
return oldcontext;
822808
}
823809

Python/pystate.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ to avoid the expense of doing their own locking).
6767
For each of these functions, the GIL must be held by the current thread.
6868
*/
6969

70-
#ifndef HAVE_THREAD_LOCAL
71-
# error "no supported thread-local variable storage classifier"
72-
#endif
7370

7471
/* The attached thread state for the current thread. */
7572
_Py_thread_local PyThreadState *_Py_tss_tstate = NULL;

0 commit comments

Comments
 (0)