Skip to content

ctypes: pass by value for structs broken on Cygwin/MinGW 64-bit #74538

Closed

Description

@embray
BPO 30353
Nosy @vsajip, @ned-deily, @embray, @eryksun, @zhangyangyu, @stratakis, @irushchyshyn
PRs
  • bpo-30353 Fix pass by value for structs on 64-bit Cygwin/MinGW #1559
  • [3.6] bpo-30353: Fix pass by value for structs on 64-bit Cygwin/MinGW (GH-1559) #5954
  • Files
  • arm64_build_log.txt
  • 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 2018-03-08.15:34:17.694>
    created_at = <Date 2017-05-12.16:19:48.894>
    labels = ['ctypes', 'type-bug', '3.7']
    title = 'ctypes: pass by value for structs broken on Cygwin/MinGW 64-bit'
    updated_at = <Date 2018-03-08.15:34:17.692>
    user = 'https://github.com/embray'

    bugs.python.org fields:

    activity = <Date 2018-03-08.15:34:17.692>
    actor = 'ned.deily'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-03-08.15:34:17.694>
    closer = 'ned.deily'
    components = ['ctypes']
    creation = <Date 2017-05-12.16:19:48.894>
    creator = 'erik.bray'
    dependencies = []
    files = ['46892']
    hgrepos = []
    issue_num = 30353
    keywords = ['patch']
    message_count = 14.0
    messages = ['293556', '293600', '293685', '293742', '293771', '293921', '294249', '294336', '294337', '294692', '295362', '295530', '313439', '313444']
    nosy_count = 7.0
    nosy_names = ['vinay.sajip', 'ned.deily', 'erik.bray', 'eryksun', 'xiang.zhang', 'cstratak', 'ishcherb']
    pr_nums = ['1559', '5954']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue30353'
    versions = ['Python 3.6', 'Python 3.7']

    Activity

    1. embray commented on May 12, 2017

      @embray
      ContributorAuthor

      The test ctypes.test.test_structures.StructureTestCase.test_pass_by_value fails on 64-bit Cygwin and MinGW using the system libffi with:

      ======================================================================
      FAIL: test_pass_by_value (ctypes.test.test_structures.StructureTestCase)
      ----------------------------------------------------------------------

      Traceback (most recent call last):
        File "/home/embray/src/python/cpython/Lib/ctypes/test/test_structures.py", line 416, in test_pass_by_value
          self.assertEqual(s.first, 0xdeadbeef)
      AssertionError: 195948557 != 3735928559

      It seems that libffi does not handle passing structs by value properly on those platforms as I explained here: libffi/libffi#305

      The upstream bug hasn't been confirmed yet by the libffi developers so I could be wrong, but I think this is fairly clearly broken there.

      I have a PR forthcoming to work around the issue.

    2. added
      type-bug
      on May 12, 2017
    3. zhangyangyu commented on May 13, 2017

      @zhangyangyu
      Member

      Looks same as bpo-29804.

    4. embray commented on May 15, 2017

      @embray
      ContributorAuthor

      Thanks for pointing that out. Indeed it's the same symptom, but slightly different cause. libffi has different implementations of its calling routines for different architectures/platforms depending on the machine architecture and calling conventions used. So this case is probably buggy for the arm64 implementation as well, as in bpo-29804.

      Off the top of my head I don't know a reliable way to check for this case, but this fix would work around the arm64 issue as well if I could check for that architecture easily at compile time.

    5. stratakis commented on May 15, 2017

      stratakismannequin
      Mannequin

      A 'defined(aarch64)' can be used for the arm64 arch. I will add it to your patch and test it on an arm64 machine to see if the test passes.

    6. irushchyshyn commented on May 16, 2017

      irushchyshynmannequin
      Mannequin

      I have added defined(__aarch64__) check to the if statement and tested the patch on arm64. The test passed.

      So could you please also add the check for defined(__aarch64__) to the pull request so that it fixes bpo-29804 as well?

    7. embray commented on May 18, 2017

      @embray
      ContributorAuthor

      Sure, thanks for pointing that out.

    8. embray commented on May 23, 2017

      @embray
      ContributorAuthor

      Iryna, I updated the pull request with a slightly updated fix. Could you confirm again, when you get a chance, that it works for arm64? Thanks.

    9. irushchyshyn commented on May 24, 2017

      irushchyshynmannequin
      Mannequin

      Thank you, Erik. I have applied your new patch, and ran another build on arm64. The tests passed. Attaching the build log for more information.

    10. embray commented on May 24, 2017

      @embray
      ContributorAuthor

      Thanks for checking!

    11. vsajip commented on May 29, 2017

      @vsajip
      Member

      Patch LGTM now, perhaps others will concur?

    12. vsajip commented on Jun 7, 2017

      @vsajip
      Member

      New changeset 9ba3aa4 by Vinay Sajip (Erik Bray) in branch 'master':
      bpo-30353: Fix pass by value for structs on 64-bit Cygwin/MinGW (GH-1559)
      9ba3aa4

    13. stratakis commented on Jun 9, 2017

      stratakismannequin
      Mannequin

      This bug affects also the 3.6 branch. Can the fix be backported?

    14. embray commented on Mar 8, 2018

      @embray
      ContributorAuthor

      This has a backport PR now for 3.6. Once that PR is merged I think we can close this as fixed.

    15. ned-deily commented on Mar 8, 2018

      @ned-deily
      Member

      New changeset 2f3ba27 by Ned Deily (Miss Islington (bot)) in branch '3.6':
      [3.6] bpo-30353: Fix pass by value for structs on 64-bit Cygwin/MinGW (GH-1559) (GH-5954)
      2f3ba27

    16. 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

      3.7 (EOL)topic-ctypestype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions