> < ^ Date: Mon, 29 May 1995 11:43:00 +0100
> < ^ From: Burkhard Hoefling <b.hoefling@tu-bs.de >
^ Subject: Compiling GAP 3.4.2 on the Apple Macintosh

Dear GAP forum,

although not yet officially announced, the distribution of GAP 3.4.2
contains an almost working port of GAP for the Apple Macintosh with
the Symantec Think C / C++ compilers, based on the Macintosh port I
sent to Aachen at the end of last year (which, in turn, relies in
part on the MPW port by Dave Bayer). This Macintosh port fixes some
of the problems with the MPW port. In particular, it offers command
line editing as described in the manual, or, alternatively, a Mac-like
user interface which allows copying and pasting from/to other
applications. Also, it can handle more than 8 Megabyte of workspace
and allows to run GAP in the background.

Unfortunately, some bugs have crept into the Symantec C port, as
distributed with GAP 3.4.2, so I will briefly describe how to fix
them and how to compile GAP 3.4.2 with the Symantec C++ 7.0 compiler.

Note that unzoo *is* available for the Macintosh ( Dave Bayer's version
is in the GAP 3.4.1 distribution; on the Aachen server ftp.math.rwth-aachen.de
, it is in the directory pub/gap-3.4/bin).

If you have any questions, bug reports or suggestions, please don't
hesitate to contact me. I would also like to know who is really
interested in a Macintosh port of GAP, in order to find out whether it
is worth while spending too much time on improvements.

Burkhard H"ofling, University of Mainz, Germany
(e-mail: hoefling@mat.mathematik.uni-mainz.de).

1. Code overflow error
======================

If you compile GAP, you will get a code overflow error when compiling
the file COSTAB.C. This is due to the size of the variables dedgen
and dedcos, defined in COSTAB.C. My solution, part of which has
already been incorporated into the file SYSTEM.C, is to allocate
these variables on the system heap. In order to do this, the file
COSTAB.C has to be modified as follows: Change the lines

static long           dedgen [40960];   /* deduction list keeping gens     */
static long           dedcos [40960];   /* deduction list keeping cosets   */
static long           dedSize = 40960;  /* size of deduction list buffers  */

to:

#ifdef SYS_IS_MAC_SYC
extern long * dedgen, * dedcos, dedSize;
#else
static long           dedgen [40960];   /* deduction list keeping gens     */
static long           dedcos [40960];   /* deduction list keeping cosets   */
static long           dedSize = 40960;  /* size of deduction list buffers  */
#endif

With this modification, you should be able to compile and run GAP
successfully.

2. Memory allocation
====================

If GAP tries to allocate more workspace than is available, the system
crashes. This can be fixed as follows. Find SyGetmem for the Mac with
Symantec C, then change the lines

