← 输入框|github.com|刷新
Skip to content

The 4th parameter of method always None or 0 on x64 Windows. #54093

Closed

Description

@owenl
mannequin
BPO 9884
Nosy @theller
Files
  • issues.zip: some simple codes for reproduce this issue
  • testPy2.dll: use this dll to reproduce the issue
  • ctypes_win64.diff: one-liner fix
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2011-02-01.02:02:21.044>
    created_at = <Date 2010-09-17.09:11:56.670>
    labels = ['type-bug', 'OS-windows']
    title = 'The 4th parameter of method always None or 0 on x64 Windows.'
    updated_at = <Date 2011-02-01.02:02:21.043>
    user = 'https://bugs.python.org/owenl'

    bugs.python.org fields:

    activity = <Date 2011-02-01.02:02:21.043>
    actor = 'owenl'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-02-01.02:02:21.044>
    closer = 'owenl'
    components = ['Windows']
    creation = <Date 2010-09-17.09:11:56.670>
    creator = 'owenl'
    dependencies = []
    files = ['18907', '18929', '20528']
    hgrepos = []
    issue_num = 9884
    keywords = ['patch']
    message_count = 12.0
    messages = ['116649', '116847', '116851', '117927', '117940', '126698', '126710', '126711', '126712', '126714', '127093', '127676']
    nosy_count = 6.0
    nosy_names = ['theller', 'ghazel', 'ocean-city', 'cgohlke', 'owenl', 'stan.mihai']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue9884'
    versions = ['Python 3.1', 'Python 2.7']

    Activity

    1. owenl commented on Sep 17, 2010

      owenlmannequin
      MannequinAuthor

      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
    2. owenl commented on Sep 19, 2010

      owenlmannequin
      MannequinAuthor

      Please reproduce this issue by 64bit Python.

    3. owenl commented on Sep 19, 2010

      owenlmannequin
      MannequinAuthor

      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))
    4. ocean-city commented on Oct 3, 2010

      ocean-citymannequin
      Mannequin

      Probably this issue is duplicate of bpo-9266.

    5. ocean-city commented on Oct 4, 2010

      ocean-citymannequin
      Mannequin

      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.

    6. owenl commented on Jan 21, 2011

      owenlmannequin
      MannequinAuthor

      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?

    7. cgohlke commented on Jan 21, 2011

      cgohlkemannequin
      Mannequin

      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.

    8. owenl commented on Jan 21, 2011

      owenlmannequin
      MannequinAuthor

      yes, I tried lots of types. The issue still happens. The same case in Ubuntu and Mac were works well.

    9. cgohlke commented on Jan 21, 2011

      cgohlkemannequin
      Mannequin

      The patch attached to bpo-8275 fixes this issue and possibly also bpo-9266.

      Tested with Python 2.7.1 64 bit on Windows 7.

    10. owenl commented on Jan 21, 2011

      owenlmannequin
      MannequinAuthor

      wow~~~ It works on my PC too (Windows 2003 STD x64). Thanks.

    11. stanmihai commented on Jan 26, 2011

      stanmihaimannequin
      Mannequin

      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.

    12. owenl commented on Feb 1, 2011

      owenlmannequin
      MannequinAuthor

      Thanks, this issue has been fixed. :-)
      fixing revisions:
      r88284 (3.2), r88285 (3.1) and r88286 (2.7)

    13. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      OS-windowstype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions