OSSP CVS Repository

ossp - Ticket #126
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Attach]  [Edit]  [History

Ticket 126: Patches for PostgreSQL 8.2 and Mac OS X

With help from Neil Conway, I managed to get the PostgreSQL library to compile and work on Mac OS X. Here are the patches I needed to get it to work:

* First I got these errors:

  make PG_CONFIG=/usr/local/pgsql/bin/pg_config
  sed -e 's;MODULE_PATHNAME;/usr/local/pgsql/lib/uuid.so;g' <uuid.sql.in >uuid.sql
  gcc -no-cpp-precomp -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Winline -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing  -I.. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal   -c -o uuid.o uuid.c
  uuid.c: In function 'pg_uuid_in':
  uuid.c:80: warning: format '%d' expects type 'int', but argument 2 has type 'size_t'
  ar crs libuuid.a uuid.o
  ranlib libuuid.a
  gcc -no-cpp-precomp -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Winline -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing  -bundle -multiply_defined suppress  uuid.o -L../.libs -L/usr/local/pgsql/lib -luuid  -o libuuid.1.0.so
  /usr/bin/ld: Undefined symbols:
  _CurrentMemoryContext
  _MemoryContextAlloc
  _errcode
  _errfinish
  _errmsg
  _errstart
  _hash_any
  collect2: ld returned 1 exit status
  make: *** [libuuid.1.0.so] Error 1

To fix this, I needed to get it to bundle the postgres binary, which defines those symbols (Thanks neilc!). Here's the patch:

  --- Makefile.old        2006-10-10 10:35:49.000000000 -0700
  +++ Makefile    2006-10-10 10:40:14.000000000 -0700
  @@ -14,6 +14,7 @@

   PG_CONFIG         ?= pg_config
   PGXS              := $(shell $(PG_CONFIG) --pgxs)
  +POSTGRES          := $(shell $(PG_CONFIG) --bindir)/postgres
   top_builddir      := $(dir $(PGXS))../..
   include           $(top_builddir)/src/Makefile.global

  @@ -23,7 +24,7 @@
   SO_MINOR_VERSION  = 0

   override CPPFLAGS := -I.. $(CPPFLAGS)
  -SHLIB_LINK        := -L../.libs -luuid
  +SHLIB_LINK        := -L../.libs -luuid -bundle_loader $(POSTGRES)
   SHLIB_LINK        += $(shell test $(shell uname -s) = FreeBSD && echo "-Wl,-Bsymbolic")
   rpath             :=

  * Next, since I'm running the 8.2 beta, I discovered that uuid.c is missing the new "magic" required in 8.2 or later. The error was:
  psql:/usr/local/pgsql/share/uuid.sql:75: ERROR:  incompatible library "/usr/local/pgsql/lib/uuid.so": missing magic block

Here's the patch for that:

  --- uuid.c.old  2006-10-10 10:33:32.000000000 -0700
  +++ uuid.c      2006-10-10 10:33:50.000000000 -0700
  @@ -41,6 +41,11 @@
   #include "lib/stringinfo.h"
   #include "access/hash.h"

  +// PostgreSQL 8.2 Magic.
  +#ifdef PG_MODULE_MAGIC
  +PG_MODULE_MAGIC;
  +#endif
  +
   /* internal UUID datum data structure */
   typedef struct {
       unsigned char uuid_bin[UUID_LEN_BIN];

* And finally, it seems that you can't cast cstrings, because cstring is a psuedo-type:

  psql:/usr/local/pgsql/share/uuid.sql:106: ERROR:  source data type cstring is a pseudo-type

So I just commented out those casts (plus silenced NOTICEs). Here's that patch:

  --- uuid.sql.in.old     2006-10-10 10:41:34.000000000 -0700
  +++ uuid.sql.in 2006-10-10 10:44:09.000000000 -0700
  @@ -32,6 +32,7 @@
   --

   SET search_path TO public;
  +SET client_min_messages = warning;

   DROP FUNCTION uuid_in(CSTRING)                    CASCADE;
   DROP FUNCTION uuid_out(uuid)                      CASCADE;
  @@ -102,12 +103,13 @@
   COMMENT ON TYPE uuid
       IS 'UUID type';

  +/*
   CREATE CAST (CSTRING AS uuid)
       WITH FUNCTION uuid_in(CSTRING) AS ASSIGNMENT;

   CREATE CAST (uuid AS CSTRING)
       WITH FUNCTION uuid_out(uuid)   AS ASSIGNMENT;
  -
  +*/
   --
   --  the UUID constructor function
   --

And now it works!

BTW, in 8.2 or later, you'll be able to silence all those errors that drop functions by using 'DROP FUNCTION IF EXISTS'. See

  http://developer.postgresql.org/pgdocs/postgres/sql-dropfunction.html

Thanks,

David

[Add remarks]

Remarks:

Properties:

Type: code           Version: 1.5.1 
Status: closed          Created: 2006-Oct-10 19:57
Severity:          Last Change: 2006-Nov-20 21:10
Priority:          Subsystem: uuid 
Assigned To: rse           Derived From:  
Creator: anonymous 

Related Check-ins:

2006-Nov-20 21:00 Check-in [5669]: Fix PostgreSQL bindings by mapping the correct DSO symbol to the functions "uuid_send" and "uuid_recv". (By rse)
2006-Nov-20 20:58 Check-in [5668]: Silence PostgreSQL processing messages Submitted by: David Wheeler <david@kineticode.com> (By rse)
2006-Nov-20 20:29 Check-in [5665]: Support MacOS X (aka Darwin) in PostgreSQL bindings by passing a "-bundle_loader" option to the linker in order to resolve the "undefined symbols" problem. (By rse)
2006-Nov-20 20:27 Check-in [5664]: remember fix (By rse)
2006-Nov-20 20:21 Check-in [5662]: Added PostgreSQL 8.2 PG_MODULE_MAGIC support. Submitted by: David Wheeler <david@kineticode.com> (By rse)

CVSTrac 2.0.1