Skip to content

Commit 0863f35

Browse files
authored
Merge branch 'main' into fetch-restore-objects
2 parents e5bf89d + d3d2074 commit 0863f35

20 files changed

+144
-229
lines changed

Doc/conf.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268
ogp_site_name = 'Python documentation'
269269
ogp_image = '_static/og-image.png'
270270
ogp_custom_meta_tags = [
271-
'<meta property="og:image:width" content="200">',
272-
'<meta property="og:image:height" content="200">',
273-
'<meta name="theme-color" content="#3776ab">',
271+
'<meta property="og:image:width" content="200" />',
272+
'<meta property="og:image:height" content="200" />',
273+
'<meta name="theme-color" content="#3776ab" />',
274274
]

Include/internal/pycore_dtoa.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ Bigint {
2424

2525
#ifdef Py_USING_MEMORY_DEBUGGER
2626

27-
struct _dtoa_runtime_state {
27+
struct _dtoa_state {
2828
int _not_used;
2929
};
30-
#define _dtoa_runtime_state_INIT {0}
30+
#define _dtoa_interp_state_INIT(INTERP) \
31+
{0}
3132

3233
#else // !Py_USING_MEMORY_DEBUGGER
3334

@@ -40,17 +41,17 @@ struct _dtoa_runtime_state {
4041
#define Bigint_PREALLOC_SIZE \
4142
((PRIVATE_MEM+sizeof(double)-1)/sizeof(double))
4243

43-
struct _dtoa_runtime_state {
44+
struct _dtoa_state {
4445
/* p5s is a linked list of powers of 5 of the form 5**(2**i), i >= 2 */
4546
// XXX This should be freed during runtime fini.
4647
struct Bigint *p5s;
4748
struct Bigint *freelist[Bigint_Kmax+1];
4849
double preallocated[Bigint_PREALLOC_SIZE];
4950
double *preallocated_next;
5051
};
51-
#define _dtoa_runtime_state_INIT(runtime) \
52+
#define _dtoa_state_INIT(INTERP) \
5253
{ \
53-
.preallocated_next = runtime.dtoa.preallocated, \
54+
.preallocated_next = (INTERP)->dtoa.preallocated, \
5455
}
5556

5657
#endif // !Py_USING_MEMORY_DEBUGGER

Include/internal/pycore_global_objects.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ extern "C" {
2727
_PyRuntime.cached_objects.NAME
2828

2929
struct _Py_cached_objects {
30-
PyObject *str_replace_inf;
31-
3230
PyObject *interned_strings;
3331
};
3432

@@ -67,11 +65,14 @@ struct _Py_static_objects {
6765
(interp)->cached_objects.NAME
6866

6967
struct _Py_interp_cached_objects {
70-
int _not_set;
68+
/* AST */
69+
PyObject *str_replace_inf;
70+
7171
/* object.__reduce__ */
7272
PyObject *objreduce;
7373
PyObject *type_slots_pname;
7474
pytype_slotdef *type_slots_ptrs[MAX_EQUIV];
75+
7576
};
7677

7778
#define _Py_INTERP_STATIC_OBJECT(interp, NAME) \

Include/internal/pycore_interp.h

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extern "C" {
1616
#include "pycore_code.h" // struct callable_cache
1717
#include "pycore_context.h" // struct _Py_context_state
1818
#include "pycore_dict_state.h" // struct _Py_dict_state
19+
#include "pycore_dtoa.h" // struct _dtoa_state
1920
#include "pycore_exceptions.h" // struct _Py_exc_state
2021
#include "pycore_floatobject.h" // struct _Py_float_state
2122
#include "pycore_function.h" // FUNC_MAX_WATCHERS
@@ -139,6 +140,7 @@ struct _is {
139140
struct _Py_unicode_state unicode;
140141
struct _Py_float_state float_state;
141142
struct _Py_long_state long_state;
143+
struct _dtoa_state dtoa;
142144
/* Using a cache is very effective since typically only a single slice is
143145
created and then deleted again. */
144146
PySliceObject *slice_cache;

Include/internal/pycore_runtime.h

-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ extern "C" {
1111
#include "pycore_atomic.h" /* _Py_atomic_address */
1212
#include "pycore_ceval_state.h" // struct _ceval_runtime_state
1313
#include "pycore_dict_state.h" // struct _Py_dict_runtime_state
14-
#include "pycore_dtoa.h" // struct _dtoa_runtime_state
1514
#include "pycore_floatobject.h" // struct _Py_float_runtime_state
1615
#include "pycore_faulthandler.h" // struct _faulthandler_runtime_state
1716
#include "pycore_function.h" // struct _func_runtime_state
@@ -141,7 +140,6 @@ typedef struct pyruntimestate {
141140
struct _ceval_runtime_state ceval;
142141
struct _gilstate_runtime_state gilstate;
143142
struct _getargs_runtime_state getargs;
144-
struct _dtoa_runtime_state dtoa;
145143
struct _fileutils_state fileutils;
146144
struct _faulthandler_runtime_state faulthandler;
147145
struct _tracemalloc_runtime_state tracemalloc;

Include/internal/pycore_runtime_init.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ extern "C" {
5353
.gilstate = { \
5454
.check_enabled = 1, \
5555
}, \
56-
.dtoa = _dtoa_runtime_state_INIT(runtime), \
5756
.fileutils = { \
5857
.force_ascii = -1, \
5958
}, \
@@ -94,10 +93,10 @@ extern "C" {
9493
}, \
9594
}, \
9695
}, \
97-
._main_interpreter = _PyInterpreterState_INIT, \
96+
._main_interpreter = _PyInterpreterState_INIT(runtime._main_interpreter), \
9897
}
9998

100-
#define _PyInterpreterState_INIT \
99+
#define _PyInterpreterState_INIT(INTERP) \
101100
{ \
102101
.id_refcount = -1, \
103102
.imports = IMPORTS_INIT, \
@@ -113,6 +112,7 @@ extern "C" {
113112
{ .threshold = 10, }, \
114113
}, \
115114
}, \
115+
.dtoa = _dtoa_state_INIT(&(INTERP)), \
116116
.static_objects = { \
117117
.singletons = { \
118118
._not_used = 1, \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cleanup Windows 7 specific special handling. Patch by Max Bachmann.

Modules/Setup

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ PYTHONPATH=$(COREPYTHONPATH)
163163

164164
# hashing builtins
165165
#_blake2 _blake2/blake2module.c _blake2/blake2b_impl.c _blake2/blake2s_impl.c
166-
#_md5 md5module.c -I$(srcdir)/Modules/_hacl/include _hacl/Hacl_Hash_MD5.c
167-
#_sha1 sha1module.c -I$(srcdir)/Modules/_hacl/include _hacl/Hacl_Hash_SHA1.c
166+
#_md5 md5module.c -I$(srcdir)/Modules/_hacl/include _hacl/Hacl_Hash_MD5.c -D_BSD_SOURCE -D_DEFAULT_SOURCE
167+
#_sha1 sha1module.c -I$(srcdir)/Modules/_hacl/include _hacl/Hacl_Hash_SHA1.c -D_BSD_SOURCE -D_DEFAULT_SOURCE
168168
#_sha2 sha2module.c -I$(srcdir)/Modules/_hacl/include Modules/_hacl/libHacl_Streaming_SHA2.a
169169
#_sha3 _sha3/sha3module.c
170170

Modules/_tkinter.c

+24-34
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,6 @@ static PyObject *Tkinter_TclError;
321321
static int quitMainLoop = 0;
322322
static int errorInCmd = 0;
323323
static PyObject *excInCmd;
324-
static PyObject *valInCmd;
325-
static PyObject *trbInCmd;
326324

327325
#ifdef TKINTER_PROTECT_LOADTK
328326
static int tk_load_failed = 0;
@@ -1222,7 +1220,7 @@ typedef struct Tkapp_CallEvent {
12221220
PyObject *args;
12231221
int flags;
12241222
PyObject **res;
1225-
PyObject **exc_type, **exc_value, **exc_tb;
1223+
PyObject **exc;
12261224
Tcl_Condition *done;
12271225
} Tkapp_CallEvent;
12281226

@@ -1339,7 +1337,7 @@ Tkapp_CallProc(Tkapp_CallEvent *e, int flags)
13391337
ENTER_PYTHON
13401338
objv = Tkapp_CallArgs(e->args, objStore, &objc);
13411339
if (!objv) {
1342-
PyErr_Fetch(e->exc_type, e->exc_value, e->exc_tb);
1340+
*(e->exc) = PyErr_GetRaisedException();
13431341
*(e->res) = NULL;
13441342
}
13451343
LEAVE_PYTHON
@@ -1354,7 +1352,7 @@ Tkapp_CallProc(Tkapp_CallEvent *e, int flags)
13541352
*(e->res) = Tkapp_ObjectResult(e->self);
13551353
}
13561354
if (*(e->res) == NULL) {
1357-
PyErr_Fetch(e->exc_type, e->exc_value, e->exc_tb);
1355+
*(e->exc) = PyErr_GetRaisedException();
13581356
}
13591357
LEAVE_PYTHON
13601358

@@ -1401,7 +1399,7 @@ Tkapp_Call(PyObject *selfptr, PyObject *args)
14011399
marshal the parameters to the interpreter thread. */
14021400
Tkapp_CallEvent *ev;
14031401
Tcl_Condition cond = NULL;
1404-
PyObject *exc_type, *exc_value, *exc_tb;
1402+
PyObject *exc;
14051403
if (!WaitForMainloop(self))
14061404
return NULL;
14071405
ev = (Tkapp_CallEvent*)attemptckalloc(sizeof(Tkapp_CallEvent));
@@ -1413,18 +1411,18 @@ Tkapp_Call(PyObject *selfptr, PyObject *args)
14131411
ev->self = self;
14141412
ev->args = args;
14151413
ev->res = &res;
1416-
ev->exc_type = &exc_type;
1417-
ev->exc_value = &exc_value;
1418-
ev->exc_tb = &exc_tb;
1414+
ev->exc = &exc;
14191415
ev->done = &cond;
14201416

14211417
Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond, &call_mutex);
14221418

14231419
if (res == NULL) {
1424-
if (exc_type)
1425-
PyErr_Restore(exc_type, exc_value, exc_tb);
1426-
else
1427-
PyErr_SetObject(Tkinter_TclError, exc_value);
1420+
if (exc) {
1421+
PyErr_SetRaisedException(exc);
1422+
}
1423+
else {
1424+
PyErr_SetObject(Tkinter_TclError, exc);
1425+
}
14281426
}
14291427
Tcl_ConditionFinalize(&cond);
14301428
}
@@ -1578,8 +1576,7 @@ typedef struct VarEvent {
15781576
int flags;
15791577
EventFunc func;
15801578
PyObject **res;
1581-
PyObject **exc_type;
1582-
PyObject **exc_val;
1579+
PyObject **exc;
15831580
Tcl_Condition *cond;
15841581
} VarEvent;
15851582

@@ -1643,12 +1640,7 @@ var_perform(VarEvent *ev)
16431640
{
16441641
*(ev->res) = ev->func(ev->self, ev->args, ev->flags);
16451642
if (!*(ev->res)) {
1646-
PyObject *exc, *val, *tb;
1647-
PyErr_Fetch(&exc, &val, &tb);
1648-
PyErr_NormalizeException(&exc, &val, &tb);
1649-
*(ev->exc_type) = exc;
1650-
*(ev->exc_val) = val;
1651-
Py_XDECREF(tb);
1643+
*(ev->exc) = PyErr_GetRaisedException();;
16521644
}
16531645

16541646
}
@@ -1672,7 +1664,7 @@ var_invoke(EventFunc func, PyObject *selfptr, PyObject *args, int flags)
16721664
TkappObject *self = (TkappObject*)selfptr;
16731665
if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) {
16741666
VarEvent *ev;
1675-
PyObject *res, *exc_type, *exc_val;
1667+
PyObject *res, *exc;
16761668
Tcl_Condition cond = NULL;
16771669

16781670
/* The current thread is not the interpreter thread. Marshal
@@ -1691,16 +1683,14 @@ var_invoke(EventFunc func, PyObject *selfptr, PyObject *args, int flags)
16911683
ev->flags = flags;
16921684
ev->func = func;
16931685
ev->res = &res;
1694-
ev->exc_type = &exc_type;
1695-
ev->exc_val = &exc_val;
1686+
ev->exc = &exc;
16961687
ev->cond = &cond;
16971688
ev->ev.proc = (Tcl_EventProc*)var_proc;
16981689
Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond, &var_mutex);
16991690
Tcl_ConditionFinalize(&cond);
17001691
if (!res) {
1701-
PyErr_SetObject(exc_type, exc_val);
1702-
Py_DECREF(exc_type);
1703-
Py_DECREF(exc_val);
1692+
PyErr_SetObject((PyObject*)Py_TYPE(exc), exc);
1693+
Py_DECREF(exc);
17041694
return NULL;
17051695
}
17061696
return res;
@@ -2188,7 +2178,7 @@ static int
21882178
PythonCmd_Error(Tcl_Interp *interp)
21892179
{
21902180
errorInCmd = 1;
2191-
PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd);
2181+
excInCmd = PyErr_GetRaisedException();
21922182
LEAVE_PYTHON
21932183
return TCL_ERROR;
21942184
}
@@ -2458,7 +2448,7 @@ FileHandler(ClientData clientData, int mask)
24582448
res = PyObject_CallFunction(func, "Oi", file, mask);
24592449
if (res == NULL) {
24602450
errorInCmd = 1;
2461-
PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd);
2451+
excInCmd = PyErr_GetRaisedException();
24622452
}
24632453
Py_XDECREF(res);
24642454
LEAVE_PYTHON
@@ -2628,7 +2618,7 @@ TimerHandler(ClientData clientData)
26282618

26292619
if (res == NULL) {
26302620
errorInCmd = 1;
2631-
PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd);
2621+
excInCmd = PyErr_GetRaisedException();
26322622
}
26332623
else
26342624
Py_DECREF(res);
@@ -2725,8 +2715,8 @@ _tkinter_tkapp_mainloop_impl(TkappObject *self, int threshold)
27252715

27262716
if (errorInCmd) {
27272717
errorInCmd = 0;
2728-
PyErr_Restore(excInCmd, valInCmd, trbInCmd);
2729-
excInCmd = valInCmd = trbInCmd = NULL;
2718+
PyErr_SetRaisedException(excInCmd);
2719+
excInCmd = NULL;
27302720
return NULL;
27312721
}
27322722
Py_RETURN_NONE;
@@ -3187,8 +3177,8 @@ EventHook(void)
31873177
#endif
31883178
if (errorInCmd) {
31893179
errorInCmd = 0;
3190-
PyErr_Restore(excInCmd, valInCmd, trbInCmd);
3191-
excInCmd = valInCmd = trbInCmd = NULL;
3180+
PyErr_SetRaisedException(excInCmd);
3181+
excInCmd = NULL;
31923182
PyErr_Print();
31933183
}
31943184
PyEval_SaveThread();

Modules/_winapi.c

+6-25
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,6 @@
6363

6464
#define T_HANDLE T_POINTER
6565

66-
/* Grab CancelIoEx dynamically from kernel32 */
67-
static int has_CancelIoEx = -1;
68-
static BOOL (CALLBACK *Py_CancelIoEx)(HANDLE, LPOVERLAPPED);
69-
70-
static int
71-
check_CancelIoEx()
72-
{
73-
if (has_CancelIoEx == -1)
74-
{
75-
HINSTANCE hKernel32 = GetModuleHandle("KERNEL32");
76-
* (FARPROC *) &Py_CancelIoEx = GetProcAddress(hKernel32,
77-
"CancelIoEx");
78-
has_CancelIoEx = (Py_CancelIoEx != NULL);
79-
}
80-
return has_CancelIoEx;
81-
}
82-
8366
typedef struct {
8467
PyTypeObject *overlapped_type;
8568
} WinApiState;
@@ -134,8 +117,7 @@ overlapped_dealloc(OverlappedObject *self)
134117

135118
PyObject_GC_UnTrack(self);
136119
if (self->pending) {
137-
if (check_CancelIoEx() &&
138-
Py_CancelIoEx(self->handle, &self->overlapped) &&
120+
if (CancelIoEx(self->handle, &self->overlapped) &&
139121
GetOverlappedResult(self->handle, &self->overlapped, &bytes, TRUE))
140122
{
141123
/* The operation is no longer pending -- nothing to do. */
@@ -306,10 +288,7 @@ _winapi_Overlapped_cancel_impl(OverlappedObject *self)
306288

307289
if (self->pending) {
308290
Py_BEGIN_ALLOW_THREADS
309-
if (check_CancelIoEx())
310-
res = Py_CancelIoEx(self->handle, &self->overlapped);
311-
else
312-
res = CancelIo(self->handle);
291+
res = CancelIoEx(self->handle, &self->overlapped);
313292
Py_END_ALLOW_THREADS
314293
}
315294

@@ -655,8 +634,10 @@ _winapi_CreateJunction_impl(PyObject *module, LPCWSTR src_path,
655634
cleanup:
656635
ret = GetLastError();
657636

658-
CloseHandle(token);
659-
CloseHandle(junction);
637+
if (token != NULL)
638+
CloseHandle(token);
639+
if (junction != NULL)
640+
CloseHandle(junction);
660641
PyMem_RawFree(rdb);
661642

662643
if (ret != 0)

Modules/getpath.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,11 @@ getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args)
227227
path = PyUnicode_AsWideCharString(pathobj, &cchPath);
228228
if (path) {
229229
#ifdef MS_WINDOWS
230-
const wchar_t *ext;
231230
DWORD attr = GetFileAttributesW(path);
232231
r = (attr != INVALID_FILE_ATTRIBUTES) &&
233232
!(attr & FILE_ATTRIBUTE_DIRECTORY) &&
234-
SUCCEEDED(PathCchFindExtension(path, cchPath + 1, &ext)) &&
235-
(CompareStringOrdinal(ext, -1, L".exe", -1, 1 /* ignore case */) == CSTR_EQUAL)
233+
(cchPath >= 4) &&
234+
(CompareStringOrdinal(path + cchPath - 4, -1, L".exe", -1, 1 /* ignore case */) == CSTR_EQUAL)
236235
? Py_True : Py_False;
237236
#else
238237
struct stat st;

0 commit comments

Comments
 (0)