fix: handle pybind11 macro defined as 0 instead of non-exist#227
Merged
XuehaiPan merged 2 commits intometaopt:mainfrom Jun 2, 2025
Merged
fix: handle pybind11 macro defined as 0 instead of non-exist#227XuehaiPan merged 2 commits intometaopt:mainfrom
pybind11 macro defined as 0 instead of non-exist#227XuehaiPan merged 2 commits intometaopt:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #227 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 14 14
Lines 1403 1403
Branches 173 173
=========================================
Hits 1403 1403 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a helper macro to correctly detect macros defined as 0 and updates several build‐time flag checks to use it.
- Define
NONZERO_OR_EMPTYto distinguish between macros defined as0vs. undefined/empty. - Apply the new check to Python and pybind11 feature flags.
- Undefine the helper macro after use.
Comments suppressed due to low confidence (3)
src/optree.cpp:67
- There are no tests covering the scenario where these build macros are defined as 0; consider adding tests that compile with macros explicitly set to 0 to verify the expected boolean behavior.
#if defined(Py_DEBUG) && NONZERO_OR_EMPTY(Py_DEBUG)
src/optree.cpp:56
- [nitpick] The macro name
NONZERO_OR_EMPTYis generic and could conflict; consider prefixing it (e.g.,OPTREE_NONZERO_OR_EMPTY) to avoid potential naming collisions.
#define NONZERO_OR_EMPTY(MACRO) ((MACRO + 0 != 0) || (0 - MACRO - 1 >= 0))
src/optree.cpp:84
- [nitpick] This line break and indentation make the condition hard to read; consider reformatting the
#ifinto multiple lines with aligned operators for clarity.
#if defined(PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT) && \
pybind11 macro defined as 0 instead of non-exist
d54764a to
7eb87d5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Describe your changes in detail.
Motivation and Context
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.
You can use the syntax
close #15213if this solves the issue #15213Related:
Checklist
Go over all the following points, and put an
xin all the boxes that apply.If you are unsure about any of these, don't hesitate to ask. We are here to help!
make format. (required)make lint. (required)make testpass. (required)