10000 . · python/cpython@cc7ba06 · GitHub
[go: up one dir, main page]

Skip to content

Commit cc7ba06

Browse files
committed
.
Merge branch 'master' of github.com:python/cpython
2 parents eb56423 + 3bb1987 commit cc7ba06

File tree

5 files changed

+130
-51
lines changed

5 files changed

+130
-51
lines changed

Doc/library/io.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,6 @@ High-level Module Interface
155155
when an unsupported operation is called on a stream.
156156

157157

158-
In-memory streams
159-
^^^^^^^^^^^^^^^^^
160-
161-
It is also possible to use a :class:`str` or :term:`bytes-like object` as a
162-
file for both reading and writing. For strings :class:`StringIO` can be used
163-
like a file opened in text mode. :class:`BytesIO` can be used like a file
164-
opened in binary mode. Both provide full read-write capabilities with random
165-
access.
166-
167-
168158
.. seealso::
169159

170160
:mod:`sys`

Doc/whatsnew/3.10.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ operates by:
215215
match
216216
5. If an exact match is not confirmed, the last case, a wildcard ``_``,
217217
if provided, will be used as the matching case. If an exact match is
218-
not confirmed and a wildcard case does not exists, the entire match
218+
not confirmed and a wildcard case does not exist, the entire match
219219
block is a no-op.
220220
221221
Declarative approach

Include/README.rst

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
The Python C API
2+
================
3+
4+
The C API is divided into three sections:
5+
6+
1. ``Include/``
7+
2. ``Include/cpython/``
8+
3. ``Include/internal/``
9+
10+
11+
Include: Limited API
12+
====================
13+
14+
``Include/``, excluding the ``cpython`` and ``internal`` subdirectories,
15+
contains the public Limited API (Application Programming Interface).
16+
The Limited API is a subset of the C API, designed to guarantee ABI
17+
stability across Python 3 versions, and is defined in :pep:`384`.
18+
19+
Guidelines for expanding the Limited API:
20+
21+
- Functions *must not* steal references
22+
- Functions *must not* return borrowed references
23+
- Functions returning references *must* return a strong reference
24+
- Macros should not expose implementation details
25+
- Please start a public discussion before expanding the API
26+
- Functions or macros with a ``_Py`` prefix do not belong in ``Include/``.
27+
28+
It is possible to add a function or macro to the Limited API from a
29+
given Python version. For example, to add a function to the Limited API
30+
from Python 3.10 and onwards, wrap it with
31+
``#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000``.
32+
33+
34+
Include/cpython: CPython implementation details
35+
===============================================
36+
37+
``Include/cpython/`` contains the public API that is excluded from the
38+
Limited API and the Stable ABI.
39+
40+
Guidelines for expanding the public API:
41+
42+
- Functions *must not* steal references
43+
- Functions *must not* return borrowed references
44+
- Functions returning references *must* return a strong reference
45+
46+
47+
Include/internal: The internal API
48+
==================================
49+
50+
51+
With PyAPI_FUNC or PyAPI_DATA
52+
-----------------------------
53+
54+
Functions or structures in ``Include/internal/`` defined with
55+
``PyAPI_FUNC`` or ``PyAPI_DATA`` are internal functions which are
56+
exposed only for specific use cases like debuggers and profilers.
57+
58+
59+
With the extern keyword
60+
-----------------------
61+
62+
Functions in ``Include/internal/`` defined with the ``extern`` keyword
63+
*must not and can not* be used outside the CPython code base. Only
64+
built-in stdlib extensions (built with the ``Py_BUILD_CORE_BUILTIN``
65+
macro defined) can use such functions.
66+
67+
When in doubt, new internal C functions should be defined in
68+
``Include/internal`` using the ``extern`` keyword.

Modules/_collectionsmodule.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,23 @@ static PyTypeObject deque_type;
118118
#define CHECK_NOT_END(link)
119119
#endif
120120

