Skip to content

Use PG_MODULE_MAGIC_EXT in PostgreSQL 18 and later#3112

Merged
cvvergara merged 1 commit into
pgRouting:developfrom
jeltz:pg-module-magic-ext
Jun 10, 2026
Merged

Use PG_MODULE_MAGIC_EXT in PostgreSQL 18 and later#3112
cvvergara merged 1 commit into
pgRouting:developfrom
jeltz:pg-module-magic-ext

Conversation

@jeltz

@jeltz jeltz commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

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().

This commit also moves the use of PG_MODULE_MAGIC to a less awkward place. While it is not 100% connected to the version functions it is much more connect to them than to Djikstra.

Changes proposed in this pull request:

  • Use PG_MODULE_MAGIC_EXT in PostgreSQL 18
  • Move PG_MODULE_MAGIC to version.c

@pgRouting/admins

Not sure if you prefer #if PG_VERSION_NUM >= 180000 or #ifdef PG_VERSION_MAGIC_EXT. I personally prefer the former but found no examples of what you normally use when looking at the code.

Summary by CodeRabbit

  • Chores
    • Updated internal module configuration for PostgreSQL extension compatibility. No user-facing changes.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 19117793-6977-4144-ab7e-5dcc934cebaf

📥 Commits

Reviewing files that changed from the base of the PR and between 1e5523e and d4f894e.

📒 Files selected for processing (2)
  • src/dijkstra/dijkstra.c
  • src/version/version.c
💤 Files with no reviewable changes (1)
  • src/dijkstra/dijkstra.c

Walkthrough

The PR updates PostgreSQL module initialization to support version-dependent behavior and consolidates magic declarations. The version module now uses PG_MODULE_MAGIC_EXT when available for PostgreSQL 18+ compatibility, while dijkstra.c removes its redundant declaration.

Changes

PostgreSQL Module Version Compatibility

Layer / File(s) Summary
Version-dependent module initialization in version module
src/version/version.c
Module initialization conditionally uses PG_MODULE_MAGIC_EXT with extension name and PROJECT_VERSION for PostgreSQL 18+, falling back to PG_MODULE_MAGIC for earlier versions.
Remove duplicate module magic from dijkstra module
src/dijkstra/dijkstra.c
PG_MODULE_MAGIC declaration is removed, consolidating module initialization to the version module.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A magic macro moves to version's care,
Dijkstra says goodbye without a spare,
PostgreSQL dances, eighteen's in sight,
One source of truth shines crystal bright!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main change: moving to PG_MODULE_MAGIC_EXT for PostgreSQL 18+.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Infer (1.2.0)
src/version/version.c

src/version/version.c:29:10: fatal error: 'c_common/postgres_connection.h' file not found
29 | #include "c_common/postgres_connection.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Error: the following clang command did not run successfully:
/opt/infer-linux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/bin/clang-18
@/tmp/coderabbit-infer/d4f894e096ccd270e52919158916461f685fb77f-2a51ef1aa298c854/tmp/clang_command_.tmp.78ca19.txt
++Contents of '/tmp/coderabbit-infer/d4f894e096ccd270e52919158916461f685fb77f-2a51ef1aa298c854/tmp/clang_command_.tmp.78ca19.txt':
"-cc1" "-load"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../../facebook-clang-plugins/libtooling/build/FacebookClangPlugin.dylib"
"-add-plugin" "BiniouASTExporter" "-plugin-arg-BiniouASTExporter" "-"
"-plugin-arg-BiniouASTExporter" "PREPEND_CURRENT_DIR=1"
"-plugin-arg-BiniouASTExporter" "MAX_STRING_SIZE=65535" "-cc1" "-triple"
"x86_64-unknown-linu

... [truncated 743 characters] ...

t/infer-linux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/lib/clang/18/include"
"-internal-isystem" "/usr/local/include" "-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"
"-internal-externc-isystem" "/include" "-internal-externc-isystem"
"/usr/include" "-Wno-ignored-optimization-argument" "-Wno-everything"
"-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf"
"-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o"
"/tmp/coderabbit-infer/2a51ef1aa298c854/file.o" "-x" "c"
"src/version/version.c" "-O0" "-fno-builtin" "-include"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../lib/clang_wrappers/global_defines.h"
"-Wno-everything"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/version/version.c`:
- Around line 32-36: Replace the version-based preprocessor check with a feature
test: instead of checking PG_VERSION_NUM use `#ifdef` PG_MODULE_MAGIC_EXT so the
code compiles correctly when PG_MODULE_MAGIC_EXT is available; update the
conditional around PG_MODULE_MAGIC_EXT(.name = "pgrouting", .version =
PROJECT_VERSION) and keep the existing fallback to PG_MODULE_MAGIC so both the
extended macro and older Postgres builds are supported.

In `@src/version/version.h.in`:
- Line 32: The generated header defines PROJECT_VERSION which collides with the
CMake -DPROJECT_VERSION compile define and can drift; rename the header macro
(e.g., change PROJECT_VERSION in version.h.in to GENERATED_PROJECT_VERSION or
PROJECT_VERSION_STRING) and update any source that includes the header and
currently uses PROJECT_VERSION (notably the PG_MODULE_MAGIC_EXT(... .version =
PROJECT_VERSION) usage) to consume the renamed macro instead; keep the existing
CMake -DPROJECT_VERSION define for compile-time overrides if needed, or remove
that -D if you prefer the header value to be authoritative, but do not leave
both named PROJECT_VERSION.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4c30c67b-b7dd-4a7f-936d-c7eb550ebcff

📥 Commits

Reviewing files that changed from the base of the PR and between be1200a and 1e5523e.

📒 Files selected for processing (3)
  • src/dijkstra/dijkstra.c
  • src/version/version.c
  • src/version/version.h.in
💤 Files with no reviewable changes (1)
  • src/dijkstra/dijkstra.c

Comment thread src/version/version.c Outdated
Comment thread src/version/version.h.in Outdated
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().

This commit also moves the use of PG_MODULE_MAGIC to a less awkward
place. While it is not 100% connected to the version functions it is
much more connect to them than to Djikstra.
@jeltz jeltz force-pushed the pg-module-magic-ext branch from 1e5523e to d4f894e Compare June 9, 2026 16:42
@cvvergara cvvergara merged commit 5b63663 into pgRouting:develop Jun 10, 2026
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants