Here are some notes on the first steps towards a port of 
Postgresql 7.0.2.

David Mathog, mathog@caltech.edu  17-AUG-2000

The good news -
   most of the code will compile ok (but it isn't up to /warn=enable=all)

The bad news - 
  the IPC sections need to be rewritten for OpenVMS.
  the spin lock section needs to be rewritten (I made a stab 
    at it, no idea if it works)
  there are some other Unix specific bits about having to do
    with passwords and authorization.
  some of the "programs" are sh scripts - these should
   be rewritten into C (or maybe perl) to make them more
   portable.
  there are some errors that look like bugs in the code
  no idea if the dlopen() stuff it seems to depend upon
   is going to work right.

************************************************************
Picked up 7.0.2 from the www.postgresql.org link.

Moved to Linux/Alpha, unpacked.

Did:

 ./configure --with-odbc --with-CC=gcc

(it had failed earlier using ccc)

creating ./config.status
creating GNUmakefile
creating Makefile.global
creating backend/port/Makefile
creating backend/catalog/genbki.sh
creating backend/utils/Gen_fmgrtab.sh
creating bin/pg_dump/Makefile
creating bin/pg_version/Makefile
creating bin/pgtclsh/mkMakefile.tcldefs.sh
creating bin/pgtclsh/mkMakefile.tkdefs.sh
creating bin/psql/Makefile
creating include/version.h
creating interfaces/libpq/Makefile
creating interfaces/ecpg/lib/Makefile
creating interfaces/ecpg/preproc/Makefile
creating interfaces/libpq++/Makefile
creating interfaces/libpgeasy/Makefile
creating interfaces/libpgtcl/Makefile
creating interfaces/odbc/GNUmakefile
creating interfaces/odbc/Makefile.global
creating pl/plpgsql/src/Makefile
creating pl/plpgsql/src/mklang.sql
creating pl/tcl/mkMakefile.tcldefs.sh
creating test/regress/GNUmakefile
creating include/config.h
include/config.h is unchanged
linking ./backend/port/dynloader/linux.c to backend/port/dynloader.c
linking ./backend/port/dynloader/linux.h to include/dynloader.h
linking ./include/port/linux.h to include/os.h
linking ./makefiles/Makefile.linux to Makefile.port
linking ./backend/port/tas/dummy.s to backend/port/tas.s
linking ./include/port to interfaces/odbc/port
linking ./makefiles to interfaces/odbc/makefiles
linking ./template to interfaces/odbc/template
linking ./include/config.h to interfaces/odbc/config.h

% make | tee make_vms.com
% make install | tee make_vms_install.com
% cat make_vms_install.com >> make_vms.com

Could NOT get a clean build on Linux/Alpha bad sign!  Did it 
again on RH 5.2/Intel. That went fine.

Unpacked postgresql 7.0.2 on OpenVMS.  Copied make_vms.com to src directory.

NOTE - any time I changed a file I left a *.c_dist or 
*.h_dist file with the original code in it.

modifications to 

  PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.INCLUDE.STORAGE]slock.c
  PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.BACKEND.STORAGE.BUFFER]ipc.h
  PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.INCLUDE.STORAGE]s_lock.h
  [.BACKEND.COMMANDS]COMMENT.C
and lots more, see below.


************************************************************

Bad programming practice detected in many modules - names too long for ANSI C standard.
Handle by defs in os.h

symbols >31 characters but unique:

 TransactionIdIsCurrentTransactionId
 ImmediateInvalidateSharedHeapTuple
 AttributeNumberGetIndexStrategySize
 RelationInvalidateCatalogCacheTuple
 RelationIdInvalidateRelationCacheByRelationId
 ReferentialIntegritySnapshotOverride
 ExecAssignResultTypeFromOuterPlan
 check_subplans_for_ungrouped_vars
 get_cheapest_fractional_path_for_pathkeys
 RelationIdInvalidateRelationCacheByRelationId

symbols >31 characters NOT unique 

 pglz_get_next_decomp_char_from_lzdata
 pglz_get_next_decomp_char_from_plain

***********************************************************

this section - using a method that does a straight compile
of all modules from the top directory.  In the end it didn't 
work out and I had to edit make_vms.com into shape.


************************************************************

Had to put caddr_t in os.h because no combination of language standards 
would build bootstrap.c otherwise.  Hmm.  Probably need to just use
/standard=relaxed  for most of it is as it depends upon this mishmash
of language standards.  Still, most routines will build with better
defined standards.

