From: Hamish.Macdonald@x400gate.bnr.ca (Hamish Macdonald)
Subject: Lucid Emacs, HPUX, and bcopy/bzero
Organization: Bell Northern Research
Date: Wed, 14 Oct 92 18:05:36 GMT

Since first building Lucid Emacs, I have been seeing problems with
inferior processes.

When running programs within cmushell, I could not interrupt the
processes.  Also, I run gnuserv, and when I quit lemacs, the gnuserv
process did not die.

I finally got around to trying to debug what is going on.

It turns out that the "kill" in process-send-signal was failing, with
an ESRCH (no such process found).  This is when emacs is trying to
kill the entire process group by calling kill with the negated group
id.

When I first compiled Lucid Emacs, it failed linking with a million
unresolved references to bcopy and bzero.

I said, "No problem, I'll just link in /usr/lib/libBSD.a", to get the
bcopy/bzero from it.  Lucid emacs linked ok, and then ran fine other
than the problems above.

I suspect that my problem is that emacs calls setpgrp expecting the
SYSV semantics (since USG is defined in the s-hpux.h config file), but
the setpgrp linked in is the one in /usr/lib/libBSD.a which has the
BSD semantics.

I decided to get rid of /usr/lib/libBSD.a.  It was somewhat painful.
I managed to get rid of most of the bcopy/bzero references by changing
m-hp9000s300.h to include the following lines:

/* #ifdef HPUX_5 */
#define bcopy(a,b,s)	memcpy (b,a,s)
#define bzero(a,s)	memset (a,0,s)
#define bcmp		memcmp
/* #endif */

In the lucid m-hp9000s300.h file, the "#ifdef" and "#endif" above
are not commented out.

In the GNU emacs distribution lying around here (18.56) they are
commented out, with the following comment:

/* Define the BSTRING functions in terms of the sysV functions.
   Version 6 of HP-UX supplies these in the BSD library,
   but that library has reported bugs in `signal'.  */

This means that they had a good reason to have these definitions
compiled in.  I don't know if this was changed in the Lucid Emacs
distribution or in an Emacs distribution since 18.56.

By making these definitions active, I managed to get rid of most of
the problems with compiling Lucid Emacs without bcopy/bzero.

Unfortunately, there were a few places which didn't include
"config.h", so I had to fix those up by hand.

These places were gmalloc.c, and lwlib.c.

In gmalloc.c, they use memset, memcpy and memmove.  Unfortunately, if
neither __GNU_LIBRARY__, STDC_HEADERS nor USG are defined, they
#define memset to be bzero etc.

Since gmalloc.c didn't include config.h, it didn't get USG defined, so
the above definitions were active.

The fix in this case was to insert:
    #ifdef emacs
    #include "config.h"
    #endif
at the beginning of gmalloc.c.

The "EmacsShell.c" source file calls bcopy at one point.  I added a
#define of bcopy to call memcpy to this file.

Unfortunately, lwlib.c calls bzero in a few places.  I changed
lwlib-internal.h to #define bzero(a,s) as memset(a,0,s) if __hpux was
defined.  I didn't like to have to do this hack, however.

I find it ironic that we are told that we need an ANSI compiler to
compile Lucid Emacs, but the source (especially the new source,
EmacsShell.c and lwlib.c, which don't come from emacs) uses this
non-ANSI bzero and bcopy routines when an ANSI programming environment
will have the ANSI routines memcpy and memset available.

Perhaps lwlib.c and EmacsShell.c should be changed to use the memset
and memcpy routines rather than bzero and bcopy.  I would imagine that
the number of programming environments without the b* routines greatly
outnumbers those without the mem* routines.

I recommend that some/all of the changes I've described above be
included in the Lucid Emacs source distribution.

These are:

1) Change m-hp9000s300.h to #define bcopy/bzero/bcmp as
   memcpy/memset/memcmp.

2) Change gmalloc.c to include "config.h" if compiling emacs (or find
   some other solution to having gmalloc.c use memset and memcpy).

3) Modify the EmacsShell.c source to avoid the use of bcopy.

4) Modify the lwlib sources to avoid the use of bzero.


You'll be happy to know that after doing all this and
compiling/linking/dumping Lucid emacs, I now have a lemacs which
properly handles subprocesses.  The gnuserv process correctly dies
when I quit emacs, and I can interrupt processes running under my
shell.
Newsgroups: alt.lucid-emacs.bug