Skip to content

Commit 4a60f4e

Browse files
authored
Merge branch 'main' into float-doc-fix
2 parents 854a77e + 3444ef9 commit 4a60f4e

9 files changed

Lines changed: 57 additions & 12 deletions

File tree

Doc/library/test.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ The :mod:`!test.support` module defines the following constants:
285285
:meth:`~socket.socket.recv` and :meth:`~socket.socket.send` methods of
286286
:class:`socket.socket`.
287287

288-
Its default value is 5 seconds.
288+
Its default value is 10 seconds.
289289

290290
See also :data:`INTERNET_TIMEOUT`.
291291

Include/internal/pycore_code.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,10 @@ PyAPI_FUNC(_Py_CODEUNIT *) _PyCode_GetTLBC(PyCodeObject *co);
582582
// Returns the reserved index or -1 on error.
583583
extern int32_t _Py_ReserveTLBCIndex(PyInterpreterState *interp);
584584

585+
// Release an index returned by _Py_ReserveTLBCIndex() that was never stored
586+
// in a PyThreadState.
587+
extern void _Py_UnreserveTLBCIndex(PyInterpreterState *interp, int32_t index);
588+
585589
// Release the current thread's index into thread-local bytecode arrays
586590
extern void _Py_ClearTLBCIndex(_PyThreadStateImpl *tstate);
587591

Lib/http/cookiejar.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def _debug(*args):
5353
HTTPONLY_ATTR = "HTTPOnly"
5454
HTTPONLY_PREFIX = "#HttpOnly_"
5555
DEFAULT_HTTP_PORT = str(http.client.HTTP_PORT)
56-
NETSCAPE_MAGIC_RGX = re.compile("#( Netscape)? HTTP Cookie File")
56+
NETSCAPE_MAGIC_RGX = re.compile("#( Netscape)? HTTP Cookie File",
57+
re.IGNORECASE | re.ASCII)
5758
MISSING_FILENAME_TEXT = ("a filename was not supplied (nor was the CookieJar "
5859
"instance initialised with one)")
5960
NETSCAPE_HEADER_TEXT = """\

Lib/test/test_http_cookiejar.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,31 @@ def test_bad_magic(self):
459459
finally:
460460
os_helper.unlink(filename)
461461

462+
def test_magic_ignores_case(self):
463+
filename = os_helper.TESTFN
464+
self.addCleanup(os_helper.unlink, filename)
465+
for magic in ("# Netscape HTTP Cookie File",
466+
"# netscape http cookie file",
467+
"# HTTP Cookie File",
468+
"# http cookie file"):
469+
with self.subTest(magic=magic):
470+
with open(filename, "w") as f:
471+
f.write(magic + "\n")
472+
MozillaCookieJar().load(filename)
473+
474+
def test_magic_is_not_unicode(self):
475+
# Unicode case folding must not be used: 'ſ' (U+017F) and 'K'
476+
# (U+212A) are case-insensitively equal to 's' and 'k' in Unicode.
477+
filename = os_helper.TESTFN
478+
self.addCleanup(os_helper.unlink, filename)
479+
for magic in ("# Netſcape HTTP Cookie File",
480+
"# Netscape HTTP CooKie File"):
481+
with self.subTest(magic=magic):
482+
with open(filename, "w", encoding="utf-8") as f:
483+
f.write(magic + "\n")
484+
self.assertRaises(LoadError, MozillaCookieJar().load, filename)
485+
486+
462487
class CookieTests(unittest.TestCase):
463488
# XXX
464489
# Get rid of string comparisons where not actually testing str / repr.

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ Peter Harris
748748
Jonathan Hartley
749749
Travis B. Hartwell
750750
Henrik Harutyunyan
751+
Ashley Harvey
751752
Shane Harvey
752753
Larry Hastings
753754
Tim Hatch
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix a leak in the :term:`free-threaded build` when creating a thread state
2+
fails after an internal QSBR slot has been reserved for it. The slot could
3+
never be reclaimed, so the QSBR array grew without bound across repeated
4+
failures.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:meth:`http.cookiejar.FileCookieJar.load` now checks the first, format
2+
signature line in a case-insensitive manner. Patch by Ashley Harvey.

Objects/codeobject.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,14 +3314,20 @@ _Py_ReserveTLBCIndex(PyInterpreterState *interp)
33143314
}
33153315

33163316
void
3317-
_Py_ClearTLBCIndex(_PyThreadStateImpl *tstate)
3317+
_Py_UnreserveTLBCIndex(PyInterpreterState *interp, int32_t index)
33183318
{
3319-
PyInterpreterState *interp = ((PyThreadState *)tstate)->interp;
33203319
if (interp->config.tlbc_enabled) {
3321-
_PyIndexPool_FreeIndex(&interp->tlbc_indices, tstate->tlbc_index);
3320+
_PyIndexPool_FreeIndex(&interp->tlbc_indices, index);
33223321
}
33233322
}
33243323

3324+
void
3325+
_Py_ClearTLBCIndex(_PyThreadStateImpl *tstate)
3326+
{
3327+
PyInterpreterState *interp = ((PyThreadState *)tstate)->interp;
3328+
_Py_UnreserveTLBCIndex(interp, tstate->tlbc_index);
3329+
}
3330+
33253331
static _PyCodeArray *
33263332
_PyCodeArray_New(Py_ssize_t size)
33273333
{

Python/pystate.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,21 +1667,23 @@ new_threadstate(PyInterpreterState *interp, int whence)
16671667
return NULL;
16681668
}
16691669

1670-
#ifdef Py_GIL_DISABLED
1671-
Py_ssize_t qsbr_idx = _Py_qsbr_reserve(interp);
1672-
if (qsbr_idx < 0) {
1670+
#ifdef Py_STATS
1671+
// The PyStats structure is quite large and is allocated separated from
1672+
// tstate.
1673+
if (!_PyStats_ThreadInit(interp, tstate)) {
16731674
free_threadstate(tstate);
16741675
return NULL;
16751676
}
1677+
#endif
1678+
#ifdef Py_GIL_DISABLED
16761679
int32_t tlbc_idx = _Py_ReserveTLBCIndex(interp);
16771680
if (tlbc_idx < 0) {
16781681
free_threadstate(tstate);
16791682
return NULL;
16801683
}
1681-
#endif
1682-
#ifdef Py_STATS
1683-
// The PyStats structure is quite large and is allocated separated from tstate.
1684-
if (!_PyStats_ThreadInit(interp, tstate)) {
1684+
Py_ssize_t qsbr_idx = _Py_qsbr_reserve(interp);
1685+
if (qsbr_idx < 0) {
1686+
_Py_UnreserveTLBCIndex(interp, tlbc_idx);
16851687
free_threadstate(tstate);
16861688
return NULL;
16871689
}

0 commit comments

Comments
 (0)