Skip to content

Update gconstructor.h handling #4620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

beutlich
Copy link
Member

@beutlich beutlich commented Apr 13, 2025

  • Introduce and apply name mangling to avoid MSVC duplicated symbols issue
  • Bump version by renaming file and macros

Closes #4576

FYI @KarlWernersson

Summary by CodeRabbit

  • Refactor
    • Updated naming conventions for constructor and destructor routines across components.
    • Adjusted method declarations and macros to align with a new, more consistent naming scheme.
    • These internal updates enhance code organization without altering functionality.

@beutlich beutlich added the L: C-Sources Issue addresses Modelica/Resources/C-Sources label Apr 13, 2025
@beutlich beutlich self-assigned this Apr 13, 2025
Copy link

coderabbitai bot commented Apr 13, 2025

"""

Walkthrough

The changes update the naming and macro conventions for constructor and destructor handling. References to gconstructor.h in the CMake file have been replaced with g2constructor.h. In several C source files, the include directives and function signatures have been updated to use the new naming macros (e.g., from G_DEFINE_CONSTRUCTOR to G2_DEFINE_CONSTRUCTOR and G_FUNCNAME to G2_FUNCNAME), while retaining static declarations. The header file g2constructor.h has been overhauled with new header guards and macro definitions to ensure consistency, particularly for MSVC builds, and introduces a G2_MODEL_PREFIX macro to support model-specific function name prefixing.

Changes

File(s) Change Summary
Modelica/Resources/BuildProjects/CMake/src.cmake Updated source lists (EXTC_SOURCES and TABLES_SOURCES) to replace gconstructor.h with g2constructor.h.
Modelica/Resources/C-Sources/ModelicaInternal.c, Modelica/Resources/C-Sources/ModelicaRandom.c, Modelica/Resources/C-Sources/ModelicaStandardTables.c Replaced header inclusions from gconstructor.h with g2constructor.h; updated function signatures to use G2_FUNCNAME and related macros (e.g., from G_HAS_CONSTRUCTORS to G2_HAS_CONSTRUCTORS); constructor and destructor macros updated accordingly; static declarations preserved.
Modelica/Resources/C-Sources/g2constructor.h Renamed header guard and all relevant macros from G_ to G2_ (e.g., G_DEFINE_CONSTRUCTORG2_DEFINE_CONSTRUCTOR, G_MSVC_CTORG2_MSVC_CTOR); introduced G2_MODEL_PREFIX macro conditionally defined by MODEL_IDENTIFIER for function name prefixing; updated all constructor/destructor macros and pragma handling to use the new G2_ prefix.

Assessment against linked issues

Objective Addressed Explanation
Ensure static declaration of constructor/destructor functions to prevent MSVC link conflicts ([#4576])
Update macros and naming conventions for constructor handling for MSVC builds ([#4576])

Poem

I'm a little rabbit, hopping in the code,
Watching old names shed their load.
With G2 macros shining bright and new,
My static functions now link smooth too.
In MSVC fields I happily roam,
Celebrating changes as I call code home!
"""

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 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 de2925b and c4bbb08.

