diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 80691c5..d4cbd69 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: test: strategy: matrix: - pg: [15, 14, 13, 12, 11, 10] + pg: [16, 15, 14, 13, 12, 11, 10] name: 🐘 PostgreSQL ${{ matrix.pg }} runs-on: ubuntu-latest container: pgxn/pgxn-tools diff --git a/.gitignore b/.gitignore index a285855..82c00fc 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ results regression.diffs regression.out + + +*.dylib diff --git a/_ltree_gist.c b/_ltree_gist.c index f272143..406264c 100644 --- a/_ltree_gist.c +++ b/_ltree_gist.c @@ -11,6 +11,10 @@ #include "access/skey.h" #include "crc32.h" #include "ltree.h" +#if PG_VERSION_NUM >= 160000 +#include "varatt.h" +#include "utils/array.h" +#endif PG_FUNCTION_INFO_V1(_ltree_compress); @@ -378,7 +382,7 @@ _ltree_picksplit(PG_FUNCTION_ARGS) _j = GETENTRY(entryvec, j); size_alpha = hemdist(datum_l, _j); size_beta = hemdist(datum_r, _j); - costvector[j - 1].cost = Abs(size_alpha - size_beta); + costvector[j - 1].cost = abs(size_alpha - size_beta); } qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost); @@ -556,7 +560,7 @@ Datum _ltree_consistent(PG_FUNCTION_ARGS) { GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); - char *query = (char *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1))); + void *query = (void *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2); /* Oid subtype = PG_GETARG_OID(3); */ diff --git a/_ltree_op.c b/_ltree_op.c index 1b53af8..bb27038 100644 --- a/_ltree_op.c +++ b/_ltree_op.c @@ -6,6 +6,10 @@ * Teodor Sigaev */ #include "postgres.h" +#if PG_VERSION_NUM >= 160000 +#include "utils/array.h" +#endif + #include diff --git a/lquery_op.c b/lquery_op.c index 31d150d..e564530 100644 --- a/lquery_op.c +++ b/lquery_op.c @@ -10,6 +10,9 @@ #include "catalog/pg_collation.h" #include "utils/formatting.h" #include "ltree.h" +#if PG_VERSION_NUM >= 160000 +#include "utils/array.h" +#endif PG_FUNCTION_INFO_V1(ltq_regex); PG_FUNCTION_INFO_V1(ltq_rregex); diff --git a/ltree.h b/ltree.h index 39abd26..b1dcf47 100644 --- a/ltree.h +++ b/ltree.h @@ -169,12 +169,20 @@ bool compare_subnode(ltree_level *t, char *q, int len, ltree *lca_inner(ltree **a, int len); int ltree_strncasecmp(const char *a, const char *b, size_t s); -#define PG_GETARG_LTREE(x) ((ltree*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x)))) -#define PG_GETARG_LTREE_COPY(x) ((ltree*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x)))) -#define PG_GETARG_LQUERY(x) ((lquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x)))) -#define PG_GETARG_LQUERY_COPY(x) ((lquery*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x)))) -#define PG_GETARG_LTXTQUERY(x) ((ltxtquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x)))) -#define PG_GETARG_LTXTQUERY_COPY(x) ((ltxtquery*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x)))) +#define DatumGetLtreeP(X) ((ltree *) PG_DETOAST_DATUM(X)) +#define DatumGetLtreePCopy(X) ((ltree *) PG_DETOAST_DATUM_COPY(X)) +#define PG_GETARG_LTREE(n) DatumGetLtreeP(PG_GETARG_DATUM(n)) +#define PG_GETARG_LTREE_COPY(n) DatumGetLtreePCopy(PG_GETARG_DATUM(n)) + +#define DatumGetLqueryP(X) ((lquery *) PG_DETOAST_DATUM(X)) +#define DatumGetLqueryPCopy(X) ((lquery *) PG_DETOAST_DATUM_COPY(X)) +#define PG_GETARG_LQUERY(n) DatumGetLqueryP(PG_GETARG_DATUM(n)) +#define PG_GETARG_LQUERY_COPY(n) DatumGetLqueryPCopy(PG_GETARG_DATUM(n)) + +#define DatumGetLtxtqueryP(X) ((ltxtquery *) PG_DETOAST_DATUM(X)) +#define DatumGetLtxtqueryPCopy(X) ((ltxtquery *) PG_DETOAST_DATUM_COPY(X)) +#define PG_GETARG_LTXTQUERY(n) DatumGetLtxtqueryP(PG_GETARG_DATUM(n)) +#define PG_GETARG_LTXTQUERY_COPY(n) DatumGetLtxtqueryPCopy(PG_GETARG_DATUM(n)) /* GiST support for ltree */ diff --git a/ltree_gist.c b/ltree_gist.c index 045974a..459e2c8 100644 --- a/ltree_gist.c +++ b/ltree_gist.c @@ -10,6 +10,11 @@ #include "crc32.h" #include "ltree.h" +#if PG_VERSION_NUM >= 160000 +#include "varatt.h" +#include "utils/array.h" +#endif + #define NEXTVAL(x) ( (lquery*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) ) PG_FUNCTION_INFO_V1(ltree_gist_in); @@ -69,7 +74,7 @@ ltree_compress(PG_FUNCTION_ARGS) if (entry->leafkey) { /* ltree */ ltree_gist *key; - ltree *val = (ltree *) DatumGetPointer(PG_DETOAST_DATUM(entry->key)); + ltree *val = DatumGetLtreeP(entry->key); int4 len = LTG_HDRSIZE + VARSIZE(val); key = (ltree_gist *) palloc(len); @@ -89,7 +94,7 @@ Datum ltree_decompress(PG_FUNCTION_ARGS) { GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0); - ltree_gist *key = (ltree_gist *) DatumGetPointer(PG_DETOAST_DATUM(entry->key)); + ltree_gist *key = (ltree_gist *) PG_DETOAST_DATUM(entry->key); if (PointerGetDatum(key) != entry->key) { @@ -707,7 +712,7 @@ ltree_consistent(PG_FUNCTION_ARGS) break; case 16: case 17: - query = DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1))); + query = PG_GETARG_ARRAYTYPE_P(1); if (GIST_LEAF(entry)) res = DatumGetBool(DirectFunctionCall2(lt_q_regex, PointerGetDatum(LTG_NODE(key)), diff --git a/ltree_io.c b/ltree_io.c index 0049fe0..000aa2b 100644 --- a/ltree_io.c +++ b/ltree_io.c @@ -10,6 +10,10 @@ #include "ltree.h" #include "crc32.h" +#if PG_VERSION_NUM >= 160000 +#include "varatt.h" +#endif + PG_FUNCTION_INFO_V1(ltree_in); Datum ltree_in(PG_FUNCTION_ARGS); diff --git a/ltree_op.c b/ltree_op.c index c8b076a..7a5a360 100644 --- a/ltree_op.c +++ b/ltree_op.c @@ -14,6 +14,9 @@ #include "utils/lsyscache.h" #include "utils/selfuncs.h" #include "ltree.h" +#if PG_VERSION_NUM >= 160000 +#include "varatt.h" +#endif PG_MODULE_MAGIC; diff --git a/ltxtquery_io.c b/ltxtquery_io.c index 826f4e1..33be326 100644 --- a/ltxtquery_io.c +++ b/ltxtquery_io.c @@ -9,6 +9,9 @@ #include "crc32.h" #include "ltree.h" +#if PG_VERSION_NUM >= 160000 +#include "varatt.h" +#endif PG_FUNCTION_INFO_V1(ltxtq_in); Datum ltxtq_in(PG_FUNCTION_ARGS); diff --git a/wltree.dylib b/wltree.dylib new file mode 100755 index 0000000..cf45fd9 Binary files /dev/null and b/wltree.dylib differ