Issue 23104: [Windows x86-64] ctypes: Incorrect function call (original) (raw)

Created on 2014-12-23 11:33 by Андрей.Парамонов, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
testlib.c Андрей.Парамонов,2014-12-23 11:33
Messages (4)
msg233042 - (view) Author: Андрей Парамонов (Андрей.Парамонов) Date: 2014-12-23 11:33
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.
msg233099 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-12-25 23:26
> 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
msg408112 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-12-09 12:20
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).
msg408113 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-12-09 12:43
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
2014-12-25 23:26:29 vstinner set nosy: + vstinnermessages: +
2014-12-23 11:33:43 Андрей.Парамонов create