support pgsql versions up to 11
authorTeodor Sigaev <teodor@sigaev.ru>
Tue, 23 Apr 2019 11:08:52 +0000 (14:08 +0300)
committerTeodor Sigaev <teodor@sigaev.ru>
Tue, 23 Apr 2019 11:08:52 +0000 (14:08 +0300)
smlar.c
smlar.h
smlar_gist.c

diff --git a/smlar.c b/smlar.c
index 5cbe5c2..13c8169 100644 (file)
--- a/smlar.c
+++ b/smlar.c
@@ -91,9 +91,14 @@ getAMProc(Oid amoid, Oid typid)
                /*
                 * Search binary-coercible type
                 */
+#ifdef SearchSysCacheList1
+               catlist = SearchSysCacheList1(CASTSOURCETARGET,
+                                                                         ObjectIdGetDatum(typid));
+#else
                catlist = SearchSysCacheList(CASTSOURCETARGET, 1,
                                                                                ObjectIdGetDatum(typid),
                                                                                0, 0, 0);
+#endif
 
                for (i = 0; i < catlist->n_members; i++)
                {
@@ -171,6 +176,10 @@ getAMProc(Oid amoid, Oid typid)
 static ProcTypeInfo *cacheProcs = NULL;
 static int nCacheProcs = 0;
 
+#ifndef TupleDescAttr
+#define TupleDescAttr(tupdesc, i)      ((tupdesc)->attrs[(i)])
+#endif
+
 static ProcTypeInfo
 fillProcs(Oid typid)
 {
@@ -192,7 +201,7 @@ fillProcs(Oid typid)
 
                if (tupdesc->natts != 2)
                        elog(ERROR,"Composite type has wrong number of fields");
-               if (tupdesc->attrs[1]->atttypid != FLOAT4OID)
+               if (TupleDescAttr(tupdesc, 1)->atttypid != FLOAT4OID)
                        elog(ERROR,"Second field of composite type is not float4");
 
                oldcontext = MemoryContextSwitchTo(TopMemoryContext);
@@ -201,8 +210,10 @@ fillProcs(Oid typid)
 
                ReleaseTupleDesc(tupdesc);
 
-               info->cmpFuncOid = getAMProc(BTREE_AM_OID, info->tupDesc->attrs[0]->atttypid);
-               info->hashFuncOid = getAMProc(HASH_AM_OID, info->tupDesc->attrs[0]->atttypid);
+               info->cmpFuncOid = getAMProc(BTREE_AM_OID,
+                                                                        TupleDescAttr(info->tupDesc, 0)->atttypid);
+               info->hashFuncOid = getAMProc(HASH_AM_OID,
+                                                                         TupleDescAttr(info->tupDesc, 0)->atttypid);
        }
        else
        {
diff --git a/smlar.h b/smlar.h
index 6cd5a27..6410326 100644 (file)
--- a/smlar.h
+++ b/smlar.h
@@ -6,6 +6,8 @@
 #include "access/tupdesc.h"
 #include "catalog/pg_collation.h"
 
+#include <math.h>
+
 typedef        struct ProcTypeInfoData *ProcTypeInfo;
 
 typedef struct ProcTypeInfoData {
index 382b932..788876c 100644 (file)
@@ -380,7 +380,7 @@ gsmlsign_compress(PG_FUNCTION_ARGS)
                retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
                gistentryinit(*retval, PointerGetDatum(sign),
                                                entry->rel, entry->page,
-                                               entry->offset, FALSE);
+                                               entry->offset, false);
        }
        else if ( ISSIGNKEY(DatumGetPointer(entry->key)) &&
                                !ISALLTRUE(DatumGetPointer(entry->key)) )
@@ -404,7 +404,7 @@ gsmlsign_compress(PG_FUNCTION_ARGS)
 
                        gistentryinit(*retval, PointerGetDatum(sign),
                                                        entry->rel, entry->page,
-                                                       entry->offset, FALSE);
+                                                       entry->offset, false);
                }
        }
 
@@ -425,7 +425,7 @@ gsmlsign_decompress(PG_FUNCTION_ARGS)
 
                gistentryinit(*retval, PointerGetDatum(key),
                                                entry->rel, entry->page,
-                                               entry->offset, FALSE);
+                                               entry->offset, false);
 
                PG_RETURN_POINTER(retval);
        }