◐ Shell
clean mode source ↗

Message 340261 - Python tracker

The issue is related to the definition of PyCArgObject:

typedef struct tagPyCArgObject PyCArgObject;

struct tagPyCArgObject {
    PyObject_HEAD
    ffi_type *pffi_type;
    char tag;
    union {
        char c;
        char b;
        short h;
        int i;
        long l;
        long long q;
        long double D;
        double d;
        float f;
        void *p;
    } value;
    PyObject *obj;
    Py_ssize_t size; /* for the 'V' tag */
};

This object must be allocated with suitable alignment (which is 16 on many platforms), and the default Python allocator apparently provides 8-byte alignment only on 64-bit platforms.  In short, using PyObject_New with PyCArgObject results in undefined behavior.

This issue potentially affects all compilers, not just Clang.