[Python-checkins] gh-118658: Modify cert generation script to extract cert3.pem (GH-124598)

2024-10-04 Thread encukou
https://github.com/python/cpython/commit/480354dc236af9ae9d47b2520aa85fb7293c7b68
commit: 480354dc236af9ae9d47b2520aa85fb7293c7b68
branch: main
author: Felix Fontein 
committer: encukou 
date: 2024-10-04T13:15:08+02:00
summary:

gh-118658: Modify cert generation script to extract cert3.pem (GH-124598)

files:
M Lib/test/certdata/cert3.pem
M Lib/test/certdata/make_ssl_certs.py

diff --git a/Lib/test/certdata/cert3.pem b/Lib/test/certdata/cert3.pem
index 034bc43ff1974e..4ab0f5ff133e3f 100644
--- a/Lib/test/certdata/cert3.pem
+++ b/Lib/test/certdata/cert3.pem
@@ -31,4 +31,4 @@ 
zqmtEM65ceSP8lo8Zbrcy+AEkCulFaZ92tyjtbe8oN4wTmTLFw06oFLSZzuiOgDV
 OaphdVKf/pvA6KBpr6izox0KQFIE5z3AAJZfKzMGDDD20xhy7jjQZNMAhjfsT+k4
 SeYB/6KafNxq08uoulj7w4Z4R/EGpkXnU96ZHYHmvGN0RnxwI1cpYHCazG8AjsK/
 anN9brBi5twTGrn+D8LRBqF5Yn+2MKkD0EdXJdtIENHP+32sPQ==
--END CERTIFICATE-
\ No newline at end of file
+-END CERTIFICATE-
diff --git a/Lib/test/certdata/make_ssl_certs.py 
b/Lib/test/certdata/make_ssl_certs.py
index 5e626baf550c5b..48f980124e1198 100644
--- a/Lib/test/certdata/make_ssl_certs.py
+++ b/Lib/test/certdata/make_ssl_certs.py
@@ -266,6 +266,8 @@ def write_cert_reference(path):
 f.write(key)
 f.write(cert)
 
+check_call(['openssl', 'x509', '-outform', 'pem', '-in', 'keycert3.pem', 
'-out', 'cert3.pem'])
+
 cert, key = make_cert_key(cmdlineargs, 'fakehostname', sign=True)
 with open('keycert4.pem', 'w') as f:
 f.write(key)

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] [3.12] gh-113993: For string interning, do not rely on (or assert) _Py_IsImmortal (GH-121358) (GH-124938)

2024-10-04 Thread encukou
https://github.com/python/cpython/commit/b3e2c0291595edddc968680689bec7707d27d2d1
commit: b3e2c0291595edddc968680689bec7707d27d2d1
branch: 3.12
author: Petr Viktorin 
committer: encukou 
date: 2024-10-04T16:50:34+02:00
summary:

[3.12] gh-113993: For string interning, do not rely on (or assert) 
_Py_IsImmortal (GH-121358) (GH-124938)

gh-113993: For string interning, do not rely on (or assert) _Py_IsImmortal 
(GH-121358)

Older stable ABI extensions are allowed to make immortal objects mortal.
Instead, use `_PyUnicode_STATE` (`interned` and `statically_allocated`).
(cherry picked from commit 956270d08d5c23f59937e2f29f8e0b7f63d68afd)

Co-authored-by: Miss Islington (bot) 
<[email protected]>

files:
A Misc/NEWS.d/next/C API/2024-07-04-13-23-27.gh-issue-113601.K3RLqp.rst
M Objects/unicodeobject.c

diff --git a/Misc/NEWS.d/next/C 
API/2024-07-04-13-23-27.gh-issue-113601.K3RLqp.rst b/Misc/NEWS.d/next/C 
API/2024-07-04-13-23-27.gh-issue-113601.K3RLqp.rst
new file mode 100644
index 00..009cc2bf017180
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2024-07-04-13-23-27.gh-issue-113601.K3RLqp.rst 
@@ -0,0 +1,2 @@
+Removed debug build assertions related to interning strings, which were
+falsely triggered by stable ABI extensions.
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 815747e1b1ed9c..7bd4b221c83cf7 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -257,7 +257,8 @@ _PyUnicode_InternedSize_Immortal(void)
 // value, to help detect bugs in optimizations.
 
 while (PyDict_Next(dict, &pos, &key, &value)) {
-   if (_Py_IsImmortal(key)) {
+assert(PyUnicode_CHECK_INTERNED(key) != 
SSTATE_INTERNED_IMMORTAL_STATIC);
+if (PyUnicode_CHECK_INTERNED(key) == SSTATE_INTERNED_IMMORTAL) {
count++;
}
 }
@@ -691,10 +692,14 @@ _PyUnicode_CheckConsistency(PyObject *op, int 
check_content)
 
 /* Check interning state */
 #ifdef Py_DEBUG
+// Note that we do not check `_Py_IsImmortal(op)`, since stable ABI
+// extensions can make immortal strings mortal (but with a high enough
+// refcount).
+// The other way is extremely unlikely (worth a potential failed assertion
+// in a debug build), so we do check `!_Py_IsImmortal(op)`.
 switch (PyUnicode_CHECK_INTERNED(op)) {
 case SSTATE_NOT_INTERNED:
 if (ascii->state.statically_allocated) {
-CHECK(_Py_IsImmortal(op));
 // This state is for two exceptions:
 // - strings are currently checked before they're interned
 // - the 256 one-latin1-character strings
@@ -710,11 +715,9 @@ _PyUnicode_CheckConsistency(PyObject *op, int 
check_content)
 break;
 case SSTATE_INTERNED_IMMORTAL:
 CHECK(!ascii->state.statically_allocated);
-CHECK(_Py_IsImmortal(op));
 break;
 case SSTATE_INTERNED_IMMORTAL_STATIC:
 CHECK(ascii->state.statically_allocated);
-CHECK(_Py_IsImmortal(op));
 break;
 default:
 Py_UNREACHABLE();
@@ -1899,7 +1902,8 @@ unicode_write_cstr(PyObject *unicode, Py_ssize_t index,
 static PyObject*
 get_latin1_char(Py_UCS1 ch)
 {
-return Py_NewRef(LATIN1(ch));
+PyObject *o = LATIN1(ch);
+return o;
 }
 
 static PyObject*
@@ -15015,7 +15019,7 @@ intern_common(PyInterpreterState *interp, PyObject *s 
/* stolen */,
 {
 PyObject *r = (PyObject *)_Py_hashtable_get(INTERNED_STRINGS, s);
 if (r != NULL) {
-assert(_Py_IsImmortal(r));
+assert(_PyUnicode_STATE(r).statically_allocated);
 assert(r != s);  // r must be statically_allocated; s is not
 Py_DECREF(s);
 return Py_NewRef(r);

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] gh-109975: Suggest ``pynntp`` instead of ``nntplib`` (#124830)

2024-10-04 Thread AA-Turner
https://github.com/python/cpython/commit/ac9648243dc0f5cb34c93621e507a98cf90550ea
commit: ac9648243dc0f5cb34c93621e507a98cf90550ea
branch: main
author: Christian Clauss 
committer: AA-Turner <[email protected]>
date: 2024-10-04T11:21:03+01:00
summary:

gh-109975: Suggest ``pynntp`` instead of ``nntplib`` (#124830)

The ``nntplib`` library has been deleted from PyPI by its author.

files:
M Doc/whatsnew/3.13.rst

diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst
index 261c3b003ccf66..e629fc122f1397 100644
--- a/Doc/whatsnew/3.13.rst
+++ b/Doc/whatsnew/3.13.rst
@@ -1559,7 +1559,7 @@ and are now removed:
 * :mod:`!msilib`
 * :mod:`!nis`
 * :mod:`!nntplib`:
-  Use the :pypi:`nntplib` library from PyPI instead.
+  Use the :pypi:`pynntp` library from PyPI instead.
 * :mod:`!ossaudiodev`:
   For audio playback, use the :pypi:`pygame` library from PyPI instead.
 * :mod:`!pipes`:

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] gh-124871: fix 'visited' tracking in compiler's reachability analysis (#124952)

2024-10-04 Thread iritkatriel
https://github.com/python/cpython/commit/f474391b26aa9208b44ca879f8635409d322f738
commit: f474391b26aa9208b44ca879f8635409d322f738
branch: main
author: Irit Katriel <[email protected]>
committer: iritkatriel <[email protected]>
date: 2024-10-04T17:37:38+01:00
summary:

gh-124871: fix 'visited' tracking in compiler's reachability analysis (#124952)

files:
A Misc/NEWS.d/next/Core and 
Builtins/2024-10-03-22-26-39.gh-issue-124871.tAMF47.rst
M Lib/test/test_compile.py
M Python/flowgraph.c

diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index e9ee72cf234fdc..e6dc7a53189e12 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -479,6 +479,19 @@ def test_dead_code_with_except_handler_compiles(self):
 x = 2
"""), '', 'exec')
 
+def test_try_except_in_while_with_chained_condition_compiles(self):
+# see gh-124871
+compile(textwrap.dedent("""
+name_1, name_2, name_3 = 1, 2, 3
+while name_3 <= name_2 > name_1:
+try:
+raise
+except:
+pass
+finally:
+pass
+"""), '', 'exec')
+
 def test_compile_invalid_namedexpr(self):
 # gh-109351
 m = ast.Module(
diff --git a/Misc/NEWS.d/next/Core and 
Builtins/2024-10-03-22-26-39.gh-issue-124871.tAMF47.rst b/Misc/NEWS.d/next/Core 
and Builtins/2024-10-03-22-26-39.gh-issue-124871.tAMF47.rst
new file mode 100644
index 00..185cb3048fadf5
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and 
Builtins/2024-10-03-22-26-39.gh-issue-124871.tAMF47.rst 
@@ -0,0 +1,2 @@
+Fix compiler bug (in some versions of 3.13) where an assertion fails during 
reachability
+analysis.
diff --git a/Python/flowgraph.c b/Python/flowgraph.c
index 69d7e0a872aa48..388862912d6826 100644
--- a/Python/flowgraph.c
+++ b/Python/flowgraph.c
@@ -1001,13 +1001,14 @@ remove_unreachable(basicblock *entryblock) {
 basicblock **sp = stack;
 entryblock->b_predecessors = 1;
 *sp++ = entryblock;
+entryblock->b_visited = 1;
 while (sp > stack) {
 basicblock *b = *(--sp);
-b->b_visited = 1;
 if (b->b_next && BB_HAS_FALLTHROUGH(b)) {
 if (!b->b_next->b_visited) {
 assert(b->b_next->b_predecessors == 0);
 *sp++ = b->b_next;
+b->b_next->b_visited = 1;
 }
 b->b_next->b_predecessors++;
 }
@@ -1017,8 +1018,8 @@ remove_unreachable(basicblock *entryblock) {
 if (is_jump(instr) || is_block_push(instr)) {
 target = instr->i_target;
 if (!target->b_visited) {
-assert(target->b_predecessors == 0 || target == b->b_next);
 *sp++ = target;
+target->b_visited = 1;
 }
 target->b_predecessors++;
 }

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] gh-124552 : Improve the accuracy of possible breakpoint check in bdb (#124553)

2024-10-04 Thread gaogaotiantian
https://github.com/python/cpython/commit/adfe7657a3f1ce5d8384694ed27a40376a18fa6c
commit: adfe7657a3f1ce5d8384694ed27a40376a18fa6c
branch: main
author: Tian Gao 
committer: gaogaotiantian 
date: 2024-10-04T21:32:57-04:00
summary:

gh-124552 : Improve the accuracy of possible breakpoint check in bdb (#124553)

files:
A Misc/NEWS.d/next/Library/2024-09-25-22-06-52.gh-issue-124552.1nQKNM.rst
M Lib/bdb.py
M Lib/test/test_pdb.py

diff --git a/Lib/bdb.py b/Lib/bdb.py
index d7543017940d4f..666f9714eb9b7a 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -3,6 +3,7 @@
 import fnmatch
 import sys
 import os
+import weakref
 from inspect import CO_GENERATOR, CO_COROUTINE, CO_ASYNC_GENERATOR
 
 __all__ = ["BdbQuit", "Bdb", "Breakpoint"]
@@ -36,6 +37,7 @@ def __init__(self, skip=None):
 self.frame_returning = None
 self.trace_opcodes = False
 self.enterframe = None
+self.code_linenos = weakref.WeakKeyDictionary()
 
 self._load_breaks()
 
@@ -155,6 +157,9 @@ def dispatch_return(self, frame, arg):
 if self.stop_here(frame) or frame == self.returnframe:
 # Ignore return events in generator except when stepping.
 if self.stopframe and frame.f_code.co_flags & 
GENERATOR_AND_COROUTINE_FLAGS:
+# It's possible to trigger a StopIteration exception in
+# the caller so we must set the trace function in the caller
+self._set_caller_tracefunc(frame)
 return self.trace_dispatch
 try:
 self.frame_returning = frame
@@ -273,9 +278,25 @@ def do_clear(self, arg):
 raise NotImplementedError("subclass of bdb must implement do_clear()")
 
 def break_anywhere(self, frame):
-"""Return True if there is any breakpoint for frame's filename.
+"""Return True if there is any breakpoint in that frame
 """
-return self.canonic(frame.f_code.co_filename) in self.breaks
+filename = self.canonic(frame.f_code.co_filename)
+if filename not in self.breaks:
+return False
+for lineno in self.breaks[filename]:
+if self._lineno_in_frame(lineno, frame):
+return True
+return False
+
+def _lineno_in_frame(self, lineno, frame):
+"""Return True if the line number is in the frame's code object.
+"""
+code = frame.f_code
+if lineno < code.co_firstlineno:
+return False
+if code not in self.code_linenos:
+self.code_linenos[code] = set(lineno for _, _, lineno in 
code.co_lines())
+return lineno in self.code_linenos[code]
 
 # Derived classes should override the user_* methods
 # to gain control.
@@ -360,7 +381,7 @@ def set_next(self, frame):
 def set_return(self, frame):
 """Stop when returning from the given frame."""
 if frame.f_code.co_flags & GENERATOR_AND_COROUTINE_FLAGS:
-self._set_stopinfo(frame, None, -1)
+self._set_stopinfo(frame, frame, -1)
 else:
 self._set_stopinfo(frame.f_back, frame)
 
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 4c64a800cb32d2..46eb00261042bc 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -518,6 +518,43 @@ def 
test_pdb_breakpoints_preserved_across_interactive_sessions():
 (Pdb) continue
 """
 
+def test_pdb_break_anywhere():
+"""Test break_anywhere() method of Pdb.
+
+>>> def outer():
+... def inner():
+... import pdb
+... import sys
+... p = pdb.Pdb(nosigint=True, readrc=False)
+... p.set_trace()
+... frame = sys._getframe()
+... print(p.break_anywhere(frame))  # inner
+... print(p.break_anywhere(frame.f_back))  # outer
+... print(p.break_anywhere(frame.f_back.f_back))  # caller
+... inner()
+
+>>> def caller():
+... outer()
+
+>>> def test_function():
+... caller()
+
+>>> reset_Breakpoint()
+>>> with PdbTestInput([  # doctest: +NORMALIZE_WHITESPACE
+... 'b 3',
+... 'c',
+... ]):
+... test_function()
+> (6)inner()
+-> p.set_trace()
+(Pdb) b 3
+Breakpoint 1 at :3
+(Pdb) c
+True
+False
+False
+"""
+
 def test_pdb_pp_repr_exc():
 """Test that do_p/do_pp do not swallow exceptions.
 
diff --git 
a/Misc/NEWS.d/next/Library/2024-09-25-22-06-52.gh-issue-124552.1nQKNM.rst 
b/Misc/NEWS.d/next/Library/2024-09-25-22-06-52.gh-issue-124552.1nQKNM.rst
new file mode 100644
index 00..39dde4c774ba5d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-09-25-22-06-52.gh-issue-124552.1nQKNM.rst
@@ -0,0 +1 @@
+Improve the accuracy of :mod:`bdb`'s check for the possibility of breakpoint 
in a frame. This makes it possible to disable unnecessary events in functions.

___
Python-checkins mailing list -- [email protected]
To unsu

[Python-checkins] gh-119786: Replace a Sphinx role with a link to `Python/errors.c` (#124990)

2024-10-04 Thread AA-Turner
https://github.com/python/cpython/commit/2d8b6a4e9d9a74e3c5270eec62716710ac197063
commit: 2d8b6a4e9d9a74e3c5270eec62716710ac197063
branch: main
author: Adam Turner <[email protected]>
committer: AA-Turner <[email protected]>
date: 2024-10-05T01:00:19+01:00
summary:

gh-119786: Replace a Sphinx role with a link to `Python/errors.c` (#124990)

files:
M InternalDocs/exception_handling.md

diff --git a/InternalDocs/exception_handling.md 
b/InternalDocs/exception_handling.md
index 2e306c7046e237..64a346b55b8413 100644
--- a/InternalDocs/exception_handling.md
+++ b/InternalDocs/exception_handling.md
@@ -190,5 +190,6 @@ Exception Chaining Implementation
 [Exception 
chaining](https://docs.python.org/dev/tutorial/errors.html#exception-chaining)
 refers to setting the ``__context__`` and ``__cause__`` fields of an exception 
as it is
 being raised. The ``__context__`` field is set by ``_PyErr_SetObject()`` in
-:cpy-file:`Python/errors.c` (which is ultimately called by all 
``PyErr_Set*()`` functions).
+[Python/errors.c](https://github.com/python/cpython/blob/main/Python/errors.c)
+(which is ultimately called by all ``PyErr_Set*()`` functions).
 The ``__cause__`` field (explicit chaining) is set by the ``RAISE_VARARGS`` 
bytecode.

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] gh-119786: move a few more details on exception handling from devguide to InternalDocs (#124989)

2024-10-04 Thread iritkatriel
https://github.com/python/cpython/commit/8bcf118dcb2cab88acc8a6dffb7968b1854802b4
commit: 8bcf118dcb2cab88acc8a6dffb7968b1854802b4
branch: main
author: Irit Katriel <[email protected]>
committer: iritkatriel <[email protected]>
date: 2024-10-05T00:48:12+01:00
summary:

gh-119786: move a few more details on exception handling from devguide to 
InternalDocs (#124989)

files:
M InternalDocs/exception_handling.md

diff --git a/InternalDocs/exception_handling.md 
b/InternalDocs/exception_handling.md
index ec09e0769929fa..2e306c7046e237 100644
--- a/InternalDocs/exception_handling.md
+++ b/InternalDocs/exception_handling.md
@@ -75,7 +75,8 @@ table. If it finds a handler, control flow transfers to it. 
Otherwise, the
 exception bubbles up to the caller, and the caller's frame is
 checked for a handler covering the `CALL` instruction. This
 repeats until a handler is found or the topmost frame is reached.
-If no handler is found, the program terminates. During unwinding,
+If no handler is found, then the interpreter function
+(``_PyEval_EvalFrameDefault()``) returns NULL. During unwinding,
 the traceback is constructed as each frame is added to it by
 ``PyTraceBack_Here()``, which is in
 
[Python/traceback.c](https://github.com/python/cpython/blob/main/Python/traceback.c).
@@ -182,3 +183,12 @@ The interpreter's function to lookup the table by 
instruction offset is
 The Python function ``_parse_exception_table()`` in
 [Lib/dis.py](https://github.com/python/cpython/blob/main/Lib/dis.py)
 returns the exception table content as a list of namedtuple instances.
+
+Exception Chaining Implementation
+-
+
+[Exception 
chaining](https://docs.python.org/dev/tutorial/errors.html#exception-chaining)
+refers to setting the ``__context__`` and ``__cause__`` fields of an exception 
as it is
+being raised. The ``__context__`` field is set by ``_PyErr_SetObject()`` in
+:cpy-file:`Python/errors.c` (which is ultimately called by all 
``PyErr_Set*()`` functions).
+The ``__cause__`` field (explicit chaining) is set by the ``RAISE_VARARGS`` 
bytecode.

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] gh-117151: increase default buffer size of shutil.copyfileobj() to 256k. (GH-119783)

2024-10-04 Thread gpshead
https://github.com/python/cpython/commit/6efd95c4650ec7c2fb5522b352c74a9d44370fe0
commit: 6efd95c4650ec7c2fb5522b352c74a9d44370fe0
branch: main
author: morotti 
committer: gpshead 
date: 2024-10-04T16:51:22-07:00
summary:

gh-117151: increase default buffer size of shutil.copyfileobj() to 256k. 
(GH-119783)

* gh-117151: increase default buffer size of shutil.copyfileobj() to 256k.

it was set to 16k in the 1990s.
it was raised to 64k in 2019. the discussion at the time mentioned another 5% 
improvement by raising to 128k and settled for a very conservative setting.

it's 2024 now, I think it should be revisited to match modern hardware. I am 
measuring 0-15% performance improvement when raising to 256k on various types 
of disk. there is no downside as far as I can tell.

this function is only intended for sequential copy of full files (or file like 
objects). it's the typical use case that benefits from larger operations.

for reference, I came across this function while trying to profile pip that is 
using it to copy files when installing python packages.

* add news

-

Co-authored-by: rmorotti 

files:
A Misc/NEWS.d/next/Library/2024-10-03-05-00-25.gh-issue-117151.Prdw_W.rst
M Lib/shutil.py

diff --git a/Lib/shutil.py b/Lib/shutil.py
index dab3ca5ee91245..dd3e0e0c5da54b 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -44,7 +44,7 @@
 else:
 _winapi = None
 
-COPY_BUFSIZE = 1024 * 1024 if _WINDOWS else 64 * 1024
+COPY_BUFSIZE = 1024 * 1024 if _WINDOWS else 256 * 1024
 # This should never be removed, see rationale in:
 # https://bugs.python.org/issue43743#msg393429
 _USE_CP_SENDFILE = (hasattr(os, "sendfile")
diff --git 
a/Misc/NEWS.d/next/Library/2024-10-03-05-00-25.gh-issue-117151.Prdw_W.rst 
b/Misc/NEWS.d/next/Library/2024-10-03-05-00-25.gh-issue-117151.Prdw_W.rst
new file mode 100644
index 00..a7d6251f1e071f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-10-03-05-00-25.gh-issue-117151.Prdw_W.rst
@@ -0,0 +1,3 @@
+The default buffer size used by :func:`shutil.copyfileobj` has been
+increased from 64k to 256k on non-Windows platforms. It was already larger
+on Windows.

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] gh-112804: Clamping timeout value for _PySemaphore_PlatformWait (gh-124914)

2024-10-04 Thread corona10
https://github.com/python/cpython/commit/a5fc50994a3fae46d0c3d496c4e1d5e00548a1b8
commit: a5fc50994a3fae46d0c3d496c4e1d5e00548a1b8
branch: main
author: Donghee Na 
committer: corona10 
date: 2024-10-05T11:27:32+09:00
summary:

gh-112804: Clamping timeout value for _PySemaphore_PlatformWait (gh-124914)

* gh-112804: Clamping timeout value for _PySemaphore_PlatformWait

* Address code review

* nit

files:
M Python/parking_lot.c

diff --git a/Python/parking_lot.c b/Python/parking_lot.c
index 841b1d71ea16cb..a7e9760e35d87a 100644
--- a/Python/parking_lot.c
+++ b/Python/parking_lot.c
@@ -102,7 +102,14 @@ _PySemaphore_PlatformWait(_PySemaphore *sema, PyTime_t 
timeout)
 millis = INFINITE;
 }
 else {
-millis = (DWORD) (timeout / 100);
+PyTime_t div = _PyTime_AsMilliseconds(timeout, _PyTime_ROUND_TIMEOUT);
+// Prevent overflow with clamping the result
+if ((PyTime_t)PY_DWORD_MAX < div) {
+millis = PY_DWORD_MAX;
+}
+else {
+millis = (DWORD) div;
+}
 }
 wait = WaitForSingleObjectEx(sema->platform_sem, millis, FALSE);
 if (wait == WAIT_OBJECT_0) {

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] gh-111178: Fix function signatures in _threadmodule.c (#124964)

2024-10-04 Thread vstinner
https://github.com/python/cpython/commit/ddccd546a00fa7c2e4140cae25284b902292ad3b
commit: ddccd546a00fa7c2e4140cae25284b902292ad3b
branch: main
author: Victor Stinner 
committer: vstinner 
date: 2024-10-04T12:50:01+02:00
summary:

gh-78: Fix function signatures in _threadmodule.c (#124964)

files:
M Modules/_threadmodule.c

diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index b3ed8e7bc56b9e..153fe85597749d 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -599,8 +599,9 @@ PyThreadHandleObject_traverse(PyThreadHandleObject *self, 
visitproc visit,
 }
 
 static void
-PyThreadHandleObject_dealloc(PyThreadHandleObject *self)
+PyThreadHandleObject_dealloc(PyObject *op)
 {
+PyThreadHandleObject *self = (PyThreadHandleObject*)op;
 PyObject_GC_UnTrack(self);
 PyTypeObject *tp = Py_TYPE(self);
 ThreadHandle_decref(self->handle);
@@ -609,23 +610,26 @@ PyThreadHandleObject_dealloc(PyThreadHandleObject *self)
 }
 
 static PyObject *
-PyThreadHandleObject_repr(PyThreadHandleObject *self)
+PyThreadHandleObject_repr(PyObject *op)
 {
+PyThreadHandleObject *self = (PyThreadHandleObject*)op;
 PyThread_ident_t ident = ThreadHandle_ident(self->handle);
 return PyUnicode_FromFormat("<%s object: ident=%" PY_FORMAT_THREAD_IDENT_T 
">",
 Py_TYPE(self)->tp_name, ident);
 }
 
 static PyObject *
-PyThreadHandleObject_get_ident(PyThreadHandleObject *self,
-   PyObject *Py_UNUSED(ignored))
+PyThreadHandleObject_get_ident(PyObject *op, void *Py_UNUSED(ignored))
 {
+PyThreadHandleObject *self = (PyThreadHandleObject*)op;
 return PyLong_FromUnsignedLongLong(ThreadHandle_ident(self->handle));
 }
 
 static PyObject *
-PyThreadHandleObject_join(PyThreadHandleObject *self, PyObject *args)
+PyThreadHandleObject_join(PyObject *op, PyObject *args)
 {
+PyThreadHandleObject *self = (PyThreadHandleObject*)op;
+
 PyObject *timeout_obj = NULL;
 if (!PyArg_ParseTuple(args, "|O:join", &timeout_obj)) {
 return NULL;
@@ -646,9 +650,9 @@ PyThreadHandleObject_join(PyThreadHandleObject *self, 
PyObject *args)
 }
 
 static PyObject *
-PyThreadHandleObject_is_done(PyThreadHandleObject *self,
- PyObject *Py_UNUSED(ignored))
+PyThreadHandleObject_is_done(PyObject *op, PyObject *Py_UNUSED(ignored))
 {
+PyThreadHandleObject *self = (PyThreadHandleObject*)op;
 if (_PyEvent_IsSet(&self->handle->thread_is_exiting)) {
 Py_RETURN_TRUE;
 }
@@ -658,9 +662,9 @@ PyThreadHandleObject_is_done(PyThreadHandleObject *self,
 }
 
 static PyObject *
-PyThreadHandleObject_set_done(PyThreadHandleObject *self,
-  PyObject *Py_UNUSED(ignored))
+PyThreadHandleObject_set_done(PyObject *op, PyObject *Py_UNUSED(ignored))
 {
+PyThreadHandleObject *self = (PyThreadHandleObject*)op;
 if (ThreadHandle_set_done(self->handle) < 0) {
 return NULL;
 }
@@ -668,20 +672,20 @@ PyThreadHandleObject_set_done(PyThreadHandleObject *self,
 }
 
 static PyGetSetDef ThreadHandle_getsetlist[] = {
-{"ident", (getter)PyThreadHandleObject_get_ident, NULL, NULL},
+{"ident", PyThreadHandleObject_get_ident, NULL, NULL},
 {0},
 };
 
 static PyMethodDef ThreadHandle_methods[] = {
-{"join", (PyCFunction)PyThreadHandleObject_join, METH_VARARGS, NULL},
-{"_set_done", (PyCFunction)PyThreadHandleObject_set_done, METH_NOARGS, 
NULL},
-{"is_done", (PyCFunction)PyThreadHandleObject_is_done, METH_NOARGS, NULL},
+{"join", PyThreadHandleObject_join, METH_VARARGS, NULL},
+{"_set_done", PyThreadHandleObject_set_done, METH_NOARGS, NULL},
+{"is_done", PyThreadHandleObject_is_done, METH_NOARGS, NULL},
 {0, 0}
 };
 
 static PyType_Slot ThreadHandle_Type_slots[] = {
-{Py_tp_dealloc, (destructor)PyThreadHandleObject_dealloc},
-{Py_tp_repr, (reprfunc)PyThreadHandleObject_repr},
+{Py_tp_dealloc, PyThreadHandleObject_dealloc},
+{Py_tp_repr, PyThreadHandleObject_repr},
 {Py_tp_getset, ThreadHandle_getsetlist},
 {Py_tp_traverse, PyThreadHandleObject_traverse},
 {Py_tp_methods, ThreadHandle_methods},
@@ -707,15 +711,16 @@ typedef struct {
 } lockobject;
 
 static int
-lock_traverse(lockobject *self, visitproc visit, void *arg)
+lock_traverse(PyObject *self, visitproc visit, void *arg)
 {
 Py_VISIT(Py_TYPE(self));
 return 0;
 }
 
 static void
-lock_dealloc(lockobject *self)
+lock_dealloc(PyObject *op)
 {
+lockobject *self = (lockobject*)op;
 PyObject_GC_UnTrack(self);
 if (self->in_weakreflist != NULL) {
 PyObject_ClearWeakRefs((PyObject *) self);
@@ -784,11 +789,14 @@ lock_acquire_parse_args(PyObject *args, PyObject *kwds,
 }
 
 static PyObject *
-lock_PyThread_acquire_lock(lockobject *self, PyObject *args, PyObject *kwds)
+lock_PyThread_acquire_lock(PyObject *op, PyObject *args, PyObject *kwds)
 {
+lockobject *self = (lockobject*)op;
+
 PyTime_t timeout;
-if (lock_acquire_parse_args(ar

[Python-checkins] gh-111178: Fix function signatures in bytearrayobject.c (#124940)

2024-10-04 Thread vstinner
https://github.com/python/cpython/commit/aace0dca8bdcde8cd8ba85fbaf04a50fa920be7d
commit: aace0dca8bdcde8cd8ba85fbaf04a50fa920be7d
branch: main
author: Victor Stinner 
committer: vstinner 
date: 2024-10-04T11:59:51+02:00
summary:

gh-78: Fix function signatures in bytearrayobject.c (#124940)

files:
M Objects/bytearrayobject.c

diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index a80e4670665a22..fd2a85a3fe0a61 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -42,15 +42,16 @@ _getbytevalue(PyObject* arg, int *value)
 }
 
 static int
-bytearray_getbuffer(PyByteArrayObject *obj, Py_buffer *view, int flags)
+bytearray_getbuffer(PyObject *self, Py_buffer *view, int flags)
 {
-void *ptr;
+PyByteArrayObject *obj = _PyByteArray_CAST(self);
 if (view == NULL) {
 PyErr_SetString(PyExc_BufferError,
 "bytearray_getbuffer: view==NULL argument is obsolete");
 return -1;
 }
-ptr = (void *) PyByteArray_AS_STRING(obj);
+
+void *ptr = (void *) PyByteArray_AS_STRING(obj);
 /* cannot fail if view != NULL and readonly == 0 */
 (void)PyBuffer_FillInfo(view, (PyObject*)obj, ptr, Py_SIZE(obj), 0, flags);
 obj->ob_exports++;
@@ -58,8 +59,9 @@ bytearray_getbuffer(PyByteArrayObject *obj, Py_buffer *view, 
int flags)
 }
 
 static void
-bytearray_releasebuffer(PyByteArrayObject *obj, Py_buffer *view)
+bytearray_releasebuffer(PyObject *self, Py_buffer *view)
 {
+PyByteArrayObject *obj = _PyByteArray_CAST(self);
 obj->ob_exports--;
 assert(obj->ob_exports >= 0);
 }
@@ -286,46 +288,53 @@ PyByteArray_Concat(PyObject *a, PyObject *b)
 /* Functions stuffed into the type object */
 
 static Py_ssize_t
-bytearray_length(PyByteArrayObject *self)
+bytearray_length(PyObject *op)
 {
+PyByteArrayObject *self = _PyByteArray_CAST(op);
 return Py_SIZE(self);
 }
 
 static PyObject *
-bytearray_iconcat(PyByteArrayObject *self, PyObject *other)
+bytearray_iconcat(PyObject *op, PyObject *other)
 {
-Py_ssize_t size;
-Py_buffer vo;
+PyByteArrayObject *self = _PyByteArray_CAST(op);
 
+Py_buffer vo;
 if (PyObject_GetBuffer(other, &vo, PyBUF_SIMPLE) != 0) {
 PyErr_Format(PyExc_TypeError, "can't concat %.100s to %.100s",
  Py_TYPE(other)->tp_name, Py_TYPE(self)->tp_name);
 return NULL;
 }
 
-size = Py_SIZE(self);
+Py_ssize_t size = Py_SIZE(self);
 if (size > PY_SSIZE_T_MAX - vo.len) {
 PyBuffer_Release(&vo);
 return PyErr_NoMemory();
 }
+
 if (PyByteArray_Resize((PyObject *)self, size + vo.len) < 0) {
 PyBuffer_Release(&vo);
 return NULL;
 }
+
 memcpy(PyByteArray_AS_STRING(self) + size, vo.buf, vo.len);
 PyBuffer_Release(&vo);
 return Py_NewRef(self);
 }
 
 static PyObject *
-bytearray_repeat(PyByteArrayObject *self, Py_ssize_t count)
+bytearray_repeat(PyObject *op, Py_ssize_t count)
 {
-if (count < 0)
+PyByteArrayObject *self = _PyByteArray_CAST(op);
+if (count < 0) {
 count = 0;
+}
 const Py_ssize_t mysize = Py_SIZE(self);
-if (count > 0 && mysize > PY_SSIZE_T_MAX / count)
+if (count > 0 && mysize > PY_SSIZE_T_MAX / count) {
 return PyErr_NoMemory();
+}
 Py_ssize_t size = mysize * count;
+
 PyByteArrayObject* result = (PyByteArrayObject 
*)PyByteArray_FromStringAndSize(NULL, size);
 const char* buf = PyByteArray_AS_STRING(self);
 if (result != NULL && size != 0) {
@@ -335,20 +344,24 @@ bytearray_repeat(PyByteArrayObject *self, Py_ssize_t 
count)
 }
 
 static PyObject *
-bytearray_irepeat(PyByteArrayObject *self, Py_ssize_t count)
+bytearray_irepeat(PyObject *op, Py_ssize_t count)
 {
-if (count < 0)
+PyByteArrayObject *self = _PyByteArray_CAST(op);
+if (count < 0) {
 count = 0;
+}
 else if (count == 1) {
 return Py_NewRef(self);
 }
 
 const Py_ssize_t mysize = Py_SIZE(self);
-if (count > 0 && mysize > PY_SSIZE_T_MAX / count)
+if (count > 0 && mysize > PY_SSIZE_T_MAX / count) {
 return PyErr_NoMemory();
+}
 const Py_ssize_t size = mysize * count;
-if (PyByteArray_Resize((PyObject *)self, size) < 0)
+if (PyByteArray_Resize((PyObject *)self, size) < 0) {
 return NULL;
+}
 
 char* buf = PyByteArray_AS_STRING(self);
 _PyBytes_Repeat(buf, size, buf, mysize);
@@ -357,8 +370,9 @@ bytearray_irepeat(PyByteArrayObject *self, Py_ssize_t count)
 }
 
 static PyObject *
-bytearray_getitem(PyByteArrayObject *self, Py_ssize_t i)
+bytearray_getitem(PyObject *op, Py_ssize_t i)
 {
+PyByteArrayObject *self = _PyByteArray_CAST(op);
 if (i < 0 || i >= Py_SIZE(self)) {
 PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
 return NULL;
@@ -367,8 +381,9 @@ bytearray_getitem(PyByteArrayObject *self, Py_ssize_t i)
 }
 
 static PyObject *
-bytearray_subscript(PyByteArrayObject *self, PyObject *index)
+bytearray_subscript(PyObject *op, P

[Python-checkins] gh-123961: Convert `curses.window` static type into a heap type (#124934)

2024-10-04 Thread vstinner
https://github.com/python/cpython/commit/f66d785861d3a210f1b6b14ebd129728b24f95bf
commit: f66d785861d3a210f1b6b14ebd129728b24f95bf
branch: main
author: Bénédikt Tran <[email protected]>
committer: vstinner 
date: 2024-10-04T11:58:34+02:00
summary:

gh-123961: Convert `curses.window` static type into a heap type (#124934)

files:
A Misc/NEWS.d/next/C_API/2024-10-03-14-06-08.gh-issue-123961.uwJQTY.rst
M Modules/_cursesmodule.c
M Modules/clinic/_cursesmodule.c.h

diff --git 
a/Misc/NEWS.d/next/C_API/2024-10-03-14-06-08.gh-issue-123961.uwJQTY.rst 
b/Misc/NEWS.d/next/C_API/2024-10-03-14-06-08.gh-issue-123961.uwJQTY.rst
new file mode 100644
index 00..40c26e15a2de92
--- /dev/null
+++ b/Misc/NEWS.d/next/C_API/2024-10-03-14-06-08.gh-issue-123961.uwJQTY.rst
@@ -0,0 +1,3 @@
+Convert the :ref:`curses.window ` static type exposed
+by the :c:macro:`!PyCursesWindow_Type` macro in ``Include/py_curses.h`` to a
+:ref:`heap type `. Patch by Bénédikt Tran.
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index f13731f6f3660c..61b65675375547 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -105,8 +105,9 @@ static const char PyCursesVersion[] = "2.2";
 #endif
 
 #include "Python.h"
-#include "pycore_long.h"  // _PyLong_GetZero()
-#include "pycore_structseq.h" // _PyStructSequence_NewType()
+#include "pycore_capsule.h" // _PyCapsule_SetTraverse()
+#include "pycore_long.h"// _PyLong_GetZero()
+#include "pycore_structseq.h"   // _PyStructSequence_NewType()
 
 #ifdef __hpux
 #define STRICT_SYSV_CURSES
@@ -173,6 +174,12 @@ get_cursesmodule_state(PyObject *Py_UNUSED(module))
 return &curses_global_state;
 }
 
+static inline _cursesmodule_state *
+get_cursesmodule_state_by_cls(PyTypeObject *Py_UNUSED(cls))
+{
+return &curses_global_state;
+}
+
 static inline _cursesmodule_state *
 get_cursesmodule_state_by_win(PyCursesWindowObject *Py_UNUSED(win))
 {
@@ -181,9 +188,9 @@ get_cursesmodule_state_by_win(PyCursesWindowObject 
*Py_UNUSED(win))
 
 /*[clinic input]
 module _curses
-class _curses.window "PyCursesWindowObject *" "&PyCursesWindow_Type"
+class _curses.window "PyCursesWindowObject *" "clinic_state()->window_type"
 [clinic start generated code]*/
-/*[clinic end generated code: output=da39a3ee5e6b4b0d input=43265c372c2887d6]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=ae6cb623018f2cbc]*/
 
 /* Tells whether setupterm() has been called to initialise terminfo.  */
 static int curses_setupterm_called = FALSE;
@@ -630,10 +637,6 @@ class component_converter(CConverter):
  The Window Object
 **/
 
-/* Definition of the window type */
-
-PyTypeObject PyCursesWindow_Type;
-
 /* Function prototype macros for Window object
 
X - function name
@@ -743,10 +746,9 @@ Window_TwoArgNoReturnFunction(wresize, int, 
"ii;lines,columns")
 /* Allocation and deallocation of Window Objects */
 
 static PyObject *
-PyCursesWindow_New(WINDOW *win, const char *encoding)
+PyCursesWindow_New(_cursesmodule_state *state,
+   WINDOW *win, const char *encoding)
 {
-PyCursesWindowObject *wo;
-
 if (encoding == NULL) {
 #if defined(MS_WINDOWS)
 char *buffer[100];
@@ -758,15 +760,20 @@ PyCursesWindow_New(WINDOW *win, const char *encoding)
 }
 #elif defined(CODESET)
 const char *codeset = nl_langinfo(CODESET);
-if (codeset != NULL && codeset[0] != 0)
+if (codeset != NULL && codeset[0] != 0) {
 encoding = codeset;
+}
 #endif
-if (encoding == NULL)
+if (encoding == NULL) {
 encoding = "utf-8";
+}
 }
 
-wo = PyObject_New(PyCursesWindowObject, &PyCursesWindow_Type);
-if (wo == NULL) return NULL;
+PyCursesWindowObject *wo = PyObject_GC_New(PyCursesWindowObject,
+   state->window_type);
+if (wo == NULL) {
+return NULL;
+}
 wo->win = win;
 wo->encoding = _PyMem_Strdup(encoding);
 if (wo->encoding == NULL) {
@@ -774,12 +781,16 @@ PyCursesWindow_New(WINDOW *win, const char *encoding)
 PyErr_NoMemory();
 return NULL;
 }
+PyObject_GC_Track((PyObject *)wo);
 return (PyObject *)wo;
 }
 
 static void
-PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
+PyCursesWindow_dealloc(PyObject *self)
 {
+PyTypeObject *window_type = Py_TYPE(self);
+PyObject_GC_UnTrack(self);
+PyCursesWindowObject *wo = (PyCursesWindowObject *)self;
 if (wo->win != stdscr && wo->win != NULL) {
 // silently ignore errors in delwin(3)
 (void)delwin(wo->win);
@@ -787,7 +798,15 @@ PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
 if (wo->encoding != NULL) {
 PyMem_Free(wo->encoding);
 }
-PyObject_Free(wo);
+window_type->tp_free(self);
+Py_DECREF(window_type);
+}
+
+static int
+PyCursesWindow_traverse(PyObject *self, visitproc vi

[Python-checkins] gh-111178: Fix function signatures in Python-ast.c (#124942)

2024-10-04 Thread vstinner
https://github.com/python/cpython/commit/6c7d5c6415fc22d35c7b8410533eb1831d46ba72
commit: 6c7d5c6415fc22d35c7b8410533eb1831d46ba72
branch: main
author: Victor Stinner 
committer: vstinner 
date: 2024-10-04T11:59:08+02:00
summary:

gh-78: Fix function signatures in Python-ast.c (#124942)

files:
M Parser/asdl_c.py
M Python/Python-ast.c

diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index fac9a7740a1fe6..ab5fd229cc46ea 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -843,8 +843,9 @@ def visitModule(self, mod):
 } AST_object;
 
 static void
-ast_dealloc(AST_object *self)
+ast_dealloc(PyObject *op)
 {
+AST_object *self = (AST_object*)op;
 /* bpo-31095: UnTrack is needed before calling any callbacks */
 PyTypeObject *tp = Py_TYPE(self);
 PyObject_GC_UnTrack(self);
@@ -856,16 +857,18 @@ def visitModule(self, mod):
 }
 
 static int
-ast_traverse(AST_object *self, visitproc visit, void *arg)
+ast_traverse(PyObject *op, visitproc visit, void *arg)
 {
+AST_object *self = (AST_object*)op;
 Py_VISIT(Py_TYPE(self));
 Py_VISIT(self->dict);
 return 0;
 }
 
 static int
-ast_clear(AST_object *self)
+ast_clear(PyObject *op)
 {
+AST_object *self = (AST_object*)op;
 Py_CLEAR(self->dict);
 return 0;
 }
@@ -1651,9 +1654,9 @@ def visitModule(self, mod):
 }
 
 static PyObject *
-ast_repr(AST_object *self)
+ast_repr(PyObject *self)
 {
-return ast_repr_max_depth(self, 3);
+return ast_repr_max_depth((AST_object*)self, 3);
 }
 
 static PyType_Slot AST_type_slots[] = {
@@ -1847,8 +1850,9 @@ def visitModule(self, mod):
 
 self.file.write(textwrap.dedent('''
 static int
-init_types(struct ast_state *state)
+init_types(void *arg)
 {
+struct ast_state *state = arg;
 if (init_identifiers(state) < 0) {
 return -1;
 }
@@ -2296,7 +2300,7 @@ def generate_module_def(mod, metadata, f, internal_h):
 };
 
 // Forward declaration
-static int init_types(struct ast_state *state);
+static int init_types(void *arg);
 
 static struct ast_state*
 get_ast_state(void)
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 860447ef9ed702..4a58c0973d1118 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -19,7 +19,7 @@ struct validator {
 };
 
 // Forward declaration
-static int init_types(struct ast_state *state);
+static int init_types(void *arg);
 
 static struct ast_state*
 get_ast_state(void)
@@ -5044,8 +5044,9 @@ typedef struct {
 } AST_object;
 
 static void
-ast_dealloc(AST_object *self)
+ast_dealloc(PyObject *op)
 {
+AST_object *self = (AST_object*)op;
 /* bpo-31095: UnTrack is needed before calling any callbacks */
 PyTypeObject *tp = Py_TYPE(self);
 PyObject_GC_UnTrack(self);
@@ -5057,16 +5058,18 @@ ast_dealloc(AST_object *self)
 }
 
 static int
-ast_traverse(AST_object *self, visitproc visit, void *arg)
+ast_traverse(PyObject *op, visitproc visit, void *arg)
 {
+AST_object *self = (AST_object*)op;
 Py_VISIT(Py_TYPE(self));
 Py_VISIT(self->dict);
 return 0;
 }
 
 static int
-ast_clear(AST_object *self)
+ast_clear(PyObject *op)
 {
+AST_object *self = (AST_object*)op;
 Py_CLEAR(self->dict);
 return 0;
 }
@@ -5852,9 +5855,9 @@ ast_repr_max_depth(AST_object *self, int depth)
 }
 
 static PyObject *
-ast_repr(AST_object *self)
+ast_repr(PyObject *self)
 {
-return ast_repr_max_depth(self, 3);
+return ast_repr_max_depth((AST_object*)self, 3);
 }
 
 static PyType_Slot AST_type_slots[] = {
@@ -6047,8 +6050,9 @@ static int add_ast_fields(struct ast_state *state)
 
 
 static int
-init_types(struct ast_state *state)
+init_types(void *arg)
 {
+struct ast_state *state = arg;
 if (init_identifiers(state) < 0) {
 return -1;
 }

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] gh-111178: Fix function signatures in classobject.c (#124943)

2024-10-04 Thread vstinner
https://github.com/python/cpython/commit/2c2ad4f76f8ec197c31145d3f33bc40b790d4aea
commit: 2c2ad4f76f8ec197c31145d3f33bc40b790d4aea
branch: main
author: Victor Stinner 
committer: vstinner 
date: 2024-10-04T12:00:00+02:00
summary:

gh-78: Fix function signatures in classobject.c (#124943)

files:
M Objects/classobject.c

diff --git a/Objects/classobject.c b/Objects/classobject.c
index 69a7d5f046e30d..775894ad5a7166 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -10,6 +10,7 @@
 
 #include "clinic/classobject.c.h"
 
+#define _PyMethodObject_CAST(op) _Py_CAST(PyMethodObject*, (op))
 #define TP_DESCR_GET(t) ((t)->tp_descr_get)
 
 /*[clinic input]
@@ -166,13 +167,14 @@ static PyMemberDef method_memberlist[] = {
should only be used for the class, not for instances */
 
 static PyObject *
-method_get_doc(PyMethodObject *im, void *context)
+method_get_doc(PyObject *self, void *context)
 {
+PyMethodObject *im = _PyMethodObject_CAST(self);
 return PyObject_GetAttr(im->im_func, &_Py_ID(__doc__));
 }
 
 static PyGetSetDef method_getset[] = {
-{"__doc__", (getter)method_get_doc, NULL, NULL},
+{"__doc__", method_get_doc, NULL, NULL},
 {0}
 };
 
@@ -235,8 +237,9 @@ method_new_impl(PyTypeObject *type, PyObject *function, 
PyObject *instance)
 }
 
 static void
-method_dealloc(PyMethodObject *im)
+method_dealloc(PyObject *self)
 {
+PyMethodObject *im = _PyMethodObject_CAST(self);
 _PyObject_GC_UNTRACK(im);
 if (im->im_weakreflist != NULL)
 PyObject_ClearWeakRefs((PyObject *)im);
@@ -274,8 +277,9 @@ method_richcompare(PyObject *self, PyObject *other, int op)
 }
 
 static PyObject *
-method_repr(PyMethodObject *a)
+method_repr(PyObject *op)
 {
+PyMethodObject *a = _PyMethodObject_CAST(op);
 PyObject *self = a->im_self;
 PyObject *func = a->im_func;
 PyObject *funcname, *result;
@@ -301,22 +305,26 @@ method_repr(PyMethodObject *a)
 }
 
 static Py_hash_t
-method_hash(PyMethodObject *a)
+method_hash(PyObject *self)
 {
-Py_hash_t x, y;
-x = PyObject_GenericHash(a->im_self);
-y = PyObject_Hash(a->im_func);
-if (y == -1)
+PyMethodObject *a = _PyMethodObject_CAST(self);
+Py_hash_t x = PyObject_GenericHash(a->im_self);
+Py_hash_t y = PyObject_Hash(a->im_func);
+if (y == -1) {
 return -1;
+}
+
 x = x ^ y;
-if (x == -1)
+if (x == -1) {
 x = -2;
+}
 return x;
 }
 
 static int
-method_traverse(PyMethodObject *im, visitproc visit, void *arg)
+method_traverse(PyObject *self, visitproc visit, void *arg)
 {
+PyMethodObject *im = _PyMethodObject_CAST(self);
 Py_VISIT(im->im_func);
 Py_VISIT(im->im_self);
 return 0;
@@ -333,17 +341,17 @@ PyTypeObject PyMethod_Type = {
 PyVarObject_HEAD_INIT(&PyType_Type, 0)
 .tp_name = "method",
 .tp_basicsize = sizeof(PyMethodObject),
-.tp_dealloc = (destructor)method_dealloc,
+.tp_dealloc = method_dealloc,
 .tp_vectorcall_offset = offsetof(PyMethodObject, vectorcall),
-.tp_repr = (reprfunc)method_repr,
-.tp_hash = (hashfunc)method_hash,
+.tp_repr = method_repr,
+.tp_hash = method_hash,
 .tp_call = PyVectorcall_Call,
 .tp_getattro = method_getattro,
 .tp_setattro = PyObject_GenericSetAttr,
 .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
 Py_TPFLAGS_HAVE_VECTORCALL,
 .tp_doc = method_new__doc__,
-.tp_traverse = (traverseproc)method_traverse,
+.tp_traverse = method_traverse,
 .tp_richcompare = method_richcompare,
 .tp_weaklistoffset = offsetof(PyMethodObject, im_weakreflist),
 .tp_methods = method_methods,
@@ -399,7 +407,7 @@ instancemethod_get_doc(PyObject *self, void *context)
 }
 
 static PyGetSetDef instancemethod_getset[] = {
-{"__doc__", (getter)instancemethod_get_doc, NULL, NULL},
+{"__doc__", instancemethod_get_doc, NULL, NULL},
 {0}
 };
 
@@ -537,7 +545,7 @@ PyTypeObject PyInstanceMethod_Type = {
 .tp_name = "instancemethod",
 .tp_basicsize = sizeof(PyInstanceMethodObject),
 .tp_dealloc = instancemethod_dealloc,
-.tp_repr = (reprfunc)instancemethod_repr,
+.tp_repr = instancemethod_repr,
 .tp_call = instancemethod_call,
 .tp_getattro = instancemethod_getattro,
 .tp_setattro = PyObject_GenericSetAttr,

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] Fix console prompt syntax in What's New in Python 3.8 (#124968)

2024-10-04 Thread AA-Turner
https://github.com/python/cpython/commit/bd393aedb84a7d84d11a996bcbbf57cad90af7db
commit: bd393aedb84a7d84d11a996bcbbf57cad90af7db
branch: main
author: Nice Zombies 
committer: AA-Turner <[email protected]>
date: 2024-10-04T12:33:54+01:00
summary:

Fix console prompt syntax in What's New in Python 3.8 (#124968)

files:
M Doc/whatsnew/3.8.rst

diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst
index d0e60bc280a217..fc9f49e65af847 100644
--- a/Doc/whatsnew/3.8.rst
+++ b/Doc/whatsnew/3.8.rst
@@ -428,9 +428,9 @@ Other Language Changes
   normal assignment syntax::
 
 >>> def parse(family):
-lastname, *members = family.split()
-return lastname.upper(), *members
-
+... lastname, *members = family.split()
+... return lastname.upper(), *members
+...
 >>> parse('simpsons homer marge bart lisa maggie')
 ('SIMPSONS', 'homer', 'marge', 'bart', 'lisa', 'maggie')
 

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] gh-124962: Convert leftover rst to markup in `InternalDocs/compiler.md` (#124971)

2024-10-04 Thread kumaraditya303
https://github.com/python/cpython/commit/994051e086b9ce624a3b16750d6f692bc4a3b07b
commit: 994051e086b9ce624a3b16750d6f692bc4a3b07b
branch: main
author: isaacjones99 <[email protected]>
committer: kumaraditya303 
date: 2024-10-04T19:53:02+05:30
summary:

gh-124962: Convert leftover rst to markup in `InternalDocs/compiler.md` 
(#124971)


Co-authored-by: Bénédikt Tran <[email protected]>

files:
M InternalDocs/compiler.md

diff --git a/InternalDocs/compiler.md b/InternalDocs/compiler.md
index ba31e16c3bbeaa..f27e73b274511f 100644
--- a/InternalDocs/compiler.md
+++ b/InternalDocs/compiler.md
@@ -324,14 +324,14 @@ basic block.
 
 As an example, consider the following code snippet:
 
-.. code-block:: Python
-
-   if x < 10:
-   f1()
-   f2()
-   else:
-   g()
-   end()
+```python
+if x < 10:
+f1()
+f2()
+else:
+g()
+end()
+```
 
 The ``x < 10`` guard is represented by its own basic block that
 compares ``x`` with ``10`` and then ends in a conditional jump based on

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] [3.13] gh-109975: Suggest ``pynntp`` instead of ``nntplib`` (GH-124830) (#124966)

2024-10-04 Thread Yhg1s
https://github.com/python/cpython/commit/dd4e62e35f3b3360fa7d5513d6564e86ad2f5275
commit: dd4e62e35f3b3360fa7d5513d6564e86ad2f5275
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: Yhg1s 
date: 2024-10-04T15:31:51-07:00
summary:

[3.13] gh-109975: Suggest ``pynntp`` instead of ``nntplib`` (GH-124830) 
(#124966)

gh-109975: Suggest ``pynntp`` instead of ``nntplib`` (GH-124830)

The ``nntplib`` library has been deleted from PyPI by its author.
(cherry picked from commit ac9648243dc0f5cb34c93621e507a98cf90550ea)

Co-authored-by: Christian Clauss 

files:
M Doc/whatsnew/3.13.rst

diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst
index 261c3b003ccf66..e629fc122f1397 100644
--- a/Doc/whatsnew/3.13.rst
+++ b/Doc/whatsnew/3.13.rst
@@ -1559,7 +1559,7 @@ and are now removed:
 * :mod:`!msilib`
 * :mod:`!nis`
 * :mod:`!nntplib`:
-  Use the :pypi:`nntplib` library from PyPI instead.
+  Use the :pypi:`pynntp` library from PyPI instead.
 * :mod:`!ossaudiodev`:
   For audio playback, use the :pypi:`pygame` library from PyPI instead.
 * :mod:`!pipes`:

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]


[Python-checkins] [3.13] gh-124871: fix 'visited' tracking in compiler's reachability analysis (GH-124952) (#124977)

2024-10-04 Thread Yhg1s
https://github.com/python/cpython/commit/b87aea6b0d299afcc03fc73c55e7b1dda78b9f35
commit: b87aea6b0d299afcc03fc73c55e7b1dda78b9f35
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: Yhg1s 
date: 2024-10-04T15:34:20-07:00
summary:

[3.13] gh-124871: fix 'visited' tracking in compiler's reachability analysis 
(GH-124952) (#124977)

gh-124871: fix 'visited' tracking in compiler's reachability analysis 
(GH-124952)
(cherry picked from commit f474391b26aa9208b44ca879f8635409d322f738)

Co-authored-by: Irit Katriel <[email protected]>

files:
A Misc/NEWS.d/next/Core and 
Builtins/2024-10-03-22-26-39.gh-issue-124871.tAMF47.rst
M Lib/test/test_compile.py
M Python/flowgraph.c

diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index cdd942b56cb7e5..ed4e6265eac438 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -476,6 +476,19 @@ def test_dead_code_with_except_handler_compiles(self):
 x = 2
"""), '', 'exec')
 
+def test_try_except_in_while_with_chained_condition_compiles(self):
+# see gh-124871
+compile(textwrap.dedent("""
+name_1, name_2, name_3 = 1, 2, 3
+while name_3 <= name_2 > name_1:
+try:
+raise
+except:
+pass
+finally:
+pass
+"""), '', 'exec')
+
 def test_compile_invalid_namedexpr(self):
 # gh-109351
 m = ast.Module(
diff --git a/Misc/NEWS.d/next/Core and 
Builtins/2024-10-03-22-26-39.gh-issue-124871.tAMF47.rst b/Misc/NEWS.d/next/Core 
and Builtins/2024-10-03-22-26-39.gh-issue-124871.tAMF47.rst
new file mode 100644
index 00..185cb3048fadf5
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and 
Builtins/2024-10-03-22-26-39.gh-issue-124871.tAMF47.rst 
@@ -0,0 +1,2 @@
+Fix compiler bug (in some versions of 3.13) where an assertion fails during 
reachability
+analysis.
diff --git a/Python/flowgraph.c b/Python/flowgraph.c
index d12b602e710094..ff70e47370241a 100644
--- a/Python/flowgraph.c
+++ b/Python/flowgraph.c
@@ -960,13 +960,14 @@ remove_unreachable(basicblock *entryblock) {
 basicblock **sp = stack;
 entryblock->b_predecessors = 1;
 *sp++ = entryblock;
+entryblock->b_visited = 1;
 while (sp > stack) {
 basicblock *b = *(--sp);
-b->b_visited = 1;
 if (b->b_next && BB_HAS_FALLTHROUGH(b)) {
 if (!b->b_next->b_visited) {
 assert(b->b_next->b_predecessors == 0);
 *sp++ = b->b_next;
+b->b_next->b_visited = 1;
 }
 b->b_next->b_predecessors++;
 }
@@ -976,8 +977,8 @@ remove_unreachable(basicblock *entryblock) {
 if (is_jump(instr) || is_block_push(instr)) {
 target = instr->i_target;
 if (!target->b_visited) {
-assert(target->b_predecessors == 0 || target == b->b_next);
 *sp++ = target;
+target->b_visited = 1;
 }
 target->b_predecessors++;
 }

___
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]