Skip to content

Commit ab55c86

Browse files
committed
Make imgsmlr compatible with PostgreSQL 16
1 parent c484a15 commit ab55c86

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

imgsmlr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
*-------------------------------------------------------------------------
1414
*/
1515
#include "postgres.h"
16+
#ifndef VARDATA_ANY
17+
#include "varatt.h"
18+
#endif
1619

1720
#include "c.h"
1821
#include "fmgr.h"

imgsmlr.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,13 @@ typedef struct
3737
#define CHECK_SIGNATURE_KEY(key) Assert(VARSIZE_ANY_EXHDR(key) == sizeof(Signature) || VARSIZE_ANY_EXHDR(key) == 2 * sizeof(Signature));
3838

3939
#endif /* IMGSMLR_H */
40+
41+
42+
#ifndef FALSE
43+
#define FALSE (0)
44+
#endif
45+
46+
47+
#ifndef TRUE
48+
#define TRUE (!FALSE)
49+
#endif

imgsmlr_idx.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
*-------------------------------------------------------------------------
1414
*/
1515
#include "postgres.h"
16+
#ifndef VARDATA_ANY
17+
#include "varatt.h"
18+
#endif
19+
1620
#include "fmgr.h"
1721
#include "imgsmlr.h"
1822
#include "access/gist.h"
@@ -77,19 +81,22 @@ signature_compress(PG_FUNCTION_ARGS)
7781
Datum
7882
signature_decompress(PG_FUNCTION_ARGS)
7983
{
80-
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
81-
bytea *key = DatumGetByteaP(PG_DETOAST_DATUM(entry->key));
82-
83-
if (key != DatumGetByteaP(entry->key))
84-
{
85-
GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
86-
87-
gistentryinit(*retval, PointerGetDatum(key),
88-
entry->rel, entry->page,
89-
entry->offset, FALSE);
90-
PG_RETURN_POINTER(retval);
91-
}
92-
PG_RETURN_POINTER(entry);
84+
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
85+
bytea *detoastedKey = DatumGetByteaP(entry->key);
86+
bytea *key = (bytea *) entry->key;
87+
88+
// Variable key is the original entry->key before detoasting, and it’s compared with the
89+
// detoasted key. If they’re different, a new GISTENTRY is created. Otherwise, the original entry is returned.
90+
if (key != detoastedKey)
91+
{
92+
GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
93+
94+
gistentryinit(*retval, PointerGetDatum(key),
95+
entry->rel, entry->page,
96+
entry->offset, FALSE);
97+
PG_RETURN_POINTER(retval);
98+
}
99+
PG_RETURN_POINTER(entry);
93100
}
94101

95102
Datum

0 commit comments

Comments
 (0)