Skip to content
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

[smart_holder] Introduce PYBIND11_SMART_HOLDER_DISABLE option. #5348

Merged
merged 4 commits into from
Sep 1, 2024

Conversation

rwgk
Copy link
Collaborator

@rwgk rwgk commented Sep 1, 2024

Description

Introduce a PYBIND11_SMART_HOLDER_DISABLE macro.

Note that the PYBIND11_INTERNALS_ID is identical with and without that define.

That way the smart_holder feature is available by default, but users concerned about compile-time or runtime overhead can use the macro to essentially eliminate the overhead completely, without breaking full internals-compatibility with pybind11 extensions that have the smart_holder feature enabled.

Probably, the extra time the preprocessor needs to strip out the smart_holder code is virtually unmeasurable. The extra compile time for the tiny internals addition is probably also unmeasurable.

See also: #5339 (comment)

Suggested changelog entry:

Ralf W. Grosse-Kunstleve added 4 commits September 1, 2024 12:03
… under include/pybind11/

At the stage `PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT` and `PYBIND11_SMART_HOLDER_ENABLED` are still equivalent.
…SUPPORT` with `PYBIND11_SMART_HOLDER_ENABLED` under tests/ and ubench/

As at the previous stage, `PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT` and `PYBIND11_SMART_HOLDER_ENABLED` are still equivalent.
…ning-as-error under macos-13

```
/Users/runner/work/pybind11/pybind11/tests/test_class_sh_trampoline_basic.cpp:67:23: error: unused parameter 'm' [-Werror,-Wunused-parameter]
void wrap(py::module_ m, const char *py_class_name) {
                      ^
/Users/runner/work/pybind11/pybind11/tests/test_class_sh_trampoline_basic.cpp:67:38: error: unused parameter 'py_class_name' [-Werror,-Wunused-parameter]
void wrap(py::module_ m, const char *py_class_name) {
                                     ^
2 errors generated.
```
@rwgk rwgk marked this pull request as ready for review September 1, 2024 21:34
@rwgk rwgk requested a review from henryiii as a code owner September 1, 2024 21:34
@rwgk rwgk merged commit bd8985a into pybind:smart_holder Sep 1, 2024
80 checks passed
@rwgk rwgk deleted the pybind11_smart_holder_disable_macro branch September 1, 2024 21:34
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Sep 1, 2024
@rwgk rwgk removed the needs changelog Possibly needs a changelog entry label Sep 1, 2024
rwgk pushed a commit to rwgk/pybind11 that referenced this pull request Sep 2, 2024
…ind#5348)

* Step 1: Establish new `PYBIND11_SMART_HOLDER_ENABLED` macro, but only under include/pybind11/

At the stage `PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT` and `PYBIND11_SMART_HOLDER_ENABLED` are still equivalent.

* Systematically replace all `PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT` with `PYBIND11_SMART_HOLDER_ENABLED` under tests/ and ubench/

As at the previous stage, `PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT` and `PYBIND11_SMART_HOLDER_ENABLED` are still equivalent.

* Introduce `PYBIND11_SMART_HOLDER_DISABLE` option.

* `#ifdef` out entire `wrap()` function to avoid `unused-parameter` warning-as-error under macos-13

```
/Users/runner/work/pybind11/pybind11/tests/test_class_sh_trampoline_basic.cpp:67:23: error: unused parameter 'm' [-Werror,-Wunused-parameter]
void wrap(py::module_ m, const char *py_class_name) {
                      ^
/Users/runner/work/pybind11/pybind11/tests/test_class_sh_trampoline_basic.cpp:67:38: error: unused parameter 'py_class_name' [-Werror,-Wunused-parameter]
void wrap(py::module_ m, const char *py_class_name) {
                                     ^
2 errors generated.
```
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.

1 participant