Skip to content

Commit 58c2fb1

Browse files
authored
Merge branch 'main' into fix-c_powi-117999
2 parents 2ae00f9 + 1f481fd commit 58c2fb1

Some content is hidden

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

48 files changed

+3509
-285
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ jobs:
388388
id: cache-hypothesis-database
389389
uses: actions/cache@v4
390390
with:
391-
path: ./hypothesis
391+
path: ${{ env.CPYTHON_BUILDDIR }}/.hypothesis/
392392
key: hypothesis-database-${{ github.head_ref || github.run_id }}
393393
restore-keys: |
394394
- hypothesis-database-
@@ -416,7 +416,7 @@ jobs:
416416
if: always()
417417
with:
418418
name: hypothesis-example-db
419-
path: .hypothesis/examples/
419+
path: ${{ env.CPYTHON_BUILDDIR }}/.hypothesis/examples/
420420

421421

422422
build_asan:

Doc/library/ctypes.rst

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -661,14 +661,18 @@ for debugging because they can provide useful information::
661661
guaranteed by the library to work in the general case. Unions and
662662
structures with bit-fields should always be passed to functions by pointer.
663663

664-
Structure/union alignment and byte order
665-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
666-
667-
By default, Structure and Union fields are aligned in the same way the C
668-
compiler does it. It is possible to override this behavior by specifying a
669-
:attr:`~Structure._pack_` class attribute in the subclass definition.
670-
This must be set to a positive integer and specifies the maximum alignment for the fields.
671-
This is what ``#pragma pack(n)`` also does in MSVC.
664+
Structure/union layout, alignment and byte order
665+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
666+
667+
By default, Structure and Union fields are laid out in the same way the C
668+
compiler does it. It is possible to override this behavior entirely by specifying a
669+
:attr:`~Structure._layout_` class attribute in the subclass definition; see
670+
the attribute documentation for details.
671+
672+
It is possible to specify the maximum alignment for the fields by setting
673+
the :attr:`~Structure._pack_` class attribute to a positive integer.
674+
This matches what ``#pragma pack(n)`` does in MSVC.
675+
672676
It is also possible to set a minimum alignment for how the subclass itself is packed in the
673677
same way ``#pragma align(n)`` works in MSVC.
674678
This can be achieved by specifying a ::attr:`~Structure._align_` class attribute
@@ -2540,6 +2544,31 @@ fields, or any other data types containing pointer type fields.
25402544
the structure when being packed or unpacked to/from memory.
25412545
Setting this attribute to 0 is the same as not setting it at all.
25422546

2547+
.. attribute:: _layout_
2548+
2549+
An optional string naming the struct/union layout. It can currently
2550+
be set to:
2551+
2552+
- ``"ms"``: the layout used by the Microsoft compiler (MSVC).
2553+
On GCC and Clang, this layout can be selected with
2554+
``__attribute__((ms_struct))``.
2555+
- ``"gcc-sysv"``: the layout used by GCC with the System V or “SysV-like”
2556+
data model, as used on Linux and macOS.
2557+
With this layout, :attr:`~Structure._pack_` must be unset or zero.
2558+
2559+
If not set explicitly, ``ctypes`` will use a default that
2560+
matches the platform conventions. This default may change in future
2561+
Python releases (for example, when a new platform gains official support,
2562+
or when a difference between similar platforms is found).
2563+
Currently the default will be:
2564+
2565+
- On Windows: ``"ms"``
2566+
- When :attr:`~Structure._pack_` is specified: ``"ms"``
2567+
- Otherwise: ``"gcc-sysv"``
2568+
2569+
:attr:`!_layout_` must already be defined when
2570+
:attr:`~Structure._fields_` is assigned, otherwise it will have no effect.
2571+
25432572
.. attribute:: _anonymous_
25442573

25452574
An optional sequence that lists the names of unnamed (anonymous) fields.

Doc/whatsnew/3.13.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,18 @@ copy
656656
any user classes which define the :meth:`!__replace__` method.
657657
(Contributed by Serhiy Storchaka in :gh:`108751`.)
658658

659+
ctypes
660+
------
661+
662+
* The layout of :ref:`bit fields <ctypes-bit-fields-in-structures-unions>` in
663+
:class:`~ctypes.Structure` and :class:`~ctypes.Union` was improved to better
664+
match platform defaults (GCC/Clang or MSC). In particular, fields no longer
665+
overlap.
666+
(Contributed by Matthias Görgens in :gh:`97702`.)
667+
* A :attr:`ctypes.Structure._layout_` class attribute can be set
668+
to help match a non-default ABI.
669+
(Contributed by Petr Viktorin in :gh:`97702`.)
670+
659671
dbm
660672
---
661673

