Commit graph

4249 commits

Author SHA1 Message Date
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
Mark Shannon bbcf42449e
GH-90230: Add stats to breakdown the origin of calls to PyEval_EvalFrame (GH-93284) 2022-05-27 16:31:41 +01:00
Victor Stinner 22b75d9bef
gh-82616: Add Py_IS_TYPE_SIGNED() macro (#93178)
_posixsubprocess: add a static assertion to ensure that the pid_t
type is signed.

Replace _Py_IntegralTypeSigned() with _Py_IS_TYPE_SIGNED().
2022-05-27 15:05:35 +02:00
Wenzel Jakob 5e34b494a0
gh-60074: add new stable API function PyType_FromMetaclass (GH-93012)
Added a new stable API function ``PyType_FromMetaclass``, which mirrors
the behavior of ``PyType_FromModuleAndSpec`` except that it takes an
additional metaclass argument. This is, e.g., useful for language
binding tools that need to store additional information in the type
object.
2022-05-27 10:27:39 +02:00
Victor Stinner 20d30ba2cc
gh-92898: Enhance _testcppext test on cast to PyObject* (#93111)
* Add StrongRef class.
* Rename and reformat functions of the _Py_CAST() implementation.
2022-05-27 01:12:39 +02:00
Ken Jin 5e6e5b98a8
gh-92777: Add LOAD_METHOD_LAZY_DICT (GH-92778) 2022-05-25 14:06:15 +01:00
Victor Stinner 71d8775fee
gh-93202: Always use %zd printf formatter (#93201)
Python now always use the ``%zu`` and ``%zd`` printf formats to
format a size_t or Py_ssize_t number. Building Python 3.12 requires a
C11 compiler, so these printf formats are now always supported.

* PyObject_Print() and _PyObject_Dump() now use the printf %zd format
  to display an object reference count.
* Update PY_FORMAT_SIZE_T comment.
* Remove outdated notes about the %zd format in PyBytes_FromFormat()
  and PyUnicode_FromFormat() documentations.
* configure no longer checks for the %zd format and no longer defines
  PY_FORMAT_SIZE_T macro in pyconfig.h.
* pymacconfig.h no longer undefines PY_FORMAT_SIZE_T: macOS 10.4 is
  no longer supported. Python 3.12 now requires macOS 10.6 (Snow
  Leopard) or newer.
2022-05-25 14:21:36 +02:00
Yury Selivanov c1f5c903a7
gh-93065: Fix HAMT to iterate correctly over 7-level deep trees (GH-93066)
Also while there, clarify a few things about why we reduce the hash to 32 bits.

Co-authored-by: Eli Libman <eli@hyro.ai>
Co-authored-by: Yury Selivanov <yury@edgedb.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2022-05-23 21:09:59 +02:00
Wenzel Jakob b2694ab469
gh-92536: Mark PyUnicode_READY() argument as unused (#93011) 2022-05-23 16:15:09 +02:00
Victor Stinner fc00667247
gh-93103: Update PyUnicode_DecodeFSDefault() doc (#93105)
Update documentation of PyUnicode_DecodeFSDefault(),
PyUnicode_DecodeFSDefaultAndSize() and PyUnicode_EncodeFSDefault():
they now use the filesystem encoding and error handler of PyConfig,
Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors
variables are no longer used.
2022-05-23 14:56:59 +02:00
serge-sans-paille 5b71b519f9
GH-92898: Make _Py_Cast C++ version compatible with cast operator (gh-92951) 2022-05-21 22:16:37 +09:00
Mark Shannon 3fd8610002
GH-89914: Make the oparg of the YIELD_VALUE instruction equal the stack depth. (GH-92960) 2022-05-19 17:49:29 +01:00
Christian Heimes 137fd3d88a
gh-90473: Decrease recursion limit and skip tests on WASI (GH-92803) 2022-05-19 12:43:16 +02:00
Mark Shannon e48ac9c100
GH-90690: Remove PRECALL instruction (GH-92925) 2022-05-19 11:05:26 +01:00
Mark Shannon a4460f2eb8
Split refcount stats into 'interpreter' and 'non-interpreter' (GH-92919) 2022-05-18 14:38:43 +01:00
David CARLIER 9a1adf2790
bpo-42047: Add native thread ID for DragonFlyBSD (#22714)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: kj <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@protonmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2022-05-18 15:10:10 +02:00
Victor Stinner 1305832362
gh-89653: Add assertions on PyUnicode_READ() index (#92883)
Add assertions on the index argument of PyUnicode_READ(),
PyUnicode_READ_CHAR() and PyUnicode_WRITE() functions.
2022-05-17 19:43:19 +02:00
Victor Stinner e6fd7992a9
gh-89653: PEP 670: Fix PyUnicode_READ() cast (#92872)
_Py_CAST() cannot be used with a constant type: use _Py_STATIC_CAST()
instead.
2022-05-17 19:20:37 +02:00
Mark Shannon fa2b8b75eb
Improve object stats (#92845)
* Add incref/decref stats

* Show ratios for allocation in summary
2022-05-16 14:35:11 +01:00
Victor Stinner 90e7230073
gh-92781: Avoid mixing declarations and code in C API (#92783)
Avoid mixing declarations and code in the C API to fix the compiler
warning: "ISO C90 forbids mixed declarations and code"
[-Werror=declaration-after-statement].
2022-05-15 11:19:52 +02:00
Victor Stinner 059b5baf98
gh-85858: Remove PyUnicode_InternImmortal() function (#92579)
Remove the PyUnicode_InternImmortal() function and the
SSTATE_INTERNED_IMMORTAL macro.

The PyUnicode_InternImmortal() function is still exported in the
stable ABI. The function is removed from the API.

PyASCIIObject.state.interned size is now a single bit, rather than 2
bits.

Keep SSTATE_NOT_INTERNED and SSTATE_INTERNED_MORTAL macros for
backward compatibility, but no longer use them internally since the
interned member is now a single bit and so can only have two values
(interned or not interned).

Update stats of _PyUnicode_ClearInterned().
2022-05-13 13:40:22 +02:00
Victor Stinner f62ad4f2c4
gh-89653: Use int type for Unicode kind (#92704)
Use the same type that PyUnicode_FromKindAndData() kind parameter
type (public C API): int.
2022-05-13 12:41:05 +02:00
Victor Stinner db388df1d9
gh-89653: PEP 670: Convert PyUnicode_KIND() macro to function (#92705)
In the limited C API version 3.12, PyUnicode_KIND() is now
implemented as a static inline function. Keep the macro for the
regular C API and for the limited C API version 3.11 and older to
prevent introducing new compiler warnings.

Update _decimal.c and stringlib/eq.h for PyUnicode_KIND().
2022-05-13 11:49:56 +02:00
Inada Naoki f9c9354a7a
gh-92536: PEP 623: Remove wstr and legacy APIs from Unicode (GH-92537) 2022-05-12 14:48:38 +09:00
Victor Stinner d0c9353a79
gh-89653: PEP 670: unicodeobject.h uses _Py_CAST() (#92696)
Use _Py_CAST() and _Py_STATIC_CAST() in macros wrapping static inline
functions of unicodeobject.h.

Change also the kind type from unsigned int to int: same parameter
type than PyUnicode_FromKindAndData().

The limited API version 3.11 no longer casts arguments to expected
types.
2022-05-12 01:35:41 +02:00
Victor Stinner f9b67ad770
gh-89653: PEP 670: Convert PyDict_GET_SIZE() macro to function (#92695)
The limited C API version 3.12 no longer casts the argument.
2022-05-12 00:58:42 +02:00
Victor Stinner 6de78ef96a
gh-89653: PEP 670: Use PyObject* type for parameters (#92694)
Use the PyObject* type for parameters of static inline functions:

* Py_SIZE(): same parameter type than PyObject_Size()
* PyList_GET_SIZE(), PyList_SET_ITEM(): same parameter type than
  PyList_Size() and PyList_SetItem()
* PyTuple_GET_SIZE(), PyTuple_SET_ITEM(): same parameter type than
  PyTuple_Size() and PyTuple_SetItem().
2022-05-12 00:49:03 +02:00
Victor Stinner d492f0ab2a
gh-89653: Add assertions to unicodeobject.h functions (#92692) 2022-05-12 00:12:42 +02:00
Victor Stinner 7d3b469e47
gh-89653: PEP 670: Limited API doesn't cast arguments (#92654)
The limited API version 3.11 no longer casts arguments to expected
types of functions of functions:

* PyList_GET_SIZE(), PyList_SET_ITEM()
* PyTuple_GET_SIZE(), PyTuple_SET_ITEM()
* PyWeakref_GET_OBJECT()
2022-05-12 00:01:42 +02:00
Victor Stinner eb88f21301
gh-89653: PEP 670: Convert unicodeobject.h macros to functions (#92648)
Convert the following Unicode macros to static inline functions.

Surrogate functions:

* Py_UNICODE_IS_SURROGATE()
* Py_UNICODE_IS_HIGH_SURROGATE()
* Py_UNICODE_IS_LOW_SURROGATE()
* Py_UNICODE_HIGH_SURROGATE()
* Py_UNICODE_LOW_SURROGATE()
* Py_UNICODE_JOIN_SURROGATES()

"Is" functions:

* Py_UNICODE_ISALNUM()
* Py_UNICODE_ISSPACE()

In the implementation of these functions, the character type is now
well defined to Py_UCS4.
2022-05-11 23:28:39 +02:00
Victor Stinner 897f14d38d
gh-89653: PEP 670: Convert PyCell macros to functions (#92653)
Convert the following macros to static inline functions:

* PyCell_GET()
* PyCell_SET()

Limited C API version 3.12 no longer casts arguments.

Fix also usage of PyCell_SET(): only delete the old value after
setting the new value.
2022-05-11 23:24:48 +02:00
Victor Stinner da5727a120
gh-92651: Remove the Include/token.h header file (#92652)
Remove the token.h header file. There was never any public tokenizer
C API. The token.h header file was only designed to be used by Python
internals.

Move Include/token.h to Include/internal/pycore_token.h. Including
this header file now requires that the Py_BUILD_CORE macro is
defined. It no longer checks for the Py_LIMITED_API macro.

Rename functions:

* PyToken_OneChar() => _PyToken_OneChar()
* PyToken_TwoChars() => _PyToken_TwoChars()
* PyToken_ThreeChars() => _PyToken_ThreeChars()
2022-05-11 23:22:50 +02:00
Victor Stinner ffcc7cd57f
gh-89653: PEP 670: Convert pycore_gc.h macros to functions (#92649)
Convert the following macros to static inline functions:

* _Py_AS_GC()
* _PyGCHead_FINALIZED(), _PyGCHead_SET_FINALIZED()
* _PyGCHead_NEXT(), _PyGCHead_SET_NEXT()
* _PyGCHead_PREV(), _PyGCHead_SET_PREV()
* _PyGC_FINALIZED(), _PyGC_SET_FINALIZED()
* _PyObject_GC_IS_TRACKED()
* _PyObject_GC_MAY_BE_TRACKED()

Add a macro wrapping the _PyObject_GC_IS_TRACKED() function to cast
the argument to PyObject*.
2022-05-11 13:37:18 +02:00
Pablo Galindo Salgado 4e6da502f4
gh-91731: Fix typo in pymacro.h (#92618)
* Fix typo in pymacro.h

* Update Include/pymacro.h

Co-authored-by: Victor Stinner <vstinner@python.org>

Co-authored-by: Victor Stinner <vstinner@python.org>
2022-05-10 13:47:22 +01:00
Pablo Galindo Salgado f0614ca980
gh-91731: Add macro compatibility for static_assert for old libcs (GH-92559) 2022-05-09 18:38:38 +01:00
Serhiy Storchaka 9d25db9db1
gh-91162: Fix substitution of unpacked tuples in generic aliases (GH-92335) 2022-05-08 18:32:32 +03:00
Pablo Galindo e851177536
Python 3.12.0a0 2022-05-08 03:40:52 +01:00
Pablo Galindo 8d32a5c8c4
Update the SOURCE_URI in pyspecific.py to point to the new branch 2022-05-06 23:56:26 +01:00
Victor Stinner c33d67c450
gh-91321: Fix _PyObject_EXTRA_INIT for C++ (#92396)
In C++, the _PyObject_EXTRA_INIT macro now uses nullptr, rather than
0, to initialize the _ob_next and _ob_prev members of the PyObject
structure.

Fix test_cppext failure when Python is built with
./configure --with-trace-refs.
2022-05-06 13:40:08 +01:00
Victor Stinner 299692afd8
gh-88279: Deprecate PySys_SetArgvEx() (#92363)
Deprecate the following C functions:

* PySys_SetArgv()
* PySys_SetArgvEx()
* PySys_SetPath()
2022-05-06 05:24:29 +02:00
Victor Stinner ada8b6d1b1
gh-57684: Add -P cmdline option and PYTHONSAFEPATH env var (#31542)
Add the -P command line option and the PYTHONSAFEPATH environment
variable to not prepend a potentially unsafe path to sys.path.

* Add sys.flags.safe_path flag.
* Add PyConfig.safe_path member.
* Programs/_bootstrap_python.c uses config.safe_path=0.
* Update subprocess._optim_args_from_interpreter_flags() to handle
  the -P command line option.
* Modules/getpath.py sets safe_path to 1 if a "._pth" file is
  present.
2022-05-06 01:34:11 +02:00
Serhiy Storchaka 1ed8d035f1
gh-87390: Fix starred tuple equality and pickling (GH-92337) 2022-05-05 20:16:06 +03:00
Victor Stinner 08b562a5df
gh-89653: PEP 670: Convert PyCFunction macros to functions (#92302)
Convert the following macros to static inline functions:

* PyCFunction_GET_CLASS()
* PyCFunction_GET_FLAGS()
* PyCFunction_GET_FUNCTION()
* PyCFunction_GET_SELF()

Limited C API version 3.11 no longer casts arguments.
2022-05-05 11:31:59 +02:00
Victor Stinner d716a0dfe2
Use static inline function Py_EnterRecursiveCall() (#91988)
Currently, calling Py_EnterRecursiveCall() and
Py_LeaveRecursiveCall() may use a function call or a static inline
function call, depending if the internal pycore_ceval.h header file
is included or not. Use a different name for the static inline
function to ensure that the static inline function is always used in
Python internals for best performance. Similar approach than
PyThreadState_GET() (function call) and _PyThreadState_GET() (static
inline function).

* Rename _Py_EnterRecursiveCall() to _Py_EnterRecursiveCallTstate()
* Rename _Py_LeaveRecursiveCall() to _Py_LeaveRecursiveCallTstate()
* pycore_ceval.h: Rename Py_EnterRecursiveCall() to
  _Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() and
  _Py_LeaveRecursiveCall()
2022-05-04 13:30:23 +02:00
Mark Shannon 836b17c9c3
Add more stats for freelist use and allocations. (GH-92211) 2022-05-03 16:40:24 -06:00
Victor Stinner 3a35b62ea0
gh-91321: Fix PyModuleDef_HEAD_INIT on C++ (#92259)
The PyModuleDef_HEAD_INIT macro now uses _Py_NULL to fix C++ compiler
warnings when using it in C++.
2022-05-03 22:40:20 +02:00
Victor Stinner 551d02b3e6
gh-91321: Add _Py_NULL macro (#92253)
Fix C++ compiler warnings: "zero as null pointer constant"
(clang -Wzero-as-null-pointer-constant).

* Add the _Py_NULL macro used by static inline functions to use
  nullptr in C++.
* Replace NULL with nullptr in _testcppext.cpp.
2022-05-03 21:38:37 +02:00
Victor Stinner ff3e9cdf33
gh-91320: Fix more old-style cast warnings in C++ (#92247)
Use _Py_CAST(), _Py_STATIC_CAST() and _PyASCIIObject_CAST() in
static inline functions to fix C++ compiler warnings:
"use of old-style cast" (clang -Wold-style-cast).

test_cppext now builds the C++ test extension with -Wold-style-cast.
2022-05-03 20:47:29 +02:00