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.

classification
Title: FAIL: test_longdouble (ctypes.test.test_callbacks.Callbacks) [SPARC/64-bit]
Type: behavior Stage: resolved
Components: ctypes Versions: Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: JohnsonCW, illumino, iritkatriel, jcea, jengelh, mark.dickinson, terry.reedy, theller
Priority: normal Keywords: patch

Created on 2009-05-15 08:49 by illumino, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
sparc_longdouble.patch JohnsonCW, 2009-05-21 20:25 Patch for SPARC64 c_longdouble handling
Messages (12)
msg87798 - (view) Author: Peter Bray (illumino) Date: 2009-05-15 08:49
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
msg87842 - (view) Author: Clifford W Johnson (JohnsonCW) Date: 2009-05-15 21:59
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)
msg88136 - (view) Author: Clifford W Johnson (JohnsonCW) Date: 2009-05-20 20:10
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)
msg88165 - (view) Author: Clifford W Johnson (JohnsonCW) Date: 2009-05-21 20:25
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.
msg90838 - (view) Author: Peter Bray (illumino) Date: 2009-07-23 05:31
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.
msg109111 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-07-02 13:47
Closed issue 9143 as a duplicate of this one.
msg221655 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-06-26 22:47
I believe this can be closed as a very similar change was done in r59626.
msg226127 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-08-30 08:07
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?
msg226130 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-08-30 09:00
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.
msg226135 - (view) Author: Peter Bray (illumino) Date: 2014-08-30 10:52
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
msg396096 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-18 21:25
The patch doesn't look anything like the current code. Is this issue still relevant?
msg396105 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-06-18 22:40
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.
History
Date User Action Args
2022-04-11 14:56:48adminsetgithub: 50279
2021-06-18 22:40:32terry.reedysetstatus: open -> closed

nosy: + jcea
messages: + msg396105

resolution: out of date
stage: resolved
2021-06-18 21:25:50iritkatrielsetnosy: + iritkatriel
messages: + msg396096
2019-04-26 20:32:29BreamoreBoysetnosy: - BreamoreBoy
2014-08-30 10:52:10illuminosetmessages: + msg226135
components: - Tests
2014-08-30 09:00:14BreamoreBoysetmessages: + msg226130
2014-08-30 08:07:18terry.reedysetversions: - Python 3.1
nosy: + terry.reedy

messages: + msg226127

assignee: theller ->
2014-06-26 22:47:43BreamoreBoysetnosy: + BreamoreBoy
messages: + msg221655
2010-08-05 00:45:36terry.reedysetversions: + Python 2.7, - Python 2.6
2010-07-02 13:47:03mark.dickinsonsetnosy: + mark.dickinson, jengelh
messages: + msg109111
2010-07-02 13:46:44mark.dickinsonlinkissue9143 superseder
2009-07-23 05:31:06illuminosetmessages: + msg90838
2009-05-21 20:25:08JohnsonCWsetfiles: + sparc_longdouble.patch
keywords: + patch
messages: + msg88165
2009-05-20 20:10:36JohnsonCWsetmessages: + msg88136
versions: + Python 2.6
2009-05-15 21:59:36JohnsonCWsetmessages: + msg87842
2009-05-15 21:37:50JohnsonCWsetnosy: + JohnsonCW
2009-05-15 08:49:07illuminocreate