Skip to content

type(byref(c_int())).__basicsize__ changes in Python 3.14b1, breaking size calculations. #136847

@junkmd

Description

@junkmd

Bug report

Summary

A change between 3.14a7 and 3.14b1 appears to have altered the value of __basicsize__ for ctypes.byref().
This breaks code that relies on this size for low-level struct manipulation.

This issue was discovered while testing comtypes on Python 3.14 after merging a fix that made comtypes.util functional again on Python 3.13 and earlier.

It's unclear whether this is a regression or an intentional change.
The following issues might be related.

I think the problem seems to lie deep within the ctypes implementation.

Reproducer

On Windows, running the comtypes test py -m unittest comtypes.test.test_util will lead to a RuntimeError.
The code snippet from comtypes/util.py (lines 42-45) is shown below:

    # additional checks to make sure that everything works as expected

    if sizeof(PyCArgObject) != type(byref(c_int())).__basicsize__:
        raise RuntimeError("sizeof(PyCArgObject) invalid")

We can find 5e241d8 on comtypes that demonstrates the issue.

Expected behavior

The script should run without raising a RuntimeError.

Actual behavior

On Python 3.14.0b1 (and later), the script fails with a RuntimeError.

The values observed for sizeof(PyCArgObject) and type(byref(c_int())).__basicsize__ are as follows:

Python Version Arch sizeof(PyCArgObject) type(byref(c_int())).__basicsize__
Python 3.14a7 (and earlier) 64-bit 56 56
32-bit 32 32
Python 3.14b1 (and later) 64-bit 56 64
32-bit 32 40

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions