Skip to content

Conversation

@XuehaiPan
Copy link
Member

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 #15213 if this solves the issue #15213

  • I have raised an issue to propose this change (required for new features and bug fixes)

Related:

Checklist

Go over all the following points, and put an x in all the boxes that apply.
If you are unsure about any of these, don't hesitate to ask. We are here to help!

  • I have read the CONTRIBUTION guide. (required)
  • My change requires a change to the documentation.
  • I have updated the tests accordingly. (required for a bug fix or a new feature)
  • I have updated the documentation accordingly.
  • I have reformatted the code using make format. (required)
  • I have checked the code using make lint. (required)
  • I have ensured make test pass. (required)

@XuehaiPan XuehaiPan self-assigned this Jun 1, 2025
@XuehaiPan XuehaiPan added enhancement New feature or request cxx Something related to the CXX source code test-with-nightly-pybind11 Use nightly pybind11 in tests upstream Something related to upstream projects labels Jun 1, 2025
@codecov
Copy link

codecov bot commented Jun 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (ffc6fcc) to head (7eb87d5).
⚠️ Report is 18 commits behind head on main.

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           
Flag Coverage Δ
unittests 100.00% <ø> (ø)
unittests-cp310-Linux 100.00% <ø> (ø)
unittests-cp310-Windows 100.00% <ø> (ø)
unittests-cp310-macOS 100.00% <ø> (ø)
unittests-cp311-Linux 100.00% <ø> (ø)
unittests-cp311-Windows 100.00% <ø> (ø)
unittests-cp311-macOS 100.00% <ø> (ø)
unittests-cp312-Linux 100.00% <ø> (ø)
unittests-cp312-Windows 100.00% <ø> (ø)
unittests-cp312-macOS 100.00% <ø> (ø)
unittests-cp313-Linux 100.00% <ø> (ø)
unittests-cp313-Windows 100.00% <ø> (ø)
unittests-cp313-macOS 100.00% <ø> (ø)
unittests-cp313t-Linux 100.00% <ø> (ø)
unittests-cp313t-Windows 100.00% <ø> (ø)
unittests-cp313t-macOS 100.00% <ø> (ø)
unittests-cp314-Linux 100.00% <ø> (ø)
unittests-cp314-Windows 100.00% <ø> (ø)
unittests-cp314-macOS 100.00% <ø> (ø)
unittests-cp314t-Linux 100.00% <ø> (ø)
unittests-cp314t-Windows 100.00% <ø> (ø)
unittests-cp314t-macOS 100.00% <ø> (ø)
unittests-cp39-Linux 100.00% <ø> (ø)
unittests-cp39-Windows 100.00% <ø> (ø)
unittests-cp39-macOS 100.00% <ø> (ø)
unittests-pp310-Linux 100.00% <ø> (ø)
unittests-pp310-Windows 100.00% <ø> (ø)
unittests-pp310-macOS 100.00% <ø> (ø)
unittests-pp311-Linux 100.00% <ø> (ø)
unittests-pp311-Windows 100.00% <ø> (ø)
unittests-pp311-macOS 100.00% <ø> (ø)
unittests-pp39-Linux 100.00% <ø> (ø)
unittests-pp39-Windows 100.00% <ø> (ø)
unittests-pp39-macOS 100.00% <ø> (ø)
unittests-pydebug 100.00% <ø> (ø)
unittests-pydebug-cp310d-Linux 100.00% <ø> (ø)
unittests-pydebug-cp310d-Windows 100.00% <ø> (ø)
unittests-pydebug-cp310d-macOS 100.00% <ø> (ø)
unittests-pydebug-cp311d-Linux 100.00% <ø> (ø)
unittests-pydebug-cp311d-Windows 100.00% <ø> (ø)
unittests-pydebug-cp311d-macOS 100.00% <ø> (ø)
unittests-pydebug-cp312d-Linux 100.00% <ø> (ø)
unittests-pydebug-cp312d-Windows 100.00% <ø> (ø)
unittests-pydebug-cp312d-macOS 100.00% <ø> (ø)
unittests-pydebug-cp313d-Linux 100.00% <ø> (ø)
unittests-pydebug-cp313d-Windows 100.00% <ø> (ø)
unittests-pydebug-cp313d-macOS 100.00% <ø> (ø)
unittests-pydebug-cp313td-Linux 100.00% <ø> (ø)
unittests-pydebug-cp313td-Windows 100.00% <ø> (ø)
unittests-pydebug-cp313td-macOS 100.00% <ø> (ø)
unittests-pydebug-cp314d-Linux 100.00% <ø> (ø)
unittests-pydebug-cp314d-Windows 100.00% <ø> (ø)
unittests-pydebug-cp314d-macOS 100.00% <ø> (ø)
unittests-pydebug-cp314td-Linux 100.00% <ø> (ø)
unittests-pydebug-cp314td-Windows 100.00% <ø> (ø)
unittests-pydebug-cp314td-macOS 100.00% <ø> (ø)
unittests-pydebug-cp39d-Linux 100.00% <ø> (ø)
unittests-pydebug-cp39d-Windows 100.00% <ø> (ø)
unittests-pydebug-cp39d-macOS 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@XuehaiPan XuehaiPan requested a review from Copilot June 1, 2025 16:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_EMPTY to distinguish between macros defined as 0 vs. 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_EMPTY is 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 #if into multiple lines with aligned operators for clarity.
#if defined(PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT) &&                                   \

@XuehaiPan XuehaiPan changed the title fix: handle pybind11 macro defined as 0 fix: handle pybind11 macro defined as 0 instead of non-exist Jun 1, 2025
@XuehaiPan XuehaiPan force-pushed the macro-defined-as-zero branch from d54764a to 7eb87d5 Compare June 1, 2025 16:43
@XuehaiPan XuehaiPan merged commit 3b950a0 into metaopt:main Jun 2, 2025
132 checks passed
@XuehaiPan XuehaiPan deleted the macro-defined-as-zero branch June 2, 2025 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cxx Something related to the CXX source code enhancement New feature or request test-with-nightly-pybind11 Use nightly pybind11 in tests upstream Something related to upstream projects

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant