Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FAIL: test_longdouble (ctypes.test.test_callbacks.Callbacks) [SPARC/64-bit] #50279

Closed
illumino mannequin opened this issue May 15, 2009 · 12 comments
Closed

FAIL: test_longdouble (ctypes.test.test_callbacks.Callbacks) [SPARC/64-bit] #50279

illumino mannequin opened this issue May 15, 2009 · 12 comments
Labels
topic-ctypes type-bug An unexpected behavior, bug, or error

Comments

@illumino
Copy link
Mannequin

illumino mannequin commented May 15, 2009

BPO 6029
Nosy @theller, @terryjreedy, @jcea, @mdickinson, @iritkatriel
Files
  • sparc_longdouble.patch: Patch for SPARC64 c_longdouble handling
  • 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 2021-06-18.22:40:32.553>
    created_at = <Date 2009-05-15.08:49:07.522>
    labels = ['ctypes', 'type-bug']
    title = 'FAIL: test_longdouble (ctypes.test.test_callbacks.Callbacks) [SPARC/64-bit]'
    updated_at = <Date 2021-06-18.22:40:32.551>
    user = 'https://bugs.python.org/illumino'

    bugs.python.org fields:

    activity = <Date 2021-06-18.22:40:32.551>
    actor = 'terry.reedy'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-06-18.22:40:32.553>
    closer = 'terry.reedy'
    components = ['ctypes']
    creation = <Date 2009-05-15.08:49:07.522>
    creator = 'illumino'
    dependencies = []
    files = ['14037']
    hgrepos = []
    issue_num = 6029
    keywords = ['patch']
    message_count = 12.0
    messages = ['87798', '87842', '88136', '88165', '90838', '109111', '221655', '226127', '226130', '226135', '396096', '396105']
    nosy_count = 8.0
    nosy_names = ['theller', 'terry.reedy', 'jcea', 'mark.dickinson', 'illumino', 'JohnsonCW', 'jengelh', 'iritkatriel']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue6029'
    versions = ['Python 2.7']

    @illumino
    Copy link
    Mannequin Author

    illumino mannequin commented May 15, 2009

    Greetings,

    I have downloaded and compiled Python 3.1b1 on Solaris 10 Update 6
    with GCC 4.1.2 on {SPARC,x86} x {32-bit,64-bit} and encountered only one
    test harness failure, which was on SPARC 64-bit.

    Included below are the initial details, is there something more I can
    do to assist, if so, please be specific.

    Regards,
    Peter

    ./python Lib/test/regrtest.py -v test_ctypes

    ======================================================================
    FAIL: test_longdouble (ctypes.test.test_callbacks.Callbacks)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/tmp/64-bit/Python-3.1b1/Lib/ctypes/test/test_callbacks.py",
    line 81, in test_longdouble
        self.check_type(c_longdouble, 3.14)
      File "/tmp/64-bit/Python-3.1b1/Lib/ctypes/test/test_callbacks.py",
    line 30, in check_type
        self.failUnlessEqual(self.got_args, (-3, arg))
    AssertionError: First differing element 1:
    0.0
    3.14
    - (-3, 0.0)
    + (-3, 3.14)

    Ran 328 tests in 3.853s

    FAILED (failures=1)
    test test_ctypes failed -- Traceback (most recent call last):
      File "/tmp/64-bit/Python-3.1b1/Lib/ctypes/test/test_callbacks.py",
    line 81, in test_longdouble
        self.check_type(c_longdouble, 3.14)
      File "/tmp/64-bit/Python-3.1b1/Lib/ctypes/test/test_callbacks.py",
    line 30, in check_type
        self.failUnlessEqual(self.got_args, (-3, arg))
    AssertionError: First differing element 1:
    0.0
    3.14
    - (-3, 0.0)
    + (-3, 3.14)

    1 test failed:
    test_ctypes

    The test code (from Python-3.1b1/Lib/ctypes/test/test_callbacks.py)

    79  
    80      def test_longdouble(self):
    81          self.check_type(c_longdouble, 3.14)
    82          self.check_type(c_longdouble, -3.14)
    83  
    

    and ealier in the same file

    11  
    12      def callback(self, \*args):
    13          self.got_args = args
    14          return args[-1]
    15  
    16      def check_type(self, typ, arg):
    17          PROTO = self.functype.\_\_func__(typ, typ)
    18          result = PROTO(self.callback)(arg)
    19          if typ == c_float:
    20              self.failUnlessAlmostEqual(result, arg, places=5)
    21          else:
    22              self.failUnlessEqual(self.got_args, (arg,))
    23              self.failUnlessEqual(result, arg)
    24  
    25          PROTO = self.functype.\_\_func__(typ, c_byte, typ)
    26          result = PROTO(self.callback)(-3, arg)
    27          if typ == c_float:
    28              self.failUnlessAlmostEqual(result, arg, places=5)
    29          else:
    30              self.failUnlessEqual(self.got_args, (-3, arg))
    31              self.failUnlessEqual(result, arg)
    32  
    

    [software@specula] 64-bit SPARC % gcc -v
    Using built-in specs.
    Target: sparc64-sun-solaris2.10
    Configured with: ../configure --prefix=/pkgs/64-bit/release/gcc-4.1.2
    --with-local-prefix=/pkgs/64-bit --disable-nls --disable-multilib
    --enable-shared --with-as=/usr/ccs/bin/as --without-gnu-as
    --with-ld=/usr/ccs/bin/ld --without-gnu-ld --with-gmp=/pkgs/64-bit
    --with-mpfr=/pkgs/64-bit --enable-languages=c,c++,objc,obj-c++,fortran
    sparc64-sun-solaris2.10
    Thread model: posix
    gcc version 4.1.2

    [software@specula] 64-bit SPARC % cat /etc/release
    Solaris 10 10/08 s10s_u6wos_07b SPARC
    Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
    Use is subject to license terms.
    Assembled 27 October 2008

    Build Procedure
    ---------------

    Python 3.1b1

    ## Note PKGS_PREFIX=/pkgs/64-bit and PKGS_RELEASE=/pkgs/64-bit/release

    gtar fxv <path>/Python-3.1b1.tar.bz2
    cd Python-3.1b1

    # The CPPFLAGS & LDFLAGS are used by setup.py in external modules builds
    CPPFLAGS="-I${PKGS_PREFIX}/include" LDFLAGS="-L${PKGS_PREFIX}/lib"
    ./configure --prefix=${PKGS_RELEASE}/Python-3.1b1
    --datarootdir=${PKGS_RELEASE}/Python-3.1b1 --with-universal-archs=64-bit

    echo "crypt cryptmodule.c" >> Modules/Setup.local ## Solaris does not
    need -lcrypt

    gmake
    gmake test

    @illumino illumino mannequin assigned theller May 15, 2009
    @illumino illumino mannequin added tests Tests in the Lib/test dir topic-ctypes type-bug An unexpected behavior, bug, or error labels May 15, 2009
    @JohnsonCW
    Copy link
    Mannequin

    JohnsonCW mannequin commented May 15, 2009

    I get a nearly identical failure building Python 2.6.2 on a SPARC64
    machine running Solaris 5.10 using GCC 4.1.1.

    # ./python ./Lib/test/test_ctypes.py
    ...
    test_longdouble (ctypes.test.test_callbacks.Callbacks) ... FAIL
    ...

    ======================================================================
    FAIL: test_longdouble (ctypes.test.test_callbacks.Callbacks)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File
    "/home/build/clifford/gpdb/tools/python/2.6.2/objs/sol10_sparc_64/Lib/ctypes/test/test_callbacks.py",
    line 81, in test_longdouble
        self.check_type(c_longdouble, 3.14)
      File
    "/home/build/clifford/gpdb/tools/python/2.6.2/objs/sol10_sparc_64/Lib/ctypes/test/test_callbacks.py",
    line 30, in check_type
        self.failUnlessEqual(self.got_args, (-3, arg))
    AssertionError: (-3, 0.0) != (-3, 3.1400000000000001)

    Ran 319 tests in 1.951s

    FAILED (failures=1)
    Traceback (most recent call last):
      File "./Lib/test/test_ctypes.py", line 12, in <module>
        test_main()
      File "./Lib/test/test_ctypes.py", line 9, in test_main
        run_unittest(unittest.TestSuite(suites))
      File
    "/home/build/clifford/gpdb/tools/python/2.6.2/objs/sol10_sparc_64/Lib/test/test_support.py",
    line 722, in run_unittest
        _run_suite(suite)
      File
    "/home/build/clifford/gpdb/tools/python/2.6.2/objs/sol10_sparc_64/Lib/test/test_support.py",
    line 705, in _run_suite
        raise TestFailed(err)
    test.test_support.TestFailed: Traceback (most recent call last):
      File
    "/home/build/clifford/gpdb/tools/python/2.6.2/objs/sol10_sparc_64/Lib/ctypes/test/test_callbacks.py",
    line 81, in test_longdouble
        self.check_type(c_longdouble, 3.14)
      File
    "/home/build/clifford/gpdb/tools/python/2.6.2/objs/sol10_sparc_64/Lib/ctypes/test/test_callbacks.py",
    line 30, in check_type
        self.failUnlessEqual(self.got_args, (-3, arg))
    AssertionError: (-3, 0.0) != (-3, 3.1400000000000001)

    @JohnsonCW
    Copy link
    Mannequin

    JohnsonCW mannequin commented May 20, 2009

    The following script (based on an extract of test_callbacks.py)
    demonstrates the problem. When run on a Sparc-based Solaris 10
    platform, the output shows correct operation only when the c_longdouble
    arguments appear first in the function call -- the use of other types
    would seem to throw off argument alignment.

    Could this be an issue with libffi?

    #!/bin/env python

    import sys
    from ctypes import *
    
    
    class Callback:
        functype = CFUNCTYPE
    
        def callback(self, *args):
            self.got_args = args
            return args[-1]
    
        def check_type(self, typ, arg):
            print "typ=%s" % (typ,)
        print "Trying (typ) ..."
        PROTO = self.functype.im_func(typ, typ)
        result = PROTO(self.callback)(arg)
        print "    %s result=%s; got_args=%r" % ("\*FAILED*" if result !=
    

    3.14 else "WORKED", result, self.got_args)

        print "Trying (c_byte, typ) ..."
        PROTO = self.functype.im_func(typ, c_byte, typ)
        result = PROTO(self.callback)(-3, arg)
        print "    %s result=%s; got_args=%r" % ("\*FAILED*" if result !=
    

    3.14 else "WORKED", result, self.got_args)

        print "Trying (typ, c_byte) ..."
        PROTO = self.functype.im_func(typ, typ, c_byte)
        result = PROTO(self.callback)(arg, -3)
        print "    %s result=%s; got_args=%r" % ("\*FAILED*" if result !=
    

    3.14 else "WORKED", result, self.got_args)

        print "Trying (c_byte, typ, typ) ..."
        PROTO = self.functype.im_func(typ, c_byte, typ, typ)
        result = PROTO(self.callback)(-3, arg, arg)
        print "    %s result=%s; got_args=%r" % ("\*FAILED*" if result !=
    

    3.14 else "WORKED", result, self.got_args)

        print "Trying (typ, typ) ..."
        PROTO = self.functype.im_func(typ, typ, typ)
        result = PROTO(self.callback)(arg, arg)
        print "    %s result=%s; got_args=%r" % ("\*FAILED*" if result !=
    

    3.14 else "WORKED", result, self.got_args)

        print "Trying (c_double, typ) ..."
        PROTO = self.functype.im_func(typ, c_double, typ)
        result = PROTO(self.callback)(arg, arg)
        print "    %s result=%s; got_args=%r" % ("\*FAILED*" if result !=
    

    3.14 else "WORKED", result, self.got_args)

        print "trying (c_int, typ) ..."
        PROTO = self.functype.im_func(typ, c_int, typ)
        result = PROTO(self.callback)(-3, arg)
        print "    %s result=%s; got_args=%r" % ("\*FAILED*" if result !=
    

    3.14 else "WORKED", result, self.got_args)

        print "trying (c_long, typ) ..."
        PROTO = self.functype.im_func(typ, c_long, typ)
        result = PROTO(self.callback)(-3, arg)
        print "    %s result=%s; got_args=%r" % ("\*FAILED*" if result !=
    

    3.14 else "WORKED", result, self.got_args)

        print "trying (c_longlong, typ) ..."
        PROTO = self.functype.im_func(typ, c_longlong, typ)
        result = PROTO(self.callback)(-3, arg)
        print "    %s result=%s; got_args=%r" % ("\*FAILED*" if result !=
    

    3.14 else "WORKED", result, self.got_args)

    callback = Callback()
    callback.check_type(c_longdouble, 3.14)
    # callback.check_type(c_longdouble, -3.14)

    ./python ~/tryLongDouble.py
    typ=<class 'ctypes.c_longdouble'>
    Trying (typ) ...
    WORKED result=3.14; got_args=(3.1400000000000001,)
    Trying (c_byte, typ) ...
    *FAILED* result=0.0; got_args=(-3, 0.0)
    Trying (typ, c_byte) ...
    *FAILED* result=-3.0; got_args=(3.1400000000000001, -3)
    Trying (c_byte, typ, typ) ...
    *FAILED* result=-inf; got_args=(-3, nan, -inf)
    Trying (typ, typ) ...
    WORKED result=3.14; got_args=(3.1400000000000001, 3.1400000000000001)
    Trying (c_double, typ) ...
    *FAILED* result=0.0; got_args=(3.1400000000000001, 0.0)
    trying (c_int, typ) ...
    *FAILED* result=0.0; got_args=(-3, 0.0)
    trying (c_long, typ) ...
    *FAILED* result=0.0; got_args=(-3, 0.0)
    trying (c_longlong, typ) ...
    *FAILED* result=0.0; got_args=(-3, 0.0)

    @JohnsonCW
    Copy link
    Mannequin

    JohnsonCW mannequin commented May 21, 2009

    Turns out the problem is really in the Sparc version of libffi -- the
    ffi_closure_sparc_inner_v9 function in
    Modules/_ctypes/libffi/src/sparc/ffi.c wasn't properly accounting for
    the 16-byte alignment of a long double in an argument stack -- it
    presumed 8-byte alignment throwing off any long double value after a
    shorter value. (16-byte alignment is specified in the SPARC Compliance
    Definition.)

    I've attached a patch which I'm sure could be improved (there's
    probably a more proper way to do things in libffi) but it passes the
    check tests for ctypes and a few other tests I threw in.

    By the way, I noticed that one of the test cases in the script I added
    in my last comment has an error in its success/failure test ...
    the "(typ, c_byte)" test should check for the result of -3 instead of
    3.14.

    @illumino
    Copy link
    Mannequin Author

    illumino mannequin commented Jul 23, 2009

    Sorry for the internet lifetime I've been away.

    I have tested the patch provided against the released 3.1 distribution
    and all tests pass without coredumping or failing on Solaris 10 Update 6
    with gcc 4.1.2. The 3.1 distribution with the patch was built and tested
    on both 32-bit and 64-bit SPARC and X86.

    The patch was rejected by GNU patch, but applying by hand (copy/paste)
    worked fine against 3.1.

    Like the patch's author I can't say if this right approach to take, that
    is for others to say but it does not break any of my builds.

    Regards,
    Peter

    And sorry for the delay.

    @mdickinson
    Copy link
    Member

    Closed bpo-9143 as a duplicate of this one.

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jun 26, 2014

    I believe this can be closed as a very similar change was done in r59626.

    @terryjreedy
    Copy link
    Member

    Mark, the rev #s are not being translated correctly. Better to use the 10 digit hex #. Can you find the commit again?

    We have a SPARC Solaris 10 buildbot
    http://buildbot.python.org/all/waterfall?category=3.x.stable&category=3.x.unstable
    The ctypes test is passing on 'Open CSW' (I don't know what that means) 2.7 and 3.5. The test suite has not been run recently on GCC recently.

    Peter or Clifford, can either of you report current status?

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Aug 30, 2014

    Terry r59626 in the file's revision history refers to eefd521f19ce which I assume is what you're after. FWIW I get that on Windows 8.1 by right clicking on the file, select TortoiseHg, then Revision History.

    @illumino
    Copy link
    Mannequin Author

    illumino mannequin commented Aug 30, 2014

    Terry,

    I no longer have easy access to SPARC64 systems (they are in boxes), so
    unfortunately I will not be able to contribute to this issue in the near
    future.

    Peter

    @illumino illumino mannequin removed the tests Tests in the Lib/test dir label Aug 30, 2014
    @iritkatriel
    Copy link
    Member

    The patch doesn't look anything like the current code. Is this issue still relevant?

    @terryjreedy
    Copy link
    Member

    The 2014 patch to our copies of libffi eefd521f19ce included patches from 2009 forward, including at least one about long double alignment on sparc. If there are any problems now on current Solaris, they are likely to be different, and someone will find and report them.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-ctypes type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants