Skip to content

Commit ef66e03

Browse files
committed
Merge
2 parents 1dce1aa + c419af9 commit ef66e03

17 files changed

+455
-157
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ repos:
3434
name: Run Black on Tools/jit/
3535
files: ^Tools/jit/
3636

37+
- repo: https://github.com/Lucas-C/pre-commit-hooks
38+
rev: v1.5.5
39+
hooks:
40+
- id: remove-tabs
41+
types: [python]
42+
exclude: ^Tools/c-analyzer/cpython/_parser.py
43+
3744
- repo: https://github.com/pre-commit/pre-commit-hooks
3845
rev: v5.0.0
3946
hooks:

Lib/_strptime.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ def _findall(haystack, needle):
4242
yield i
4343
i += len(needle)
4444

45+
def _fixmonths(months):
46+
yield from months
47+
# The lower case of 'İ' ('\u0130') is 'i\u0307'.
48+
# The re module only supports 1-to-1 character matching in
49+
# case-insensitive mode.
50+
for s in months:
51+
if 'i\u0307' in s:
52+
yield s.replace('i\u0307', '\u0130')
4553

4654
lzh_TW_alt_digits = (
4755
# 〇:一:二:三:四:五:六:七:八:九
@@ -366,8 +374,8 @@ def __init__(self, locale_time=None):
366374
'z': r"(?P<z>([+-]\d\d:?[0-5]\d(:?[0-5]\d(\.\d{1,6})?)?)|(?-i:Z))?",
367375
'A': self.__seqToRE(self.locale_time.f_weekday, 'A'),
368376
'a': self.__seqToRE(self.locale_time.a_weekday, 'a'),
369-
'B': self.__seqToRE(self.locale_time.f_month[1:], 'B'),
370-
'b': self.__seqToRE(self.locale_time.a_month[1:], 'b'),
377+
'B': self.__seqToRE(_fixmonths(self.locale_time.f_month[1:]), 'B'),
378+
'b': self.__seqToRE(_fixmonths(self.locale_time.a_month[1:]), 'b'),
371379
'p': self.__seqToRE(self.locale_time.am_pm, 'p'),
372380
'Z': self.__seqToRE((tz for tz_names in self.locale_time.timezone
373381
for tz in tz_names),

Lib/test/test_hashlib.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,10 @@ def test_clinic_signature(self):
279279
with self.assertWarnsRegex(DeprecationWarning,
280280
DEPRECATED_STRING_PARAMETER):
281281
hashlib.new(digest_name, string=b'')
282-
if self._hashlib:
282+
# Make sure that _hashlib contains the constructor
283+
# to test when using a combination of libcrypto and
284+
# interned hash implementations.
285+
if self._hashlib and digest_name in self._hashlib._constructors:
283286
self._hashlib.new(digest_name, b'')
284287
self._hashlib.new(digest_name, data=b'')
285288
with self.assertWarnsRegex(DeprecationWarning,
@@ -333,7 +336,8 @@ def test_clinic_signature_errors(self):
333336
with self.subTest(digest_name, args=args, kwds=kwds):
334337
with self.assertRaisesRegex(TypeError, errmsg):
335338
hashlib.new(digest_name, *args, **kwds)
336-
if self._hashlib:
339+
if (self._hashlib and
340+
digest_name in self._hashlib._constructors):
337341
with self.assertRaisesRegex(TypeError, errmsg):
338342
self._hashlib.new(digest_name, *args, **kwds)
339343

Lib/test/test_strptime.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,15 @@ def test_month_locale(self):
337337
self.roundtrip('%B', 1, (1900, m, 1, 0, 0, 0, 0, 1, 0))
338338
self.roundtrip('%b', 1, (1900, m, 1, 0, 0, 0, 0, 1, 0))
339339

340+
@run_with_locales('LC_TIME', 'az_AZ', 'ber_DZ', 'ber_MA', 'crh_UA')
341+
def test_month_locale2(self):
342+
# Test for month directives
343+
# Month name contains 'İ' ('\u0130')
344+
self.roundtrip('%B', 1, (2025, 6, 1, 0, 0, 0, 6, 152, 0))
345+
self.roundtrip('%b', 1, (2025, 6, 1, 0, 0, 0, 6, 152, 0))
346+
self.roundtrip('%B', 1, (2025, 7, 1, 0, 0, 0, 1, 182, 0))
347+
self.roundtrip('%b', 1, (2025, 7, 1, 0, 0, 0, 1, 182, 0))
348+
340349
def test_day(self):
341350
# Test for day directives
342351
self.roundtrip('%d %Y', 2)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Perform more aggressive control-flow optimizations on the machine code
2+
templates emitted by the experimental JIT compiler.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix parsing month names containing "İ" (U+0130, LATIN CAPITAL LETTER I WITH
2+
DOT ABOVE) in :func:`time.strptime`. This affects locales az_AZ, ber_DZ,
3+
ber_MA and crh_UA.

Modules/_stat.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ typedef unsigned short mode_t;
5757
* Only the names are defined by POSIX but not their value. All common file
5858
* types seems to have the same numeric value on all platforms, though.
5959
*
60-
* pyport.h guarantees S_IFMT, S_IFDIR, S_IFCHR, S_IFREG and S_IFLNK
60+
* fileutils.h guarantees S_IFMT, S_IFDIR, S_IFCHR, S_IFREG and S_IFLNK
6161
*/
6262

6363
#ifndef S_IFBLK
@@ -86,7 +86,7 @@ typedef unsigned short mode_t;
8686

8787

8888
/* S_ISXXX()
89-
* pyport.h defines S_ISDIR(), S_ISREG() and S_ISCHR()
89+
* fileutils.h defines S_ISDIR(), S_ISREG() and S_ISCHR()
9090
*/
9191

9292
#ifndef S_ISBLK

Modules/blake2module.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,25 @@
4343

4444
// SIMD256 can't be compiled on macOS ARM64, and performance of SIMD128 isn't
4545
// great; but when compiling a universal2 binary, autoconf will set
46-
// HACL_CAN_COMPILE_SIMD128 and HACL_CAN_COMPILE_SIMD256 because they *can* be
47-
// compiled on x86_64. If we're on macOS ARM64, disable these preprocessor
48-
// symbols.
46+
// _Py_HACL_CAN_COMPILE_VEC{128,256} because they *can* be compiled on x86_64.
47+
// If we're on macOS ARM64, we however disable these preprocessor symbols.
4948
#if defined(__APPLE__) && defined(__arm64__)
50-
# undef HACL_CAN_COMPILE_SIMD128
51-
# undef HACL_CAN_COMPILE_SIMD256
49+
# undef _Py_HACL_CAN_COMPILE_VEC128
50+
# undef _Py_HACL_CAN_COMPILE_VEC256
5251
#endif
5352

54-
// Small mismatch between the variable names Python defines as part of configure
55-
// at the ones HACL* expects to be set in order to enable those headers.
56-
#define HACL_CAN_COMPILE_VEC128 HACL_CAN_COMPILE_SIMD128
57-
#define HACL_CAN_COMPILE_VEC256 HACL_CAN_COMPILE_SIMD256
53+
// HACL* expects HACL_CAN_COMPILE_VEC* macros to be set in order to enable
54+
// the corresponding SIMD instructions so we need to "forward" the values
55+
// we just deduced above.
56+
#define HACL_CAN_COMPILE_VEC128 _Py_HACL_CAN_COMPILE_VEC128
57+
#define HACL_CAN_COMPILE_VEC256 _Py_HACL_CAN_COMPILE_VEC256
5858

5959
#include "_hacl/Hacl_Hash_Blake2s.h"
6060
#include "_hacl/Hacl_Hash_Blake2b.h"
61-
#if HACL_CAN_COMPILE_SIMD128
61+
#if _Py_HACL_CAN_COMPILE_VEC128
6262
#include "_hacl/Hacl_Hash_Blake2s_Simd128.h"
6363
#endif
64-
#if HACL_CAN_COMPILE_SIMD256
64+
#if _Py_HACL_CAN_COMPILE_VEC256
6565
#include "_hacl/Hacl_Hash_Blake2b_Simd256.h"
6666
#endif
6767

@@ -88,7 +88,7 @@ blake2_get_state(PyObject *module)
8888
return (Blake2State *)state;
8989
}
9090

91-
#if defined(HACL_CAN_COMPILE_SIMD128) || defined(HACL_CAN_COMPILE_SIMD256)
91+
#if defined(_Py_HACL_CAN_COMPILE_VEC128) || defined(_Py_HACL_CAN_COMPILE_VEC256)
9292
static inline Blake2State *
9393
blake2_get_state_from_type(PyTypeObject *module)
9494
{
@@ -181,7 +181,7 @@ blake2module_init_cpu_features(Blake2State *state)
181181
#undef ECX_SSE3
182182
#undef EBX_AVX2
183183

184-
#if HACL_CAN_COMPILE_SIMD128
184+
#if _Py_HACL_CAN_COMPILE_VEC128
185185
// TODO(picnixz): use py_cpuid_features (gh-125022) to improve detection
186186
state->can_run_simd128 = sse && sse2 && sse3 && sse41 && sse42 && cmov;
187187
#else
@@ -191,7 +191,7 @@ blake2module_init_cpu_features(Blake2State *state)
191191
state->can_run_simd128 = false;
192192
#endif
193193

194-
#if HACL_CAN_COMPILE_SIMD256
194+
#if _Py_HACL_CAN_COMPILE_VEC256
195195
// TODO(picnixz): use py_cpuid_features (gh-125022) to improve detection
196196
state->can_run_simd256 = state->can_run_simd128 && avx && avx2;
197197
#else
@@ -332,18 +332,18 @@ is_blake2s(blake2_impl impl)
332332
static inline blake2_impl
333333
type_to_impl(PyTypeObject *type)
334334
{
335-
#if defined(HACL_CAN_COMPILE_SIMD128) || defined(HACL_CAN_COMPILE_SIMD256)
335+
#if defined(_Py_HACL_CAN_COMPILE_VEC128) || defined(_Py_HACL_CAN_COMPILE_VEC256)
336336
Blake2State *st = blake2_get_state_from_type(type);
337337
#endif
338338
if (!strcmp(type->tp_name, blake2b_type_spec.name)) {
339-
#if HACL_CAN_COMPILE_SIMD256
339+
#if _Py_HACL_CAN_COMPILE_VEC256
340340
return st->can_run_simd256 ? Blake2b_256 : Blake2b;
341341
#else
342342
return Blake2b;
343343
#endif
344344
}
345345
else if (!strcmp(type->tp_name, blake2s_type_spec.name)) {
346-
#if HACL_CAN_COMPILE_SIMD128
346+
#if _Py_HACL_CAN_COMPILE_VEC128
347347
return st->can_run_simd128 ? Blake2s_128 : Blake2s;
348348
#else
349349
return Blake2s;
@@ -357,10 +357,10 @@ typedef struct {
357357
union {
358358
Hacl_Hash_Blake2s_state_t *blake2s_state;
359359
Hacl_Hash_Blake2b_state_t *blake2b_state;
360-
#if HACL_CAN_COMPILE_SIMD128
360+
#if _Py_HACL_CAN_COMPILE_VEC128
361361
Hacl_Hash_Blake2s_Simd128_state_t *blake2s_128_state;
362362
#endif
363-
#if HACL_CAN_COMPILE_SIMD256
363+
#if _Py_HACL_CAN_COMPILE_VEC256
364364
Hacl_Hash_Blake2b_Simd256_state_t *blake2b_256_state;
365365
#endif
366366
};
@@ -429,13 +429,13 @@ blake2_update_unlocked(Blake2Object *self, uint8_t *buf, Py_ssize_t len)
429429
switch (self->impl) {
430430
// blake2b_256_state and blake2s_128_state must be if'd since
431431
// otherwise this results in an unresolved symbol at link-time.
432-
#if HACL_CAN_COMPILE_SIMD256
432+
#if _Py_HACL_CAN_COMPILE_VEC256
433433
case Blake2b_256:
434434
HACL_UPDATE(Hacl_Hash_Blake2b_Simd256_update,
435435
self->blake2b_256_state, buf, len);
436436
return;
437437
#endif
438-
#if HACL_CAN_COMPILE_SIMD128
438+
#if _Py_HACL_CAN_COMPILE_VEC128
439439
case Blake2s_128:
440440
HACL_UPDATE(Hacl_Hash_Blake2s_Simd128_update,
441441
self->blake2s_128_state, buf, len);
@@ -555,12 +555,12 @@ py_blake2_new(PyTypeObject *type, PyObject *data, int digest_size,
555555
// Ensure that the states are NULL-initialized in case of an error.
556556
// See: py_blake2_clear() for more details.
557557
switch (self->impl) {
558-
#if HACL_CAN_COMPILE_SIMD256
558+
#if _Py_HACL_CAN_COMPILE_VEC256
559559
case Blake2b_256:
560560
self->blake2b_256_state = NULL;
561561
break;
562562
#endif
563-
#if HACL_CAN_COMPILE_SIMD128
563+
#if _Py_HACL_CAN_COMPILE_VEC128
564564
case Blake2s_128:
565565
self->blake2s_128_state = NULL;
566566
break;
@@ -623,12 +623,12 @@ py_blake2_new(PyTypeObject *type, PyObject *data, int digest_size,
623623
} while (0)
624624

625625
switch (self->impl) {
626-
#if HACL_CAN_COMPILE_SIMD256
626+
#if _Py_HACL_CAN_COMPILE_VEC256
627627
case Blake2b_256:
628628
BLAKE2_MALLOC(Blake2b_Simd256, self->blake2b_256_state);
629629
break;
630630
#endif
631-
#if HACL_CAN_COMPILE_SIMD128
631+
#if _Py_HACL_CAN_COMPILE_VEC128
632632
case Blake2s_128:
633633
BLAKE2_MALLOC(Blake2s_Simd128, self->blake2s_128_state);
634634
break;
@@ -756,12 +756,12 @@ blake2_blake2b_copy_unlocked(Blake2Object *self, Blake2Object *cpy)
756756
} while (0)
757757

758758
switch (self->impl) {
759-
#if HACL_CAN_COMPILE_SIMD256
759+
#if _Py_HACL_CAN_COMPILE_VEC256
760760
case Blake2b_256:
761761
BLAKE2_COPY(Blake2b_Simd256, blake2b_256_state);
762762
break;
763763
#endif
764-
#if HACL_CAN_COMPILE_SIMD128
764+
#if _Py_HACL_CAN_COMPILE_VEC128
765765
case Blake2s_128:
766766
BLAKE2_COPY(Blake2s_Simd128, blake2s_128_state);
767767
break;
@@ -840,12 +840,12 @@ static uint8_t
840840
blake2_blake2b_compute_digest(Blake2Object *self, uint8_t *digest)
841841
{
842842
switch (self->impl) {
843-
#if HACL_CAN_COMPILE_SIMD256
843+
#if _Py_HACL_CAN_COMPILE_VEC256
844844
case Blake2b_256:
845845
return Hacl_Hash_Blake2b_Simd256_digest(
846846
self->blake2b_256_state, digest);
847847
#endif
848-
#if HACL_CAN_COMPILE_SIMD128
848+
#if _Py_HACL_CAN_COMPILE_VEC128
849849
case Blake2s_128:
850850
return Hacl_Hash_Blake2s_Simd128_digest(
851851
self->blake2s_128_state, digest);
@@ -923,11 +923,11 @@ static Hacl_Hash_Blake2b_index
923923
hacl_get_blake2_info(Blake2Object *self)
924924
{
925925
switch (self->impl) {
926-
#if HACL_CAN_COMPILE_SIMD256
926+
#if _Py_HACL_CAN_COMPILE_VEC256
927927
case Blake2b_256:
928928
return Hacl_Hash_Blake2b_Simd256_info(self->blake2b_256_state);
929929
#endif
930-
#if HACL_CAN_COMPILE_SIMD128
930+
#if _Py_HACL_CAN_COMPILE_VEC128
931931
case Blake2s_128:
932932
return Hacl_Hash_Blake2s_Simd128_info(self->blake2s_128_state);
933933
#endif
@@ -975,12 +975,12 @@ py_blake2_clear(PyObject *op)
975975
} while (0)
976976

977977
switch (self->impl) {
978-
#if HACL_CAN_COMPILE_SIMD256
978+
#if _Py_HACL_CAN_COMPILE_VEC256
979979
case Blake2b_256:
980980
BLAKE2_FREE(Blake2b_Simd256, self->blake2b_256_state);
981981
break;
982982
#endif
983-
#if HACL_CAN_COMPILE_SIMD128
983+
#if _Py_HACL_CAN_COMPILE_VEC128
984984
case Blake2s_128:
985985
BLAKE2_FREE(Blake2s_Simd128, self->blake2s_128_state);
986986
break;

Modules/hmacmodule.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131
#endif
3232

3333
#if defined(__APPLE__) && defined(__arm64__)
34-
# undef HACL_CAN_COMPILE_SIMD128
35-
# undef HACL_CAN_COMPILE_SIMD256
34+
# undef _Py_HACL_CAN_COMPILE_VEC128
35+
# undef _Py_HACL_CAN_COMPILE_VEC256
3636
#endif
3737

38-
// Small mismatch between the variable names Python defines as part of configure
39-
// at the ones HACL* expects to be set in order to enable those headers.
40-
#define HACL_CAN_COMPILE_VEC128 HACL_CAN_COMPILE_SIMD128
41-
#define HACL_CAN_COMPILE_VEC256 HACL_CAN_COMPILE_SIMD256
38+
// HACL* expects HACL_CAN_COMPILE_VEC* macros to be set in order to enable
39+
// the corresponding SIMD instructions so we need to "forward" the values
40+
// we just deduced above.
41+
#define HACL_CAN_COMPILE_VEC128 _Py_HACL_CAN_COMPILE_VEC128
42+
#define HACL_CAN_COMPILE_VEC256 _Py_HACL_CAN_COMPILE_VEC256
4243

4344
#include "_hacl/Hacl_HMAC.h"
4445
#include "_hacl/Hacl_Streaming_HMAC.h" // Hacl_Agile_Hash_* identifiers
@@ -361,15 +362,15 @@ narrow_hmac_hash_kind(hmacmodule_state *state, HMAC_Hash_Kind kind)
361362
{
362363
switch (kind) {
363364
case Py_hmac_kind_hmac_blake2s_32: {
364-
#if HACL_CAN_COMPILE_SIMD128
365+
#if _Py_HACL_CAN_COMPILE_VEC128
365366
if (state->can_run_simd128) {
366367
return Py_hmac_kind_hmac_vectorized_blake2s_32;
367368
}
368369
#endif
369370
return kind;
370371
}
371372
case Py_hmac_kind_hmac_blake2b_32: {
372-
#if HACL_CAN_COMPILE_SIMD256
373+
#if _Py_HACL_CAN_COMPILE_VEC256
373374
if (state->can_run_simd256) {
374375
return Py_hmac_kind_hmac_vectorized_blake2b_32;
375376
}
@@ -1601,7 +1602,7 @@ hmacmodule_init_cpu_features(hmacmodule_state *state)
16011602
#undef ECX_SSE3
16021603
#undef EBX_AVX2
16031604

1604-
#if HACL_CAN_COMPILE_SIMD128
1605+
#if _Py_HACL_CAN_COMPILE_VEC128
16051606
// TODO(picnixz): use py_cpuid_features (gh-125022) to improve detection
16061607
state->can_run_simd128 = sse && sse2 && sse3 && sse41 && sse42 && cmov;
16071608
#else
@@ -1611,7 +1612,7 @@ hmacmodule_init_cpu_features(hmacmodule_state *state)
16111612
state->can_run_simd128 = false;
16121613
#endif
16131614

1614-
#if HACL_CAN_COMPILE_SIMD256
1615+
#if _Py_HACL_CAN_COMPILE_VEC256
16151616
// TODO(picnixz): use py_cpuid_features (gh-125022) to improve detection
16161617
state->can_run_simd256 = state->can_run_simd128 && avx && avx2;
16171618
#else

PCbuild/pythoncore.vcxproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,12 @@
419419
<ClCompile Include="..\Modules\_abc.c" />
420420
<ClCompile Include="..\Modules\_bisectmodule.c" />
421421
<ClCompile Include="..\Modules\blake2module.c">
422-
<PreprocessorDefinitions Condition="'$(Platform)' == 'x64'">HACL_CAN_COMPILE_SIMD128;%(PreprocessorDefinitions)</PreprocessorDefinitions>
423-
<PreprocessorDefinitions Condition="'$(Platform)' == 'x64'">HACL_CAN_COMPILE_SIMD256;%(PreprocessorDefinitions)</PreprocessorDefinitions>
422+
<PreprocessorDefinitions Condition="'$(Platform)' == 'x64'">
423+
_Py_HACL_CAN_COMPILE_VEC128;%(PreprocessorDefinitions)
424+
</PreprocessorDefinitions>
425+
<PreprocessorDefinitions Condition="'$(Platform)' == 'x64'">
426+
_Py_HACL_CAN_COMPILE_VEC256;%(PreprocessorDefinitions)
427+
</PreprocessorDefinitions>
424428
</ClCompile>
425429
<ClCompile Include="..\Modules\_codecsmodule.c" />
426430
<ClCompile Include="..\Modules\_collectionsmodule.c" />

0 commit comments

Comments
 (0)