Doc/whatsnew/3.14.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ Porting to Python 3.14
231231
Deprecated
232232
----------
233233

234+
* Macros :c:macro:`!Py_IS_NAN`, :c:macro:`!Py_IS_INFINITY`
235+
and :c:macro:`!Py_IS_FINITE` are :term:`soft deprecated`,
236+
use instead :c:macro:`!isnan`, :c:macro:`!isinf` and
237+
:c:macro:`!isfinite` available from :file:`math.h`
238+
since C99. (Contributed by Sergey B Kirpichev in :gh:`119613`.)
239+
234240
Removed
235241
-------
236242

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ struct _Py_global_strings {
256256
STRUCT_FOR_ID(_initializing)
257257
STRUCT_FOR_ID(_io)
258258
STRUCT_FOR_ID(_is_text_encoding)
259+
STRUCT_FOR_ID(_layout_)
259260
STRUCT_FOR_ID(_length_)
260261
STRUCT_FOR_ID(_limbo)
261262
STRUCT_FOR_ID(_lock_unlock_module)

Include/internal/pycore_opcode_metadata.h

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_runtime_init_generated.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/pymath.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@
2929

3030
// Py_IS_NAN(X)
3131
// Return 1 if float or double arg is a NaN, else 0.
32+
// Soft deprecated since Python 3.14, use isnan() instead.
3233
#define Py_IS_NAN(X) isnan(X)
3334

3435
// Py_IS_INFINITY(X)
3536
// Return 1 if float or double arg is an infinity, else 0.
37+
// Soft deprecated since Python 3.14, use isinf() instead.
3638
#define Py_IS_INFINITY(X) isinf(X)
3739

3840
// Py_IS_FINITE(X)
3941
// Return 1 if float or double arg is neither infinite nor NAN, else 0.
42+
// Soft deprecated since Python 3.14, use isfinite() instead.
4043
#define Py_IS_FINITE(X) isfinite(X)
4144

4245
// Py_INFINITY: Value that evaluates to a positive double infinity.

Lib/test/libregrtest/run_workers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,20 @@ def _kill(self) -> None:
142142
return
143143
self._killed = True
144144

145-
if USE_PROCESS_GROUP:
145+
use_killpg = USE_PROCESS_GROUP
146+
if use_killpg:
147+
parent_sid = os.getsid(0)
148+
sid = os.getsid(popen.pid)
149+
use_killpg = (sid != parent_sid)
150+
151+
if use_killpg:
146152
what = f"{self} process group"
147153
else:
148154
what = f"{self} process"
149155

150156
print(f"Kill {what}", file=sys.stderr, flush=True)
151157
try:
152-
if USE_PROCESS_GROUP:
158+
if use_killpg:
153159
os.killpg(popen.pid, signal.SIGKILL)
154160
else:
155161
popen.kill()

Lib/test/libregrtest/worker.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515

1616
USE_PROCESS_GROUP = (hasattr(os, "setsid") and hasattr(os, "killpg"))
17+
NEED_TTY = set('''
18+
test_ioctl
19+
'''.split())
1720

1821

1922
def create_worker_process(runtests: WorkerRunTests, output_fd: int,
@@ -47,7 +50,10 @@ def create_worker_process(runtests: WorkerRunTests, output_fd: int,
4750
close_fds=True,
4851
cwd=work_dir,
4952
)
50-
if USE_PROCESS_GROUP:
53+
54+
# Don't use setsid() in tests using TTY
55+
test_name = runtests.tests[0]
56+
if USE_PROCESS_GROUP and test_name not in NEED_TTY:
5157
kwargs['start_new_session'] = True
5258

5359
# Pass json_file to the worker process

Lib/test/support/hypothesis_helper.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
except ImportError:
66
from . import _hypothesis_stubs as hypothesis
77
else:
8+
# Regrtest changes to use a tempdir as the working directory, so we have
9+
# to tell Hypothesis to use the original in order to persist the database.
10+
from .os_helper import SAVEDCWD
11+
from hypothesis.configuration import set_hypothesis_home_dir
12+
13+
set_hypothesis_home_dir(os.path.join(SAVEDCWD, ".hypothesis"))
14+
815
# When using the real Hypothesis, we'll configure it to ignore occasional
916
# slow tests (avoiding flakiness from random VM slowness in CI).
1017
hypothesis.settings.register_profile(

0 commit comments

Comments
 (0)