8000 Merge remote-tracking branch 'cpython/main' into gh-102519 · python/cpython@afaa312 · GitHub
[go: up one dir, main page]

Skip to content

Commit afaa312

Browse files
committed
Merge remote-tracking branch 'cpython/main' into gh-102519
2 parents 3147f63 + c6858d1 commit afaa312

Some content is hidden

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

66 files changed

+3212
-304
lines changed

Doc/whatsnew/3.12.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ Other Language Changes
189189
part of comprehensions (like ``a``) is still disallowed, as per :pep:`572`.
190190
(Contributed by Nikita Sobolev in :gh:`100581`.)
191191

192+
* :class:`slice` objects are now hashable, allowing them to be used as dict keys and
193+
set items. (Contributed by Furkan Onder in :gh:`101264`.)
192194

193195
New Modules
194196
===========

Include/cpython/import.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ PyAPI_FUNC(PyObject *) _PyImport_GetModuleId(_Py_Identifier *name);
1010
PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module);
1111
PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject* module);
1212

13-
PyAPI_FUNC(void) _PyImport_AcquireLock(void);
14-
PyAPI_FUNC(int) _PyImport_ReleaseLock(void);
13+
PyAPI_FUNC(void) _PyImport_AcquireLock(PyInterpreterState *interp);
14+
PyAPI_FUNC(int) _PyImport_ReleaseLock(PyInterpreterState *interp);
1515

1616
PyAPI_FUNC(int) _PyImport_FixupBuiltin(
1717
PyObject *mod,

Include/internal/pycore_dict.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ extern PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);
3737

3838
/* Gets a version number unique to the current state of the keys of dict, if possible.
3939
* Returns the version number, or zero if it was not possible to get a version number. */
40-
extern uint32_t _PyDictKeys_GetVersionForCurrentState(PyDictKeysObject *dictkeys);
40+
extern uint32_t _PyDictKeys_GetVersionForCurrentState(
41+
PyInterpreterState *interp, PyDictKeysObject *dictkeys);
4142

4243
extern size_t _PyDict_KeysSize(PyDictKeysObject *keys);
4344

