From 3811bf317ed02a0d0d5eb9c5361efecf43314b09 Mon Sep 17 00:00:00 2001 From: Binaek Sarkar Date: Fri, 19 Jan 2024 16:27:58 +0530 Subject: [PATCH] support for pg16 --- Makefile | 6 ++++++ fdw/Makefile | 8 +++++++- fdw/fdw_helpers.h | 11 +++++++++-- helpers.go | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 418a81dd..5fb700f8 100644 --- a/Makefile +++ b/Makefile @@ -9,8 +9,14 @@ install: build if test -d ~/.steampipe/db/14.2.0; then \ cp ./build-$(PLATFORM)/steampipe_postgres_fdw--1.0.sql $(STEAMPIPE_INSTALL_DIR)/db/14.2.0/postgres/share/postgresql/extension/; \ cp ./build-$(PLATFORM)/steampipe_postgres_fdw.control $(STEAMPIPE_INSTALL_DIR)/db/14.2.0/postgres/share/postgresql/extension/; \ + fi + + if test -f ./build-$(PLATFORM)/steampipe_postgres_fdw.so; then \ cp ./build-$(PLATFORM)/steampipe_postgres_fdw.so $(STEAMPIPE_INSTALL_DIR)/db/14.2.0/postgres/lib/postgresql/; \ fi + if test -f ./build-$(PLATFORM)/steampipe_postgres_fdw.dylib; then \ + cp ./build-$(PLATFORM)/steampipe_postgres_fdw.dylib $(STEAMPIPE_INSTALL_DIR)/db/14.2.0/postgres/lib/postgresql/; \ + fi # build standalone standalone: validate_plugin prebuild.go diff --git a/fdw/Makefile b/fdw/Makefile index 0907f7d2..865d4eba 100644 --- a/fdw/Makefile +++ b/fdw/Makefile @@ -44,11 +44,17 @@ ifeq ($(shell uname -s),Darwin) export CGO_LDFLAGS = -Wl,-undefined,dynamic_lookup endif +# if we are building for pg16, we need to use the pg10 build tags +ifeq ($(shell $(PG_CONFIG) --version | cut -d' ' -f2 | cut -d'.' -f1), 14) + BUILD_TAGS := $(BUILD_TAGS),pg14 +endif + go: ../fdw.go + @echo $(BUILD_TAGS) # we are building with the net package from go # this has the caveat that, since we are not binding to lresolv, DNS resolution may # have some subtle differences from system DNS resolution - CGO_ENABLED=1 go build -v -x -o steampipe_postgres_fdw.a -tags "$(BUILD_TAGS)" -buildmode=c-archive ../*.go + CGO_ENABLED=1 go build -v -o steampipe_postgres_fdw.a -tags "$(BUILD_TAGS)" -buildmode=c-archive ../*.go inst: mkdir -p ../build-${PLATFORM} diff --git a/fdw/fdw_helpers.h b/fdw/fdw_helpers.h index e504af88..91ae072b 100644 --- a/fdw/fdw_helpers.h +++ b/fdw/fdw_helpers.h @@ -39,8 +39,6 @@ static inline void *fdw_getStruct(HeapTuple tuple) { return GETSTRUCT(tuple); } static inline NodeTag fdw_nodeTag(Expr *node) { return nodeTag(node); } -static inline Datum fdw_boolGetDatum(bool b) { PG_RETURN_BOOL(b); } - #if PG_VERSION_NUM >= 160000 static inline Datum fdw_cStringGetDatum(const char *str) { PG_RETURN_DATUM(CStringGetTextDatum((char *)str)); } static inline Datum fdw_jsonbGetDatum(const char *str) { PG_RETURN_JSONB_P((char *)DirectFunctionCall1(jsonb_in, CStringGetDatum(str))); } @@ -48,6 +46,8 @@ static inline Datum fdw_jsonbGetDatum(const char *str) { PG_RETURN_JSONB_P((char static inline Datum fdw_cStringGetDatum(const char *str) { PG_RETURN_TEXT_P(CStringGetTextDatum(str)); } static inline Datum fdw_jsonbGetDatum(const char *str) { PG_RETURN_JSONB_P(DirectFunctionCall1(jsonb_in, CStringGetDatum(str))); } #endif + +static inline Datum fdw_boolGetDatum(bool b) { PG_RETURN_BOOL(b); } static inline Datum fdw_numericGetDatum(int64_t num) { PG_RETURN_INT64(Int64GetDatum(num)); } static inline Datum fdw_floatGetDatum(double num) { PG_RETURN_FLOAT8(Float8GetDatum(num)); } static inline Datum fdw_pointerGetDatum(void *num) { PG_RETURN_DATUM(PointerGetDatum(num)); } @@ -70,6 +70,13 @@ static inline char *valueString(String *v) { return strVal(v); } #else static inline char *valueString(Value *v) { return (((Value *)(v))->val.str); } #endif + +#if PG_VERSION_NUM >= 160000 +static inline void fdw_appendBinaryStringInfo(StringInfo str, const char *data, int datalen) { appendBinaryStringInfo(str,(void *)data,datalen); } +#else +static inline void fdw_appendBinaryStringInfo(StringInfo str, const char *data, int datalen) { appendBinaryStringInfo(str,data,datalen); } +#endif + static inline char **incStringPointer(char **ptr) { return ++ptr; } static inline unsigned char *incUcharPointer(unsigned char *ptr) { return ++ptr; } static inline unsigned char *ipAddr(inet *i) { return ip_addr(i); } diff --git a/helpers.go b/helpers.go index 9e770733..7b682861 100644 --- a/helpers.go +++ b/helpers.go @@ -197,7 +197,7 @@ func valToBuffer(val interface{}, oid C.Oid, buffer C.StringInfo) (err error) { } C.resetStringInfo(buffer) - C.appendBinaryStringInfo(buffer, unsafe.Pointer(C.CString(valueString)), C.int(len(valueString))) + C.fdw_appendBinaryStringInfo(buffer, C.CString(valueString), C.int(len(valueString))) return }