This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients mark.dickinson
Date 2014-01-07.09:37:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The argument-passing code for passing structs larger than 8 bytes is broken on 64-bit Windows, leading to potential segmentation faults or other unpredictable behaviour.  According to

structs not of size 1, 2, 4 or 8 bytes should be passed by pointer.  ctypes instead puts sizeof(struct) bytes onto the stack.  The offending code is in ffi_prep_args in /Modules/_ctypes/libffi_msvc/ffi.c, which apparently hasn't been kept up to date with the /Modules/_ctypes/libffi/src/x86/ffi.c.  The latter module works correctly: it has an extra #ifdef X86_WIN64 block (shown below) to take care of structs not of size 1, 2, 4 or 8. That block is missing in the libffi_msvc version.

      z = (*p_arg)->size;
#ifdef X86_WIN64
      if (z > sizeof(ffi_arg)
          || ((*p_arg)->type == FFI_TYPE_STRUCT
              && (z != 1 && z != 2 && z != 4 && z != 8))
          || ((*p_arg)->type == FFI_TYPE_LONGDOUBLE)
          z = sizeof(ffi_arg);
          *(void **)argp = *p_argv;
      else if ((*p_arg)->type == FFI_TYPE_FLOAT)
          memcpy(argp, *p_argv, z);

It looks to me as though issue 17310 may be related.

Credit for this discovery should go to Freek Mank.
Date User Action Args
2014-01-07 09:37:54mark.dickinsonsetrecipients: + mark.dickinson
2014-01-07 09:37:54mark.dickinsonsetmessageid: <>
2014-01-07 09:37:54mark.dickinsonlinkissue20160 messages
2014-01-07 09:37:53mark.dickinsoncreate