Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lbartoletti
Copy link
Contributor

This PR supersedes https://git.osgeo.org/gitea/postgis/postgis/pulls/208 and #777.

@ralian If I'm not mistaken, you don't need to include _USE_MATH_DEFINES in multiple files. It can be defined once globally. Could you test this PR?
If the AC_DEFINE approach is not sufficient, you can define it by adding CPPFLAGS="$CPPFLAGS -D_USE_MATH_DEFINES".

I'm also proposing an alternative version of the attribute macro that could be reused elsewhere in the codebase.

Introduce PRINTF_FORMAT(fmt, args) macro in new header `lwgeom_config.h` to handle
GCC and Clang-specific printf format checking. This improves portability by avoiding
direct usage of `__attribute__((format))` in function declarations.

Affected functions:
- lwnotice
- lwerror
- lwdebug
- GEOSMessageHandler
- lwgeom_geos_error
@lbartoletti lbartoletti requested review from robe2 and strk May 16, 2025 06:53
@lbartoletti
Copy link
Contributor Author

@robe2 @strk as mentioned on IRC/Matrix months ago, I also tried to switch from gnu11 to c11 in another branch. It's OK for *BSD (FreeBSD and macOs tested) but not for Linux, because of a problem in PostgreSQL elog.h (sigjmp_buf not defined):

In file included from /usr/local/pgsql/include/server/postgres.h:47,
from lwgeom_pg.c:17:
/usr/local/pgsql/include/server/utils/elog.h:358:20: error: unknown type name 'sigjmp_buf'
358 | extern PGDLLIMPORT sigjmp_buf *PG_exception_stack;
| ^~~~~~~~~~
In file included from /usr/local/pgsql/include/server/postgres.h:47,
from lwgeom_transform.c:15:
/usr/local/pgsql/include/server/utils/elog.h:358:20: error: unknown type name 'sigjmp_buf'
358 | extern PGDLLIMPORT sigjmp_buf *PG_exception_stack;
| ^~~~~~~~~~
In file included from /usr/local/pgsql/include/server/postgres.h:47,
from lwgeom_cache.c:13:
/usr/local/pgsql/include/server/utils/elog.h:358:20: error: unknown type name 'sigjmp_buf'
358 | extern PGDLLIMPORT sigjmp_buf *PG_exception_stack;
| ^~~~~~~~~~
In file included from /usr/local/pgsql/include/server/postgres.h:47,
from gserialized_gist.c:17:
/usr/local/pgsql/include/server/utils/elog.h:358:20: error: unknown type name 'sigjmp_buf'
358 | extern PGDLLIMPORT sigjmp_buf *PG_exception_stack;
| ^~~~~~~~~~
In file included from /usr/local/pgsql/include/server/postgres.h:47,
from lwgeom_cache.h:15,
from shared_gserialized.c:48:
/usr/local/pgsql/include/server/utils/elog.h:358:20: error: unknown type name 'sigjmp_buf'
358 | extern PGDLLIMPORT sigjmp_buf *PG_exception_stack;
| ^~~~~~~~~~
make[1]: *** [Makefile:68: shared_gserialized.o] Error 1

Here's where I stand at the moment.

@coderabbitai
Copy link

coderabbitai bot commented May 16, 2025

📝 Walkthrough

Walkthrough

A macro for format string checking, PRINTF_FORMAT, was introduced in a new configuration header and applied to relevant variadic function declarations in logging and GEOS-related headers. The build configuration script was updated to define _USE_MATH_DEFINES for enabling math constants, with no changes to logic or control flow.

Changes

File(s) Change Summary
configure.ac Added unconditional definition of _USE_MATH_DEFINES for enabling math constants, mainly for MSVC support.
liblwgeom/lwgeom_config.h New header defining PRINTF_FORMAT macro for compiler-specific format string checking attributes.
liblwgeom/lwgeom_geos.h Replaced direct use of GCC format attribute with PRINTF_FORMAT macro; included lwgeom_config.h.
liblwgeom/lwgeom_log.h Replaced direct use of GCC format attribute with PRINTF_FORMAT macro; included lwgeom_config.h.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Application
    participant lwgeom_log.h
    participant lwgeom_config.h

    User->>Application: Calls logging function (e.g., lwnotice)
    Application->>lwgeom_log.h: Uses PRINTF_FORMAT macro in declaration
    lwgeom_log.h->>lwgeom_config.h: Expands PRINTF_FORMAT for compiler
    lwgeom_config.h-->>lwgeom_log.h: Provides attribute or nothing
    Application-->>User: Logging proceeds with format string checking (if supported)
