From 894f9bb1c44926716449ddd1aefb795e014fa323 Mon Sep 17 00:00:00 2001 From: Vitaly Davydov Date: Tue, 27 Jun 2023 12:07:28 +0300 Subject: [PATCH] [ISSUE-10] Implemented propagation of pg sphere version. --- Makefile | 3 +++ expected/init.out | 6 ++++++ sql/init.sql | 2 ++ src/output.c | 14 +++++++++++--- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index bc82eb4..a98cccd 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,9 @@ TESTS = init_test tables points euler circle line ellipse poly path box in contains_ops contains_ops_compat bounding_box_gist gnomo healpix \ moc mocautocast epochprop +PG_CFLAGS += -DPGSPHERE_VERSION=$(PGSPHERE_VERSION) +PG_CPPFLAGS += -DPGSPHERE_VERSION=$(PGSPHERE_VERSION) + ifndef CXXFLAGS # no support for CXXFLAGS in PGXS before v11 CXXFLAGS = -Wall -Wpointer-arith -Wendif-labels \ diff --git a/expected/init.out b/expected/init.out index 0af7764..375eeaf 100644 --- a/expected/init.out +++ b/expected/init.out @@ -3,3 +3,9 @@ -- does not depend on contents of pg_sphere.sql. -- CREATE EXTENSION pg_sphere; +select pg_sphere_version(); + pg_sphere_version +------------------- + 1.2.1 +(1 row) + diff --git a/sql/init.sql b/sql/init.sql index 0af7764..05b3516 100644 --- a/sql/init.sql +++ b/sql/init.sql @@ -3,3 +3,5 @@ -- does not depend on contents of pg_sphere.sql. -- CREATE EXTENSION pg_sphere; + +select pg_sphere_version(); diff --git a/src/output.c b/src/output.c index 865e458..60e7464 100644 --- a/src/output.c +++ b/src/output.c @@ -1,5 +1,12 @@ #include "types.h" +#if !defined(PGSPHERE_VERSION) +#error "PGSPHERE_VERSION macro is not set" +#endif + +#define PGSPHERE_STRINGIFY_INTERNAL(x) #x +#define PGSPHERE_STRINGIFY(x) PGSPHERE_STRINGIFY_INTERNAL(x) + /* Output functions */ @@ -527,7 +534,8 @@ spherebox_out(PG_FUNCTION_ARGS) Datum pg_sphere_version(PG_FUNCTION_ARGS) { - char *buffer = (char *) palloc(20); - sprintf(buffer, "1.1.5"); - PG_RETURN_CSTRING(buffer); + const char *s = PGSPHERE_STRINGIFY(PGSPHERE_VERSION); + char *p = (char *)palloc(strlen(s) + 1); + strcpy(p, s); + PG_RETURN_CSTRING(p); }