@@ -148,8 +149,8 @@ static inline PyDictUnicodeEntry* DK_UNICODE_ENTRIES(PyDictKeysObject *dk) {
148149
#define DICT_VERSION_INCREMENT (1 << DICT_MAX_WATCHERS)
149150
#define DICT_VERSION_MASK (DICT_VERSION_INCREMENT - 1)
150151

151-
#define DICT_NEXT_VERSION() \
152-
(_PyRuntime.dict_state.global_version += DICT_VERSION_INCREMENT)
152+
#define DICT_NEXT_VERSION(INTERP) \
153+
((INTERP)->dict_state.global_version += DICT_VERSION_INCREMENT)
153154

154155
void
155156
_PyDict_SendEvent(int watcher_bits,
@@ -159,7 +160,8 @@ _PyDict_SendEvent(int watcher_bits,
159160
PyObject *value);
160161

161162
static inline uint64_t
162-
_PyDict_NotifyEvent(PyDict_WatchEvent event,
163+
_PyDict_N 10000 otifyEvent(PyInterpreterState *interp,
164+
PyDict_WatchEvent event,
163165
PyDictObject *mp,
164166
PyObject *key,
165167
PyObject *value)
@@ -168,9 +170,9 @@ _PyDict_NotifyEvent(PyDict_WatchEvent event,
168170
int watcher_bits = mp->ma_version_tag & DICT_VERSION_MASK;
169171
if (watcher_bits) {
170172
_PyDict_SendEvent(watcher_bits, event, mp, key, value);
171-
return DICT_NEXT_VERSION() | watcher_bits;
173+
return DICT_NEXT_VERSION(interp) | watcher_bits;
172174
}
173-
return DICT_NEXT_VERSION();
175+
return DICT_NEXT_VERSION(interp);
174176
}
175177

176178
extern PyObject *_PyObject_MakeDictFromInstanceAttributes(PyObject *obj, PyDictValues *values);

Include/internal/pycore_dict_state.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ extern "C" {
99
#endif
1010

1111

12-
struct _Py_dict_runtime_state {
13-
/*Global counter used to set ma_version_tag field of dictionary.
14-
* It is incremented each time that a dictionary is created and each
15-
* time that a dictionary is modified. */
16-
uint64_t global_version;
17-
uint32_t next_keys_version;
18-
};
19-
20-
2112
#ifndef WITH_FREELISTS
2213
// without freelists
2314
# define PyDict_MAXFREELIST 0
@@ -30,13 +21,20 @@ struct _Py_dict_runtime_state {
3021
#define DICT_MAX_WATCHERS 8
3122

3223
struct _Py_dict_state {
24+
/*Global counter used to set ma_version_tag field of dictionary.
25+
* It is incremented each time that a dictionary is created and each
26+
* time that a dictionary is modified. */
27+
uint64_t global_version;
28+
uint32_t next_keys_version;
29+
3330
#if PyDict_MAXFREELIST > 0
3431
/* Dictionary reuse scheme to save calls to malloc and free */
3532
PyDictObject *free_list[PyDict_MAXFREELIST];
3633
PyDictKeysObject *keys_free_list[PyDict_MAXFREELIST];
3734
int numfree;
3835
int keys_numfree;
3936
#endif
37+
4038
PyDict_WatchCallback watchers[DICT_MAX_WATCHERS];
4139
};
4240

Include/internal/pycore_fileutils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,14 @@ extern int _Py_add_relfile(wchar_t *dirname,
251251
extern size_t _Py_find_basename(const wchar_t *filename);
252252
PyAPI_FUNC(wchar_t *) _Py_normpath(wchar_t *path, Py_ssize_t size);
253253

254+
// The Windows Games API family does not provide these functions
255+
// so provide our own implementations. Remove them in case they get added
256+
// to the Games API family
257+
#if defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP)
258+
#include <winerror.h>
259+
260+
extern HRESULT PathCchSkipRoot(const wchar_t *pszPath, const wchar_t **ppszRootEnd);
261+
#endif /* defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) */
254262

255263
// Macros to protect CRT calls against instant termination when passed an
256264
// invalid parameter (bpo-23524). IPH stands for Invalid Parameter Handler.

Include/internal/pycore_function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern "C" {
1010

1111
#define FUNC_MAX_WATCHERS 8
1212

13-
struct _py_func_runtime_state {
13+
struct _py_func_state {
1414
uint32_t next_version;
1515
};
1616

Include/internal/pycore_import.h

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,6 @@ struct _import_runtime_state {
2121
This is initialized lazily in _PyImport_FixupExtensionObject().
2222
Modules are added there and looked up in _imp.find_extension(). */
2323
PyObject *extensions;
24-
/* The global import lock. */
25-
struct {
26-
PyThread_type_lock mutex;
27-
unsigned long thread;
28-
int level;
29-
} lock;
30-
struct {
31-
int import_level;
32-
_PyTime_t accumulated;
33-
int header;
34-
} find_and_load;
3524
/* Package context -- the full module name for package imports */
3625
const char * pkgcontext;
3726
};
@@ -69,6 +58,18 @@ struct _import_state {
6958
int dlopenflags;
7059
#endif
7160
PyObject *import_func;
61+
/* The global import lock. */
62+
struct {
63+
PyThread_type_lock mutex;
64+
unsigned long thread;
65+
int level;
66+
} lock;
67+
/* diagnostic info in PyImport_ImportModuleLevelObject() */
68+
struct {
69+
int import_level;
70+
_PyTime_t accumulated;
71+
int header;
72+
} find_and_load;
7273
};
7374

7475
#ifdef HAVE_DLOPEN
@@ -86,8 +87,15 @@ struct _import_state {
8687

8788
#define IMPORTS_INIT \
8889
{ \
89-
.override_frozen_modules = 0, \
9090
DLOPENFLAGS_INIT \
91+
.lock = { \
92+
.mutex = NULL, \
93+
.thread = PYTHREAD_INVALID_THREAD_ID, \
94+
.level = 0, \
95+
}, \
96+
.find_and_load = { \
97+
.header = 1, \
98+
}, \
9199
}
92100

93101
extern void _PyImport_ClearCore(PyInterpreterState *interp);
@@ -138,7 +146,7 @@ extern void _PyImport_FiniExternal(PyInterpreterState *interp);
138146

139147

140148
#ifdef HAVE_FORK
141-
extern PyStatus _PyImport_ReInitLock(void);
149+
extern PyStatus _PyImport_ReInitLock(PyInterpreterState *interp);
142150
#endif
143151

144152

Include/internal/pycore_interp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ struct _is {
141141
struct _Py_float_state float_state;
142142
struct _Py_long_state long_state;
143143
struct _dtoa_state dtoa;
144+
struct _py_func_state func_state;
144145
/* Using a cache is very effective since typically only a single slice is
145146
created and then deleted again. */
146147
PySliceObject *slice_cache;

Include/internal/pycore_runtime.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ extern "C" {
1010

1111
#include "pycore_atomic.h" /* _Py_atomic_address */
1212
#include "pycore_ceval_state.h" // struct _ceval_runtime_state
13-
#include "pycore_dict_state.h" // struct _Py_dict_runtime_state
1413
#include "pycore_floatobject.h" // struct _Py_float_runtime_state
1514
#include "pycore_faulthandler.h" // struct _faulthandler_runtime_state
16-
#include "pycore_function.h" // struct _func_runtime_state
1715
#include "pycore_global_objects.h" // struct _Py_global_objects
1816
#include "pycore_import.h" // struct _import_runtime_state
1917
#include "pycore_interp.h" // PyInterpreterState
@@ -154,8 +152,6 @@ typedef struct pyruntimestate {
154152

155153
struct _Py_float_runtime_state float_state;
156154
struct _Py_unicode_runtime_state unicode_state;
157-
struct _Py_dict_runtime_state dict_state;
158-
struct _py_func_runtime_state func_state;
159155

160156
struct {
161157
/* Used to set PyTypeObject.tp_version_tag */

Include/internal/pycore_runtime_init.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ extern PyTypeObject _PyExc_MemoryError;
4040
in accordance with the specification. */ \
4141
.autoTSSkey = Py_tss_NEEDS_INIT, \
4242
.parser = _parser_runtime_state_INIT, \
43-
.imports = { \
44-
.lock = { \
45-
.mutex = NULL, \
46-
.thread = PYTHREAD_INVALID_THREAD_ID, \
47-
.level = 0, \
48-
}, \
49-
.find_and_load = { \
50-
.header = 1, \
51-
}, \
52-
}, \
5343
.ceval = { \
5444
.perf = _PyEval_RUNTIME_PERF_INIT, \
5545
}, \
@@ -65,12 +55,6 @@ extern PyTypeObject _PyExc_MemoryError;
6555
.float_format = _py_float_format_unknown, \
6656
.double_format = _py_float_format_unknown, \
6757
}, \
68-
.dict_state = { \
69-
.next_keys_version = 2, \
70-
}, \
71-
.func_state = { \
72-
.next_version = 1, \
73-
}, \
7458
.types = { \
7559
.next_version_tag = 1, \
7660
}, \
@@ -116,6 +100,12 @@ extern PyTypeObject _PyExc_MemoryError;
116100
}, \
117101
}, \
118102
.dtoa = _dtoa_state_INIT(&(INTERP)), \
103+
.dict_state = { \
104+
.next_keys_version = 2, \
105+
}, \
106+
.func_state = { \
107+
.next_version = 1, \
108+
}, \
119109
.static_objects = { \
120110
.singletons = { \
121111
._not_used = 1, \

Lib/test/test_os.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3127,11 +3127,13 @@ def test_device_encoding(self):
31273127
class PidTests(unittest.TestCase):
31283128
@unittest.skipUnless(hasattr(os, 'getppid'), "test needs os.getppid")
31293129
def test_getppid(self):
3130-
p = subprocess.Popen([sys.executable, '-c',
3130+
p = subprocess.Popen([sys._base_executable, '-c',
31313131
'import os; print(os.getppid())'],
3132-
stdout=subprocess.PIPE)
3133-
stdout, _ = p.communicate()
3132+
stdout=subprocess.PIPE,
3133+
stderr=subprocess.PIPE)
3134+
stdout, error = p.communicate()
31343135
# We are the parent of our subprocess
3136+
self.assertEqual(error, b'')
31353137
self.assertEqual(int(stdout), os.getpid())
31363138

31373139
def check_waitpid(self, code, exitcode, callback=None):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve build support for the Xbox. Patch by Max Bachmann.

Modules/_io/_iomodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
317317
_PyIO_State *state = get_io_state(module);
318318
{
319319
PyObject *RawIO_class = (PyObject *)state->PyFileIO_Type;
320-
#ifdef MS_WINDOWS
320+
#ifdef HAVE_WINDOWS_CONSOLE_IO
321321
const PyConfig *config = _Py_GetConfig();
322322
if (!config->legacy_windows_stdio && _PyIO_get_console_type(path_or_fd) != '\0') {
323323
RawIO_class = (PyObject *)&PyWindowsConsoleIO_Type;
@@ -660,7 +660,7 @@ static PyTypeObject* static_types[] = {
660660

661661
// PyRawIOBase_Type(PyIOBase_Type) subclasses
662662
&_PyBytesIOBuffer_Type,
663-
#ifdef MS_WINDOWS
663+
#ifdef HAVE_WINDOWS_CONSOLE_IO
664664
&PyWindowsConsoleIO_Type,
665665
#endif
666666
};
@@ -718,7 +718,7 @@ PyInit__io(void)
718718
}
719719

720720
// Set type base classes
721-
#ifdef MS_WINDOWS
721+
#ifdef HAVE_WINDOWS_CONSOLE_IO
722722
PyWindowsConsoleIO_Type.tp_base = &PyRawIOBase_Type;
723723
#endif
724724

Modules/_io/_iomodule.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ extern PyType_Spec fileio_spec;
2626
extern PyType_Spec stringio_spec;
2727
extern PyType_Spec textiowrapper_spec;
2828

29-
#ifdef MS_WINDOWS
29+
#ifdef HAVE_WINDOWS_CONSOLE_IO
3030
extern PyTypeObject PyWindowsConsoleIO_Type;
31-
#endif /* MS_WINDOWS */
31+
#endif /* HAVE_WINDOWS_CONSOLE_IO */
3232

3333
/* These functions are used as METH_NOARGS methods, are normally called
3434
* with args=NULL, and return a new reference.
@@ -178,7 +178,7 @@ find_io_state_by_def(PyTypeObject *type)
178178

179179
extern _PyIO_State *_PyIO_get_module_state(void);
180180

181-
#ifdef MS_WINDOWS
181+
#ifdef HAVE_WINDOWS_CONSOLE_IO
182182
extern char _PyIO_get_console_type(PyObject *);
183183
#endif
184184

0 commit comments

Comments
 (0)
0