Subject: Postgres port to NeXT

From: Andreas F. Muller <[email-masked]>
Date: Sun, 29 Aug 93 22:46:18 +0200

Hi Paul,

from the traffic on the postgres mailing list I got the
impression that You are somehow the public relations manager
for the postgres project, so You are probably the person
that can help me to get my Postgres 4.1 port for the NeXT
running. At least You may be intersted about how things work
out.

So far I got the sources to compile and to link, there was
already a fair amount of hacking necessary to get this done.
I have taken some notes which may be of use to You because
they show some problems with the prototypes (incorrect
number of arguments, wrong arguments even in some places).
I will append the log at the end of this message. There may
be a lot of details You are not interested in: points where
an ANSI compiler complains.

So far I did the following: I have replacements for shared
memory, semaphores (a nice Mach server), the dynamic loader
(there is a good library, rld, that is included with NeXT
Mach), putenv (done using setenv from the bmake sources
[BTW, no problems to build bmake], there is nothing like
setenv in the NeXT's libraries). There is one source,
mcxt.c, on which cpp-precomp dumps core, but cc -E works
perfectly on it, and (g)cc can compile the output of cc -E.
I have replaced every occurrence of <varargs.h> by
<stdargs.h> calls (an ANSI compiler wants at least one
argument completely declared, (...) as an argument list is
unaceptable). Everything compiles now (with quite a few warnings,
but mostly types not matching exactly, probably innocuous),
and when I start postmaster, at least it doesn't dump core
or eat all CPU time. 

At this point I still have a little problem with the
semaphore server, which prevents me from really running
postgres, but I'm quite confident that this will be resolved
shortly. Unfortunately I don't have the disk space to
compile postgres with -g, the binaries would be 11MB each...

Here are some more specific questions:

1. When postgres allocates memory, does it in the end use
malloc, or does it do some nasty things with the brk (which
would not be portable to Mach)? I admit that I still don't
really see through the postgres sources yet.  I have
encountered this problem when porting ingres to NeXT, it
used it's own version of free that relied on the way free
is implemented in some Unices, but that's completely
incompatible with Mach.

2. in backend/catalog/index.c, he function
UpdateIndexPredicate calls cnfify with only one argument.
Should the second argument be "false"?

3. backend/parser/ylib.c, l. 576 calls MakeFunc with 2
arguments too many, probably 0 and LispNil. Is that correct?

4. backend/parser/gram.y, l.2063 calls lispCons with 3
arguments although it only has 2, which one is bogus? I've
set $1-1 temporarily, but does this make sense?

5. backend/planner/path/indxpath.c,
backend/planner/path/orindxpath.c,
backend/planner/util/pathnode.c call set_difference with 3
instead of 2 arguments, I have deleted the last argument
(LispNil) in these cases. Is that OK?

I would appreciate Your help on these points, in any
case, I will keep You informed of my progress. Best regards

				Andreas

------------------------------------------------------------
Dr. Andreas Mueller            <[email-masked]>
Mathematisches Institut der Uni           <[email-masked]>
Im Neuenheimer Feld 288             Wilhelm-Mayer-Strasse 10
D - 69120 Heidelberg                        D - 69181 Leimen
------------------------------------------------------------
Here comes my very unsystematic PortLog:

Porting Postgres to NeXT
========================

All file names are relative to the src directory.

* Makefile.global

NeXT cpp does not include headers specified with the format
#include "foo/bar/header.h" relative to the present working
directory, but rather relative to the directory where the
C source file resides. Adding -I. to the CFLAGS in the
makefile cures this problem.

Furthermore, our nonstandard shmem code is in
/usr/local/include/sys, so we add /usr/local/include to the
directories to be searched by the CPP.

* backend/nodes/Gen_accessors.sh

This script wants to use
#define _SHARP_ #
this doesn't work with the default settings, the traditional
flag must be given.

* backend/tmp/c.h

contains the macro
#define offsetof(type, field)	((long) &((type *)0)->field)
already defined on the NeXT, #undef it away to prevent
clash. Furthermore, there are non ANSI compatible declarations
of malloc and free. The #defines for TRUE and FALSE should not
be executed if these symbols are already known.

* backend/utils/log.h

The variable argument list in elog needs to be declared in a
more standard way.

* backend/utils/Gen_fmgrtab.sh

same problem with variable argument list. Furthermore, there is
a problem with values.h

* backend/access/valid.h
* backend/access/iqual.h
* backend/access/skey.h
* backend/access/atval.h
* backend/access/itup.h
* backend/access/tupdesc.h
* backend/access/genam.h
* backend/access/istrat.h
* backend/access/isop.h
* backend/access/xact.h
* backend/commands/command.h
* backend/executor/externs.h
* backend/access/newam.h
* backend/lib/index.h
* backend/catalog/indexing.h
* backend/catalog/pg_protos.h
* backend/parser/parse_query.h
* backend/planner/prepqual.h
* backend/nodes/primnodes.a.h
* backend/planner/costsize.h
* backend/planner/indxpath.h
* backend/planner/orindxpath.h
* backend/planner/setrefs.h
* backend/planner/indexnode.h
* backend/planner/pathnode.h
* backend/rewrite/locks.h
* backend/rules/prs2.h
* backend/storage/bufmgr.h
* backend/storage/bufpage.h
* backend/tmp/acl.h
* backend/tcop/dest.h
* backend/utils/adt/arrayfuncs.c
* backend/tmp/datum.h
* backend/utils/adt/datum.c
* backend/utils/geo-decls.h
* backend/utils/adt/geo-selfuncs.c
* backend/utils/adt/numutils.c
* backend/utils/builtins.h
* backend/utils/adt/selfuncs.c
* backend/utils/inval.h
* backend/utils/error/exec.h
* backend/utils/module.h
* backend/tmp/miscadmin.h
* backend/utils/mctx.h
* backend/utils/palloc.h
* backend/utils/pg_malloc.h
* backend/tmp/portal.h
* backend/access/tqual.h
* backend/postmaster/postmaster.c
* bin/monitor/monitor.c

problem with short argument in prototype (see chapter on
GCC troubleshooting in NeXT developer Documentation), only
the prototypes need to be adapted. This seems to be a very
common problem in these sources.

* backend/access/index/indexam.c

There seems to be a problem with gcc interpreting the Macros
GET_REL_PROCEDURE and GET_SCAN_PROCEDURE, probably some
clash with Objective-C ?

* backend/parser/ylib.c

l. 576 calls MakeFunc with 2 arguments too many, probably 0 and
LispNil.

* backend/lib/index.h

contains incorrect prototype for UpdateStats, UpdateIndexRelation

* backend/commands/copy.c

also needs to include backend/nodes/plannodes.h

* backend/planner/xfunc.h

the prototype for xfunc_in_stream was incorrect

* backend/executor/externs.h

incorrect prototype for ExecEvalFunc

* backend/lib/index.h
* backend/catalog/indexing.h

needs to include backend/nodes/execnodes.h

* backend/catalog/index.c

The function UpdateIndexPredicate calls cnfify with only one
argument. Should the second argument be "false"?

* backend/tmp/libpq.h

needs to include <netinet/in.h>

* backend/tmp/libpq-be.h

needs to include catalog/pg_attribute.h

* backend/libpq/auth.h l.43

wrong prototype of function be_recvauth, type of first argument
should be MsgType, not Msgtype.

* backend/parser/parse_query.h

l.18: typo in prototype for setup_tlist, last argument should be of
type ObjectId, not ObjectID. l.9: missing argument char optype in
function prototype make_op. l.25 bogus prototype for setup_tlist.

* backend/parser/parse_query.h

needs to include "nodes/primnodes.h"

* backend/parser/gram.y

l.2063 calls lispCons with 3 arguments although it only has 2,
which one is bogus? I've set $1-1 temporarily, but does this
make sense?

* backend/executor/x_qual.h

prototype for ExecEvalExpr not consistent with executor/externs.h

* backend/planner/path/indxpath.c
* backend/planner/path/orindxpath.c
* backend/planner/util/pathnode.c

call set_difference with 3 instead of 2 arguments, I have deleted
the last argument (LispNil) in these cases.

* backend/planner/path/xfunc.c

calls xfunc_card_unreferenced with two instead of 1 arguments.

* backend/planner/xfunc.h

wrong prototype for xfunc_total_path_cost, xfunc_card_unreferenced,
xfunc_fixvars, xfunc_pullup

* backend/utils/Gen_fmgrtab.sh

needs to include <varargs.h> and "tmp/postgres.h"

* backend/storage/ipc/ipc.c

seems to use bogus (struct sembuf **) casts in semop calls. Furthermore,
there are semctl calls with NULL as 4th element, have to replace
these by (union semun)0 for the compiler to accept them.

* backend/tmp/acl.h

contains bogus prototype for pg_ownercheck (2 arguments, whereas
the definition of the function specifies 3).

* backend/tcop/pquery.h

incorrect prototype for function CreateQueryDesc, and ProcessQuery,
see below.

* backend/tcp/pquery.c

fixed calls of CreateQueryDesc (argument 3), it was also necessary to
adapt the definition of the function ProcessQuery and its prototype
(see above).

* backend/utils/adt/date.c

l.219, gcc stubles over a macro index: index is declared in the
ANSI library, as a macro, which CPP tries to expand, CPP doesn't
understand the extern...

* backend/utils/adt/datum.c

contains duplicate prototypes for its functions, they are already in
tmp/datum.h 

* backend/utils/adt/varlena.c

we don't need to declare bcopy() extern inside of functions,
they are already visible.

* backend/utils/cache/relcache.c

incorrect prototyp for RelationFlushIndexes

* backend/utils/catcache.h 

needs to include nodes/mnodes.h, and it also needs to declare extern
the variable CacheCxt.

* backend/utils/error/elog.c

don't need to locally declare errno, ctime, sprintf

* backend/utils/fmgr/fmgr.c
* backend/utils/Gen_fmgrtag.sh

switched to ANSI compatible library <stdarg.h>, depending on whether
the symbol __STDC__ is defined or not. This required changes in some
other files too, I lost track of all of them. Found them by greping
for va_list and varargs.h.

* backend/utils/init/miscinit.c

The constants S_IRUSR etc. are not defined in the NeXT's libraries.

* backend/utils/mmgr/mcxt.c

This file does not compile with the cc of Nextstep 3.0.  cpp-precomp
produces a bus error! One has to start cc1obj and the assembler
by hand (maybe there is some option somewhere that bypasses cpp-precomp).

* backend/utils/pg_malloc.h

change order of includes to prevent redefinition of offsetof in stddef.h

* backend/utils/psort.h
* backend/utils/sort/psort.c

moved declaration of struct tape to header file.

* backend/lib/Makefile.inc

why should we not use the qsort that comes in our shared
library?

* backend/storage/ipc/s_lock.c

use the sun3 settings for spin locks

* backend/tmp/datum.h
* backend/tmp/postgres.h

contain definitions of GET_4_BYTES and relatives which
depend on whether the processor is bigendian or littleendian,
added NeXT to the #if's.

* backend/Makefile

for the lexer-symbols, it is necessary to add the linker
flag -ll

* backend/postmaster/postmaster.c

replaced <values.h> by equivalent construction with <limits.h>.
Furthermore, there is not putenv on the NeXT, at least I didn't
find one. But we can use the function setenv that comes with
bmake of the same distribution.

* backend/tmp/libpq-fe.h

incorrect prototype for dump_tuple, too few arguments. Incorrect
prototype for elog, no arguments.

* libpq/fe-pqstubs.c

switched from <varargs.h> to <stdarg.h>

* libpq/fe-pqufs.c

switch from putenv to setenv

* backend/utils/fmgr/ufp.c

added prototypes to comply with ANSI

* utils/lib/lipsread.c
* backend/utils/adt/float.c

several other files as well us local prototypes for atof(), they
should rather include <stdlib.h>.

* backend/utils/palloc.h
* backend/utils/log.h

palloc and pfree are also referenced in UFP, where they are
redefined. I've ifdefed  these prototypes out from palloc.h
depending on whether UFP is defined or not. The same holds for
the function elog prototyped in backend/utils/log.h

* bin/pg_ufp/Makefile

gives -N as a linker option, this is not a good idea on the
NeXT, as it doesn't understand this option...

* bin/shmemdoc/shmemdoc.c

semctl calls use an incorrect argument, added appropriate cast.

* bin/unfsd/unfsd.c

l. 78: dont redefine malloc, use header file.

* bin/unfsd/unfsd.c
* bin/fsutils/icopy/icopy.c

call p_mkdir with the wrong number of parameters (missing
mode parameter).

* bin/unfsd/init.c

call of openlog from syslog.h with only two parameters, have
added LOG_USER as the third argument, which is the default.
furthermore, on BSD systems, one usually has <sys/dir.h>
instead of <dirent.h>.

* bin/fsutils/pls/ls.c
* bin/fsutils/pls/fts.h
* bin/fsutils/pls/fts.c
* bin/fsutils/pls/extern.h

incorrect function prototypes, nonexistent <unistd.h>, wie have
to replace all Macros S_ISBLK S_ISCHR S_ISLNK etc by explicit
(S_IFBLK & ...) constructions.

* regress/demo/circle.c
* regress/regress/regress.c

shouldn't redeclare the macro atof() inside function, rather
include header file.

PROBLEMS:
- try to get rid of malloc_debug, it is defined on the NeXT and is 

  only used in the following files
          ./backend/tmp/c.h
          ./backend/utils/mmgr/palloc.c
          ./backend/utils/palloc.h
          ./contrib/tkmonitor/c.h
  We do this by conditionally replacing the name malloc_debug by
  pg_malloc_debug

- we should really include setenv in the lippq library. It should
  go into, we need to change the Makefile to include this thing