Patch for OSX 10.1 and Postgresql 7.3.1

From: "Serge Sozonoff" <serge(at)globalbeach(dot)com>
To: <pgsql-hackers(at)postgresql(dot)org>
Subject: Patch for OSX 10.1 and Postgresql 7.3.1
Date: 2001-10-08 13:53:43
Message-ID: FC5F4607A61DF94286E9E68DB0AAFD1710A306@MAIL1
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> Hi,
>
> It apears that getting Postgres and OSX 10.1 to work is not just a
> case of some compiler flags.
>
> I have attached a patch, not sure who wrote this patch, but it seems
> to work for me!
>
> I am asuming that the author has submitted it to the pgsql team, but
> if not here it is.
>
Have fun,
> Serge
>
P.S. I give NO guarantees, like I said... I did not write this!

----cut ----

> diff -ru postgresql-7.1.3/src/Makefile.shlib
> postgresql-7.1.3-posix/src/Makefile.shlib
> --- postgresql-7.1.3/src/Makefile.shlib Sun Apr 15 05:25:07 2001
> +++ postgresql-7.1.3-posix/src/Makefile.shlib Wed Sep 19 23:00:08 2001
> @@ -113,7 +113,7 @@
>
> ifeq ($(PORTNAME), darwin)
> shlib :=
> lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
> - LINK.shared = $(COMPILER) $(CFLAGS_SL)
> + LINK.shared = $(COMPILER)
> endif
>
> ifeq ($(PORTNAME), openbsd)
> diff -ru postgresql-7.1.3/src/backend/storage/ipc/ipc.c
> postgresql-7.1.3-posix/src/backend/storage/ipc/ipc.c
> --- postgresql-7.1.3/src/backend/storage/ipc/ipc.c Fri Mar 23
> 05:49:54 2001
> +++ postgresql-7.1.3-posix/src/backend/storage/ipc/ipc.c Wed Sep
> 19 23:09:06 2001
> @@ -29,10 +29,20 @@
>
> #include <sys/types.h>
> #include <sys/file.h>
> +#define POSIX_SHARED_MEMORY
> +#ifdef POSIX_SHARED_MEMORY
> +#include <sys/stat.h>
> +#include <sys/mman.h>
> +#endif
> #include <errno.h>
> #include <signal.h>
> #include <unistd.h>
>
> +#ifdef POSIX_SHARED_MEMORY
> +#define IpcMemoryId unsigned int
> +#define IpcMemoryKey unsigned int
> +#endif
> +
> #include "storage/ipc.h"
> #include "storage/s_lock.h"
> /* In Ultrix, sem.h and shm.h must be included AFTER ipc.h */
> @@ -77,6 +87,13 @@
> static void *PrivateMemoryCreate(uint32 size);
> static void PrivateMemoryDelete(int status, Datum memaddr);
>
> +#ifdef POSIX_SHARED_MEMORY
> +uint32 posix_shmget(uint32 key, uint32 size, int permissions);
> +void *posix_shmat(uint32 id);
> +uint32 posix_shm_count(uint32 id);
> +void decrement_posix_shm_count(void *address);
> +int posix_shmrm(uint32 id);
> +#endif
>
> /* ----------------------------------------------------------------
> * exit() handling stuff
> @@ -265,6 +282,9 @@
> * print out an error and abort. Other types of errors are not
> recoverable.
> * ----------------------------------------------------------------
> */
> +#ifdef POSIX_SHARED_MEMORY
> +#define shmget(a, b, c) posix_shmget(a,b,c)
> +#endif
> static IpcSemaphoreId
> InternalIpcSemaphoreCreate(IpcSemaphoreKey semKey,
> int numSems, int
> permission,
> @@ -620,7 +640,11 @@
> on_shmem_exit(IpcMemoryDelete, Int32GetDatum(shmid));
>
> /* OK, should be able to attach to the segment */
> +#ifdef POSIX_SHARED_MEMORY
> + memAddress = posix_shmat(shmid);
> +#else
> memAddress = shmat(shmid, 0, 0);
> +#endif
>
> if (memAddress == (void *) -1)
> {
> @@ -646,10 +670,13 @@
> static void
> IpcMemoryDetach(int status, Datum shmaddr)
> {
> +#ifndef POSIX_SHARED_MEMORY
> if (shmdt(DatumGetPointer(shmaddr)) < 0)
> fprintf(stderr, "IpcMemoryDetach: shmdt(%p) failed:
> %s\n",
> DatumGetPointer(shmaddr),
> strerror(errno));
> -
> +#else
> + decrement_posix_shm_count(DatumGetPointer(shmaddr));
> +#endif
> /*
> * We used to report a failure via elog(NOTICE), but that's
> pretty
> * pointless considering any client has long since disconnected
> ...
> @@ -663,10 +690,13 @@
> static void
> IpcMemoryDelete(int status, Datum shmId)
> {
> +#ifdef POSIX_SHARED_MEMORY
> + if (posix_shmrm(DatumGetInt32(shmId)) == -1)
> +#else
> if (shmctl(DatumGetInt32(shmId), IPC_RMID, (struct shmid_ds *)
> NULL) < 0)
> +#endif
> fprintf(stderr, "IpcMemoryDelete: shmctl(%d, %d, 0)
> failed: %s\n",
> DatumGetInt32(shmId), IPC_RMID,
> strerror(errno));
> -
> /*
> * We used to report a failure via elog(NOTICE), but that's
> pretty
> * pointless considering any client has long since disconnected
> ...
> @@ -679,8 +709,9 @@
> bool
> SharedMemoryIsInUse(IpcMemoryKey shmKey, IpcMemoryId shmId)
> {
> +#ifndef POSIX_SHARED_MEMORY
> struct shmid_ds shmStat;
> -
> +#endif
> /*
> * We detect whether a shared memory segment is in use by seeing
> * whether it (a) exists and (b) has any processes are attached
> to it.
> @@ -689,6 +720,9 @@
> * nonexistence of the segment (most likely, because it doesn't
> belong
> * to our userid), assume it is in use.
> */
> +#ifdef POSIX_SHARED_MEMORY
> + return (posix_shm_count(DatumGetInt32(shmId)) != 0);
> +#else
> if (shmctl(shmId, IPC_STAT, &shmStat) < 0)
> {
>
> @@ -706,6 +740,7 @@
> if (shmStat.shm_nattch != 0)
> return true;
> return false;
> +#endif
> }
>
>
> @@ -801,9 +836,17 @@
> shmid = shmget(NextShmemSegID, sizeof(PGShmemHeader),
> 0);
> if (shmid < 0)
> continue; /* failed: must
> be some other app's */
> +#ifdef POSIX_SHARED_MEMORY
> + memAddress = posix_shmat(shmid);
> +#else
> memAddress = shmat(shmid, 0, 0);
> +#endif
> if (memAddress == (void *) -1)
> continue; /* failed: must
> be some other app's */
> +#ifdef POSIX_SHARED_MEMORY
> + if (memAddress == NULL) continue;
> + else break;
> +#else
> hdr = (PGShmemHeader *) memAddress;
> if (hdr->magic != PGShmemMagic)
> {
> @@ -848,6 +891,7 @@
> * same shmem key before we did. Let him have that one,
> loop
> * around to try next key.
> */
> +#endif
> }
>
> /*
> @@ -966,3 +1010,124 @@
>
> return semId;
> }
> +
> +#ifdef POSIX_SHARED_MEMORY
> +
> +#define PSM_MAX_SEGS 10
> +int psm_initted = 0;
> +struct psm_map_ent {
> + int valid;
> + int32 id;
> + void *address;
> + int size;
> + int count;
> + int fd;
> +};
> +
> +struct psm_map_ent map_array[PSM_MAX_SEGS];
> +
> +uint32 posix_shmget(uint32 key, uint32 size, int permissions)
> +{
> +int i;
> +char name[32];
> +
> + /* Initialize structure if not already initted */
> + if (!psm_initted) {
> + for (i=0; i<PSM_MAX_SEGS; i++) {
> + map_array[i].valid = 0;
> + map_array[i].id = -1;
> + map_array[i].address = NULL;
> + map_array[i].count = 0;
> + map_array[i].size = 0;
> + map_array[i].fd = -1;
> + }
> + }
> + for (i=0; i<PSM_MAX_SEGS; i++) {
> + if (!map_array[i].valid) break;
> + }
> + if (map_array[i].valid) return -1;
> +
> + /* Here's where we do the real work */
> + sprintf(name, "psm_%d", key);
> + map_array[i].fd = shm_open(name, (O_CREAT | O_RDWR | O_TRUNC),
> + (S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP));
> + map_array[i].size = size;
> + map_array[i].id = key;
> +
> + return i;
> +}
> +
> +void *posix_shmat(uint32 id)
> +{
> + int i;
> +
> +#if 0
> + for (i=0; i<PSM_MAX_SEGS; i++)
> + if (map_array[i].id == id) break;
> +
> + if (map_array[i].id == id)
> + return NULL;
> +#else
> +i = id;
> +if (i == -1) return NULL;
> +#endif
> +
> + map_array[i].address = mmap(NULL, map_array[i].size,
> + (PROT_READ | PROT_WRITE),
> + (MAP_ANON | MAP_INHERIT | MAP_SHARED), map_array[i].fd, 0);
> + if (map_array[i].address == -1) {
> + perror("posix_shmat");
> + return NULL;
> + }
> + if (map_array[i].address != 0) {
> + map_array[i].valid = 1;
> + map_array[i].count = 1;
> + return (map_array[i].address);
> + } else {
> + return NULL;
> + }
> +}
> +
> +uint32 posix_shm_count(uint32 id) {
> + int i;
> +
> +#if 0
> + for (i=0; i<PSM_MAX_SEGS; i++) {
> + if (map_array[i].id == id)
> + return map_array[i].count;
> + }
> + return -1;
> +#else
> + i = id;
> + if (i == -1) return -1;
> + return map_array[i].count;
> +#endif
> +}
> +
> +void decrement_posix_shm_count(void *address)
> +{
> + int i;
> +
> + for (i=0; i<PSM_MAX_SEGS; i++) {
> + if (map_array[i].address == address) break;
> + }
> +
> + if (map_array[i].address == address) {
> + map_array[i].count --;
> + }
> + if (map_array[i].count < 0) {
> + /* This should never happen.... */
> + fprintf(stderr, "AIEEEEEE! Map count < 0 in
> decrement_posix_shm_count!\n");
> + }
> +}
> +
> +int posix_shmrm(uint32 id)
> +{
> +char name[32];
> +
> + sprintf(name, "psm_%d", id);
> +
> + return shm_unlink(name);
> +}
> +
> +#endif
> diff -ru postgresql-7.1.3/src/makefiles/Makefile.darwin
> postgresql-7.1.3-posix/src/makefiles/Makefile.darwin
> --- postgresql-7.1.3/src/makefiles/Makefile.darwin Mon Dec 11
> 01:49:52 2000
> +++ postgresql-7.1.3-posix/src/makefiles/Makefile.darwin Wed Sep
> 19 22:59:24 2001
> @@ -2,7 +2,7 @@
> AWK= awk
>
> DLSUFFIX = .so
> -CFLAGS_SL = -bundle -undefined suppress
> +CFLAGS_SL = -bundle -flat_namespace -undefined suppress
>
> %.so: %.o
> $(CC) $(CFLAGS) $(CFLAGS_SL) -o $@ $<
>
>

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dave Page 2001-10-08 14:02:17 Re: [HACKERS] What about CREATE OR REPLACE FUNC
Previous Message Lamar Owen 2001-10-08 13:49:46 Temprary issue gripes(was:Re: cvs problem)