> < ^ Date: Mon, 04 Oct 1993 20:07:42 +0100
> < ^ From: Martin Schoenert <martin.schoenert@math.rwth-aachen.de >
^ Subject: GAP under HP-UX 9.01

A while ago Donald White reported that GAP compiled on a HP 9000/730
workstation under HP-UX 9.0 did not work. At that time the bug could not
be found (the problem was solved by taking an executable compiled under
HP-UX 8.07 which worked fine under HP-UX 9.0).

Now I received the following e-mail, which I forward for those using GAP
under HP-UX 9.0. I would like to point out that this workaround will be
available in GAP 3.3 shortly. Also I would like to point out that the
problem is really a bug in the C compiler, not sloppy programming in GAP
(not that there isn't enough of that in GAP ;-).

Martin.

-- .- .-. - .. -.  .-.. --- ...- . ...  .- -. -. .. -.- .-
Martin Sch"onert,   Martin.Schoenert@Math.RWTH-Aachen.DE,   +49 241 804551
Lehrstuhl D f"ur Mathematik, Templergraben 64, RWTH, 52056 Aachen, Germany

Forwarded e-mail from valentin@venus.isa.cie.uva.es of 1993/09/30:

PROBLEM : Possible C compiler bug in HP-UX 9.01.
MACHINE : HP9000 Series 700 / 735.
HOSTNAME: venus.isa.cie.uva.es
IPADDR  : 157.88.109.254
OS      : HP-UX 9.01
COMPILER: HP-UX 9.01 C Compiler

DESCRIPTION FOLLOWS:

Gap3.2 got made at first step with no compilation errors when
using Gap3.2 distribution stored in ftp.csc.liv.ac.uk (/hpux9/Math/Gap...)
but when I run the program, it showed the very well known
'Memory fault(coredump)' message (which appears to be the only one
in UNIX, by the way).

Going into the details of the problem, I went into the file gasman.c
and discovered that an apparently inocuous sentence was the one
to blame for the dumping. I include the original code and the
correction I made to have things working.

--------------- BEGIN OF ORIGINAL CODE (gasman.c) -------------
1121 void            InitGasman ()
1122 {
1123     /* first get some memory from the operating system                    */
1124     if ( SyMemory < 32 * 1024 )  SyMemory = 32 * 1024;
1125     SyMemory = (SyMemory + 1023) & ~1023;
1126     HdFree = (TypHandle)SyGetmem( SyMemory );
1127     if ( HdFree == (TypHandle)-1 ) {
1128         SyFputs("Gasman: can not get memory for the initial workspace.\n",3);
1129         SyExit( 1 );
1130     }
1131
1132     /* the free bag initialy ocupies three quarter of the memory */
1133     HdFree->type = T_FREEBAG;
1134     HdFree->size = (3 * SyMemory / 4 - SIZE_HD) & ~(SIZE_HD-1);

1135     HdFree->ptr  = (TypHandle*)((char*)HdFree + SyMemory - HdFree->size);
^^^^^^^^^^^^^^^^^^^^^^^^ COMPILER CANNOT HANDLE THIS CORRECTLY ^^^^^^^^^^^^^^

1136     PTR(HdFree)[-1] = HdFree;
--------------- END OF ORIGINAL CODE (gasman.c) ---------------

--------------- BEGIN OF CORRECTED CODE (gasman.c) -------------
1121 void            InitGasman ()
1122 {
1123     /* first get some memory from the operating system                     */
1124     if ( SyMemory < 32 * 1024 )  SyMemory = 32 * 1024;
1125     SyMemory = (SyMemory + 1023) & ~1023;
1126     HdFree = (TypHandle)SyGetmem( SyMemory );
1127     if ( HdFree == (TypHandle)-1 ) {
1128         SyFputs("Gasman: can not get memory for the initial workspace.\n",3);
1129         SyExit( 1 );
1130     }
1131
1132     /* the free bag initialy ocupies three quarter of the memory */
1133     HdFree->type = T_FREEBAG;
1134     HdFree->size = (3 * SyMemory / 4 - SIZE_HD) & ~(SIZE_HD-1);

1135     HdFree->ptr  = (TypHandle*)((char*)HdFree + (SyMemory - HdFree->size));
^^^^^^^^^^^^^^^^^^^^^^^^ COMPILER HANDLES THIS CORRECTLY (NOTE THE ()'s ) ^^^^^

1136     PTR(HdFree)[-1] = HdFree;
--------------- END OF CORRECTED CODE (gasman.c) ---------------

So, it might be you are interested in adding the pair of parenthesis
in future releases, just to make sure that no stupid compiler is going
to misunderstand the code. I know it sounds crazy, but I suggest you
test the following example if you have a machine like mine at hand in order
to understand why I am so angry.

--------------- BEGIN OF EXAMPLE SHOWING THE BUG --------------
/*
** Prueba del compilador C de HP-UX 9.01
**
** ASUNTO: Aritmetica de punteros incorrecta??
**
** COMPILE: cc [-Aa -D_HPUX_SOURCE] pointer.c -o pointer
*/

typedef unsigned long ulong;

extern
 char   *sbrk() ;

char    *p1 ;
long     n2 = 100L ;    /* To reproduce Gap example */
ulong    n3 = 50L ;     /* To reproduce Gap example */

main()
{
        p1 = sbrk(0) ;  /* Could be any other reasonable thing */
        printf("p1 = 0x%8.8lx\n", p1);
        printf("n2 = 0x%8.8lx\n", n2);
        printf("n3 = 0x%8.8lx\n", n3);
        printf("(p1 +  n2 - n3 ) = 0x%8.8lx\n", p1 + n2 - n3);
        printf("(p1 + (n2 - n3)) = 0x%8.8lx\n", p1 + (n2 - n3));
}
--------------- END OF EXAMPLE SHOWING THE BUG --------------

Anyway I'm not an expert on standarizarion of C, but I couldn't find
any reference telling that this problem shouldn't be avoided in
any C compiler (specially a commercial one). In fact, I tested the
latter examples using GNU C 2.4.5 and it worked out with them
perfectly.


> < [top]