Possible slowdown of regex searching in 3.11 · Issue #91404 · python/cpython (original) (raw)

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

Character ranges with upper bound less that lower bound (e.g. [c-a]) are now interpreted as empty ranges, for compatibility with other glob pattern implementations. Previously it was re.error.

taks -> tasks

WASI does not have the chmod(2) syscall yet.

Co-authored-by: Alex Waygood Alex.Waygood@Gmail.com

Note: This change is not effective on Microsoft Windows.

Cookies can store sensitive information and should therefore be protected against unauthorized third parties. This is also described in issue #79096.

The filesystem permissions are currently set to 644, everyone can read the file. This commit changes the permissions to 600, only the creater of the file can read and modify it. This improves security, because it reduces the attack surface. Now the attacker needs control of the user that created the cookie or a ways to circumvent the filesystems permissions.

This change is backwards incompatible. Systems that rely on world-readable cookies will breake. However, one could argue that those are misconfigured in the first place.

Also, provide getHandlerByName() and getHandlerNames() APIs.

Closes #93162.

Co-authored-by: Sean Fleming Co-authored-by: Adam Turner 9087854+AA-Turner@users.noreply.github.com Co-authored-by: Łukasz Langa lukasz@langa.pl

Co-authored-by: Łukasz Langa lukasz@langa.pl

These are currently broken as they refer to :meth:Path.relative_to rather than :meth:PurePath.relative_to, and relative_to is a method on PurePath.

Co-authored-by: Alex Waygood Alex.Waygood@Gmail.com Co-authored-by: Adam Turner 9087854+AA-Turner@users.noreply.github.com Co-authored-by: Erlend E. Aasland erlend.aasland@protonmail.com

All install targets use the "all" target as synchronization point to prevent race conditions with PGO builds. PGO builds use recursive make, which can lead to two parallel ./python setup.py build processes that step on each others toes.

"test" targets now correctly compile PGO build in a clean repo.

Nowadays everything that is in the Limited API has a note added automatically. These notes could mislead people to think that these functions could never be added to the limited API. Remove them.

Fixup of GH-93463:

Co-authored-by: Łukasz Langa lukasz@langa.pl

copy.copy() and copy.deepcopy() now always raise a TypeError if reduce() returns a tuple with length 6 instead of silently ignore the 6th item or produce incorrect result.

This checks the bases of of a type created using the FromSpec API to inherit the bases metaclasses. The metaclass's alloc function will be called as is done in tp_new for classes created in Python.

Co-authored-by: Petr Viktorin encukou@gmail.com Co-authored-by: Erlend Egeberg Aasland erlend.aasland@protonmail.com

Co-authored-by: XD Trol milestonejxd@gmail.com Co-authored-by: Antoine Pitrou pitrou@free.fr

Use C APIs such as PyModule_AddType instead of PyModule_AddObject. Also remove incorrect module decrefs if module fails to initialise.

Co-authored-by: Adam Turner 9087854+AA-Turner@users.noreply.github.com Co-authored-by: Steve Dower steve.dower@microsoft.com Co-authored-by: Erlend Egeberg Aasland erlend.aasland@protonmail.com

Co-authored-by: Łukasz Langa lukasz@langa.pl

Documentation for pathlib says:

Spurious slashes and single dots are collapsed, but double dots ('..') are not, since this would change the meaning of a path in the face of symbolic links:

However, it omits that initial double slashes also aren't collapsed.

Later, in documentation of PurePath.drive, PurePath.root, and PurePath.name it mentions UNC but:

For context, see the BPO entry.

Co-authored-by: Brett Cannon brett@python.org

Add what's new entry for PEP 682 in Python 3.11.

For example:

A[T, *Ts][*tuple[int, ...]] -> A[int, *tuple[int, ...]] A[*Ts, T][*tuple[int, ...]] -> A[*tuple[int, ...], int]

Convert PyFunction macros to static inline functions.

The macro was exposed by mistake.

Fix the importlib.resources.as_file() context manager to remove the temporary file if destroyed late during Python finalization: keep a local reference to the os.remove() function. Patch by Victor Stinner.

Header files in the Include/cpython/ are only included if the Py_LIMITED_API macro is not defined.

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.

Classes ReferenceType, ProxyType and CallableProxyType have now correct atrtributes module, name and qualname. It makes them (types, not instances) pickleable.

