Skip to content

Commit

Permalink
Merge remote-tracking branch 'cpython/main' into pythongh-102519
Browse files Browse the repository at this point in the history
  • Loading branch information
zooba committed Mar 9, 2023
2 parents 3147f63 + c6858d1 commit afaa312
Show file tree
Hide file tree
Showing 66 changed files with 3,212 additions and 304 deletions.
2 changes: 2 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ Other Language Changes
part of comprehensions (like ``a``) is still disallowed, as per :pep:`572`.
(Contributed by Nikita Sobolev in :gh:`100581`.)

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

New Modules
===========
Expand Down
4 changes: 2 additions & 2 deletions Include/cpython/import.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ PyAPI_FUNC(PyObject *) _PyImport_GetModuleId(_Py_Identifier *name);
PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module);
PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject* module);

PyAPI_FUNC(void) _PyImport_AcquireLock(void);
PyAPI_FUNC(int) _PyImport_ReleaseLock(void);
PyAPI_FUNC(void) _PyImport_AcquireLock(PyInterpreterState *interp);
PyAPI_FUNC(int) _PyImport_ReleaseLock(PyInterpreterState *interp);

PyAPI_FUNC(int) _PyImport_FixupBuiltin(
PyObject *mod,
Expand Down
14 changes: 8 additions & 6 deletions Include/internal/pycore_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ extern PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);

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

extern size_t _PyDict_KeysSize(PyDictKeysObject *keys);

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

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

