msg116649 - (view) |
Author: Owen (owenl) |
Date: 2010-09-17 09:11 |
OS: Windows 2003STD x64 en I have try to call python method from c++ dll by "WINFUNCTYPE". But the 4th parameter is always None or 0 if the type is int or void* (float is works fine). Following is the part of source code: ==code========================================== import sys from ctypes import * windll.LoadLibrary("testPy2.dll") ######################################### def test3(param1,param2,param3,param4,param5,param6,param7,param8,param9,param10): print("================") print(param1) print(param2) print(param3) # the 4th param4 is always 0. print(param4) print(param5) print(param6) print(param7) print(param8) print(param9) print(param10) print("================") return 20 C_METHOD_TYPE4 = WINFUNCTYPE(c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32) windll.testPy2.fntestPy7(9,C_METHOD_TYPE4(test3)) ==code========================================== To my knowledge, both visual c++ and gcc use registers for the first few parameters, and then after that use the stack. Maybe this is the reason. I have attached some simple codes for reproduce this issue. issues - testPy2 <- source code of the dll - test.py <- python file to reproduce the issue - testPy2.dll <- the dll to reproduce the issue |
|
|
msg116847 - (view) |
Author: Owen (owenl) |
Date: 2010-09-19 01:35 |
Please reproduce this issue by 64bit Python. |
|
|
msg116851 - (view) |
Author: Owen (owenl) |
Date: 2010-09-19 08:27 |
Note: This issue also occurs on other 64 bit windows OS(i.e. windows xp 64bit) Load "testPy2.dll" needs vc++ runtime library (http://download.microsoft.com/download/2/d/6/2d61c766-107b-409d-8fba-c39e61ca08e8/vcredist_x64.exe) Update "testPy2.dll", use this to reproduce the issue. python code: import sys from ctypes import * windll.LoadLibrary("testPy2.dll") ######################################### def test3(param1,param2,param3,param4,param5,param6,param7,param8,param9,param10): print("================") print(param1) print(param2) print(param3) print(param4) print(param5) print(param6) print(param7) print(param8) print(param9) print(param10) print("================") return 20 C_METHOD_TYPE4 = WINFUNCTYPE(c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32) windll.testPy2.fntestPy7(9,C_METHOD_TYPE4(test3)) ######################################### def test4(param1,param2,param3,param4,param5,param6,param7,param8,param9,param10): print("================") print(param1) print(param2) print(param3) print(param4) print(param5) print(param6) print(param7) print(param8) print(param9) print(param10) print("================") return 20 C_METHOD_TYPE5 = WINFUNCTYPE(c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32) windll.testPy2.fntestPy8(10,C_METHOD_TYPE5(test4)) ######################################### def test5(param1,param2,param3,param4,param5,param6,param7,param8,param9,param10): print("================") print(param1) print(param2) print(param3) print(param4) print(param5) print(param6) print(param7) print(param8) print(param9) print(param10) print("================") return 20 C_METHOD_TYPE6 = WINFUNCTYPE(c_int32, c_float, c_float, c_float, c_float, c_float, c_float, c_float, c_float, c_float, c_float) windll.testPy2.fntestPy9(11,C_METHOD_TYPE6(test5)) |
|
|
msg117927 - (view) |
Author: Hirokazu Yamamoto (ocean-city) *  |
Date: 2010-10-03 19:34 |
Probably this issue is duplicate of #9266. |
|
|
msg117940 - (view) |
Author: Hirokazu Yamamoto (ocean-city) *  |
Date: 2010-10-04 07:17 |
I don't have x64 machine, so I cannot test this. So this is just an idea. It seems Modules/_ctypes/libffi_msvc is a bit old. Modules/_ctypes/libffi/src/x86 is newer. Maybe this issue can be fixed by using newer one? Thank you. |
|
|
msg126698 - (view) |
Author: Owen (owenl) |
Date: 2011-01-21 06:46 |
I tested this issue in Python2.7.1, Python3.1.3 and Python 3.2rc1. It's still can reproduce. Would you please check this "Callback functions" issue? |
|
|
msg126710 - (view) |
Author: Christoph Gohlke (cgohlke) |
Date: 2011-01-21 09:34 |
The provided example has two problems: The DLL should be loaded as cdll, not windll. C_METHOD_TYPE4 uses c_int32 as parameter type while pyFunc4Type in testPy2.cpp uses LPVOID (64 bit on win-amd64). Even with those corrections the issue remains. |
|
|
msg126711 - (view) |
Author: Owen (owenl) |
Date: 2011-01-21 09:57 |
yes, I tried lots of types. The issue still happens. The same case in Ubuntu and Mac were works well. |
|
|
msg126712 - (view) |
Author: Christoph Gohlke (cgohlke) |
Date: 2011-01-21 10:01 |
The patch attached to #8275 fixes this issue and possibly also #9266. Tested with Python 2.7.1 64 bit on Windows 7. |
|
|
msg126714 - (view) |
Author: Owen (owenl) |
Date: 2011-01-21 10:37 |
wow~~~ It works on my PC too (Windows 2003 STD x64). Thanks. |
|
|
msg127093 - (view) |
Author: stan mihai (stan.mihai) |
Date: 2011-01-26 09:16 |
Disabling optimizations doesn't really fix the issue, just hides it, for now. The problem was an uninitialized variable. Attached is the patch that fixes it. |
|
|
msg127676 - (view) |
Author: Owen (owenl) |
Date: 2011-02-01 02:02 |
Thanks, this issue has been fixed. :-) fixing revisions: r88284 (3.2), r88285 (3.1) and r88286 (2.7) |
|
|