Suppress writing an XML declaration in open files in ElementTree.write() with encoding='unicode' and xml_declaration=None.

If file patch is passed to ElementTree.write() with encoding='unicode', always open a new file in UTF-8.

When changing PyType_FromMetaclass recently (GH-93012, GH-93466, GH-28748) I found a bunch of opportunities to improve the code. Here they are.

Fixes: #89546

Automerge-Triggered-By: GH:encukou

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.

When running tests with -jN, create a temporary directory per process and mark a test as "environment changed" if a test leaks a temporary file or directory.

The fix involves using pysqlite_check_remaining_sql(), not only to check for multiple statements, but now also to strip leading comments and whitespace from SQL statements, so we can improve DML query detection.

pysqlite_check_remaining_sql() is renamed lstrip_sql(), to more accurately reflect its function, and hardened to handle more SQL comment corner cases.

fix #93814

Automerge-Triggered-By: GH:rhettinger

package => packet

Co-authored-by: Victor Norman

Add busy_retry() and sleeping_retry() functions to test.support.

Align the docs for the following methods with the actual implementation:

test_thread.test_count() now fails if it takes longer than LONG_TIMEOUT seconds.

Corrected targets for the following audit-events:

run_until() of test.test_asyncio.utils now uses an exponential sleep delay (max: 1 second), rather than a fixed delay of 1 ms. Similar design than support.sleeping_retry() wait strategy that applies exponential backoff.

Remove time.sleep(0.01) in test_asyncore capture_server(). The sleep was redundant and inefficient, since the loop starts with select.select() which also implements a sleep (poll for socket data with a timeout).

Tests now call busy_retry() and sleeping_retry() with SHORT_TIMEOUT or LONG_TIMEOUT (of test.support), rather than hardcoded constants.

Add also WAIT_ACTIVE_CHILDREN_TIMEOUT constant to _test_multiprocessing.

Co-authored-by: Brett Cannon brett@python.org

GH-26658 introduced a regression in copy / pickle protocol for combined enum.Flags. copy.copy(re.A | re.I) would fail with AttributeError: ASCII|IGNORECASE.

enum.Flag now has a __reduce_ex__() method that reduces flags by combined value, not by combined name.

Tests no longer call busy_retry() and sleeping_retry() with error=False: raise an exception if the loop times out.

Don't build _testcppext.cpp with -Wzero-as-null-pointer-constant when testing C++03: only use this compiler flag with C++11.

SharedMemory.unlink() uses the unregister() function from resource_tracker. Previously it was imported in the method, but this can fail if the method is called during interpreter shutdown, for example when unlink is part of a del() method.

Moving the import to the top of the file, means that the unregister() method is available during interpreter shutdown.

The register call in SharedMemory.init() can also use this imported resource_tracker.

regrtest now also implements checking for leaked temporary files and directories when using -jN for N >= 2. Use tempfile.mkdtemp() to create the temporary directory. Skip this check on WASI.

Closes #83658.

Revert "bpo-23689: re module, fix memory leak when a match is terminated by a signal or memory allocation failure (GH-32283)"

This reverts commit 6e3eee5.

Manual fixups to increase the MAGIC number and to handle conflicts with a couple of changes that landed after that.

Thanks for reviews by Ma Lin and Serhiy Storchaka.

test_asyncio, test_logging, test_socket and test_socketserver now create AF_UNIX domains in the current directory to no longer fail with OSError("AF_UNIX path too long") if the temporary directory (the TMPDIR environment variable) is too long.

Modify the following tests to use create_unix_domain_name():

test_asyncio.utils: remove unused time import.

Set timeout, don't create a local variable with the same name.

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().

Co-authored-by: chilaxan 35645806+chilaxan@users.noreply.github.com Co-authored-by: Serhiy Storchaka 3659035+serhiy-storchaka@users.noreply.github.com

Per @brettcannon 's suggestions on the Discourse thread, discussed in #92611 and as a followup to PR #92612 , this PR add additional specific per-function replacement information for the utility functions in the cgi module deprecated by PEP 594 (PEP-594).

@brettcannon , should this be backported (without the deprecated-removed , which I would update it accordingly and re-add in my other PR adding that to the others for 3.11+), or just go in 3.11+?

Co-authored-by: Brett Cannon brett@python.org

Co-authored-by: Ezio Melotti ezio.melotti@gmail.com

