FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Use _Alignof to query alignments in the struct module · Issue #132868 · python/cpython · GitHub

Repository navigation

Use _Alignof to query alignments in the struct module #132868

Description

Feature or enhancement

Proposal:

The struct module uses pre-C11 hacks to determine alignment for types:

cpython/Modules/_struct.c

Lines 79 to 106 in 5808889

/* Define various structs to figure out the alignments of types */
typedef struct { char c; short x; } st_short;
typedef struct { char c; int x; } st_int;
typedef struct { char c; long x; } st_long;
typedef struct { char c; float x; } st_float;
typedef struct { char c; double x; } st_double;
#ifdef Py_HAVE_C_COMPLEX
typedef struct { char c; float complex x; } st_float_complex;
typedef struct { char c; double complex x; } st_double_complex;
#endif
typedef struct { char c; void *x; } st_void_p;
typedef struct { char c; size_t x; } st_size_t;
typedef struct { char c; _Bool x; } st_bool;
#define SHORT_ALIGN (sizeof(st_short) - sizeof(short))
#define INT_ALIGN (sizeof(st_int) - sizeof(int))
#define LONG_ALIGN (sizeof(st_long) - sizeof(long))
#define FLOAT_ALIGN (sizeof(st_float) - sizeof(float))
#define DOUBLE_ALIGN (sizeof(st_double) - sizeof(double))
#ifdef Py_HAVE_C_COMPLEX
# define FLOAT_COMPLEX_ALIGN (sizeof(st_float_complex) - sizeof(float complex))
# define DOUBLE_COMPLEX_ALIGN (sizeof(st_double_complex) - sizeof(double complex))
#endif
#define VOID_P_ALIGN (sizeof(st_void_p) - sizeof(void *))
#define SIZE_T_ALIGN (sizeof(st_size_t) - sizeof(size_t))
#define BOOL_ALIGN (sizeof(st_bool) - sizeof(_Bool))

Now we can use _Alignof operator, as C11-compatible compiler is a build requireent.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. self-assigned this
    on Apr 24, 2025
  2. added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    and removed
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    on Apr 24, 2025
  3. picnixz commented on Apr 24, 2025

    Member

    Considering I did use _Alignof in my recent PR (#132428), I support this proposal.

  4. added a commit that references this issue on Apr 24, 2025
  5. skirpichev commented on Apr 24, 2025

    MemberAuthor

    PR is ready: #132872

  6. added a commit that references this issue on Apr 25, 2025
  7. removed their assignment
    on Apr 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-featureA feature request or enhancement

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL