Vlad Riscutia <riscutiav...@gmail.com> added the comment:

Attached patch for this issue.

This only happens on MSVC x64 (I actually tired to repro on Arch Linux x64 
before starting work on it and it didn't repro).

What happens is that MSVC on x64 always passes structures larger than 8 bytes 
by reference. See here: 
http://msdn.microsoft.com/en-us/library/ms235286(v=vs.90).aspx

Now this was accounted for in callproc.c, line 1143 in development branch with 
this:

        if (atypes[i]->type == FFI_TYPE_STRUCT
#ifdef _WIN64
            && atypes[i]->size <= sizeof(void *)
#endif
            )
            avalues[i] = (void *)args[i].value.p;
        else
            avalues[i] = (void *)&args[i].value;

This fix wasn't made in libffi_msvc/ffi.c though. Here, regardless of whether 
we have x64 or x86 build, if z >= sizeof(int) we will hit else branch in 
libffi_msvc/ffi.c at line 114 and do:

      else
        {
          memcpy(argp, *p_argv, z);
        }
      p_argv++;
      argp += z;

In our case, we copy 28 bytes as arguments (size of our structure) but in fact 
for x64 we only need 8 as structure is passed by reference so argument is just 
a pointer. My patch will adjust z before hitting if statement on x64 and it 
will cause correct copy as pointer.

----------
nosy: +vladris
Added file: http://bugs.python.org/file22899/issue11835_patch.diff

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

Reply via email to