From 5558840285f37a383358122ed825bf4580e6b989 Mon Sep 17 00:00:00 2001 From: Andreas Karlsson Date: Mon, 8 Jun 2026 16:29:41 +0200 Subject: [PATCH 1/2] feat: use PG_MODULE_MAGIC_EXT in PostgreSQL 18 and later The PG_MODULE_MAGIC_EXT macro was added in PostgreSQL 18 and makes it possible to see which version of the library is actually loaded using pg_get_loaded_modules(). --- CHANGELOG.md | 1 + h3/src/init.c | 5 +++++ h3_postgis/CMakeLists.txt | 9 +++++++++ h3_postgis/src/config.h.in | 22 ++++++++++++++++++++++ h3_postgis/src/init.c | 6 ++++++ 5 files changed, 43 insertions(+) create mode 100644 h3_postgis/src/config.h.in diff --git a/CHANGELOG.md b/CHANGELOG.md index e3ae27cb..9ebc8f90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ avoid adding features or APIs which do not map onto the ## [4.5.0] - 2026-06-08 +- Use `PG_MODULE_MAGIC_EXT` macro in PostgreSQL 18 and later ([Andreas Karlsson]) ### Project diff --git a/h3/src/init.c b/h3/src/init.c index 1cd9700e..8f4940af 100644 --- a/h3/src/init.c +++ b/h3/src/init.c @@ -21,10 +21,15 @@ #include // PG_MODULE_MAGIC +#include "config.h" #include "guc.h" /* see https://www.postgresql.org/docs/current/xfunc-c.html#XFUNC-C-DYNLOAD */ +#if POSTGRESQL_VERSION_MAJOR >= 18 +PG_MODULE_MAGIC_EXT(.name = "h3", .version = POSTGRESQL_H3_VERSION); +#else PG_MODULE_MAGIC; +#endif void _PG_init(void) diff --git a/h3_postgis/CMakeLists.txt b/h3_postgis/CMakeLists.txt index 0ec8e22f..855ec635 100644 --- a/h3_postgis/CMakeLists.txt +++ b/h3_postgis/CMakeLists.txt @@ -45,6 +45,15 @@ PostgreSQL_add_extension(postgresql_h3_postgis sql/updates/h3_postgis--4.5.0--unreleased.sql ) +# configure +configure_file(src/config.h.in src/config.h) + +# include +target_include_directories(postgresql_h3_postgis PRIVATE + ${CMAKE_CURRENT_BINARY_DIR}/src + src +) + # link target_link_libraries(postgresql_h3_postgis PRIVATE postgresql_h3_shared h3) target_include_directories(postgresql_h3_postgis PRIVATE ${H3_INTERNAL_INCLUDE_DIR}) diff --git a/h3_postgis/src/config.h.in b/h3_postgis/src/config.h.in new file mode 100644 index 00000000..124d1ffd --- /dev/null +++ b/h3_postgis/src/config.h.in @@ -0,0 +1,22 @@ +/* + * Copyright 2023-2024 Zacharias Knudsen + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PGH3_CONFIG_H +#define PGH3_CONFIG_H + +#define POSTGRESQL_PGH3_VERSION "@INSTALL_VERSION@" + +#endif /* PGH3_CONFIG_H */ diff --git a/h3_postgis/src/init.c b/h3_postgis/src/init.c index a41447d3..b1a6676e 100644 --- a/h3_postgis/src/init.c +++ b/h3_postgis/src/init.c @@ -18,5 +18,11 @@ #include // PG_MODULE_MAGIC +#include "config.h" + /* see https://www.postgresql.org/docs/current/xfunc-c.html#XFUNC-C-DYNLOAD */ +#if POSTGRESQL_VERSION_MAJOR >= 18 +PG_MODULE_MAGIC_EXT(.name = "h3_postgis", .version = POSTGRESQL_PGH3_VERSION); +#else PG_MODULE_MAGIC; +#endif From 05f4d86c8000f4d811eae4256841e86805e17ced Mon Sep 17 00:00:00 2001 From: Darafei Praliaskouski Date: Mon, 8 Jun 2026 19:43:33 +0400 Subject: [PATCH 2/2] docs: address PG_MODULE_MAGIC_EXT review comments --- CHANGELOG.md | 6 ++++-- h3_postgis/src/config.h.in | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ebc8f90..63c8ada6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,9 +20,9 @@ avoid adding features or APIs which do not map onto the ## [Unreleased] -## [4.5.0] - 2026-06-08 +- Use `PG_MODULE_MAGIC_EXT` macro in PostgreSQL 18 and later ([#203], [Andreas Karlsson]) -- Use `PG_MODULE_MAGIC_EXT` macro in PostgreSQL 18 and later ([Andreas Karlsson]) +## [4.5.0] - 2026-06-08 ### Project @@ -357,7 +357,9 @@ avoid adding features or APIs which do not map onto the [#192]: https://github.com/postgis/h3-pg/issues/192 [#194]: https://github.com/postgis/h3-pg/pull/194 [#197]: https://github.com/postgis/h3-pg/pull/197 +[#203]: https://github.com/postgis/h3-pg/pull/203 [Abel Vázquez Montoro]: https://github.com/AbelVM +[Andreas Karlsson]: https://github.com/jeltz [Darafei Praliaskouski]: https://github.com/Komzpa [Eric Schoffstall]: https://github.com/yocontra [Paul Ramsey]: https://github.com/pramsey diff --git a/h3_postgis/src/config.h.in b/h3_postgis/src/config.h.in index 124d1ffd..fb4bb002 100644 --- a/h3_postgis/src/config.h.in +++ b/h3_postgis/src/config.h.in @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 Zacharias Knudsen + * Copyright 2026 Andreas Karlsson * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.