Loading

Poem

In the realm of code, a macro appears,
PRINTF_FORMAT hops in, dispelling old fears.
Math constants enabled, logs now precise,
With headers and scripts all playing nice.
A rabbit applauds with a jubilant cheer—
“To safer formats and math constants this year!”
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8bc70be and 7833d91.

📒 Files selected for processing (4)
  • configure.ac (1 hunks)
  • liblwgeom/lwgeom_config.h (1 hunks)
  • liblwgeom/lwgeom_geos.h (2 hunks)
  • liblwgeom/lwgeom_log.h (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: macOS
  • GitHub Check: 14.2-RELEASE
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: CI (latest, tests)
  • GitHub Check: CI (pg13-geos38-gdal31-proj71, tests)
  • GitHub Check: CI (pg14-geos39-gdal33-proj71, tests)
  • GitHub Check: CI (pg12-geos38-gdal30-proj611, tests)
  • GitHub Check: CI (pg16-geos312-gdal37-proj921, coverage)
  • GitHub Check: CI (pg15-clang-geos311-gdal35-proj90, usan_clang)
  • GitHub Check: CI (pg13-clang-geos39-gdal31-proj71, usan_clang)
  • GitHub Check: CI (pg15-geos311-gdal35-proj90, coverage)
  • GitHub Check: CI (pg17-geosmain-gdal39-proj94, coverage)
🔇 Additional comments (8)
liblwgeom/lwgeom_config.h (2)

1-24: Well-structured license and copyright header.

The standard PostGIS license header and copyright information is appropriately included.


26-30: Good implementation of a compiler-agnostic format attribute macro.

The PRINTF_FORMAT macro is well-designed to handle compiler differences, using the __attribute__ mechanism for GCC and Clang while gracefully degrading for other compilers like MSVC.

This approach improves cross-platform compatibility while maintaining the benefits of format string checking where supported. The use of preprocessor conditionals is appropriate for this use case.

configure.ac (1)

189-192: Good approach for defining MSVC math constants globally.

Adding _USE_MATH_DEFINES once in the build configuration is cleaner than including it in multiple source files, as mentioned in the PR objectives.

This definition enables access to math constants like M_PI in MSVC builds, improving cross-platform compatibility.

liblwgeom/lwgeom_geos.h (3)

26-27: Appropriate include of the new configuration header.

Including lwgeom_config.h provides access to the PRINTF_FORMAT macro needed later in this file.


30-30: Successfully replaced GCC-specific attribute with portable macro.

The typedef for GEOSMessageHandler now uses the portable PRINTF_FORMAT macro instead of a direct compiler-specific attribute.


55-55: Consistent use of the portable format attribute macro.

The function declaration for lwgeom_geos_error now uses the portable PRINTF_FORMAT macro, ensuring consistency with the other changes.

liblwgeom/lwgeom_log.h (2)

33-33: Appropriate include of the new configuration header.

Including lwgeom_config.h provides access to the PRINTF_FORMAT macro needed for the function declarations in this file.


130-130: Consistent application of the portable format attribute macro.

All three logging function declarations (lwnotice, lwerror, and lwdebug) now use the portable PRINTF_FORMAT macro instead of compiler-specific attributes.

This change maintains the format string checking capability for supported compilers while improving compatibility with MSVC.

Also applies to: 140-140, 149-149

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@robe2
Copy link
Member

robe2 commented Oct 13, 2025

@lbartoletti sorry haven't had a chance to look at this. Regarding https://gitea.osgeo.org/gitea/postgis/postgis/pulls/208 I had pushed this pull request over there so we could have more thorough testing.

@robe2
Copy link
Member

robe2 commented Oct 13, 2025

Oh wait I didn't notice there were 2 so I'll update https://gitea.osgeo.org/gitea/postgis/postgis/pulls/208 with this one

@robe2
Copy link
Member

robe2 commented Oct 13, 2025

Oh wait I didn't notice there were 2 so I'll update https://gitea.osgeo.org/gitea/postgis/postgis/pulls/208 with this one

Okay repointed the gitea one to what you have here so far.

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