************************************************************
[.BACKEND.CATALOG]ACLCHK.C
                old_acl = (Acl *) heap_getattr(tuple,
..................................^
%CC-I-BADSUBSCRIPT, In this statement, an array subscript expression is 
either less than zero or greater than the largest value that  can be
represented by the size_t type. at line number 121 in file
PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.BACKEND.CATALOG]ACLCHK.C;1

in multiple places.  Looks like a bug 
************************************************************
$ mycc [.BACKEND.CATALOG]HEAP.C

extern DLLIMPORT sigjmp_buf Warn_restart;
............................^
%CC-E-NOSEMI, Missing ";". at line number 26 in file
PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.INCLUDE.TCOP]TCOPPROT.H;1 

************************************************************
$ mycc [.BACKEND.CATALOG]PG_PROC.C

                if (fmgr_lookupByName(prosrc) == (func_ptr) NULL)
............................................................^
%CC-I-NONSTANDCAST, In this statement, "((void ...)0)" of type "pointer to 
void", is being converted to "pointer to function () returning pointer to char".
Such a cast is not permitted by the standard.
at line number 246 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.
BACKEND.CATALOG]PG_PROC.C;1

They should probably use a nullfunction() to do this.

************************************************************

$ mycc [.BACKEND.COMMANDS]ASYNC.C
$ mycc [.BACKEND.COMMANDS]COPY.C
$ mycc [.BACKEND.COMMANDS]TRIGGER.C
various problems including C++ style // comments in some of the includes, 
notably GPPS.H.  Fix these later.

************************************************************
$ mycc [.BACKEND.COMMANDS]COMMENT.C

#include "../backend/parser/parse.h"
.^
%CC-F-NOINCLFILEF, Cannot find file "../backend/parser/parse.h" specified 
in #include directive. at line number 34 in file
PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.BACKEND.COMMANDS]COMMENT.C;1 

Relative include.  Change it to "parse.h" which is a unique name and will
be picked up by the include statements.

************************************************************
$ mycc [.BACKEND.COMMANDS]DBCOMMANDS.C

                        *ownerIdP = (int4) heap_getattr(tuple,
...........................................^
%CC-I-BADSUBSCRIPT, In this statement, an array subscript expression is 
either less than zero or greater than the largest value that  can be
represented by the size_t type. at line number 338 in file
PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.BACKEND.COMMANDS]DBCOMMANDS.C;1

probable bug
************************************************************
 mycc [.BACKEND.COMMANDS]VACUUM.C

        struct timeval ru_utime;        /* user time used */
.......................^
%CC-E-INCOMPMEM, The member "ru_utime" has an incomplete type. at line
number 26 in file
PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.INCLUDE]RUSAGESTUB.H;1 

Some problem picking up timeval probably.  Yup, it needs
_XOPEN_SOURCE_EXTENDED


                d = heap_getattr(tuple, Anum_pg_class_relname, tupdesc, &n);
....................^
%CC-I-BADSUBSCRIPT, In this statement, an array subscript expression is 
either less than zero or greater than the largest value that can be
represented by the size_t type. at line number 358 in file
PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.BACKEND.COMMANDS]VACUUM.C;1 


UGH.  There is a "resource.h" file which conflicts with the 
<sys/resource.h> name.  [.BACKEND.COMMANDS]VACUUM.C triggers this by 
calling wait.h which includes resource.h.  POSTED to comp.os.vms,
how do I force the <> form to always check the library first?

Rejiggered build command from the file's directory fixed it.

************************************************************

Started over with make_vms.com_raw from a successful build
on RH 5.2/Linux.  The modified version is make_vms.com.
Edited it into the right format. 

Build...

warnings in

xlog.c
aclchk.c

************************************************************
blew up in async.c

$ mycc /DEFINE=(_POSIX_C_SOURCE=2,_XOPEN_SOURCE_EXTENDED) /include=([--.
include...],[--.backend...],[-])   async.c

    u_short rhdr_offset;         /* data offset in IPv6 packet */
....^
%CC-E-MISSINGTYPE, Missing type specifier or type qualifier.
at line number 458 in module IN6 of text library SYS$COMMON:[SYSLIB]
DECC$RTLDEF.TLB;4

It must not be picking up u_short anywhere.  It also wants <sys/un.h>
from PQCOMM.H and there's no such thing on OpenVMS.  Ok, u_short
and u_char come up in socket.h within:

