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 Igor Kudrin
Recipients Igor Kudrin, christian.heimes, doko, mark.dickinson, meador.inge, paul.moore, steve.dower, tim.golden, vinay.sajip, zach.ware
Date 2017-02-15.09:48:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1487152114.39.0.2484958241.issue29565@psf.upfronthosting.co.za>
In-reply-to
Content
It looks like resolving https://bugs.python.org/issue20160 didn't fix all the issues. When a large struct is used as a parameter, a reference to the object itself is passed to the function, not a reference to a temporary copy, as it is required in https://msdn.microsoft.com/en-us/library/zthk2dkh.aspx.

Here is the reproduction sample:

=== Sample.c: ===
typedef struct
{
  int v[3];
} Data;

__declspec(dllexport) void Cripple(Data data)
{
  data.v[0] = 0;
}

=== Sample.py ===
from ctypes import *

class Data(Structure):
    _fields_ = [("v", c_int * 3)]

lib = cdll.LoadLibrary('Sample.dll')
getattr(lib, 'Cripple').argtypes = [Data]

data = Data()
data.v[0] = 42
lib.Cripple(data)
assert data.v[0] == 42
print "OK"

=== repro.cmd ===
call "%VS140COMNTOOLS%/../../VC/vcvarsall.bat" x86_amd64
cl /LD Sample.c
python Sample.py
History
Date User Action Args
2017-02-15 09:48:34Igor Kudrinsetrecipients: + Igor Kudrin, doko, paul.moore, vinay.sajip, mark.dickinson, christian.heimes, tim.golden, meador.inge, zach.ware, steve.dower
2017-02-15 09:48:34Igor Kudrinsetmessageid: <1487152114.39.0.2484958241.issue29565@psf.upfronthosting.co.za>
2017-02-15 09:48:34Igor Kudrinlinkissue29565 messages
2017-02-15 09:48:33Igor Kudrincreate