Skip to content

Commit 7279b51

Browse files
elpransvstinner
authored andcommitted
bpo-34537: Fix test_gdb:test_strings with LC_ALL=C (pythonGH-9483)
We cannot simply call locale.getpreferredencoding() here, as GDB might have been linked against a different version of Python with a different encoding and coercion policy with respect to PEP 538 and PEP 540. Thanks to Victor Stinner for a hint on how to fix this.
1 parent d64ee1a commit 7279b51

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Lib/test/test_gdb.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,20 @@ def test_bytes(self):
321321

322322
def test_strings(self):
323323
'Verify the pretty-printing of unicode strings'
324-
encoding = locale.getpreferredencoding()
324+
# We cannot simply call locale.getpreferredencoding() here,
325+
# as GDB might have been linked against a different version
326+
# of Python with a different encoding and coercion policy
327+
# with respect to PEP 538 and PEP 540.
328+
out, err = run_gdb(
329+
'--eval-command',
330+
'python import locale; print(locale.getpreferredencoding())')
331+
332+
encoding = out.rstrip()
333+
if err or not encoding:
334+
raise RuntimeError(
335+
f'unable to determine the preferred encoding '
336+
f'of embedded Python in GDB: {err}')
337+
325338
def check_repr(text):
326339
try:
327340
text.encode(encoding)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``test_gdb.test_strings()`` when ``LC_ALL=C`` and GDB was compiled with
2+
Python 3.6 or earlier.

0 commit comments

Comments
 (0)