void
_PyDict_SendEvent(int watcher_bits,
Expand All @@ -159,7 +160,8 @@ _PyDict_SendEvent(int watcher_bits,
PyObject *value);

static inline uint64_t
_PyDict_NotifyEvent(PyDict_WatchEvent event,
_PyDict_NotifyEvent(PyInterpreterState *interp,
PyDict_WatchEvent event,
PyDictObject *mp,
PyObject *key,
PyObject *value)
Expand All @@ -168,9 +170,9 @@ _PyDict_NotifyEvent(PyDict_WatchEvent event,
int watcher_bits = mp->ma_version_tag & DICT_VERSION_MASK;
if (watcher_bits) {
_PyDict_SendEvent(watcher_bits, event, mp, key, value);
return DICT_NEXT_VERSION() | watcher_bits;
return DICT_NEXT_VERSION(interp) | watcher_bits;
}
return DICT_NEXT_VERSION();
return DICT_NEXT_VERSION(interp);
}

extern PyObject *_PyObject_MakeDictFromInstanceAttributes(PyObject *obj, PyDictValues *values);
Expand Down
16 changes: 7 additions & 9 deletions Include/internal/pycore_dict_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ extern "C" {
#endif


struct _Py_dict_runtime_state {
/*Global counter used to set ma_version_tag field of dictionary.
* It is incremented each time that a dictionary is created and each
* time that a dictionary is modified. */
uint64_t global_version;
uint32_t next_keys_version;
};


#ifndef WITH_FREELISTS
// without freelists
# define PyDict_MAXFREELIST 0
Expand All @@ -30,13 +21,20 @@ struct _Py_dict_runtime_state {
#define DICT_MAX_WATCHERS 8

struct _Py_dict_state {
/*Global counter used to set ma_version_tag field of dictionary.
* It is incremented each time that a dictionary is created and each
* time that a dictionary is modified. */
uint64_t global_version;
uint32_t next_keys_version;

#if PyDict_MAXFREELIST > 0
/* Dictionary reuse scheme to save calls to malloc and free */
PyDictObject *free_list[PyDict_MAXFREELIST];
PyDictKeysObject *keys_free_list[PyDict_MAXFREELIST];
int numfree;
int keys_numfree;
#endif

PyDict_WatchCallback watchers[DICT_MAX_WATCHERS];
};

Expand Down
8 changes: 8 additions & 0 deletions Include/internal/pycore_fileutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ extern int _Py_add_relfile(wchar_t *dirname,
extern size_t _Py_find_basename(const wchar_t *filename);
PyAPI_FUNC(wchar_t *) _Py_normpath(wchar_t *path, Py_ssize_t size);

// The Windows Games API family does not provide these functions
// so provide our own implementations. Remove them in case they get added
// to the Games API family
#if defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP)
#include <winerror.h>

extern HRESULT PathCchSkipRoot(const wchar_t *pszPath, const wchar_t **ppszRootEnd);
#endif /* defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) */

// Macros to protect CRT calls against instant termination when passed an
// invalid parameter (bpo-23524). IPH stands for Invalid Parameter Handler.
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extern "C" {

#define FUNC_MAX_WATCHERS 8

struct _py_func_runtime_state {
struct _py_func_state {
uint32_t next_version;
};

Expand Down
34 changes: 21 additions & 13 deletions Include/internal/pycore_import.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ struct _import_runtime_state {
This is initialized lazily in _PyImport_FixupExtensionObject().
Modules are added there and looked up in _imp.find_extension(). */
PyObject *extensions;
/* The global import lock. */
struct {
PyThread_type_lock mutex;
unsigned long thread;
int level;
} lock;
struct {
int import_level;
_PyTime_t accumulated;
int header;
} find_and_load;
/* Package context -- the full module name for package imports */
const char * pkgcontext;
};
Expand Down Expand Up @@ -69,6 +58,18 @@ struct _import_state {
int dlopenflags;
#endif
PyObject *import_func;
/* The global import lock. */
struct {
PyThread_type_lock mutex;
unsigned long thread;
int level;
} lock;
/* diagnostic info in PyImport_ImportModuleLevelObject() */
struct {
int import_level;
_PyTime_t accumulated;
int header;
} find_and_load;
};

#ifdef HAVE_DLOPEN
Expand All @@ -86,8 +87,15 @@ struct _import_state {

#define IMPORTS_INIT \
{ \
.override_frozen_modules = 0, \
DLOPENFLAGS_INIT \
.lock = { \
.mutex = NULL, \
.thread = PYTHREAD_INVALID_THREAD_ID, \
.level = 0, \
}, \
.find_and_load = { \
.header = 1, \
}, \
}

extern void _PyImport_ClearCore(PyInterpreterState *interp);
Expand Down Expand Up @@ -138,7 +146,7 @@ extern void _PyImport_FiniExternal(PyInterpreterState *interp);


#ifdef HAVE_FORK
extern PyStatus _PyImport_ReInitLock(void);
extern PyStatus _PyImport_ReInitLock(PyInterpreterState *interp);
#endif


Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ struct _is {
struct _Py_float_state float_state;
struct _Py_long_state long_state;
struct _dtoa_state dtoa;
struct _py_func_state func_state;
/* Using a cache is very effective since typically only a single slice is
created and then deleted again. */
PySliceObject *slice_cache;
Expand Down
4 changes: 0 additions & 4 deletions Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ extern "C" {

#include "pycore_atomic.h" /* _Py_atomic_address */
#include "pycore_ceval_state.h" // struct _ceval_runtime_state
#include "pycore_dict_state.h" // struct _Py_dict_runtime_state
#include "pycore_floatobject.h" // struct _Py_float_runtime_state
#include "pycore_faulthandler.h" // struct _faulthandler_runtime_state
#include "pycore_function.h" // struct _func_runtime_state
#include "pycore_global_objects.h" // struct _Py_global_objects
#include "pycore_import.h" // struct _import_runtime_state
#include "pycore_interp.h" // PyInterpreterState
Expand Down Expand Up @@ -154,8 +152,6 @@ typedef struct pyruntimestate {

struct _Py_float_runtime_state float_state;
struct _Py_unicode_runtime_state unicode_state;
struct _Py_dict_runtime_state dict_state;
struct _py_func_runtime_state func_state;

struct {
/* Used to set PyTypeObject.tp_version_tag */
Expand Down
22 changes: 6 additions & 16 deletions Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ extern PyTypeObject _PyExc_MemoryError;
in accordance with the specification. */ \
.autoTSSkey = Py_tss_NEEDS_INIT, \
.parser = _parser_runtime_state_INIT, \
.imports = { \
.lock = { \
.mutex = NULL, \
.thread = PYTHREAD_INVALID_THREAD_ID, \
.level = 0, \
}, \
.find_and_load = { \
.header = 1, \
}, \
}, \
.ceval = { \
.perf = _PyEval_RUNTIME_PERF_INIT, \
}, \
Expand All @@ -65,12 +55,6 @@ extern PyTypeObject _PyExc_MemoryError;
.float_format = _py_float_format_unknown, \
.double_format = _py_float_format_unknown, \
}, \
.dict_state = { \
.next_keys_version = 2, \
}, \
.func_state = { \
.next_version = 1, \
}, \
.types = { \
.next_version_tag = 1, \
}, \
Expand Down Expand Up @@ -116,6 +100,12 @@ extern PyTypeObject _PyExc_MemoryError;
}, \
}, \
.dtoa = _dtoa_state_INIT(&(INTERP)), \
.dict_state = { \
.next_keys_version = 2, \
}, \
.func_state = { \
.next_version = 1, \
}, \
.static_objects = { \
.singletons = { \
._not_used = 1, \
Expand Down
8 changes: 5 additions & 3 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -3127,11 +3127,13 @@ def test_device_encoding(self):
class PidTests(unittest.TestCase):
@unittest.skipUnless(hasattr(os, 'getppid'), "test needs os.getppid")
def test_getppid(self):
p = subprocess.Popen([sys.executable, '-c',
p = subprocess.Popen([sys._base_executable, '-c',
'import os; print(os.getppid())'],
stdout=subprocess.PIPE)
stdout, _ = p.communicate()
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, error = p.communicate()
# We are the parent of our subprocess
self.assertEqual(error, b'')
self.assertEqual(int(stdout), os.getpid())

def check_waitpid(self, code, exitcode, callback=None):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve build support for the Xbox. Patch by Max Bachmann.
6 changes: 3 additions & 3 deletions Modules/_io/_iomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
_PyIO_State *state = get_io_state(module);
{
PyObject *RawIO_class = (PyObject *)state->PyFileIO_Type;
#ifdef MS_WINDOWS
#ifdef HAVE_WINDOWS_CONSOLE_IO
const PyConfig *config = _Py_GetConfig();
if (!config->legacy_windows_stdio && _PyIO_get_console_type(path_or_fd) != '\0') {
RawIO_class = (PyObject *)&PyWindowsConsoleIO_Type;
Expand Down Expand Up @@ -660,7 +660,7 @@ static PyTypeObject* static_types[] = {

// PyRawIOBase_Type(PyIOBase_Type) subclasses
&_PyBytesIOBuffer_Type,
#ifdef MS_WINDOWS
#ifdef HAVE_WINDOWS_CONSOLE_IO
&PyWindowsConsoleIO_Type,
#endif
};
Expand Down Expand Up @@ -718,7 +718,7 @@ PyInit__io(void)
}

// Set type base classes
#ifdef MS_WINDOWS
#ifdef HAVE_WINDOWS_CONSOLE_IO
PyWindowsConsoleIO_Type.tp_base = &PyRawIOBase_Type;
#endif

Expand Down
6 changes: 3 additions & 3 deletions Modules/_io/_iomodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ extern PyType_Spec fileio_spec;
extern PyType_Spec stringio_spec;
extern PyType_Spec textiowrapper_spec;

#ifdef MS_WINDOWS
#ifdef HAVE_WINDOWS_CONSOLE_IO
extern PyTypeObject PyWindowsConsoleIO_Type;
#endif /* MS_WINDOWS */
#endif /* HAVE_WINDOWS_CONSOLE_IO */

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

extern _PyIO_State *_PyIO_get_module_state(void);

#ifdef MS_WINDOWS
#ifdef HAVE_WINDOWS_CONSOLE_IO
extern char _PyIO_get_console_type(PyObject *);
#endif

Expand Down
Loading

0 comments on commit afaa312

Please sign in to comment.