Skip to content

Commit ab78d05

Browse files
authored
Merge branch 'main' into pyrepl_utils
2 parents 3699678 + 7ec1742 commit ab78d05

File tree

16 files changed

+529
-165
lines changed

16 files changed

+529
-165
lines changed

Android/android-env.sh

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# This script must be sourced with the following variables already set:
2-
: ${ANDROID_HOME:?} # Path to Android SDK
3-
: ${HOST:?} # GNU target triplet
2+
: "${ANDROID_HOME:?}" # Path to Android SDK
3+
: "${HOST:?}" # GNU target triplet
44

55
# You may also override the following:
6-
: ${api_level:=24} # Minimum Android API level the build will run on
7-
: ${PREFIX:-} # Path in which to find required libraries
6+
: "${api_level:=24}" # Minimum Android API level the build will run on
7+
: "${PREFIX:-}" # Path in which to find required libraries
88

99

1010
# Print all messages on stderr so they're visible when running within build-wheel.
@@ -27,20 +27,20 @@ fail() {
2727
ndk_version=27.1.12297006
2828

2929
ndk=$ANDROID_HOME/ndk/$ndk_version
30-
if ! [ -e $ndk ]; then
30+
if ! [ -e "$ndk" ]; then
3131
log "Installing NDK - this may take several minutes"
32-
yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "ndk;$ndk_version"
32+
yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" "ndk;$ndk_version"
3333
fi
3434

35-
if [ $HOST = "arm-linux-androideabi" ]; then
35+
if [ "$HOST" = "arm-linux-androideabi" ]; then
3636
clang_triplet=armv7a-linux-androideabi
3737
else
38-
clang_triplet=$HOST
38+
clang_triplet="$HOST"
3939
fi
4040

4141
# These variables are based on BuildSystemMaintainers.md above, and
4242
# $ndk/build/cmake/android.toolchain.cmake.
43-
toolchain=$(echo $ndk/toolchains/llvm/prebuilt/*)
43+
toolchain=$(echo "$ndk"/toolchains/llvm/prebuilt/*)
4444
export AR="$toolchain/bin/llvm-ar"
4545
export AS="$toolchain/bin/llvm-as"
4646
export CC="$toolchain/bin/${clang_triplet}${api_level}-clang"
@@ -72,12 +72,12 @@ LDFLAGS="$LDFLAGS -lm"
7272

7373
# -mstackrealign is included where necessary in the clang launcher scripts which are
7474
# pointed to by $CC, so we don't need to include it here.
75-
if [ $HOST = "arm-linux-androideabi" ]; then
75+
if [ "$HOST" = "arm-linux-androideabi" ]; then
7676
CFLAGS="$CFLAGS -march=armv7-a -mthumb"
7777
fi
7878

7979
if [ -n "${PREFIX:-}" ]; then
80-
abs_prefix=$(realpath $PREFIX)
80+
abs_prefix="$(realpath "$PREFIX")"
8181
CFLAGS="$CFLAGS -I$abs_prefix/include"
8282
LDFLAGS="$LDFLAGS -L$abs_prefix/lib"
8383

@@ -87,11 +87,13 @@ fi
8787

8888
# When compiling C++, some build systems will combine CFLAGS and CXXFLAGS, and some will
8989
# use CXXFLAGS alone.
90-
export CXXFLAGS=$CFLAGS
90+
export CXXFLAGS="$CFLAGS"
9191

9292
# Use the same variable name as conda-build
93-
if [ $(uname) = "Darwin" ]; then
94-
export CPU_COUNT=$(sysctl -n hw.ncpu)
93+
if [ "$(uname)" = "Darwin" ]; then
94+
CPU_COUNT="$(sysctl -n hw.ncpu)"
95+
export CPU_COUNT
9596
else
96-
export CPU_COUNT=$(nproc)
97+
CPU_COUNT="$(nproc)"
98+
export CPU_COUNT
9799
fi

Doc/c-api/long.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,6 @@ The :c:type:`PyLongWriter` API can be used to import an integer.
824824
825825
Discard a :c:type:`PyLongWriter` created by :c:func:`PyLongWriter_Create`.
826826
827-
*writer* must not be ``NULL``.
827+
If *writer* is ``NULL``, no operation is performed.
828828
829829
The writer instance and the *digits* array are invalid after the call.

Doc/whatsnew/3.14.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ New features
12921292
* :c:func:`PyLongWriter_Finish`;
12931293
* :c:func:`PyLongWriter_Discard`.
12941294

1295-
(Contributed by Victor Stinner in :gh:`102471`.)
1295+
(Contributed by Sergey B Kirpichev and Victor Stinner in :gh:`102471`.)
12961296

12971297
* Add :c:func:`PyType_GetBaseByToken` and :c:data:`Py_tp_token` slot for easier
12981298
superclass identification, which attempts to resolve the `type checking issue

Lib/pdb.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,19 @@ def do_quit(self, arg):
17251725
17261726
Quit from the debugger. The program being executed is aborted.
17271727
"""
1728+
if self.mode == 'inline':
1729+
while True:
1730+
try:
1731+
reply = input('Quitting pdb will kill the process. Quit anyway? [y/n] ')
1732+
reply = reply.lower().strip()
1733+
except EOFError:
1734+
reply = 'y'
1735+
self.message('')
1736+
if reply == 'y' or reply == '':
1737+
sys.exit(0)
1738+
elif reply.lower() == 'n':
1739+
return
1740+
17281741
self._user_requested_quit = True
17291742
self.set_quit()
17301743
return 1
@@ -1738,9 +1751,7 @@ def do_EOF(self, arg):
17381751
Handles the receipt of EOF as a command.
17391752
"""
17401753
self.message('')
1741-
self._user_requested_quit = True
1742-
self.set_quit()
1743-
return 1
1754+
return self.do_quit(arg)
17441755

17451756
def do_args(self, arg):
17461757
"""a(rgs)

Lib/test/test_generated_cases.py

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,12 @@ def run_cases_test(self, input: str, expected: str):
281281
)
282282

283283
with open(self.temp_output_filename) as temp_output:
284-
lines = temp_output.readlines()
285-
while lines and lines[0].startswith(("// ", "#", " #", "\n")):
286-
lines.pop(0)
287-
while lines and lines[-1].startswith(("#", "\n")):
288-
lines.pop(-1)
289-
actual = "".join(lines)
284+
lines = temp_output.read()
285+
_, rest = lines.split(tier1_generator.INSTRUCTION_START_MARKER)
286+
instructions, labels_with_prelude_and_postlude = rest.split(tier1_generator.INSTRUCTION_END_MARKER)
287+
_, labels_with_postlude = labels_with_prelude_and_postlude.split(tier1_generator.LABEL_START_MARKER)
288+
labels, _ = labels_with_postlude.split(tier1_generator.LABEL_END_MARKER)
289+
actual = instructions + labels
290290
# if actual.strip() != expected.strip():
291291
# print("Actual:")
292292
# print(actual)
@@ -1756,6 +1756,61 @@ def test_kill_in_wrong_order(self):
17561756
with self.assertRaises(SyntaxError):
17571757
self.run_cases_test(input, "")
17581758

1759+
def test_complex_label(self):
1760+
input = """
1761+
label(my_label) {
1762+
// Comment
1763+
do_thing()
1764+
if (complex) {
1765+
goto other_label;
1766+
}
1767+
goto other_label2;
1768+
}
1769+
"""
1770+
1771+
output = """
1772+
my_label:
1773+
{
1774+
// Comment
1775+
do_thing()
1776+
if (complex) {
1777+
goto other_label;
1778+
}
1779+
goto other_label2;
1780+
}
1781+
"""
1782+
self.run_cases_test(input, output)
1783+
1784+
def test_multiple_labels(self):
1785+
input = """
1786+
label(my_label_1) {
1787+
// Comment
1788+
do_thing1();
1789+
goto my_label_2;
1790+
}
1791+
1792+
label(my_label_2) {
1793+
// Comment
1794+
do_thing2();
1795+
goto my_label_3;
1796+
}
1797+
"""
1798+
1799+
output = """
1800+
my_label_1:
1801+
{
1802+
// Comment
1803+
do_thing1();
1804+
goto my_label_2;
1805+
}
1806+
1807+
my_label_2:
1808+
{
1809+
// Comment
1810+
do_thing2();
1811+
goto my_label_3;
1812+
}
1813+
"""
17591814

17601815
class TestGeneratedAbstractCases(unittest.TestCase):
17611816
def setUp(self) -> None:

Lib/test/test_pdb.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4237,6 +4237,62 @@ def test_checkline_is_not_executable(self):
42374237
self.assertFalse(db.checkline(os_helper.TESTFN, lineno))
42384238

42394239

4240+
@support.requires_subprocess()
4241+
class PdbTestInline(unittest.TestCase):
4242+
@unittest.skipIf(sys.flags.safe_path,
4243+
'PYTHONSAFEPATH changes default sys.path')
4244+
def _run_script(self, script, commands,
4245+
expected_returncode=0,
4246+
extra_env=None):
4247+
self.addCleanup(os_helper.rmtree, '__pycache__')
4248+
filename = 'main.py'
4249+
with open(filename, 'w') as f:
4250+
f.write(textwrap.dedent(script))
4251+
self.addCleanup(os_helper.unlink, filename)
4252+
4253+
commands = textwrap.dedent(commands)
4254+
4255+
cmd = [sys.executable, 'main.py']
4256+
if extra_env is not None:
4257+
env = os.environ | extra_env
4258+
else:
4259+
env = os.environ
4260+
with subprocess.Popen(
4261+
cmd,
4262+
stdout=subprocess.PIPE,
4263+
stdin=subprocess.PIPE,
4264+
stderr=subprocess.PIPE,
4265+
env = {**env, 'PYTHONIOENCODING': 'utf-8'}
4266+
) as proc:
4267+
stdout, stderr = proc.communicate(str.encode(commands))
4268+
stdout = bytes.decode(stdout) if isinstance(stdout, bytes) else stdout
4269+
stderr = bytes.decode(stderr) if isinstance(stderr, bytes) else stderr
4270+
self.assertEqual(
4271+
proc.returncode,
4272+
expected_returncode,
4273+
f"Unexpected return code\nstdout: {stdout}\nstderr: {stderr}"
4274+
)
4275+
return stdout, stderr
4276+
4277+
def test_quit(self):
4278+
script = """
4279+
x = 1
4280+
breakpoint()
4281+
"""
4282+
4283+
commands = """
4284+
quit
4285+
n
4286+
p x + 1
4287+
quit
4288+
y
4289+
"""
4290+
4291+
stdout, stderr = self._run_script(script, commands)
4292+
self.assertIn("2", stdout)
4293+
self.assertIn("Quit anyway", stdout)
4294+
4295+
42404296
@support.requires_subprocess()
42414297
class PdbTestReadline(unittest.TestCase):
42424298
def setUpClass():
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Quitting :mod:`pdb` in ``inline`` mode will emit a confirmation prompt and exit gracefully now, instead of printing an exception traceback.

Objects/longobject.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6953,6 +6953,10 @@ PyLongWriter_Create(int negative, Py_ssize_t ndigits, void **digits)
69536953
void
69546954
PyLongWriter_Discard(PyLongWriter *writer)
69556955
{
6956+
if (writer == NULL) {
6957+
return;
6958+
}
6959+
69566960
PyLongObject *obj = (PyLongObject *)writer;
69576961
assert(Py_REFCNT(obj) == 1);
69586962
Py_DECREF(obj);

0 commit comments

Comments
 (0)