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.

classification
Title: [Windows x86-64] ctypes: Incorrect function call
Type: behavior Stage: resolved
Components: ctypes Versions: Python 3.4
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, iritkatriel, vstinner, Андрей.Парамонов
Priority: normal Keywords:

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:11adminsetgithub: 67293
2021-12-09 12:44:09eryksunsettype: behavior
2021-12-09 12:43:39eryksunsetresolution: out of date

messages: + msg408113
nosy: + eryksun
2021-12-09 12:20:07iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg408112

stage: resolved
2014-12-25 23:26:36vstinnersettitle: [Windows x86-64] Incorrect function call -> [Windows x86-64] ctypes: Incorrect function call
2014-12-25 23:26:29vstinnersetnosy: + vstinner
messages: + msg233099
2014-12-23 11:33:43Андрей.Парамоновcreate