Skip to content

Commit 8a312ca

Browse files
committed
Merge remote-tracking branch 'origin/main' into generate-ceval-switch
2 parents d8e6db8 + c053284 commit 8a312ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+531
-509
lines changed

Doc/c-api/memory.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ for the I/O buffer escapes completely the Python memory manager.
9595
Allocator Domains
9696
=================
9797

98+
.. _allocator-domains:
99+
98100
All allocating functions belong to one of three different "domains" (see also
99101
:c:type:`PyMemAllocatorDomain`). These domains represent different allocation
100102
strategies and are optimized for different purposes. The specific details on
@@ -479,6 +481,25 @@ Customize Memory Allocators
479481
See also :c:member:`PyPreConfig.allocator` and :ref:`Preinitialize Python
480482
with PyPreConfig <c-preinit>`.
481483
484+
.. warning::
485+
486+
:c:func:`PyMem_SetAllocator` does have the following contract:
487+
488+
* It can be called after :c:func:`Py_PreInitialize` and before
489+
:c:func:`Py_InitializeFromConfig` to install a custom memory
490+
allocator. There are no restrictions over the installed allocator
491+
other than the ones imposed by the domain (for instance, the Raw
492+
Domain allows the allocator to be called without the GIL held). See
493+
:ref:`the section on allocator domains <allocator-domains>` for more
494+
information.
495+
496+
* If called after Python has finish initializing (after
497+
:c:func:`Py_InitializeFromConfig` has been called) the allocator
498+
**must** wrap the existing allocator. Substituting the current
499+
allocator for some other arbitrary one is **not supported**.
500+
501+
502+
482503
.. c:function:: void PyMem_SetupDebugHooks(void)
483504
484505
Setup :ref:`debug hooks in the Python memory allocators <pymem-debug-hooks>`

