Skip to content

Commit 0c49350

Browse files
Merge branch 'main' into expat-2.9.0
2 parents b3e0aa0 + 82c62ab commit 0c49350

11 files changed

Lines changed: 79 additions & 84 deletions

File tree

‎Include/pymacro.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@
214214
//
215215
// gh-158810: Do not use __builtin_types_compatible_p() in strict C ANSI mode
216216
// and on C++.
217-
#if (defined(__GNUC__) && __GNUC__ >= 4 \
217+
#if (defined(__GNUC__) && __GNUC__ >= 4 && defined(_Py_TYPEOF) \
218218
&& !defined(__STRICT_ANSI__) && !defined(__cplusplus))
219219
#define Py_ARRAY_LENGTH(array) \
220220
(sizeof(array) / sizeof((array)[0]) \
221-
+ Py_BUILD_ASSERT_EXPR(!__builtin_types_compatible_p(typeof(array), \
222-
typeof(&(array)[0]))))
221+
+ Py_BUILD_ASSERT_EXPR(!__builtin_types_compatible_p(_Py_TYPEOF(array), \
222+
_Py_TYPEOF(&(array)[0]))))
223223
#else
224224
#define Py_ARRAY_LENGTH(array) \
225225
(sizeof(array) / sizeof((array)[0]))