Co-authored-by: Ezio Melotti ezio.melotti@gmail.com

list[int].class returned type, and isinstance(list[int], type) returned True. It caused numerous problems in code that checks isinstance(x, type).

wasm_assets script did not take the ABIFLAG flag of sysconfigdata into account.

WASI's rmdir() syscall does not like the trailing slash.

This change does three things:

  1. Extract a function for trapping output in subprocesses.
  2. Emit both stdout and stderr when encountering an error.
  3. Apply the change to ensurepip._uninstall check.

Co-authored-by: Ezio Melotti ezio.melotti@gmail.com

Co-authored-by: Ezio Melotti ezio.melotti@gmail.com

Fix a race condition in test_config_queue_handler() of test_logging.

Reformat the pthread implementation of PyThread_acquire_lock_timed() using a mutex and a conditioinal variable.

Move the follow functions and type from frameobject.h to pyframe.h, so the standard <Python.h> provide frame getter functions:

Remove #include "frameobject.h" from many C files. It's no longer needed.

gh-93991: Use boolean instead of 0/1 for condition check

GH-93992 removed geteuid() and enabled the test again on Emscripten.

Co-authored-by: CAM Gerlach CAM.Gerlach@Gerlach.CAM

Explicitly note that transactions are only closed if there is an open transation at __exit__, and that transactions are not implicitly opened during __enter__.

Co-authored-by: CAM Gerlach CAM.Gerlach@Gerlach.CAM Co-authored-by: Stanley 46876382+slateny@users.noreply.github.com

Automerge-Triggered-By: GH:erlend-aasland

Co-authored-by: Erlend E. Aasland erlend.aasland@protonmail.com

Add unit test on Py_MEMBER_SIZE() and some other macros.

On Windows, PyOS_StdioReadline() now gets PyConfig.legacy_windows_stdio from _PyOS_ReadlineTState, rather than using the deprecated global Py_LegacyWindowsStdioFlag variable.

Fix also a compiler warning in Py_SetStandardStreamEncoding().

Fixes failing tests on WebAssembly platforms.

Automerge-Triggered-By: GH:tiran

pthread _PyThread_cond_after() implementation now uses the _PyTime_t type to handle properly overflow: clamp to the maximum value.

Remove MICROSECONDS_TO_TIMESPEC() function.

This reverts commit 5c1f15b

This reverts commit b63a620.

Fixes #94068

Automerge-Triggered-By: GH:zware

Closes #93675

When we construct the upper and lower candidates in limit_denominator, the numerator and denominator are already relatively prime (and the denominator positive) by construction, so there's no need to go through the usual normalisation in the constructor. This saves a couple of potentially expensive gcd calls.

Suggested by Michael Scott Asato Cuthbert in GH-93477.

Co-authored-by: Adam Turner 9087854+AA-Turner@users.noreply.github.com

Because of the way wrap_descr_get is written, the second argument to get methods implemented through the wrapper is always optional.

Fix an open redirection vulnerability in the http.server module when an URI path starts with // that could produce a 301 Location header with a misleading target. Vulnerability discovered, and logic fix proposed, by Hamza Avvan (@hamzaavvan).

Test and comments authored by Gregory P. Smith [Google].

https://github.com/python/cpython/issue/89336: Remove configparser 3.12 deprecations.

Co-authored-by: Hugo van Kemenade hugovk@users.noreply.github.com

Co-authored-by: Windson yang wiwindson@outlook.com

Co-authored-by: Ethan Furman ethan@stoneleaf.us

It is no longer changed when create a zip or tar archive.

It is still changed for custom archivers registered with shutil.register_archive_format() if root_dir is not None.

Co-authored-by: Éric merwok@netwok.org Co-authored-by: Łukasz Langa lukasz@langa.pl

Fixes #94101

Automerge-Triggered-By: GH:tiran

Co-authored-by: Łukasz Langa lukasz@langa.pl

Co-authored-by: Brett Cannon brett@python.org

Co-authored-by: Hugo van Kemenade hugovk@users.noreply.github.com Co-authored-by: Adam Turner 9087854+AA-Turner@users.noreply.github.com

Move imports in doctests to prevent false alarms in pyflakes.

Remove commented code in test_debugger_r.py.

Co-authored-by: Terry Jan Reedy tjreedy@udel.edu

The URL is now https://pyvideo.org, which uses HTTPS and avoids a redirect.