Include/cpython/code.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ typedef struct {
7070
PyObject *co_exceptiontable; /* Byte string encoding exception handling \
7171
table */ \
7272
int co_flags; /* CO_..., see below */ \
73-
short co_warmup; /* Warmup counter for quickening */ \
7473
short _co_linearray_entry_size; /* Size of each entry in _co_linearray */ \
7574
\
7675
/* The rest are not so impactful on performance. */ \

Include/internal/pycore_code.h

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,8 @@ typedef struct {
9191

9292
#define INLINE_CACHE_ENTRIES_FOR_ITER CACHE_ENTRIES(_PyForIterCache)
9393

94-
#define QUICKENING_WARMUP_DELAY 8
95-
96-
/* We want to compare to zero for efficiency, so we offset values accordingly */
97-
#define QUICKENING_INITIAL_WARMUP_VALUE (-QUICKENING_WARMUP_DELAY)
98-
99-
void _PyCode_Quicken(PyCodeObject *code);
100-
101-
static inline void
102-
_PyCode_Warmup(PyCodeObject *code)
103-
{
104-
if (code->co_warmup != 0) {
105-
code->co_warmup++;
106-
if (code->co_warmup == 0) {
107-
_PyCode_Quicken(code);
108-
}
109-
}
110-
}
111-
11294
extern uint8_t _PyOpcode_Adaptive[256];
11395

114-
extern Py_ssize_t _Py_QuickenedCount;
115-
11696
// Borrowed references to common callables:
11797
struct callable_cache {
11898
PyObject *isinstance;
@@ -252,10 +232,10 @@ extern void _Py_Specialize_UnpackSequence(PyObject *seq, _Py_CODEUNIT *instr,
252232
int oparg);
253233
extern void _Py_Specialize_ForIter(PyObject *iter, _Py_CODEUNIT *instr);
254234

255-
/* Deallocator function for static codeobjects used in deepfreeze.py */
256-
extern void _PyStaticCode_Dealloc(PyCodeObject *co);
257-
/* Function to intern strings of codeobjects */
258-
extern int _PyStaticCode_InternStrings(PyCodeObject *co);
235+
/* Finalizer function for static codeobjects used in deepfreeze.py */
236+
extern void _PyStaticCode_Fini(PyCodeObject *co);
237+
/* Function to intern strings of codeobjects and quicken the bytecode */
238+
extern int _PyStaticCode_Init(PyCodeObject *co);
259239

260240
#ifdef Py_STATS
261241

@@ -397,8 +377,8 @@ write_location_entry_start(uint8_t *ptr, int code, int length)
397377

398378
/* With a 16-bit counter, we have 12 bits for the counter value, and 4 bits for the backoff */
399379
#define ADAPTIVE_BACKOFF_BITS 4
400-
/* The initial counter value is 31 == 2**ADAPTIVE_BACKOFF_START - 1 */
401-
#define ADAPTIVE_BACKOFF_START 5
380+
/* The initial counter value is 1 == 2**ADAPTIVE_BACKOFF_START - 1 */
381+
#define ADAPTIVE_BACKOFF_START 1
402382

403383
#define MAX_BACKOFF_VALUE (16 - ADAPTIVE_BACKOFF_BITS)
404384

Include/internal/pycore_global_strings.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct _Py_global_strings {
4444
STRUCT_FOR_STR(dot, ".")
4545
STRUCT_FOR_STR(dot_locals, ".<locals>")
4646
STRUCT_FOR_STR(empty, "")
47+
STRUCT_FOR_STR(json_decoder, "json.decoder")
4748
STRUCT_FOR_STR(list_err, "list index out of range")
4849
STRUCT_FOR_STR(newline, "\n")
4950
STRUCT_FOR_STR(open_br, "{")
@@ -52,7 +53,11 @@ struct _Py_global_strings {
5253
} literals;
5354

5455
struct {
56+
STRUCT_FOR_ID(CANCELLED)
57+
STRUCT_FOR_ID(FINISHED)
5558
STRUCT_FOR_ID(False)
59+
STRUCT_FOR_ID(JSONDecodeError)
60+
STRUCT_FOR_ID(PENDING)
5661
STRUCT_FOR_ID(Py_Repr)
5762
STRUCT_FOR_ID(TextIOWrapper)
5863
STRUCT_FOR_ID(True)
@@ -71,6 +76,7 @@ struct _Py_global_strings {
7176
STRUCT_FOR_ID(__anext__)
7277
STRUCT_FOR_ID(__annotations__)
7378
STRUCT_FOR_ID(__args__)
79+
STRUCT_FOR_ID(__asyncio_running_event_loop__)
7480
STRUCT_FOR_ID(__await__)
7581
STRUCT_FOR_ID(__bases__)
7682
STRUCT_FOR_ID(__bool__)
@@ -212,6 +218,7 @@ struct _Py_global_strings {
212218
STRUCT_FOR_ID(__xor__)
213219
STRUCT_FOR_ID(_abc_impl)
214220
STRUCT_FOR_ID(_annotation)
221+
STRUCT_FOR_ID(_asyncio_future_blocking)
215222
STRUCT_FOR_ID(_blksize)
216223
STRUCT_FOR_ID(_bootstrap)
217224
STRUCT_FOR_ID(_dealloc_warn)
@@ -224,6 +231,7 @@ struct _Py_global_strings {
224231
STRUCT_FOR_ID(_initializing)
225232
STRUCT_FOR_ID(_is_text_encoding)
226233
STRUCT_FOR_ID(_lock_unlock_module)
234+
STRUCT_FOR_ID(_loop)
227235
STRUCT_FOR_ID(_showwarnmsg)
228236
STRUCT_FOR_ID(_shutdown)
229237
STRUCT_FOR_ID(_slotnames)
@@ -234,6 +242,7 @@ struct _Py_global_strings {
234242
STRUCT_FOR_ID(abs_tol)
235243
STRUCT_FOR_ID(access)
236244
STRUCT_FOR_ID(add)
245+
STRUCT_FOR_ID(add_done_callback)
237246
STRUCT_FOR_ID(after_in_child)
238247
STRUCT_FOR_ID(after_in_parent)
239248
STRUCT_FOR_ID(aggregate_class)
@@ -267,6 +276,9 @@ struct _Py_global_strings {
267276
STRUCT_FOR_ID(cadata)
268277
STRUCT_FOR_ID(cafile)
269278
STRUCT_FOR_ID(call)
279+
STRUCT_FOR_ID(call_exception_handler)
280+
STRUCT_FOR_ID(call_soon)
281+
STRUCT_FOR_ID(cancel)
270282
STRUCT_FOR_ID(capath)
271283
STRUCT_FOR_ID(category)
272284
STRUCT_FOR_ID(cb_type)
@@ -324,6 +336,7 @@ struct _Py_global_strings {
324336
STRUCT_FOR_ID(digest_size)
325337
STRUCT_FOR_ID(digestmod)
326338
STRUCT_FOR_ID(dir_fd)
339+
STRUCT_FOR_ID(discard)
327340
STRUCT_FOR_ID(dispatch_table)
328341
STRUCT_FOR_ID(displayhook)
329342
STRUCT_FOR_ID(dklen)
@@ -352,6 +365,7 @@ struct _Py_global_strings {
352365
STRUCT_FOR_ID(extend)
353366
STRUCT_FOR_ID(facility)
354367
STRUCT_FOR_ID(factory)
368+
STRUCT_FOR_ID(false)
355369
STRUCT_FOR_ID(family)
356370
STRUCT_FOR_ID(fanout)
357371
STRUCT_FOR_ID(fd)
@@ -376,9 +390,13 @@ struct _Py_global_strings {
376390
STRUCT_FOR_ID(fromlist)
377391
STRUCT_FOR_ID(fset)
378392
STRUCT_FOR_ID(func)
393+
STRUCT_FOR_ID(future)
379394
STRUCT_FOR_ID(generation)
380395
STRUCT_FOR_ID(genexpr)
381396
STRUCT_FOR_ID(get)
397+
STRUCT_FOR_ID(get_debug)
398+
STRUCT_FOR_ID(get_event_loop)
399+
STRUCT_FOR_ID(get_loop)
382400
STRUCT_FOR_ID(get_source)
383401
STRUCT_FOR_ID(getattr)
384402
STRUCT_FOR_ID(getstate)
@@ -491,6 +509,7 @@ struct _Py_global_strings {
491509
STRUCT_FOR_ID(node_offset)
492510
STRUCT_FOR_ID(ns)
493511
STRUCT_FOR_ID(nstype)
512+
STRUCT_FOR_ID(null)
494513
STRUCT_FOR_ID(number)
495514
STRUCT_FOR_ID(obj)
496515
STRUCT_FOR_ID(object)
@@ -588,6 +607,7 @@ struct _Py_global_strings {
588607
STRUCT_FOR_ID(sort)
589608
STRUCT_FOR_ID(sound)
590609
STRUCT_FOR_ID(source)
610+
STRUCT_FOR_ID(source_traceback)
591611
STRUCT_FOR_ID(src)
592612
STRUCT_FOR_ID(src_dir_fd)
593613
STRUCT_FOR_ID(stacklevel)
@@ -627,6 +647,7 @@ struct _Py_global_strings {
627647
STRUCT_FOR_ID(traceback)
628648
STRUCT_FOR_ID(trailers)
629649
STRUCT_FOR_ID(translate)
650+
STRUCT_FOR_ID(true)
630651
STRUCT_FOR_ID(truncate)
631652
STRUCT_FOR_ID(twice)
632653
STRUCT_FOR_ID(txt)

Include/internal/pycore_opcode.h

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)