Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,8 @@ class mod_gil_not_used {
bool flag_;
};

inline mod_gil_not_used mod_gil_used() { return mod_gil_not_used(false); }

class multiple_interpreters {
public:
enum class level {
Expand Down
5 changes: 2 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,13 @@ function(pybind11_enable_warnings target_name)
${target_name}
PRIVATE -Wall
-Wextra
-Wpedantic
-Wconversion
-Wcast-qual
-Wdeprecated
-Wundef
-Wnon-virtual-dtor)
if(DEFINED CMAKE_CXX_STANDARD AND NOT CMAKE_CXX_STANDARD VERSION_LESS 20)
target_compile_options(${target_name} PRIVATE -Wpedantic)
endif()
target_link_options(${target_name} PRIVATE -Werror -Wodr -Wlto-type-mismatch)
endif()

if(PYBIND11_WERROR)
Expand Down
2 changes: 1 addition & 1 deletion tests/exo_planet_pybind11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace pybind11_tests {
namespace test_cpp_conduit {

PYBIND11_MODULE(exo_planet_pybind11, m) {
PYBIND11_MODULE(exo_planet_pybind11, m, pybind11::mod_gil_used()) {
wrap_traveler(m);
m.def("wrap_very_lonely_traveler", [m]() { wrap_very_lonely_traveler(m); });
}
Expand Down
2 changes: 1 addition & 1 deletion tests/extra_setuptools/test_setuphelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_simple_setup_py(monkeypatch, tmpdir, parallel, std):
int f(int x) {
return x * 3;
}
PYBIND11_MODULE(simple_setup, m) {
PYBIND11_MODULE(simple_setup, m, pybind11::mod_gil_used()) {
m.def("f", &f);
}
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/home_planet_very_lonely_traveler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace pybind11_tests {
namespace test_cpp_conduit {

PYBIND11_MODULE(home_planet_very_lonely_traveler, m) {
PYBIND11_MODULE(home_planet_very_lonely_traveler, m, py::mod_gil_used()) {
m.def("wrap_very_lonely_traveler", [m]() { wrap_very_lonely_traveler(m); });
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_class_sh_trampoline_shared_ptr_cpp_arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ std::shared_ptr<SpBase> pass_through_shd_ptr(const std::shared_ptr<SpBase> &obj)

struct PySpBase : SpBase, py::trampoline_self_life_support {
using SpBase::SpBase;
bool is_base_used() override { PYBIND11_OVERRIDE(bool, SpBase, is_base_used); }
bool is_base_used() override { PYBIND11_OVERRIDE(bool, SpBase, is_base_used, ); }
};

struct SpBaseTester {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_class_sh_trampoline_unique_ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ namespace class_sh_trampoline_unique_ptr {
class PyClass : public Class, public py::trampoline_self_life_support {
public:
std::unique_ptr<Class> clone() const override {
PYBIND11_OVERRIDE_PURE(std::unique_ptr<Class>, Class, clone);
PYBIND11_OVERRIDE_PURE(std::unique_ptr<Class>, Class, clone, );
}

int foo() const override { PYBIND11_OVERRIDE_PURE(int, Class, foo); }
int foo() const override { PYBIND11_OVERRIDE_PURE(int, Class, foo, ); }
};

} // namespace class_sh_trampoline_unique_ptr
Expand Down
4 changes: 2 additions & 2 deletions tests/test_class_sh_virtual_py_cpp_mix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ int get_from_cpp_unique_ptr(std::unique_ptr<Base> b) { return b->get() + 5000; }
struct BaseVirtualOverrider : Base, py::trampoline_self_life_support {
using Base::Base;

int get() const override { PYBIND11_OVERRIDE(int, Base, get); }
int get() const override { PYBIND11_OVERRIDE(int, Base, get, ); }
};

struct CppDerivedVirtualOverrider : CppDerived, py::trampoline_self_life_support {
using CppDerived::CppDerived;

int get() const override { PYBIND11_OVERRIDE(int, CppDerived, get); }
int get() const override { PYBIND11_OVERRIDE(int, CppDerived, get, ); }
};

} // namespace class_sh_virtual_py_cpp_mix
Expand Down
4 changes: 3 additions & 1 deletion tests/test_cmake_build/embed.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <pybind11/embed.h>
#include <pybind11/pybind11.h>

namespace py = pybind11;

PYBIND11_EMBEDDED_MODULE(test_cmake_build, m) {
PYBIND11_EMBEDDED_MODULE(test_cmake_build, m, py::multiple_interpreters::not_supported()) {
m.def("add", [](int i, int j) { return i + j; });
}

Expand Down
4 changes: 2 additions & 2 deletions tests/test_cross_module_rtti/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
class BaseTrampoline : public lib::Base, public pybind11::trampoline_self_life_support {
public:
using lib::Base::Base;
int get() const override { PYBIND11_OVERLOAD(int, lib::Base, get); }
int get() const override { PYBIND11_OVERLOAD(int, lib::Base, get, ); }
};

PYBIND11_MODULE(test_cross_module_rtti_bindings, m) {
PYBIND11_MODULE(test_cross_module_rtti_bindings, m, pybind11::mod_gil_used()) {
pybind11::classh<lib::Base, BaseTrampoline>(m, "Base")
.def(pybind11::init<int, int>())
.def_readwrite("a", &lib::Base::a)
Expand Down
15 changes: 9 additions & 6 deletions tests/test_embed/test_interpreter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <pybind11/critical_section.h>
#include <pybind11/embed.h>
#include <pybind11/pybind11.h>

// Silence MSVC C++17 deprecation warning from Catch regarding std::uncaught_exceptions (up to
// catch 2.0.1; this should be fixed in the next catch release after 2.0.1).
Expand Down Expand Up @@ -45,8 +46,8 @@ class Widget {
class PyWidget final : public Widget {
using Widget::Widget;

int the_answer() const override { PYBIND11_OVERRIDE_PURE(int, Widget, the_answer); }
std::string argv0() const override { PYBIND11_OVERRIDE_PURE(std::string, Widget, argv0); }
int the_answer() const override { PYBIND11_OVERRIDE_PURE(int, Widget, the_answer, ); }
std::string argv0() const override { PYBIND11_OVERRIDE_PURE(std::string, Widget, argv0, ); }
};

class test_override_cache_helper {
Expand All @@ -62,7 +63,7 @@ class test_override_cache_helper {
};

class test_override_cache_helper_trampoline : public test_override_cache_helper {
int func() override { PYBIND11_OVERRIDE(int, test_override_cache_helper, func); }
int func() override { PYBIND11_OVERRIDE(int, test_override_cache_helper, func, ); }
};

PYBIND11_EMBEDDED_MODULE(widget_module, m, py::multiple_interpreters::per_interpreter_gil()) {
Expand All @@ -76,17 +77,19 @@ PYBIND11_EMBEDDED_MODULE(widget_module, m, py::multiple_interpreters::per_interp
sub.def("add", [](int i, int j) { return i + j; });
}

PYBIND11_EMBEDDED_MODULE(trampoline_module, m) {
PYBIND11_EMBEDDED_MODULE(trampoline_module, m, py::multiple_interpreters::not_supported()) {
py::class_<test_override_cache_helper,
test_override_cache_helper_trampoline,
std::shared_ptr<test_override_cache_helper>>(m, "test_override_cache_helper")
.def(py::init_alias<>())
.def("func", &test_override_cache_helper::func);
}

PYBIND11_EMBEDDED_MODULE(throw_exception, ) { throw std::runtime_error("C++ Error"); }
PYBIND11_EMBEDDED_MODULE(throw_exception, , py::multiple_interpreters::not_supported()) {
throw std::runtime_error("C++ Error");
}

PYBIND11_EMBEDDED_MODULE(throw_error_already_set, ) {
PYBIND11_EMBEDDED_MODULE(throw_error_already_set, , py::multiple_interpreters::not_supported()) {
auto d = py::dict();
d["missing"].cast<py::object>();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_potentially_slicing_weak_ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ const char *determine_trampoline_state(const std::shared_ptr<VB> &sp) {

struct PyVirtBaseSH : VirtBaseSH, py::trampoline_self_life_support, trampoline_is_alive_simple {
using VirtBaseSH::VirtBaseSH;
int get_code() override { PYBIND11_OVERRIDE(int, VirtBaseSH, get_code); }
int get_code() override { PYBIND11_OVERRIDE(int, VirtBaseSH, get_code, ); }
};

struct PyVirtBaseSP : VirtBaseSP, trampoline_is_alive_simple { // self-life-support not available
using VirtBaseSP::VirtBaseSP;
int get_code() override { PYBIND11_OVERRIDE(int, VirtBaseSP, get_code); }
int get_code() override { PYBIND11_OVERRIDE(int, VirtBaseSP, get_code, ); }
};

template <typename VB>
Expand Down
10 changes: 5 additions & 5 deletions tests/test_smart_ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ struct holder_helper<ref<T>> {
PYBIND11_DECLARE_HOLDER_TYPE(T, ref<T>, true)
PYBIND11_DECLARE_HOLDER_TYPE(T, const_only_shared_ptr<T>, true)
// The following is not required anymore for std::shared_ptr, but it should compile without error:
PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>)
PYBIND11_DECLARE_HOLDER_TYPE(T, huge_unique_ptr<T>)
PYBIND11_DECLARE_HOLDER_TYPE(T, custom_unique_ptr<T>)
PYBIND11_DECLARE_HOLDER_TYPE(T, shared_ptr_with_addressof_operator<T>)
PYBIND11_DECLARE_HOLDER_TYPE(T, unique_ptr_with_addressof_operator<T>)
PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>, )
PYBIND11_DECLARE_HOLDER_TYPE(T, huge_unique_ptr<T>, )
PYBIND11_DECLARE_HOLDER_TYPE(T, custom_unique_ptr<T>, )
PYBIND11_DECLARE_HOLDER_TYPE(T, shared_ptr_with_addressof_operator<T>, )
PYBIND11_DECLARE_HOLDER_TYPE(T, unique_ptr_with_addressof_operator<T>, )

namespace holder_caster_traits_test {
struct example_base {};
Expand Down
16 changes: 8 additions & 8 deletions tests/test_virtual_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class test_override_cache_helper {
};

class test_override_cache_helper_trampoline : public test_override_cache_helper {
int func() override { PYBIND11_OVERRIDE(int, test_override_cache_helper, func); }
int func() override { PYBIND11_OVERRIDE(int, test_override_cache_helper, func, ); }
};

inline int test_override_cache(std::shared_ptr<test_override_cache_helper> const &instance) {
Expand Down Expand Up @@ -280,7 +280,7 @@ TEST_SUBMODULE(virtual_functions, m) {
py::print("PyA.f()");
// This convolution just gives a `void`, but tests that PYBIND11_TYPE() works to
// protect a type containing a ,
PYBIND11_OVERRIDE(PYBIND11_TYPE(typename std::enable_if<true, void>::type), A, f);
PYBIND11_OVERRIDE(PYBIND11_TYPE(typename std::enable_if<true, void>::type), A, f, );
}
};

Expand All @@ -303,7 +303,7 @@ TEST_SUBMODULE(virtual_functions, m) {
~PyA2() override { py::print("PyA2.~PyA2()"); }
void f() override {
py::print("PyA2.f()");
PYBIND11_OVERRIDE(void, A2, f);
PYBIND11_OVERRIDE(void, A2, f, );
}
};

Expand Down Expand Up @@ -371,26 +371,26 @@ TEST_SUBMODULE(virtual_functions, m) {
public:
using OverrideTest::OverrideTest;
std::string str_value() override {
PYBIND11_OVERRIDE(std::string, OverrideTest, str_value);
PYBIND11_OVERRIDE(std::string, OverrideTest, str_value, );
}
// Not allowed (enabling the below should hit a static_assert failure): we can't get a
// reference to a python numeric value, since we only copy values in the numeric type
// caster:
#ifdef PYBIND11_NEVER_DEFINED_EVER
std::string &str_ref() override {
PYBIND11_OVERRIDE(std::string &, OverrideTest, str_ref);
PYBIND11_OVERRIDE(std::string &, OverrideTest, str_ref, );
}
#endif
// But we can work around it like this:
private:
std::string _tmp;
std::string str_ref_helper() { PYBIND11_OVERRIDE(std::string, OverrideTest, str_ref); }
std::string str_ref_helper() { PYBIND11_OVERRIDE(std::string, OverrideTest, str_ref, ); }

public:
std::string &str_ref() override { return _tmp = str_ref_helper(); }

A A_value() override { PYBIND11_OVERRIDE(A, OverrideTest, A_value); }
A &A_ref() override { PYBIND11_OVERRIDE(A &, OverrideTest, A_ref); }
A A_value() override { PYBIND11_OVERRIDE(A, OverrideTest, A_value, ); }
A &A_ref() override { PYBIND11_OVERRIDE(A &, OverrideTest, A_ref, ); }
};

py::class_<OverrideTest::A>(m, "OverrideTest_A")
Expand Down
Loading