To reproduce: 0) Compile attached testlib.c 1) Run the following code: from __future__ import print_function from __future__ import unicode_literals from ctypes import * testlib = windll.LoadLibrary('testlib') testfun = testlib.test class objid(Structure): _fields_ = [('bytes', c_ubyte*16)] print('Calling...') testfun(objid(), c_wchar_p('test')) print('Done.') --- It gives different output for different versions of Python and processor architectures: >c:\python27\python test.py Calling... test Done. >c:\python34\python test.py Calling... test Done. >c:\python27-64\python test.py Calling... test Done. >c:\python34-64\python test.py Calling... Done. It appears that Python 3.4 on Windows x86-64 generates incorrect function call code.
> testfun(objid(), c_wchar_p('test')) I'm not sure that the objid object lives until testfun() is called. It would be safer to write: o = objid() testfun(o, c_wchar_p('test'))) o = None
I'm closing as there was no reply to Victor's suggestion and this is 7 years old. Please create a new issue if you are still having a problem with this in a supported python version (>= 3.9).
Victor's comment wasn't relevant. objid() stays referenced during the call. Anyway, I just built testlib.c and verified that this ctypes example works correctly in both 64-bit 3.4.4 and 3.10, so the issue is out of date.
History
Date
User
Action
Args
2022-04-11 14:58:11
admin
set
github: 67293
2021-12-09 12:44:09
eryksun
set
type: behavior
2021-12-09 12:43:39
eryksun
set
resolution: out of datemessages: + nosy: + eryksun
2021-12-09 12:20:07
iritkatriel
set
status: open -> closednosy: + iritkatrielmessages: + stage: resolved
2014-12-25 23:26:36
vstinner
set
title: [Windows x86-64] Incorrect function call -> [Windows x86-64] ctypes: Incorrect function call