📒 Files selected for processing (5)
  • Modelica/Resources/BuildProjects/CMake/src.cmake (2 hunks)
  • Modelica/Resources/C-Sources/ModelicaInternal.c (3 hunks)
  • Modelica/Resources/C-Sources/ModelicaRandom.c (2 hunks)
  • Modelica/Resources/C-Sources/ModelicaStandardTables.c (3 hunks)
  • Modelica/Resources/C-Sources/g2constructor.h (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Modelica/Resources/BuildProjects/CMake/src.cmake
🚧 Files skipped from review as they are similar to previous changes (2)
  • Modelica/Resources/C-Sources/ModelicaStandardTables.c
  • Modelica/Resources/C-Sources/g2constructor.h
🧰 Additional context used
🧬 Code Graph Analysis (1)
Modelica/Resources/C-Sources/ModelicaInternal.c (1)
.CI/Test/Common.c (1)
  • ModelicaError (44-48)
🪛 Cppcheck (2.10-2)
Modelica/Resources/C-Sources/ModelicaInternal.c

[error] 805-805: There is an unknown macro here somewhere. Configuration is required. If G2_DEFINE_CONSTRUCTOR is a macro then please configure it.

(unknownMacro)

Modelica/Resources/C-Sources/ModelicaRandom.c

[error] 80-80: There is an unknown macro here somewhere. Configuration is required. If G2_DEFINE_CONSTRUCTOR is a macro then please configure it.

(unknownMacro)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: external_c_checks_cmake_windows-msvc
  • GitHub Check: external_c_checks_cmake_windows-cygwin
🔇 Additional comments (9)
Modelica/Resources/C-Sources/ModelicaRandom.c (4)

51-51: Approved header file update.

The include directive is updated from gconstructor.h to g2constructor.h, which is part of the version bump and name mangling implementation to resolve the duplicate symbols issue with MSVC.


71-71: Approved conditional macro update.

The conditional compilation macro is updated from G_HAS_CONSTRUCTORS to G2_HAS_CONSTRUCTORS, maintaining consistency with the updated header file.


77-81: Approved constructor macro and pragma update.

The constructor-related macros are consistently updated with the G2_ prefix, and function name is now wrapped with G2_FUNCNAME to implement name mangling, which will help prevent duplicate symbols during linking with MSVC.

🧰 Tools
🪛 Cppcheck (2.10-2)

[error] 80-80: There is an unknown macro here somewhere. Configuration is required. If G2_DEFINE_CONSTRUCTOR is a macro then please configure it.

(unknownMacro)


84-89: Approved destructor macro and pragma update.

The destructor-related macros are consistently updated with the G2_ prefix, and function name is now wrapped with G2_FUNCNAME to implement name mangling, maintaining consistency with the constructor changes.

Modelica/Resources/C-Sources/ModelicaInternal.c (5)

282-282: Approved header file update.

The include directive is updated from gconstructor.h to g2constructor.h, consistent with the change in ModelicaRandom.c and part of the version bump to fix duplicate symbols in MSVC.


777-777: Approved conditional macro update for POSIX systems.

The conditional compilation macro is updated from G_HAS_CONSTRUCTORS to G2_HAS_CONSTRUCTORS for POSIX systems, maintaining consistency with the updated header file.


779-790: Approved constructor/destructor macro and function name updates for mutex handling.

The constructor and destructor macros for mutex initialization and destruction on POSIX systems are updated with the G2_ prefix, and function names are properly wrapped with G2_FUNCNAME to implement name mangling.


796-796: Approved conditional macro update for Windows systems.

The conditional compilation macro is updated from G_HAS_CONSTRUCTORS to G2_HAS_CONSTRUCTORS for Windows systems, maintaining consistency with the updated header file and the POSIX implementation.


802-815: Approved constructor/destructor macro and function name updates for critical section handling.

The constructor and destructor macros for critical section initialization and deletion on Windows are updated with the G2_ prefix, and function names are properly wrapped with G2_FUNCNAME to implement name mangling, consistent with the POSIX implementation.

🧰 Tools
🪛 Cppcheck (2.10-2)

[error] 805-805: There is an unknown macro here somewhere. Configuration is required. If G2_DEFINE_CONSTRUCTOR is a macro then please configure it.

(unknownMacro)

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

@beutlich beutlich changed the title Update gconstructor handling Update gconstructor.h handling Apr 13, 2025
Copy link
Contributor

@HansOlsson HansOlsson left a comment

Choose a reason for hiding this comment

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

LGTM

@beutlich beutlich enabled auto-merge (squash) April 15, 2025 04:59
* Introduce and apply name mangling to avoid MSVC duplicated symbols issue
* Bump version by renaming file and macros
@beutlich beutlich force-pushed the update-gconstructor-handling branch from de2925b to c4bbb08 Compare April 21, 2025 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L: C-Sources Issue addresses Modelica/Resources/C-Sources
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problems with gconstructor.h and source FMU's in MSVC
2 participants