#1661 logic of matherr is backwards

obsolete: 8.4a4
closed-fixed
Don Porter
5
2002-05-31
2001-10-24
Don Porter
No

A simple look at the cvs history of
unix/tclMtherr.c shows the introduction of
a bug:

cvs diff -r core-8-0-5 -r core-8-1-0 tclMtherr.c
...
matherr(xPtr)
struct exception *xPtr; /* Describes error that
occurred. */
{
- if (!tcl_MathInProgress) {
+ if (TclMathInProgress()) {
return 0;
...

The "!" did not survive the transition from
access of a global variable to call of an internal
function. The logic of matherr() became reversed.
The obvious fix is to restore the proper logic.

It's worth pausing though and asking why this
bug hasn't been noticed in the 3 years since it
was introduced. I am unable to come up with
any script on any platform that exposes this error.

It seems that Tcl behaves the same whether the
logic is forwards or backwards.
It would seem then that Tcl would also behave the
same if the logic were completely removed. I welcome
second opinions on this, but my inclination would
be to remove the matherr() routine altogether
unless someone can demonstrate it's serving a
useful purpose somewhere. (And how useful can
it be if it's been wrong since Tcl 8.1.0 ?)

Discussion

1 2 > >> (Page 1 of 2)
  • Jeffrey Hobbs
    Jeffrey Hobbs
    2001-10-24

    Logged In: YES
    user_id=72656

    And note that win/tclWinMtherr.c actually has the correct !
    in that compat function. Note that it is a compat
    function. You'd like have to ask the older core guys
    (JohnO or Brian Lewis who did the original compiler)
    directly if/what meaning this had.

     
  • Jeffrey Hobbs
    Jeffrey Hobbs
    2001-10-24

    Logged In: YES
    user_id=72656

    Of course, the comments for the Windows version say only
    Borland C++ uses it. However, that should be verified, as
    that used to be the official compiler of the sources, and
    the comment may be incorrect.

     
  • Don Porter
    Don Porter
    2001-10-24

    Logged In: YES
    user_id=80530

    Agreed that second opinions from the old-timers
    will be very helpful.

    I also note, that matherr() and _matherr() are the
    only callers of TclMathInProgress() so if they go,
    so can that.

     
  • Mo DeJong
    Mo DeJong
    2002-01-11

    Logged In: YES
    user_id=90858

    I don't have anything useful to add, assigning this
    bug back to hobbs.

     
  • Mo DeJong
    Mo DeJong
    2002-01-11

    • assigned_to: mdejong --> hobbs
     
  • Joe English
    Joe English
    2002-01-16

    Logged In: YES
    user_id=68433

    On the Unices that I have available, 'matherr()' is only
    used if you statically link against a special library
    instead of the default -lm (IRIX: -lmx; AIX: -lmsaa; Linux
    (RH 6.2, 7.0,7.1,7.2, SuSE 6.2): apparently not supported).

    A google search shows that matherr is supported on HP-UX and
    a few others, but the default behaviour (set errno and
    continue) is exactly the same as what's in
    unix/tclMtherr.c, so the latter is redundant.

    It would appear that this is either unused or redundant on
    all Unix platforms, and can safely be removed (except for
    one problem, see below).

    In unix/tclAppInit.c the following should also be taken out:

    /*
    * The following variable is a special hack that is needed
    in order for
    * Sun shared libraries to be used for Tcl.
    */
    extern int matherr();
    int *tclDummyMathPtr = (int *) matherr;

    This bit of code has been around since Tcl 7.4, but has long
    since been rendered obsolete by Stubs and newer versions of
    SunOS.

    The only problem with removing unix/tclMtherr.c is that all
    the custom tclsh's and wishes out there that have retained
    the tclDummyMathPtr definition for cargo-cult reasons will
    fail to link on platforms that don't have matherr(). It's
    an easy fix -- just get rid of the definition -- so this
    probably isn't much of an issue.

     
  • Don Porter
    Don Porter
    2002-02-20

    • assigned_to: hobbs --> dgp
    • priority: 5 --> 7
     
  • Don Porter
    Don Porter
    2002-02-20

    Logged In: YES
    user_id=80530

    davgrvy, can you comment on whether the
    _matherr() function in win/tclWinMtherr.c
    is still needed by Borland compilers?

     
  • Don Porter
    Don Porter
    2002-02-20

    • assigned_to: dgp --> davygrvy
    • status: open --> pending
     
  • Don Porter
    Don Porter
    2002-02-21

    • status: pending --> open
     
1 2 > >> (Page 1 of 2)