if ( syWorkspace == 0 ) {
    syWorkspace = (char*)NewPtr( size + 3 );
    syWorkspace = (char*)(((long)syWorkspace + 3) & ~3);
    memset( syWorkspace, 0, size );

to

if ( syWorkspace == 0 ) {
    syWorkspace = (char*)NewPtr( size + 3 );
    if (syWorkspace == 0)
       return (char*)-1;
    syWorkspace = (char*)(((long)syWorkspace + 3) & ~3);
    memset( syWorkspace, 0, size );

Be sure you change the right version of SyGetmem, since the MPW port
for the Mac looks very similar (and probably contains the same bug).
In my opinion, the MPW version contains another bug: it does not clear
the workspace, which will confuse Gasman).

3. Power Macintosh compatibility
================================

For all those who might try to compile GAP as a native program for the
Power Macintosh, I would like to mention that the port distributed
from Aachen contains a direct reference to a low-memory global
variable at 0x016A (which does not exist on the Power Mac). As a
consequence, you might not be able to interrupt a native version of
GAP. To avoid this problem, in the code for the procedure SyIsIntr in
the file SYSTEM.C, the expression

(*(long*)0x016A)

should be replaced by

LMGetTicks()

(there are four references to 0x016A in SyIsIntr).

4. Cutting and pasting
======================

Sometimes, it is convenient to use the -n switch on the Macintosh. On
the one side, this disables GAP's command line editing and also the
history function. On the other side, with the -n option on, cutting and
pasting are activated. There is only one problem with the new port: if
GAP detects a user interrupt (CMD-. key) during line editing, GAP
quits. The reason is that an i/o error is signalled, which GAP
interprets as an EOF and aborts. Unfortunately, this cannot be
intercepted by the interrupt signal procedure. This makes the
following fixes necessary. The following changes in SyFgets (in the
file SYSTEM.C) solve the problem:

Change the lines

#if SYS_MAC_SYC
extern  int             syGetch2   P(( long fid, int cur ));
#endif

to

#if SYS_MAC_SYC
extern  int             syGetch2   P(( long fid, int cur ));
#include <errno.h>
#endif

and replace

/* no line editing if the user disabled it                             */
if ( syLineEdit == 0 ) {
    syStopTime = SyTime();
    p = fgets( line, (int)length, syBuf[fid].fp );
    syStartTime += SyTime() - syStopTime;
    return p;
}

by the lines

    /* no line editing if the user disabled it                             */
    if ( syLineEdit == 0 ) {
        syStopTime = SyTime();
#if SYS_MAC_SYC
                   errno = 0;
           p = fgets( line, (int)length, syBuf[fid].fp );
           if (errno == EINTR) {
              line[0] = '\n';
              line[1] = '\0';
              p = line;
           }
#else
        p = fgets( line, (int)length, syBuf[fid].fp );
#endif
        syStartTime += SyTime() - syStopTime;
        return p;
    }

The procedures SyAnswerInt and SyIsIntr should be replaced by the
following:

void            syAnswerIntr ( signr )
    int                 signr;
{
    /* reinstall the signal handler                                        */
    signal( SIGINT, &syAnswerIntr );
    syIsIntr = true;

}


long            SyIsIntr ()
{
    struct QHdr *       queue;
    struct EvQEl *      qentry;
    EventRecord         theEvent;

/* don't check for interrupts every time 'SyIsIntr' is called */
if ( LMGetTicks() <= syIsIntrCount )
return 0;
syIsIntrCount = LMGetTicks() + syIsIntrFreq;

/* allow for system activities                                         */
if ( syIsBackCount < LMGetTicks() ) {
    syIsBackCount = LMGetTicks() + syIsBackFreq;
    SystemTask();
    SEvtEnb = false;
    GetNextEvent( activMask, &theEvent );
}

/* look through the event queue for <command>-'.' or <control>-'C'     */
queue = GetEvQHdr();
qentry = (struct EvQEl *)(queue->qHead);
while ( qentry ) {
    if ( qentry->evtQWhat == keyDown
        &&   ( ((qentry->evtQModifiers & controlKey) != 0)
            && ((qentry->evtQMessage & charCodeMask) ==   3))
          || ( ((qentry->evtQModifiers & cmdKey    ) != 0)
            && ((qentry->evtQMessage & charCodeMask) == '.')) ) {
        syIsIntr = true;
    }
    qentry = (struct EvQEl *)(qentry->qLink);
}
    /* flush away all keyboard events after an interrupt                   */
    if ( syIsIntr ) {
        FlushEvents( keyDownMask, 0 );
        syIsIntr = false;
        return true;
    }
    else
        return false;
}

#endif

This also includes the Power Macintosh fix that I have described
in Section 2 above.

5. Compiling GAP using a Symantec compiler
==========================================

Here are the necessary steps to compile GAP with the Symantec C++ 7.0
compiler (other Symantec Compilers, such as Think C 6.0, should be
similar). Unless you have upgraded to Symantec C++ v.7.04, do *not*
use the code motion global optimization, because there seems to be a
bug in C++ v.7.00! (but do use the other optimizations).

GAP has to be compiled with the 4 byte ints option on, so make copies
of the ANSI and Unix libraries and recompile them using this option,
as described in the C++ manual.

Now create a new project (empty project) and remove main.c from the
project window. Then choose 'Add files' from the source window and
add the modified ANSI Unix libraries to the project. Then click ANSI
settings in the Think C language options; after that select the
Think C language extensions.

In the prefix dialog (prefix dialog in the Think C options), delete
the line #include <MacHeaders.h> and any other contents, and add the
line

#define SYS_IS_MAC_SYC

Finally, choose 'Set project type ...' from the project menu. Set the
partition size to 5120K and the Size flags to 1880. Then click Far
Data and Separate Strings. Now you are ready to compile GAP.


> < [top]