#if !defined __SOCKET_TYPEDEFS && !defined _XOPEN_SOURCE_EXTENDED
#   define __SOCKET_TYPEDEFS 1

Getting rid of the XOPEN let's it compile - sort of.

Ugh.  skip it for now and come back later.    [SHOULD WORK 
WITH /standard=relaxed, as will most similar errors.]

************************************************************
at line number 1058 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.
BACKEND.COMMANDS]USER.C;1

                datum = heap_getattr(tuple, Anum_pg_group_groname, pg_group_dsc, &null);
........................^
%CC-I-BADSUBSCRIPT, In this statement, an array subscript expression is 
either less than zero or greater than the largest value that
 can be represented by the size_t type.
at line number 1123 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.
BACKEND.COMMANDS]USER.C;1

about a zillion times.  Something really wrong with this heap_getattr stuff

Same error in
dbcommands.c

************************************************************
$ mycc /DEFINE=(_POSIX_C_SOURCE=2) /include=([--.include...],[--.backend...],[-])   portalbuf.c

        if (size <= 0)
............^
%CC-I-QUESTCOMPARE, In this statement, the unsigned expression "size" is 
being compared with a relational operator to a constant who
se value is not greater than zero.  This might not be what you intended.
at line number 110 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.
BACKEND.LIBPQ]PORTALBUF.C;1

BUG!

************************************************************


PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.BACKEND.LIBPQ]auth.c
                                                            pqcomm.c

do some odd thing so that it doesn't pick up u_int on OpenVMS.
Hardwired so that it would.

************************************************************
$ mycc /DEFINE=(_POSIX_C_SOURCE=2,_XOPEN_SOURCE_EXTENDED) /include=([---.
include...],[---.backend...],[--])  planner.c

        else if ((rt_index = first_inherit_rt_entry(rangetable)) != -1)
.................^
%CC-I-QUESTCOMPARE1, In this statement, the unsigned expression "(rt_index=
first_inherit_rt_entry(...))" is being compared with an e
quality operator to a constant whose value is negative.  This might not be 
what you intended.
at line number 274 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.
BACKEND.OPTIMIZER.PLAN]PLANNER.C;1

************************************************************
Postmaster.c looks bad.  It has fork() and all sorts of nasty stuff in it.

************************************************************

bufmgr.c needs work on Spinlock sections.  Come back to this

************************************************************
                if (result->queue.next == INVALID_OFFSET)
....................^
%CC-I-QUESTCOMPARE1, In this statement, the unsigned expression "result->
queue.next" is being compared with an equality operator to
a constant whose value is negative.  This might not be what you intended.
at line number 1220 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.
BACKEND.STORAGE.LMGR]LOCK.C;1

Bug

************************************************************

modified postgres.c to pick up "parse.h"  and ifdef properly timezone
modified utility.c to picku up "parse.h"
************************************************************

$ myccr /include=([---.include...],[---.backend...],[--])  datum.c

                if (len == -1)
....................^
%CC-I-QUESTCOMPARE1, In this statement, the unsigned expression "len" is 
being compared with an equality operator to a constant whose 
value is negative.  This might not be what you intended.
at line number 67 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.
BACKEND.UTILS.ADT]DATUM.C;1

Bug

************************************************************

filename.c, ifdef sys/param.h properly

************************************************************

nabstime.c ifdef timezone properly
************************************************************

float.c only works if IEEE floats are used as all sorts of other constants
cause errors.  Missing prototype for "isinf".  Even with IEEE it
expands the line:  val = NAN;   to val = ( 0.0 / 0.0 ) which
generates a warning.

************************************************************

$ myccr /include=([---.include...],[---.backend...],[--])  nabstime.c

        if (time(&sec) < 0)
............^
%CC-I-QUESTCOMPARE, In this statement, the unsigned expression "time(...)" 
is being compared with a relational operator to a constan
t whose value is not greater than zero.  This might not be what you 
intended.
at line number 1067 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.
BACKEND.UTILS.ADT]NABSTIME.C;2

Bug

************************************************************
$ myccr /include=([---.include...],[---.backend...],[--])  oracle_compat.c

                ptr2 = ptr2 == VARDATA(string2) + VARSIZE(string2) - VARHDRSZ - 1 ? VARDATA(string2) : ++ptr2;