When used with plain Enum, auto() returns the last numeric value assigned, skipping any incompatible member values (such as strings); starting in 3.13 the default auto() for plain Enums will require all the values to be of compatible types, and will return a new value that is 1 higher than any existing value.

Co-authored-by: Ethan Furman ethan@stoneleaf.us

Make sure statements that have run to completion or errored are reset and cleared off the cursor for all paths in execute() and executemany().

Remove io.OpenWrapper and _pyio.OpenWrapper, deprecated in Python 3.10: just use :func:open instead. The open() (io.open()) function is a built-in function. Since Python 3.10, _pyio.open() is also a static method.

Remove the ssl.RAND_pseudo_bytes() function, deprecated in Python 3.6: use os.urandom() or ssl.RAND_bytes() instead.

gzip: Remove the filename attribute of gzip.GzipFile, deprecated since Python 2.6, use the name attribute instead. In write mode, the filename attribute added '.gz' file extension if it was not present.

The message was only emitted when the build succeeded and there were missing modules.

The urllib.request no longer uses the deprecated check_hostname parameter of the http.client module.

Add private http.client._create_https_context() helper to http.client, used by urllib.request.

Remove the now redundant check on check_hostname and verify_mode in http.client: the SSLContext.check_hostname setter already implements the check.

Sync up co_code changes with 3.11 commit 852b4d4.

The existing test covering this case passed only incidentally. We explicitly disallow doing this and add a proper error message.

Co-authored-by: Serhiy Storchaka storchaka@gmail.com

tarfile already accepts a compressionlevel argument for creating files. This patch adds the same for stream-based tarfile usage. The default is 9, the value that was previously hard-coded.

Make _struct.Struct a GC type

This fixes a memory leak in the _struct module, where as soon as a Struct object is stored in the cache, there's a cycle from the _struct module to the cache to Struct objects to the Struct type back to the module. If _struct.Struct is not gc-tracked, that cycle is never collected.

This PR makes _struct.Struct GC-tracked, and adds a regression test.

Seems in the past the copy of builtins was not made in some scenarios, and the error was silenced. Write it now to stderr, so we have a chance to see it.

Also add adapters and converter recipes.

Co-authored-by: CAM Gerlach CAM.Gerlach@Gerlach.CAM Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com

Syncs with importlib_metadata 4.12.0.

