Skip to content

Commit

Permalink
Update context.cpp to comply with pybind11 2.0+ docs (#297)
Browse files Browse the repository at this point in the history
* LLVM 18 compatibility
* Update context.cpp to comply with pybind11 2.0+ docs
  • Loading branch information
andriish authored Apr 8, 2024
1 parent f8aeced commit bb23ba7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions source/class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,11 @@ bool is_callback_structure_needed(CXXRecordDecl const *C)
// check if all pure-virtual methods could be overridden in Python
if( C->isAbstract() ) {
for( auto m = C->method_begin(); m != C->method_end(); ++m ) {
#if( LLVM_VERSION_MAJOR >= 18 )
if( m->isPureVirtual() and is_const_overload(*m) ) return false; // it is not clear how to deal with this case since we can't overrdie const versions in Python, - so disabling for now
#else
if( m->isPure() and is_const_overload(*m) ) return false; // it is not clear how to deal with this case since we can't overrdie const versions in Python, - so disabling for now
#endif
}
}

Expand Down Expand Up @@ -644,7 +648,11 @@ bool is_callback_structure_constructible(CXXRecordDecl const *C)
{
if( C->isAbstract() ) {
for( auto m = C->method_begin(); m != C->method_end(); ++m ) {
#if( LLVM_VERSION_MAJOR >= 18 )
if( m->isPureVirtual() and !isa<CXXConstructorDecl>(*m) and (m->getAccess() == AS_private or !is_bindable(*m) or is_skipping_requested(*m, Config::get())) ) return false;
#else
if( m->isPure() and !isa<CXXConstructorDecl>(*m) and (m->getAccess() == AS_private or !is_bindable(*m) or is_skipping_requested(*m, Config::get())) ) return false;
#endif
}

for( auto b = C->bases_begin(); b != C->bases_end(); ++b ) {
Expand Down Expand Up @@ -766,7 +774,11 @@ string bind_member_functions_for_call_back(CXXRecordDecl const *C, string const
string custom_function_info = Config::get().is_custom_trampoline_function_requested(member_function_name);
if( custom_function_info == "" ) {
c += indent(fmt::format(call_back_function_body_template, class_name, /*class_qualified_name(C), */ python_name, std::get<1>(args), return_type), "\t\t");
#if( LLVM_VERSION_MAJOR >= 18 )
if( m->isPureVirtual() ) c += "\t\tpybind11::pybind11_fail(\"Tried to call pure virtual function \\\"{}::{}\\\"\");\n"_format(C->getNameAsString(), python_name);
#else
if( m->isPure() ) c += "\t\tpybind11::pybind11_fail(\"Tried to call pure virtual function \\\"{}::{}\\\"\");\n"_format(C->getNameAsString(), python_name);
#endif
else c += "\t\treturn {}::{}({});\n"_format(C->getNameAsString(), m->getNameAsString(), std::get<1>(args));
}
else {
Expand Down
4 changes: 2 additions & 2 deletions source/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const char *module_header = R"_(
#ifndef BINDER_PYBIND11_TYPE_CASTER
#define BINDER_PYBIND11_TYPE_CASTER
{2}
PYBIND11_DECLARE_HOLDER_TYPE(T, T*)
PYBIND11_DECLARE_HOLDER_TYPE(T, T*, false)
{3}
#endif
Expand Down Expand Up @@ -437,7 +437,7 @@ void Context::generate(Config const &config)

string const holder_type = Config::get().holder_type();

string shared_declare = "PYBIND11_DECLARE_HOLDER_TYPE(T, "+holder_type+"<T>)";
string shared_declare = "PYBIND11_DECLARE_HOLDER_TYPE(T, "+holder_type+"<T>, false)";
string shared_make_opaque = "PYBIND11_MAKE_OPAQUE("+holder_type+"<void>)";

string const pybind11_include = "#include <" + Config::get().pybind11_include_file() + ">";
Expand Down

0 comments on commit bb23ba7

Please sign in to comment.