Eryk Sun added the comment:

Notes on fix-22273-02.diff:

In the second pass over _fields_, you can (should) use dict->length and 
dict->proto for array types instead of the _length_ and _type_ attributes. 

When reassigning stgdict->ffi_type_pointer.elements, if 
use_broken_old_ctypes_semantics is false, then you also have to allocate space 
for and copy the elements from the base class if any (i.e. if basedict && 
basedict->length > 0).

Regarding structs with bitfields and unions, we could add an stgdict flag to 
prevent passing them as arguments in the Unix X86_64 ABI -- e.g.   add a flag 
named TYPEFLAG_NONARGTYPE (0x400). ConvParam (callproc.c) and 
converters_from_argtypes (_ctypes.c) would raise an ArgumentError or TypeError 
in this case. Subclasses of structs and unions would inherit this flag value in 
StructUnionType_new.

The first pass in PyCStructUnionType_update_stgdict can set arrays_seen and 
bitfields_seen. Also, per the above suggestion, isArgType can be added. 
Moreover, since we don't have to worry about bitfields if we forbid passing 
structs with bitfields in this ABI, then MAX_ELEMENTS can be reduced to 8. For 
example:

    #ifdef X86_64
    #define MAX_ELEMENTS 8
    isArgType = (!(stgdict->flags & TYPEFLAG_NONARGTYPE) &&
                 isStruct && !bitfields_seen);
    if (!isArgType) {
        stgdict->flags |= TYPEFLAG_NONARGTYPE;
    } else if (size <= 16 && arrays_seen) {
        ffi_type *actual_types[MAX_ELEMENTS + 1];
        int actual_type_index = 0;

        /* second pass over _fields_ */

    }

This is speculative based on how we address passing unions and structs with 
bitfields in the 64-bit Unix ABI. Raising a descriptive exception is at least 
an improvement over abruptly aborting the process.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22273>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to