Co-authored-by: Irit Katriel 1055913+iritkatriel@users.noreply.github.com Co-authored-by: Ulises Ojeda ulises.odysseus22@gmail.com Co-authored-by: jackh-ncl 1750152+jackh-ncl@users.noreply.github.com Co-authored-by: Mark Dickinson dickinsm@gmail.com Co-authored-by: Colin Delahunty 72827203+colin99d@users.noreply.github.com Co-authored-by: Neil Schemenauer nas-github@arctrix.com Co-authored-by: Christian Heimes christian@python.org Co-authored-by: Dennis Sweeney 36520290+sweeneyde@users.noreply.github.com Co-authored-by: Cyker Way cykerway@gmail.com Co-authored-by: Hugo van Kemenade hugovk@users.noreply.github.com Co-authored-by: Omer Katz omer.katz@omerkatz.com Co-authored-by: Stanley 46876382+slateny@users.noreply.github.com Co-authored-by: Thomas Grainger tagrain@gmail.com Co-authored-by: Illia Volochii illia.volochii@gmail.com Co-authored-by: Erlend Egeberg Aasland erlend.aasland@protonmail.com Co-authored-by: Alex Waygood Alex.Waygood@Gmail.com Co-authored-by: AN Long aisk@users.noreply.github.com Co-authored-by: Samodya Abeysiriwardane 379594+sransara@users.noreply.github.com Co-authored-by: Evorage owner@evorage.com Co-authored-by: Davide Rizzo sorcio@gmail.com Co-authored-by: Pascal Wittmann mail@pascal-wittmann.de Co-authored-by: Vinay Sajip vinay_sajip@yahoo.co.uk Co-authored-by: Adam Turner 9087854+AA-Turner@users.noreply.github.com Co-authored-by: Łukasz Langa lukasz@langa.pl Co-authored-by: Andreas Grommek 76997441+agrommek@users.noreply.github.com Co-authored-by: Mark Shannon mark@hotpy.org Co-authored-by: Ken Jin kenjin4096@gmail.com Co-authored-by: Adrian Garcia Badaracco 1755071+adriangb@users.noreply.github.com Co-authored-by: jacksonriley 52106215+jacksonriley@users.noreply.github.com Co-authored-by: Kalyan kalyan.ben10@live.com Co-authored-by: Bluenix bluenixdev@gmail.com Co-authored-by: Petr Viktorin encukou@gmail.com Co-authored-by: CAM Gerlach CAM.Gerlach@Gerlach.CAM Co-authored-by: Sebastian Berg sebastian@sipsolutions.net Co-authored-by: Leo Trol milestone.jxd@gmail.com Co-authored-by: XD Trol milestonejxd@gmail.com Co-authored-by: Antoine Pitrou pitrou@free.fr Co-authored-by: neonene 53406459+neonene@users.noreply.github.com Co-authored-by: Steve Dower steve.dower@microsoft.com Co-authored-by: Pablo Galindo Salgado Pablogsal@gmail.com Co-authored-by: Barney Gale barney.gale@gmail.com Co-authored-by: Oleg Iarygin oleg@arhadthedev.net Co-authored-by: Brett Cannon brett@python.org Co-authored-by: John Belmonte john@neggie.net Co-authored-by: Julien Palard julien@palard.fr Co-authored-by: Pamela Fox pamela.fox@gmail.com Co-authored-by: Dong-hee Na donghee.na@python.org Co-authored-by: Kumar Aditya 59607654+kumaraditya303@users.noreply.github.com Co-authored-by: Victor Stinner vstinner@python.org Co-authored-by: Sanket Shanbhag TechieBoy@users.noreply.github.com Co-authored-by: Jeong YunWon 69878+youknowone@users.noreply.github.com Co-authored-by: Steve Dower steve.dower@python.org Co-authored-by: samtygier samtygier@yahoo.co.uk Co-authored-by: Ken Jin kenjin@python.org Co-authored-by: Brandt Bucher brandtbucher@microsoft.com Co-authored-by: Gregory P. Smith greg@krypto.org Co-authored-by: chilaxan 35645806+chilaxan@users.noreply.github.com Co-authored-by: Serhiy Storchaka 3659035+serhiy-storchaka@users.noreply.github.com Co-authored-by: Chris Fernald chrisf671@gmail.com Co-authored-by: Jason R. Coombs jaraco@jaraco.com Co-authored-by: Ezio Melotti ezio.melotti@gmail.com Co-authored-by: Lei Zhang leizhanghello@gmail.com Co-authored-by: Erlend Egeberg Aasland erlend.aasland@innova.no Co-authored-by: itssme itssme3000@gmail.com Co-authored-by: Matthias Köppe mkoeppe@math.ucdavis.edu Co-authored-by: MilanJuhas 81162136+MilanJuhas@users.noreply.github.com Co-authored-by: luzpaz luzpaz@users.noreply.github.com Co-authored-by: paulreece 96156234+paulreece@users.noreply.github.com Co-authored-by: max 36980911+pr2502@users.noreply.github.com Co-authored-by: Jelle Zijlstra jelle.zijlstra@gmail.com Co-authored-by: Thomas A Caswell tcaswell@gmail.com Co-authored-by: Windson yang wiwindson@outlook.com Co-authored-by: Carl Bordum Hansen carl@bordum.dk Co-authored-by: Ethan Furman ethan@stoneleaf.us Co-authored-by: Éric merwok@netwok.org Co-authored-by: chgnrdv 52372310+chgnrdv@users.noreply.github.com Co-authored-by: fikotta 81991278+fikotta@users.noreply.github.com Co-authored-by: partev petrosyan@gmail.com Co-authored-by: Terry Jan Reedy tjreedy@udel.edu Co-authored-by: Inada Naoki songofacandy@gmail.com Co-authored-by: Oscar R 89599049+oscar-LT@users.noreply.github.com Co-authored-by: wookie184 wookie1840@gmail.com Co-authored-by: Guido van Rossum guido@python.org Co-authored-by: Myron Walker myron.walker@hotmail.com Co-authored-by: Sam Ezeh sam.z.ezeh@gmail.com Co-authored-by: Ken Jin 28750310+Fidget-Spinner@users.noreply.github.com Co-authored-by: Gregory Beauregard greg@greg.red Co-authored-by: Yaron de Leeuw me@jarondl.net Co-authored-by: Mark Dickinson mdickinson@enthought.com