121+
/* A simple freelisting scheme is used to minimize calls to the memory
122+
allocator. It accommodates common use cases where new blocks are being
123+
added at about the same rate as old blocks are being freed.
124+
*/
125+
126+
#define MAXFREEBLOCKS 16
127+
static Py_ssize_t numfreeblocks = 0;
128+
static block *freeblocks[MAXFREEBLOCKS];
129+
121130
static block *
122131
newblock(void) {
123-
block *b = PyMem_Malloc(sizeof(block));
132+
block *b;
133+
if (numfreeblocks) {
134+
numfreeblocks--;
135+
return freeblocks[numfreeblocks];
136+
}
137+
b = PyMem_Malloc(sizeof(block));
124138
if (b != NULL) {
125139
return b;
126140
}
@@ -131,7 +145,12 @@ newblock(void) {
131145
static void
132146
freeblock(block *b)
133147
{
134-
PyMem_Free(b);
148+
if (numfreeblocks < MAXFREEBLOCKS) {
149+
freeblocks[numfreeblocks] = b;
150+
numfreeblocks++;
151+
} else {
152+
PyMem_Free(b);
153+
}
135154
}
136155

137156
static PyObject *

Python/ceval.c

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,40 +1231,6 @@ eval_frame_handle_pending(PyThreadState *tstate)
12311231
return 0;
12321232
}
12331233

1234-
PyObject* _Py_HOT_FUNCTION
1235-
_PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
1236-
{
1237-
_Py_EnsureTstateNotNULL(tstate);
1238-
1239-
#ifdef DXPAIRS
1240-
int lastopcode = 0;
1241-
#endif
1242-
PyObject **stack_pointer; /* Next free slot in value stack */
1243-
const _Py_CODEUNIT *next_instr;
1244-
int opcode; /* Current opcode */
1245-
int oparg; /* Current opcode argument, if any */
1246-
PyObject **fastlocals, **freevars;
1247-
PyObject *retval = NULL; /* Return value */
1248-
struct _ceval_state * const ceval2 = &tstate->interp->ceval;
1249-
_Py_atomic_int * const eval_breaker = &ceval2->eval_breaker;
1250-
PyCodeObject *co;
1251-
1252-
/* when tracing we set things up so that
1253-
1254-
not (instr_lb <= current_bytecode_offset < instr_ub)
1255-
1256-
is true when the line being executed has changed. The
1257-
initial values are such as to make this false the first
1258-
time it is tested. */
1259-
1260-
const _Py_CODEUNIT *first_instr;
1261-
PyObject *names;
1262-
PyObject *consts;
1263-
_PyOpcache *co_opcache;
1264-
1265-
#ifdef LLTRACE
1266-
_Py_IDENTIFIER(__ltrace__);
1267-
#endif
12681234

12691235
/* Computed GOTOs, or
12701236
the-optimization-commonly-but-improperly-known-as-"threaded code"
@@ -1323,9 +1289,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
13231289
#endif
13241290

13251291
#if USE_COMPUTED_GOTOS
1326-
/* Import the static jump table */
1327-
#include "opcode_targets.h"
1328-
13291292
#define TARGET(op) \
13301293
op: \
13311294
TARGET_##op
@@ -1619,7 +1582,46 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
16191582

16201583
#endif
16211584

1622-
/* Start of code */
1585+
1586+
PyObject* _Py_HOT_FUNCTION
1587+
_PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
1588+
{
1589+
_Py_EnsureTstateNotNULL(tstate);
1590+
1591+
#if USE_COMPUTED_GOTOS
1592+
/* Import the static jump table */
1593+
#include "opcode_targets.h"
1594+
#endif
1595+
1596+
#ifdef DXPAIRS
1597+
int lastopcode = 0;
1598+
#endif
1599+
PyObject **stack_pointer; /* Next free slot in value stack */
1600+
const _Py_CODEUNIT *next_instr;
1601+
int opcode; /* Current opcode */
1602+
int oparg; /* Current opcode argument, if any */
1603+
PyObject **fastlocals, **freevars;
1604+
PyObject *retval = NULL; /* Return value */
1605+
struct _ceval_state * const ceval2 = &tstate->interp->ceval;
1606+
_Py_atomic_int * const eval_breaker = &ceval2->eval_breaker;
1607+
PyCodeObject *co;
1608+
1609+
/* when tracing we set things up so that
1610+
1611+
not (instr_lb <= current_bytecode_offset < instr_ub)
1612+
1613+
is true when the line being executed has changed. The
1614+
initial values are such as to make this false the first
1615+
time it is tested. */
1616+
1617+
const _Py_CODEUNIT *first_instr;
1618+
PyObject *names;
1619+
PyObject *consts;
1620+
_PyOpcache *co_opcache;
1621+
1622+
#ifdef LLTRACE
1623+
_Py_IDENTIFIER(__ltrace__);
1624+
#endif
16231625

16241626
if (_Py_EnterRecursiveCall(tstate, "")) {
16251627
return NULL;

0 commit comments

Comments
 (0)
0