‎Lib/test/test_cext/extension.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,11 @@ module_exec(PyObject *module)
388388
return -1;
389389
}
390390
#endif
391+
#ifdef __STRICT_ANSI__
392+
if (PyModule_AddIntConstant(module, "__STRICT_ANSI__", 1) < 0) {
393+
return -1;
394+
}
395+
#endif
391396
#ifdef __cplusplus
392397
if (PyModule_AddIntMacro(module, __cplusplus) < 0) {
393398
return -1;

‎Lib/test/test_cext/runtests.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ def main():
2828
testmod = importlib.import_module(module_name)
2929

3030
newline = False
31-
for name in ('__STDC_VERSION__', '__cplusplus', '_MSVC_LANG'):
31+
for name in (
32+
'__STDC_VERSION__',
33+
'__STRICT_ANSI__',
34+
'__cplusplus',
35+
'_MSVC_LANG',
36+
):
3237
try:
3338
value = getattr(testmod, name)
3439
except AttributeError:

‎Lib/test/test_cext/setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def main():
135135
# option emits a C++ compiler warning. Remove "-std11" option from the
136136
# CC command.
137137
cmd = (sysconfig.get_config_var('CC') or '')
138-
if cmd is not None:
138+
if cmd is not None and 'CC' not in os.environ:
139139
if support.MS_WINDOWS:
140140
std_prefix = '/std'
141141
else:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Stop creating an empty Modules/Setup.local file as it no longer seems to be
2+
required to statically link the extension modules.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Use compiler option ``-Og`` in case of clang-cl debug builds on Windows to
2+
reduce stack usage. Patch by Chris Eibl.

‎Modules/_elementtree.c‎

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,11 +1497,13 @@ _elementtree_Element_get_impl(ElementObject *self, PyObject *key,
14971497
{
14981498
if (self->extra && self->extra->attrib) {
14991499
PyObject *attrib = Py_NewRef(self->extra->attrib);
1500-
PyObject *value = Py_XNewRef(PyDict_GetItemWithError(attrib, key));
1501-
Py_DECREF(attrib);
1502-
if (value != NULL || PyErr_Occurred()) {
1500+
PyObject *value;
1501+
if (PyDict_GetItemRef(attrib, key, &value) != 0) {
1502+
Py_DECREF(attrib);
1503+
// The key exists or an error occurred
15031504
return value;
15041505
}
1506+
Py_DECREF(attrib);
15051507
}
15061508

15071509
return Py_NewRef(default_value);
@@ -3177,56 +3179,58 @@ makeuniversal(XMLParserObject* self, const char* string)
31773179
if (!key)
31783180
return NULL;
31793181

3180-
value = Py_XNewRef(PyDict_GetItemWithError(self->names, key));
3181-
3182-
if (value == NULL && !PyErr_Occurred()) {
3183-
/* new name. convert to universal name, and decode as
3184-
necessary */
3185-
3186-
PyObject* tag;
3187-
Py_ssize_t i;
3182+
if (PyDict_GetItemRef(self->names, key, &value) != 0) {
3183+
// The key exists or an error occurred
3184+
Py_DECREF(key);
3185+
return value;
3186+
}
31883187

3189-
/* look for namespace separator */
3190-
for (i = 0; i < size; i++)
3191-
if (string[i] == '}')
3192-
break;
3193-
if (i != size) {
3194-
/* convert to universal name */
3195-
PyBytesWriter *writer = PyBytesWriter_Create(1 + size);
3196-
if (writer == NULL) {
3197-
Py_DECREF(key);
3198-
return NULL;
3199-
}
3200-
char *p = PyBytesWriter_GetData(writer);
3201-
p[0] = '{';
3202-
memcpy(p+1, string, size);
3203-
size++;
3188+
/* new name. convert to universal name, and decode as
3189+
necessary */
32043190

3205-
tag = PyBytesWriter_Finish(writer);
3206-
if (tag == NULL) {
3207-
Py_DECREF(key);
3208-
return NULL;
3209-
}
3210-
} else {
3211-
/* plain name; use key as tag */
3212-
tag = Py_NewRef(key);
3213-
}
3191+
PyObject* tag;
3192+
Py_ssize_t i;
32143193

3215-
/* decode universal name */
3216-
const char *p = PyBytes_AS_STRING(tag);
3217-
value = PyUnicode_DecodeUTF8(p, size, "strict");
3218-
Py_DECREF(tag);
3219-
if (!value) {
3194+
/* look for namespace separator */
3195+
for (i = 0; i < size; i++)
3196+
if (string[i] == '}')
3197+
break;
3198+
if (i != size) {
3199+
/* convert to universal name */
3200+
PyBytesWriter *writer = PyBytesWriter_Create(1 + size);
3201+
if (writer == NULL) {
32203202
Py_DECREF(key);
32213203
return NULL;
32223204
}
3205+
char *p = PyBytesWriter_GetData(writer);
3206+
p[0] = '{';
3207+
memcpy(p+1, string, size);
3208+
size++;
32233209

3224-
/* add to names dictionary */
3225-
if (PyDict_SetItem(self->names, key, value) < 0) {
3210+
tag = PyBytesWriter_Finish(writer);
3211+
if (tag == NULL) {
32263212
Py_DECREF(key);
3227-
Py_DECREF(value);
32283213
return NULL;
32293214
}
3215+
} else {
3216+
/* plain name; use key as tag */
3217+
tag = Py_NewRef(key);
3218+
}
3219+
3220+
/* decode universal name */
3221+
const char *p = PyBytes_AS_STRING(tag);
3222+
value = PyUnicode_DecodeUTF8(p, size, "strict");
3223+
Py_DECREF(tag);
3224+
if (!value) {
3225+
Py_DECREF(key);
3226+
return NULL;
3227+
}
3228+
3229+
/* add to names dictionary */
3230+
if (PyDict_SetItem(self->names, key, value) < 0) {
3231+
Py_DECREF(key);
3232+
Py_DECREF(value);
3233+
return NULL;
32303234
}
32313235

32323236
Py_DECREF(key);
@@ -3304,7 +3308,11 @@ expat_default_handler(void *op, const XML_Char *data_in, int data_len)
33043308
if (!key)
33053309
return;
33063310

3307-
value = PyDict_GetItemWithError(self->entity, key);
3311+
if (PyDict_GetItemRef(self->entity, key, &value) < 0) {
3312+
Py_DECREF(key);
3313+
return;
3314+
}
3315+
Py_DECREF(key);
33083316

33093317
elementtreestate *st = self->state;
33103318
if (value) {
@@ -3316,8 +3324,10 @@ expat_default_handler(void *op, const XML_Char *data_in, int data_len)
33163324
res = PyObject_CallOneArg(self->handle_data, value);
33173325
else
33183326
res = NULL;
3327+
Py_DECREF(value);
33193328
Py_XDECREF(res);
3320-
} else if (!PyErr_Occurred()) {
3329+
}
3330+
else {
33213331
/* Report the first error, not the last */
33223332
char message[128] = "undefined entity ";
33233333
strncat(message, data_in, data_len < 100?data_len:100);
@@ -3329,8 +3339,6 @@ expat_default_handler(void *op, const XML_Char *data_in, int data_len)
33293339
message
33303340
);
33313341
}
3332-
3333-
Py_DECREF(key);
33343342
}
33353343

33363344
/* Append (action, node) to the list of events of the pull parser. */

‎Objects/dictobject.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4269,12 +4269,12 @@ dict_dict_merge(PyDictObject *mp, PyDictObject *other, int override, PyObject **
42694269

42704270
while (_PyDict_Next((PyObject*)other, &pos, &key, &value, &hash)) {
42714271
int err = 0;
4272-
Py_INCREF(key);
4273-
Py_INCREF(value);
42744272
if (override == 1) {
42754273
err = insertdict(mp, Py_NewRef(key), hash, Py_NewRef(value));
42764274
}
42774275
else {
4276+
Py_INCREF(key);
4277+
Py_INCREF(value);
42784278
err = _PyDict_Contains_KnownHash((PyObject *)mp, key, hash);
42794279
if (err == 0) {
42804280
err = insertdict(mp, Py_NewRef(key), hash, Py_NewRef(value));
@@ -4287,9 +4287,9 @@ dict_dict_merge(PyDictObject *mp, PyDictObject *other, int override, PyObject **
42874287
}
42884288
err = 0;
42894289
}
4290+
Py_DECREF(value);
4291+
Py_DECREF(key);
42904292
}
4291-
Py_DECREF(value);
4292-
Py_DECREF(key);
42934293
if (err != 0)
42944294
return -1;
42954295

‎PCbuild/pyproject-clangcl.props‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<AdditionalOptions Condition="'$(Platform)' == 'Win32'">-m32 %(AdditionalOptions)</AdditionalOptions>
5151
<AdditionalOptions Condition="'$(Platform)' == 'x64'">-m64 %(AdditionalOptions)</AdditionalOptions>
5252
<AdditionalOptions Condition="$(Configuration) != 'Debug'">-flto=thin %(AdditionalOptions)</AdditionalOptions>
53+
<AdditionalOptions Condition="$(Configuration) == 'Debug'">%(AdditionalOptions) -Xclang -Og</AdditionalOptions>
5354
<AdditionalOptions Condition="$(SupportPGO) and $(Configuration) == 'PGInstrument'">-fprofile-instr-generate=$(_CLANG_PROFILE_PATH)$(TargetName)_%m.profraw %(AdditionalOptions)</AdditionalOptions>
5455
<AdditionalOptions Condition="$(SupportPGO) and $(Configuration) == 'PGUpdate'">-fprofile-instr-use=$(OutDir)instrumented\profdata.profdata -Wno-profile-instr-unprofiled %(AdditionalOptions)</AdditionalOptions>
5556
</ClCompile>

‎Platforms/WASI/_build.py‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525

2626
import _shared
2727

28-
LOCAL_SETUP_MARKER = (
29-
b"# Generated by Platforms/WASI .\n"
30-
b"# Required to statically build extension modules."
31-
)
32-
3328
WASMTIME_VAR_NAME = "WASMTIME"
3429
WASMTIME_HOST_RUNNER_VAR = f"{{{WASMTIME_VAR_NAME}}}"
3530

@@ -147,18 +142,6 @@ def call(command, *, context=None, quiet=False, **kwargs):
147142
@subdir("build_python_path", clean_ok=True)
148143
def configure_build_python(context, working_dir):
149144
"""Configure the build/host Python."""
150-
if context.setup_local_path.exists():
151-
if context.setup_local_path.read_bytes() == LOCAL_SETUP_MARKER:
152-
_shared.log("👍", f"{context.setup_local_path} exists ...")
153-
else:
154-
_shared.log(
155-
"⚠️",
156-
f"{context.setup_local_path} exists, but has unexpected contents",
157-
)
158-
else:
159-
_shared.log("📝", f"Creating {context.setup_local_path} ...")
160-
context.setup_local_path.write_bytes(LOCAL_SETUP_MARKER)
161-
162145
configure = [os.path.relpath(context.checkout / "configure", working_dir)]
163146
if context.args:
164147
configure.extend(context.args)
@@ -300,13 +283,6 @@ def clean_contents(context):
300283
_shared.log("🧹", f"Deleting {context.cross_build_path} ...")
301284
shutil.rmtree(context.cross_build_path)
302285

303-
if context.setup_local_path.exists():
304-
if context.setup_local_path.read_bytes() == LOCAL_SETUP_MARKER:
305-
_shared.log(
306-
"🧹", f"Deleting generated {context.setup_local_path} ..."
307-
)
308-
context.setup_local_path.unlink()
309-
310286

311287
@subdir("build_python_path")
312288
def pythoninfo_build_python(context, working_dir):

0 commit comments

Comments
 (0)