................^
%CC-W-UNDEFVARMOD, In this statement, the expression "ptr2=ptr2==(((struct 
varlena ...)(string2))->vl_dat)+(((struct varlena ...)(st
ring2))->vl_len)-((int32)sizeof(int32))-1?(((struct varlena ...)(string2))-
>vl_dat):++ptr2" modifies the variable "ptr2" more than once without an intervening sequence point.  This behavior is 
undefined.
at line number 179 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.
BACKEND.UTILS.ADT]ORACLE_COMPAT.C;1

Bug.  (Kind of funny that it occurs in the Oracle compatibility section!!!
************************************************************

$ myccr /include=([---.include...],[---.backend...],[--])  regproc.c

                        result = (RegProcedure) heap_getattr(proctup,
................................................^
%CC-I-BADSUBSCRIPT, In this statement, an array subscript expression is 
either less than zero or greater than the largest value that
 can be represented by the size_t type.
at line number 140 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.
BACKEND.UTILS.ADT]REGPROC.C;1

same probably bug as everywhere else for heap_getattr()


************************************************************
$ myccr /include=([---.include...],[---.backend...],[--])  inet_net_pton.c

                        return size == -1 ?
...............................^
%CC-I-QUESTCOMPARE1, In this statement, the unsigned expression "size" is 
being compared with an equality operator to a constant who
se value is negative.  This might not be what you intended.

and many related errors

************************************************************

UGH!!!

$ mycc /DEFINE=(_POSIX_C_SOURCE=2,_XOPEN_SOURCE_EXTENDED) /include=([---.include...],[---.backend...],[--])  inval.c

        ((InvalidationUserData *) entry)->dataP[-1] =
................................................^
%CC-I-BADSUBSCRIPT, In this statement, an array subscript expression is either less than zero or greater than the largest value that
 can be represented by the size_t type.
at line number 153 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.BACKEND.UTILS.CACHE]INVAL.C;1

                        &((InvalidationUserData *) invalid)->dataP[-1];
...................................................................^
%CC-I-BADSUBSCRIPT, In this statement, an array subscript expression is either less than zero or greater than the largest value that
 can be represented by the size_t type.
at line number 173 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.BACKEND.UTILS.CACHE]INVAL.C;1

                if (PointerIsValid(function))
....................^
%CC-I-NONSTANDCAST, In this statement, "(function)" of type "pointer to function () returning void", is being converted to "pointer
to void".  Such a cast is not permitted by the standard.
at line number 175 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.BACKEND.UTILS.CACHE]INVAL.C;1

                LocalInvalidInvalidate(locinv, (void (*) ()) NULL, true);
.............................................................^
%CC-I-NONSTANDCAST, In this statement, "((void ...)0)" of type "pointer to void", is being converted to "pointer to function () retu
rning void".  Such a cast is not permitted by the standard.
at line number 197 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.BACKEND.UTILS.CACHE]INVAL.C;1

        free((Pointer) &((InvalidationUserData *) message)->dataP[-1]);
..................................................................^
%CC-I-BADSUBSCRIPT, In this statement, an array subscript expression is either less than zero or greater than the largest value that
 can be represented by the size_t type.
at line number 357 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.BACKEND.UTILS.CACHE]INVAL.C;1

etc.  Skip for now, needs to be fixed!

************************************************************
                ruleaction = heap_getattr(pg_rewrite_tuple,
.............................^
%CC-I-BADSUBSCRIPT, In this statement, an array subscript expression is either less than zero or greater than the largest value that
 can be represented by the size_t type.
at line number 715 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.BACKEND.UTILS.CACHE]RELCACHE.C;1

as everywhere else for heap_getattr


************************************************************
dfmgr.c has some type warnings, possible truncation, loss of sign,
and the like.

************************************************************

miscinit.c needed ifdef work

************************************************************

fe-auth.c needed ifdef work on sys/param.h
ugh. all sorts of other Unixy stuff in there (crypt, funny sockets,etc.)
Skip the whole libpq for now.

************************************************************
        struct variable **list = &((*stmt)->inlist);
....................................^
%CC-W-UNINIT1, The scalar variable "stmt", declared in "ECPGdo", is fetched but not initialized.  Detected when this routine was inl
ined at line number 842 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.INTERFACES.ECPG.LIB]EXECUTE.C;1.  And there m
ay be other such fetches of this variable that have not been reported in this compilation.
at line number 146 in file PRGDISK:[SHARED.PROGRAMS.POSTGRESQL-7_0_2.SRC.INTERFACES.ECPG.LIB]EXECUTE.C;1


bug

************************************************************

Ok, I'm giving up for now.  Lots of work to be done, but at least it seems like there is
a possibility of a running product at the end of it.
