Skip to content

Commit 522c9a4

Browse files
Merge branch '3.15' into backport-4b9a1ca-3.15
2 parents d243735 + e839679 commit 522c9a4

5 files changed

Lines changed: 37 additions & 12 deletions

File tree

Doc/library/csv.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ The :mod:`!csv` module defines the following classes:
314314

315315
If several delimiters fit the sample equally well ---
316316
for example if both ``','`` and ``';'`` split every row consistently ---
317-
the delimiters ``','``, ``'\t'``, ``';'``, ``' '`` and ``':'``
318-
are preferred, in this order,
317+
the delimiters listed in the :attr:`~Sniffer.preferred` attribute
318+
are preferred, in that order,
319319
no matter how many times each of them occurs.
320320

321321
.. method:: has_header(sample)
@@ -337,6 +337,15 @@ The :mod:`!csv` module defines the following classes:
337337
This method is a rough heuristic and may produce both false positives and
338338
negatives.
339339

340+
The :class:`Sniffer` class has the following attribute:
341+
342+
.. attribute:: preferred
343+
344+
The list of the delimiters preferred for breaking ties,
345+
in the order of preference.
346+
It can be modified.
347+
Its initial value is ``[',', '\t', ';', ' ', ':']``.
348+
340349
An example for :class:`Sniffer` use::
341350

342351
with open('example.csv', newline='') as csvfile:

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

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.

Objects/codeobject.c

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

33153315
void
3316-
_Py_ClearTLBCIndex(_PyThreadStateImpl *tstate)
3316+
_Py_UnreserveTLBCIndex(PyInterpreterState *interp, int32_t index)
33173317
{
3318-
PyInterpreterState *interp = ((PyThreadState *)tstate)->interp;
33193318
if (interp->config.tlbc_enabled) {
3320-
_PyIndexPool_FreeIndex(&interp->tlbc_indices, tstate->tlbc_index);
3319+
_PyIndexPool_FreeIndex(&interp->tlbc_indices, index);
33213320
}
33223321
}
33233322

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

Python/pystate.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,21 +1638,23 @@ new_threadstate(PyInterpreterState *interp, int whence)
16381638
return NULL;
16391639
}
16401640

1641-
#ifdef Py_GIL_DISABLED
1642-
Py_ssize_t qsbr_idx = _Py_qsbr_reserve(interp);
1643-
if (qsbr_idx < 0) {
1641+
#ifdef Py_STATS
1642+
// The PyStats structure is quite large and is allocated separated from
1643+
// tstate.
1644+
if (!_PyStats_ThreadInit(interp, tstate)) {
16441645
free_threadstate(tstate);
16451646
return NULL;
16461647
}
1648+
#endif
1649+
#ifdef Py_GIL_DISABLED
16471650
int32_t tlbc_idx = _Py_ReserveTLBCIndex(interp);
16481651
if (tlbc_idx < 0) {
16491652
free_threadstate(tstate);
16501653
return NULL;
16511654
}
1652-
#endif
1653-
#ifdef Py_STATS
1654-
// The PyStats structure is quite large and is allocated separated from tstate.
1655-
if (!_PyStats_ThreadInit(interp, tstate)) {
1655+
Py_ssize_t qsbr_idx = _Py_qsbr_reserve(interp);
1656+
if (qsbr_idx < 0) {
1657+
_Py_UnreserveTLBCIndex(interp, tlbc_idx);
16561658
free_threadstate(tstate);
16571659
return NULL;
16581660
}

0 commit comments

Comments
 (0)