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

calling a private destructor of class #289

Closed
MFaisalZaki opened this issue Mar 30, 2021 · 8 comments · Fixed by JuliaInterop/libcxxwrap-julia#92
Closed

calling a private destructor of class #289

MFaisalZaki opened this issue Mar 30, 2021 · 8 comments · Fixed by JuliaInterop/libcxxwrap-julia#92

Comments

@MFaisalZaki
Copy link

I'm trying to wrap the spot library for LTL using CxxWrap and I get this warning when trying to define the fnode type.

cpp code:
`
#include <jlcxx/jlcxx.hpp>

#include

#include
#include

#include <spot/tl/formula.hh>
#include <spot/tl/parse.hh>
#include <spot/tl/print.hh>
#include <spot/tl/apcollect.hh>

#include <spot/twa/formula2bdd.hh>
#include <spot/twa/acc.hh>
#include <spot/twaalgos/translate.hh>
#include <spot/twaalgos/dot.hh>
#include <spot/twaalgos/isdet.hh>
#include <spot/twaalgos/split.hh>
#include <spot/twaalgos/totgba.hh>

// std::cout << spot::parse_formula("[]<>p0 || <>[]p1") << '\n';
// spot::formula f = spot::parse_formula("& & G p0 p1 p2");

JLCXX_MODULE define_julia_module(jlcxx::Module& mod)
{
mod.add_typespot::fnode("fnode");
mod.method("parse_formula", &spot::parse_formula);
}

`

and when building I get this error:
Screen Shot 2021-03-30 at 7 33 26 PM

@stemann
Copy link

stemann commented Aug 24, 2021

Using CxxWrap 0.11.2 (and Julia 1.6), I just hit a similar obstacle, wrapping a class like:

    class CTlFactory
    {
    public:
        static CTlFactory& GetInstance();
    private:
        CTlFactory( void );
        CTlFactory& operator=( const CTlFactory& );
        CTlFactory( const CTlFactory& );

        virtual ~CTlFactory(void);
    };

with

JLCXX_MODULE define_pylon_wrapper(jlcxx::Module& module)
{
  module.add_type<CTlFactory>("TlFactory");
}

complaining:

[build] In file included from /root/.julia/artifacts/16e1de4679fb8520a8af4e6831c7c8e9893d18b4/include/jlcxx/jlcxx.hpp:14:
[build] /root/.julia/artifacts/16e1de4679fb8520a8af4e6831c7c8e9893d18b4/include/jlcxx/module.hpp:892:12: error: calling a private destructor of class 'Pylon::CTlFactory'
[build]     delete to_delete;
[build]            ^
[build] /root/.julia/artifacts/16e1de4679fb8520a8af4e6831c7c8e9893d18b4/include/jlcxx/module.hpp:937:34: note: in instantiation of function template specialization 'jlcxx::detail::finalize<Pylon::CTlFactory>' requested here
[build]   mod.method("__delete", detail::finalize<T>);
[build]                                  ^
[build] /root/.julia/artifacts/16e1de4679fb8520a8af4e6831c7c8e9893d18b4/include/jlcxx/module.hpp:1183:5: note: in instantiation of function template specialization 'jlcxx::add_default_methods<Pylon::CTlFactory>' requested here
[build]     add_default_methods<T>(*this);
[build]     ^
[build] /root/.julia/artifacts/16e1de4679fb8520a8af4e6831c7c8e9893d18b4/include/jlcxx/module.hpp:1194:10: note: in instantiation of function template specialization 'jlcxx::Module::add_type_internal<Pylon::CTlFactory, jlcxx::ParameterList<>, _jl_datatype_t>' requested here
[build]   return add_type_internal<T, SuperParametersT>(name, super);
[build]          ^
[build] /workspaces/pylon_julia_wrapper/src/pylon_wrapper.cpp:363:10: note: in instantiation of function template specialization 'jlcxx::Module::add_type<Pylon::CTlFactory, jlcxx::ParameterList<>, _jl_datatype_t>' requested here
[build]   module.add_type<CTlFactory>("TlFactory");
[build]          ^
[build] /opt/pylon5/include/pylon/TlFactory.h:116:17: note: declared private here
[build]         virtual ~CTlFactory(void);
[build]                 ^

@barche Is it possible to avoid adding the finalizer for the type?

Is the solution here to use jlcxx::create<ClassWithPrivateDestructor>(...) (and how?)

@stemann
Copy link

stemann commented Aug 27, 2021

Seems like it wasn't possible to just use jlcxx::create<ClassWithPrivateDestructor>(...):

JLCXX_MODULE define_pylon_wrapper(jlcxx::Module& module)
{
  module.add_type<CInstantCamera>("InstantCamera")
    .constructor(false)
    .method("InstantCamera", [](void* device) // constructor for InstantCamera
    {
      return jlcxx::create<CInstantCamera>((IPylonDevice*)device);
    });
}

as it is the add_type which sets up the finalizer...

Related discussion: https://discourse.julialang.org/t/cxxwrap-based-wrapper-throws-error-in-running-finalizer-readonlymemoryerror/67097

@stemann
Copy link

stemann commented Aug 27, 2021

@MFaisalZaki Maybe you can write a wrapper class for working around the private destructor in your spot::fnode example: https://spot.lrde.epita.fr/doxygen/classspot_1_1fnode.html

https://spot.lrde.epita.fr/doxygen/formula_8hh_source.html

But an overload for add_type would obviously be more convenient.

@barche
Copy link
Collaborator

barche commented Aug 28, 2021

It turns out that we can just filter out the creation of the finalizer using the std::is_destructible type trait, PR JuliaInterop/libcxxwrap-julia#92 should fix this.

@stemann
Copy link

stemann commented Aug 29, 2021

@barche Excellent! Thanks a lot!

@stemann
Copy link

stemann commented Jan 3, 2022

@barche I still seem to get errors when trying to wrap classes with protected or private destructors, e.g.: https://docs.nvidia.com/jetson/l4t-multimedia/CameraProvider_8h_source.html#l00065

As mentioned in JuliaInterop/libcxxwrap-julia#83 the so/dylib file is named libcxxwrap_julia.so.0.8.3 - even in libcxxwrap_julia-v0.8.8+1 - and the changes to module.hpp does not seem to be present:
grep -B7 -A2 __delete ~/.julia/artifacts/8b0751cbc7248b543c0989b4dc7bbae8ae9e984d/include/jlcxx/module.hpp

inline void add_default_methods(Module& mod)
{
  if (!std::is_same<supertype<T>, T>::value)
  {
    mod.method("cxxupcast", UpCast<T>::apply);
    mod.last_function().set_override_module(get_cxxwrap_module());
  }
  mod.method("__delete", detail::finalize<T>);
  mod.last_function().set_override_module(get_cxxwrap_module());
}

My Manifest.toml references libcxxwrap_julia_jll version 0.8.8+1.

@barche
Copy link
Collaborator

barche commented Jan 3, 2022

Yes, this needs a new release. Is requiring Julia 1.6 a problem for you? Since that is the plan for the subsequent releases, notably to avoid this difference in version between the libcxxwrap_julia_jll and the library itself.

@stemann
Copy link

stemann commented Jan 4, 2022

No problem to require Julia 1.6.

It seems like v0.9 is almost ready - anything I can do to help?

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 a pull request may close this issue.

3 participants