Commit Graph

4296 Commits

Author SHA1 Message Date
Eric Snow 3e7cad3bca
gh-94673: Add Per-Interpreter tp_weaklist for Static Builtin Types (#95302)
* Store tp_weaklist on the interpreter state for static builtin types.

* Factor out _PyStaticType_GET_WEAKREFS_LISTPTR().

* Add _PyStaticType_ClearWeakRefs().

* Add a comment about how _PyStaticType_ClearWeakRefs() loops.

* Document the change.

* Update Doc/whatsnew/3.12.rst

* Fix a typo.
2022-07-28 19:23:47 -06:00
Mark Shannon b8b2990fb3
GH-90081: Run python tracers at full speed (GH-95328) 2022-07-28 10:17:22 +01:00
Christian Heimes 0fe645d6fd
gh-95174: Add pthread stubs for WASI (GH-95234)
Co-authored-by: Brett Cannon <brett@python.org>
2022-07-27 20:28:06 +02:00
Aivars Kalvāns 8c88e360e7
gh-95005: Replace PyAccu with PyUnicodeWriter (gh-95006) 2022-07-27 17:43:34 +09:00
Eric Snow 47e75a0025
gh-94673: Add Per-Interpreter Storage for Static Builtin Types (#95255)
This is the last precursor to storing tp_subclasses (and tp_weaklist) on the interpreter state for static builtin types.

Here we add per-type storage on PyInterpreterState, but only for the static builtin types.  This involves the following:

* add PyInterpreterState.types
   * move PyInterpreterState.type_cache to it
   * add a "num_builtins_initialized" field
   * add a "builtins" field (a static array big enough for all the static builtin types)
* add _PyStaticType_GetState() to look up a static builtin type's state
* (temporarily) add PyTypeObject.tp_static_builtin_index (to hold the type's index into PyInterpreterState.types.builtins)

We will be eliminating tp_static_builtin_index in a later change.
2022-07-26 17:26:43 -06:00
Pieter Eendebak 2ef73be891
gh-91247: Use memcpy for list and tuple repeat (#91482)
* Add _Py_memory_repeat function to pycore_list

* Add _Py_RefcntAdd function to pycore_object

* Use the new functions in tuplerepeat, list_repeat, and list_inplace_repeat
2022-07-25 22:10:23 -04:00
Mark Shannon 27055d766a
GH-92678: Expose managed dict clear and visit functions (#95246) 2022-07-25 22:30:53 +01:00
Eric Snow 4a1dd73431
gh-94673: Add _PyStaticType_InitBuiltin() (#95152)
This is the first of several precursors to storing tp_subclasses (and tp_weaklist) on the interpreter state for static builtin types.

We do the following:

* add `_PyStaticType_InitBuiltin()`
* add `_Py_TPFLAGS_STATIC_BUILTIN`
* set it on all static builtin types in `_PyStaticType_InitBuiltin()`
* shuffle some code around to be able to use _PyStaticType_InitBuiltin()
    * rename `_PyStructSequence_InitType()` to `_PyStructSequence_InitBuiltinWithFlags()`
    * add `_PyStructSequence_InitBuiltin()`.
2022-07-25 12:47:31 -06:00
Kumar Aditya 73ee5a6b86
GH-94851: check refcnt of immortal objects after finalization (GH-95001) 2022-07-25 10:43:59 -07:00
Pablo Galindo Salgado 0047447294
gh-95185: Check recursion depth in the AST constructor (#95186)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-07-24 15:58:52 +01:00
Brandt Bucher e402b26b7f
GH-95113: Don't use EXTENDED_ARG_QUICK in unquickened code (GH-95121) 2022-07-22 11:04:20 -07:00
Mark Shannon 2f8bff6879
GH-94739: Mark stacks of exception handling blocks for setting frame.f_lineno in the debugger. (GH-94958) 2022-07-18 16:06:42 +01:00
Petr Viktorin 6cbb57f62d
gh-94731: Revert to C-style casts for _Py_CAST (GH-94782)
Co-authored-by: da-woods <dw-git@d-woods.co.uk>
2022-07-14 11:57:18 +02:00
Itamar Ostricher 0fc8ac0b0d
pycore_interp.h: Fix comment about pytypedefs.h (#93188)
GH-31527 moved this typedef to `Include/pytypedefs.h`, so this comment
should point at the correct location
2022-07-09 15:58:30 +02:00
Kumar Aditya 9dff9f4814
GH-90699: Intern statically allocated strings (GH-93597)
This is similar to how strings are interned for deepfreeze.
2022-07-08 10:47:37 -07:00
Kumar Aditya 71697664d7
GH-90699: Move generated static initializer to pycore_runtime_generated.h (GH-94051) 2022-07-07 13:04:05 -07:00
Irit Katriel c57aad777a
gh-94216: add pseudo instructions to the dis/opcodes modules (GH-94241) 2022-07-01 15:33:35 +01:00
Mark Shannon 544531de23
GH-94262: Don't create frame objects for frames that aren't yet complete. (GH-94371) 2022-07-01 11:08:20 +01:00
Christian Heimes e5e51556e4
gh-90473: Reduce recursion limit on WASI even further (GH-94333)
750 fails sometimes with newer wasmtime versions. 600 is a more
conservative value.
2022-06-27 16:19:47 +02:00
Mark Shannon c0453a40fa
GH-94163: Add BINARY_SLICE and STORE_SLICE instructions. (GH-94168) 2022-06-27 12:24:23 +01:00
Victor Stinner 44c8e68b8c
gh-87347: Fix PyObject_NEW() regression (#94234)
Don't add parenthesis around the type parameter.

Add unit tests on PyObject_NEW() and similar functions.
2022-06-26 12:40:17 +02:00
Ken Jin 50a5ab2c0b
gh-93382: Sync up `co_code` changes with 3.11 (GH-94227)
Sync up co_code changes with 3.11 commit 852b4d4bcd.
2022-06-25 01:55:18 +08:00
Mark Shannon 6f8875eba3
GH-93841: Allow stats to be turned on and off, cleared and dumped at runtime. (GH-93843) 2022-06-21 15:40:54 +01:00
Dennis Sweeney 5fcfdd87c9
GH-91432: Specialize FOR_ITER (GH-91713)
* Adds FOR_ITER_LIST and FOR_ITER_RANGE specializations.

* Adds _PyLong_AssignValue() internal function to avoid temporary boxing of ints.
2022-06-21 11:19:26 +01:00
Victor Stinner 7ad6f74fcf
gh-87347: Add parenthesis around macro arguments (#93915)
Add unit test on Py_MEMBER_SIZE() and some other macros.
2022-06-20 16:04:52 +02:00
Mark Shannon ab0e601016
GH-93516: Speedup line number checks when tracing. (GH-93763)
* Use a lookup table to reduce overhead of getting line numbers during tracing.
2022-06-20 13:00:42 +01:00
Mark Shannon 45e62a2bc1
GH-93897: Store frame size in code object and de-opt if insufficient space on thread frame stack. (GH-93908) 2022-06-20 12:59:25 +01:00
Victor Stinner 27b9894033
gh-93937, C API: Move PyFrame_GetBack() to Python.h (#93938)
Move the follow functions and type from frameobject.h to pyframe.h,
so the standard <Python.h> provide frame getter functions:

* PyFrame_Check()
* PyFrame_GetBack()
* PyFrame_GetBuiltins()
* PyFrame_GetGenerator()
* PyFrame_GetGlobals()
* PyFrame_GetLasti()
* PyFrame_GetLocals()
* PyFrame_Type

Remove #include "frameobject.h" from many C files. It's no longer
needed.
2022-06-19 12:02:33 +02:00
Ken Jin a51742ab82
gh-93911: Specialize `LOAD_ATTR_PROPERTY` (GH-93912) 2022-06-17 23:13:17 +08:00
Victor Stinner 0ff626f210
gh-77782: Deprecate global configuration variable (#93943)
Deprecate global configuration variable like
Py_IgnoreEnvironmentFlag: the Py_InitializeFromConfig() API should be
instead.

Fix declaration of Py_GETENV(): use PyAPI_FUNC(), not PyAPI_DATA().
2022-06-17 16:12:00 +02:00
Victor Stinner e444752fab
gh-74953: Add _PyTime_FromMicrosecondsClamp() function (#93942) 2022-06-17 16:11:13 +02:00
Victor Stinner 7546914e3f
gh-87347: Add parenthesis around PyXXX_Check() arguments (#92815) 2022-06-16 13:49:43 +02:00
Ken Jin b083450f88
GH-93429: Merge `LOAD_METHOD` back into `LOAD_ATTR` (GH-93430) 2022-06-14 11:36:22 +01:00
Mark Shannon 3cd1a5d3ec
GH-93516: Store offset of first traceable instruction in code object (GH-93769) 2022-06-14 11:09:30 +01:00
Victor Stinner 4caf5c2753
gh-91321: Fix compatibility with C++ older than C++11 (#93784)
Fix the compatibility of the Python C API with C++ older than C++11.

_Py_NULL is only defined as nullptr on C++11 and newer.
2022-06-14 11:43:08 +02:00
Serhiy Storchaka 6fd4c8ec77
gh-93741: Add private C API _PyImport_GetModuleAttrString() (GH-93742)
It combines PyImport_ImportModule() and PyObject_GetAttrString()
and saves 4-6 lines of code on every use.

Add also _PyImport_GetModuleAttr() which takes Python strings as arguments.
2022-06-14 07:15:26 +03:00
Victor Stinner df22eec421
gh-89653: PEP 670: Macros always cast arguments in cpython/ (#93766)
Header files in the Include/cpython/ are only included if
the Py_LIMITED_API macro is not defined.
2022-06-13 20:09:40 +02:00
Pablo Galindo Salgado 65ff27c7d3
gh-91731: Don't define 'static_assert' in C++11 where is a keyword to avoid UB (GH-93700) 2022-06-13 15:49:08 +01:00
Victor Stinner 65ac273280
Remove ANY_VARARGS() macro from the C API (#93764)
The macro was exposed by mistake.
2022-06-13 16:24:19 +02:00
Victor Stinner 272bec4adf
gh-89653: PEP 670: Convert PyFunction macros (#93765)
Convert PyFunction macros to static inline functions.
2022-06-13 15:15:27 +02:00
Kumar Aditya 9331087966
GH-90699: use statically allocated strings in typeobject.c (gh-93751) 2022-06-13 01:38:18 +09:00
Serhiy Storchaka 3473817106
gh-91162: Support splitting of unpacked arbitrary-length tuple over TypeVar and TypeVarTuple parameters (alt) (GH-93412)
For example:

  A[T, *Ts][*tuple[int, ...]] -> A[int, *tuple[int, ...]]
  A[*Ts, T][*tuple[int, ...]] -> A[*tuple[int, ...], int]
2022-06-12 16:22:01 +03:00
Mark Shannon f012df706c
Shrink the LOAD_METHOD cache by one codeunit. (#93537) 2022-06-07 10:28:53 +01:00
Neil Schemenauer 8bcc3fa345
gh-93442: Make C++ version of _Py_CAST work with 0/NULL. (#93500)
Add C++ overloads for _Py_CAST_impl() to handle 0/NULL.  This will allow
C++ extensions that pass 0 or NULL to macros using _Py_CAST() to
continue to compile.  Without this, you get an error like:

    invalid ‘static_cast’ from type ‘int’ to type ‘_object*’

The modern way to use a NULL value in C++ is to use nullptr.  However,
we want to not break extensions that do things the old way.

Co-authored-by: serge-sans-paille
2022-06-04 18:49:39 -07:00
Ken Jin d52ffc1d1f
gh-93382: Cache result of `PyCode_GetCode` in codeobject (GH-93383)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
2022-06-04 00:41:18 +08:00
Victor Stinner 941d7054c1
gh-91320: Fix more old-style cast warnings in C++ (#93285)
Use _PyObject_CAST() in the public C API to fix C++ compiler
warnings: "use of old-style cast" (clang -Wold-style-cast).
2022-06-03 00:59:57 +02:00
Dennis Sweeney f425f3bb27
gh-93143: Avoid NULL check in LOAD_FAST based on analysis in the compiler (GH-93144) 2022-05-31 16:32:30 -04:00
Mark Shannon eb618d5ff0
GH-93354: Use exponential backoff to avoid excessive specialization attempts. (GH-93355) 2022-05-31 11:58:26 +01:00
Will Hawkins 61e008a4ab
gh-93244: Document Py_PRINT_RAW in PyObject_Print() comment (93245) 2022-05-29 19:18:52 +02:00
Eric Snow caa279d6fd
bpo-40514: Drop EXPERIMENTAL_ISOLATED_SUBINTERPRETERS (gh-93185)
This was added for bpo-40514 (gh-84694) to test out a per-interpreter GIL. However, it has since proven unnecessary to keep the experiment in the repo. (It can be done as a branch in a fork like normal.) So here we are removing:

* the configure option
* the macro
* the code enabled by the macro
2022-05-27 17:38:01 -06:00