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.
Created on 2010年09月17日 09:11 by owenl, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| issues.zip | owenl, 2010年09月17日 09:11 | some simple codes for reproduce this issue | ||
| testPy2.dll | owenl, 2010年09月19日 08:27 | use this dll to reproduce the issue | ||
| ctypes_win64.diff | stan.mihai, 2011年01月26日 09:16 | one-liner fix | ||
| Messages (12) | |||
|---|---|---|---|
| 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) * (Python committer) | Date: 2010年10月03日 19:34 | |
Probably this issue is duplicate of #9266. |
|||
| msg117940 - (view) | Author: Hirokazu Yamamoto (ocean-city) * (Python committer) | 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) |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:06 | admin | set | github: 54093 |
| 2011年02月01日 02:02:21 | owenl | set | status: open -> closed messages: + msg127676 resolution: fixed nosy: theller, ghazel, ocean-city, cgohlke, owenl, stan.mihai |
| 2011年01月26日 09:16:03 | stan.mihai | set | files:
+ ctypes_win64.diff nosy: + stan.mihai messages: + msg127093 keywords: + patch |
| 2011年01月21日 10:37:35 | owenl | set | nosy:
theller, ghazel, ocean-city, cgohlke, owenl messages: + msg126714 |
| 2011年01月21日 10:01:36 | cgohlke | set | nosy:
theller, ghazel, ocean-city, cgohlke, owenl messages: + msg126712 |
| 2011年01月21日 09:57:59 | owenl | set | nosy:
theller, ghazel, ocean-city, cgohlke, owenl messages: + msg126711 |
| 2011年01月21日 09:34:48 | cgohlke | set | nosy:
+ cgohlke messages: + msg126710 |
| 2011年01月21日 06:46:30 | owenl | set | nosy:
theller, ghazel, ocean-city, owenl messages: + msg126698 |
| 2010年10月04日 07:17:08 | ocean-city | set | messages: + msg117940 |
| 2010年10月03日 19:36:41 | ghazel | set | nosy:
+ ghazel |
| 2010年10月03日 19:34:03 | ocean-city | set | nosy:
+ ocean-city messages: + msg117927 |
| 2010年09月19日 08:27:14 | owenl | set | files:
+ testPy2.dll messages: + msg116851 |
| 2010年09月19日 01:35:32 | owenl | set | messages: + msg116847 |
| 2010年09月18日 03:43:46 | terry.reedy | set | nosy:
+ theller |
| 2010年09月17日 09:13:24 | owenl | set | type: behavior |
| 2010年09月17日 09:11:56 | owenl | create | |