Commit Graph

269 Commits

Author SHA1 Message Date
Eric Snow a9c6e0618f
gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205)
Here we are doing no more than adding the value for Py_mod_multiple_interpreters and using it for stdlib modules.  We will start checking for it in gh-104206 (once PyInterpreterState.ceval.own_gil is added in gh-104204).
2023-05-05 21:11:27 +00:00
Erlend E. Aasland ccd98a3146
gh-101476: Add _PyType_GetModuleState (GH-101477)
For fast module state access from heap type methods.
2023-02-23 13:42:15 -08:00
Erlend E. Aasland 826bf0e695
gh-101277: Finalise isolating itertools (GH-101305)
Add repeat, islice, chain, tee, teedataobject, and batched types to module state.

Automerge-Triggered-By: GH:erlend-aasland
2023-02-10 03:58:14 -08:00
Erlend E. Aasland de3669ebcb
gh-101277: Port more itertools static types to heap types (#101304)
Add accumulate, compress, count, filterfalse, pairwise, product,
and zip_longest types to module state.
2023-02-08 21:25:42 +01:00
Erlend E. Aasland a52cc9853f
gh-101277: Port more `itertools` static types to heap types (#101303)
Add dropwhile, takewhile, starmap, combinations*, and permutations types to module state.
2023-02-03 15:24:27 +05:30
Erlend E. Aasland 2b3e02a705
gh-101277: Isolate itertools, add group and _grouper types to module state (#101302)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2023-02-01 12:41:30 +01:00
Raymond Hettinger 8c215466db
GH-98363: Shrink the physical size as well as the logical size (GH-100138) 2022-12-09 11:02:35 -06:00
Raymond Hettinger 35cc0ea736
GH-98363: Have batched() return tuples (GH-100118) 2022-12-08 15:08:16 -06:00
Serhiy Storchaka 922a6cf6c2
gh-60203: Revert changes in cycle.__setstate__ (#99982)
In case if only True/False be supported as boolean arguments in future,
we should continue to support 1/0 here.
2022-12-05 17:27:40 +01:00
Serhiy Storchaka a87c46eab3
bpo-15999: Accept arbitrary values for boolean parameters. (#15609)
builtins and extension module functions and methods that expect boolean values for parameters now accept any Python object rather than just a bool or int type. This is more consistent with how native Python code itself behaves.
2022-12-03 11:52:21 -08:00
Victor Stinner 85dd6cb6df
gh-99845: Use size_t type in __sizeof__() methods (#99846)
The implementation of __sizeof__() methods using _PyObject_SIZE() now
use an unsigned type (size_t) to compute the size, rather than a signed
type (Py_ssize_t).

Cast explicitly signed (Py_ssize_t) values to unsigned type
(Py_ssize_t).
2022-11-30 17:22:52 +01:00
Victor Stinner 7e3f09cad9
gh-99537: Use Py_SETREF() function in C code (#99656)
Fix potential race condition in code patterns:

* Replace "Py_DECREF(var); var = new;" with "Py_SETREF(var, new);"
* Replace "Py_XDECREF(var); var = new;" with "Py_XSETREF(var, new);"
* Replace "Py_CLEAR(var); var = new;" with "Py_XSETREF(var, new);"

Other changes:

* Replace "old = var; var = new; Py_DECREF(var)"
  with "Py_SETREF(var, new);"
* Replace "old = var; var = new; Py_XDECREF(var)"
  with "Py_XSETREF(var, new);"
* And remove the "old" variable.
2022-11-22 14:22:22 +01:00
Victor Stinner 0bedc28d14
gh-99300: Use Py_NewRef() in Modules/itertoolsmodule.c (#99439)
Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and
Py_XNewRef() in Modules/itertoolsmodule.c.
2022-11-13 16:04:22 +01:00
Raymond Hettinger 5871e19942
GH-98363: Slicing isn't necessary. A size reduction will suffice. (GH-98538) 2022-10-22 07:21:06 -05:00
Raymond Hettinger 8d574234d4
GH-98363: Use better accessor macro (#98535) 2022-10-21 18:44:49 -05:00
Raymond Hettinger a5ff80c8bc
GH-98363: Fix exception handling in batched() (GH-98523) 2022-10-21 12:31:52 -05:00
Raymond Hettinger c1e02d4e4e
GH-98363: Presize the list for batched() (GH-98419) 2022-10-20 02:28:17 -05:00
Raymond Hettinger 9608bef84a
Fix typos in comments (GH-98375) 2022-10-17 21:01:28 -05:00
Raymond Hettinger de3ece769a
GH-98363: Add itertools.batched() (GH-98364) 2022-10-17 18:53:45 -05:00
DongGeon Lee 278fdd3e3a
bpo-46728: fix docstring of combinations_with_replacement for consistency (GH-31293) 2022-02-15 09:02:21 +09:00
Eric Snow 81c72044a1
bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized global objects. (gh-30928)
We're no longer using _Py_IDENTIFIER() (or _Py_static_string()) in any core CPython code.  It is still used in a number of non-builtin stdlib modules.

The replacement is: PyUnicodeObject (not pointer) fields under _PyRuntimeState, statically initialized as part of _PyRuntime.  A new _Py_GET_GLOBAL_IDENTIFIER() macro facilitates lookup of the fields (along with _Py_GET_GLOBAL_STRING() for non-identifier strings).

https://bugs.python.org/issue46541#msg411799 explains the rationale for this change.

The core of the change is in:

* (new) Include/internal/pycore_global_strings.h - the declarations for the global strings, along with the macros
* Include/internal/pycore_runtime_init.h - added the static initializers for the global strings
* Include/internal/pycore_global_objects.h - where the struct in pycore_global_strings.h is hooked into _PyRuntimeState
* Tools/scripts/generate_global_objects.py - added generation of the global string declarations and static initializers

I've also added a --check flag to generate_global_objects.py (along with make check-global-objects) to check for unused global strings.  That check is added to the PR CI config.

The remainder of this change updates the core code to use _Py_GET_GLOBAL_IDENTIFIER() instead of _Py_IDENTIFIER() and the related _Py*Id functions (likewise for _Py_GET_GLOBAL_STRING() instead of _Py_static_string()).  This includes adding a few functions where there wasn't already an alternative to _Py*Id(), replacing the _Py_Identifier * parameter with PyObject *.

The following are not changed (yet):

* stop using _Py_IDENTIFIER() in the stdlib modules
* (maybe) get rid of _Py_IDENTIFIER(), etc. entirely -- this may not be doable as at least one package on PyPI using this (private) API
* (maybe) intern the strings during runtime init

https://bugs.python.org/issue46541
2022-02-08 13:39:07 -07:00
Victor Stinner d943d19172
bpo-45439: Move _PyObject_CallNoArgs() to pycore_call.h (GH-28895)
* Move _PyObject_CallNoArgs() to pycore_call.h (internal C API).
* _ssl, _sqlite and _testcapi extensions now call the public
  PyObject_CallNoArgs() function, rather than _PyObject_CallNoArgs().
* _lsprof extension is now built with Py_BUILD_CORE_MODULE macro
  defined to get access to internal _PyObject_CallNoArgs().
2021-10-12 08:38:19 +02:00
Victor Stinner ce3489cfdb
bpo-45439: Rename _PyObject_CallNoArg() to _PyObject_CallNoArgs() (GH-28891)
Fix typo in the private _PyObject_CallNoArg() function name: rename
it to _PyObject_CallNoArgs() to be consistent with the public
function PyObject_CallNoArgs().
2021-10-12 00:42:23 +02:00
Serhiy Storchaka f25f2e2e8c
Clean up initialization __class_getitem__ with Py_GenericAlias. (GH-28450)
The cast to PyCFunction is redundant. Overuse of redundant casts
can hide actual bugs.
2021-09-19 18:05:30 +03:00
Serhiy Storchaka 92bf8691fb
bpo-43413: Fix handling keyword arguments in subclasses of some buitin classes (GH-26456)
* Constructors of subclasses of some buitin classes (e.g. tuple, list,
  frozenset) no longer accept arbitrary keyword arguments.
* Subclass of set can now define a __new__() method with additional
  keyword parameters without overriding also __init__().
2021-09-12 13:27:50 +03:00
Serhiy Storchaka f64de53ff0
bpo-44563: Fix error handling in tee.fromiterable() (GH-27020)
In debug build failed tee.fromiterable() corrupted the linked list of all GC objects.
2021-07-05 23:19:35 +01:00
Brandt Bucher 226a012d1c
bpo-42536: GC track recycled tuples (GH-23623)
Several built-in and standard library types now ensure that their internal result tuples are always tracked by the garbage collector:

- collections.OrderedDict.items
- dict.items
- enumerate
- functools.reduce
- itertools.combinations
- itertools.combinations_with_replacement
- itertools.permutations
- itertools.product
- itertools.zip_longest
- zip

Previously, they could have become untracked by a prior garbage collection.
2020-12-04 19:45:57 -08:00
Raymond Hettinger cc061d0e6f
bpo-38200: Add itertools.pairwise() (GH-23549) 2020-11-30 20:42:54 -08:00
Victor Stinner 37834136d0
bpo-42161: Modules/ uses _PyLong_GetZero() and _PyLong_GetOne() (GH-22998)
Use _PyLong_GetZero() and _PyLong_GetOne() in Modules/ directory.

_cursesmodule.c and zoneinfo.c are now built with
Py_BUILD_CORE_MODULE macro defined.
2020-10-27 17:12:53 +01:00
Victor Stinner 384621c42f
bpo-41078: Rename pycore_tupleobject.h to pycore_tuple.h (GH-21056) 2020-06-22 17:27:35 +02:00
Hai Shi 47a23fc63f
bpo-40898: Remove redundant if statements in tp_traverse (GH-20692) 2020-06-07 21:05:36 +09:00
Victor Stinner 4a21e57fe5
bpo-40268: Remove unused structmember.h includes (GH-19530)
If only offsetof() is needed: include stddef.h instead.

When structmember.h is used, add a comment explaining that
PyMemberDef is used.
2020-04-15 02:35:41 +02:00
Ethan Smith a8403d057d
Generic itertools.chain (GH-19417) 2020-04-09 20:28:08 -07:00
AlphaHot 8dd1792c68
bpo-40036: Deleting duplicates in itertoolsmodule.c (GH-18958) 2020-03-23 13:14:39 -07:00
Dong-hee Na 05e4a296ec
bpo-40024: Add PyModule_AddType() helper function (GH-19088) 2020-03-22 17:17:34 +01:00
Dong-hee Na 514c469719
bpo-1635741: Port itertools module to multiphase initialization (GH-19044) 2020-03-17 18:46:24 +01:00
Andy Lester 557287075c
bpo-39573: Use Py_IS_TYPE() macro to check for types (GH-18809)
Co-authored-by: Victor Stinner <vstinner@python.org>
2020-03-06 23:53:17 +01:00
Andy Lester dffe4c0709
bpo-39573: Finish converting to new Py_IS_TYPE() macro (GH-18601) 2020-03-04 14:15:20 +01:00
Petr Viktorin ffd9753a94
bpo-39245: Switch to public API for Vectorcall (GH-18460)
The bulk of this patch was generated automatically with:

    for name in \
        PyObject_Vectorcall \
        Py_TPFLAGS_HAVE_VECTORCALL \
        PyObject_VectorcallMethod \
        PyVectorcall_Function \
        PyObject_CallOneArg \
        PyObject_CallMethodNoArgs \
        PyObject_CallMethodOneArg \
    ;
    do
        echo $name
        git grep -lwz _$name | xargs -0 sed -i "s/\b_$name\b/$name/g"
    done

    old=_PyObject_FastCallDict
    new=PyObject_VectorcallDict
    git grep -lwz $old | xargs -0 sed -i "s/\b$old\b/$new/g"

and then cleaned up:

- Revert changes to in docs & news
- Revert changes to backcompat defines in headers
- Nudge misaligned comments
2020-02-11 17:46:57 +01:00
Victor Stinner d2ec81a8c9
bpo-39573: Add Py_SET_TYPE() function (GH-18394)
Add Py_SET_TYPE() function to set the type of an object.
2020-02-07 09:17:07 +01:00
Raymond Hettinger af46450bb9
Minor readability improvement for argument handling in itertools.repeat() (GH-17101) 2019-11-09 20:28:31 -08:00
Sergey 0078a0c2a5 Permutations Python code equivalent in comment was invalid for Python 3 (GH-16927) 2019-10-28 22:10:24 -07:00
Serhiy Storchaka 526a01467b
bpo-34410: Fix a crash in the tee iterator when re-enter it. (GH-15625)
RuntimeError is now raised in this case.
2019-09-09 11:47:14 +03:00
Serhiy Storchaka 918b468b7d
Revert "Raise a RuntimeError when tee iterator is consumed from different threads (GH-15567)" (GH-15736)
This reverts commit fa220ec763.
2019-09-09 11:18:16 +03:00
Serhiy Storchaka 1f21eaa15e
bpo-15999: Clean up of handling boolean arguments. (GH-15610)
* Use the 'p' format unit instead of manually called PyObject_IsTrue().
* Pass boolean value instead 0/1 integers to functions that needs boolean.
* Convert some arguments to boolean only once.
2019-09-01 12:16:51 +03:00
Sergey Fedoseev 6a650aaf77 bpo-37976: Prevent shadowing of TypeError in zip() (GH-15592) 2019-08-29 21:25:48 -07:00
HongWeipeng fa220ec763 Raise a RuntimeError when tee iterator is consumed from different threads (GH-15567) 2019-08-28 20:39:25 -07:00
Jeroen Demeyer 196a530e00 bpo-37483: add _PyObject_CallOneArg() function (#14558) 2019-07-04 19:31:34 +09:00
Jeroen Demeyer 530f506ac9 bpo-36974: tp_print -> tp_vectorcall_offset and tp_reserved -> tp_as_async (GH-13464)
Automatically replace
tp_print -> tp_vectorcall_offset
tp_compare -> tp_as_async
tp_reserved -> tp_as_async
2019-05-30 19:13:39 -07:00
Zackery Spytz 0523c39e77 bpo-36430: Fix a possible reference leak in itertools.count(). (GH-12551) 2019-03-26 08:05:29 +02:00