-
Notifications
You must be signed in to change notification settings - Fork 14
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
Support for T&& function parameters and the special move constructor case #24
Comments
I don't remember where the issue comes from. The easiest way to start with to address it, is to comment this part of code and run wrapit on a function that takes a pass-by-r-value argument. |
Thanks, well the generated code errors in circle.hh #include <iostream>
#include <utility>
using namespace std;
class Circle {
public:
Circle(int r)
{
_radius = r;
cout << "Standard constructor. Radius: " << _radius << endl;
}
Circle(const Circle& c)
{
_radius = c.radius();
cout << "Copy constructor with lvalue reference. Radius: " << _radius << endl;
}
Circle(Circle&& c)
{
_radius = c.radius();
cout << "Move constructor with rvalue reference. Radius: " << _radius << endl;
}
int radius() const {
return _radius;
}
private:
int _radius;
};
void test()
{
cout << "== from c++ ==" << endl;
Circle c1(2);
Circle c2(c1);
Circle c3(std::move(c2));
} conf.toml module_name = "Circ"
input = ["circle.hh"]
#include <type_traits>
#include "jlcxx/jlcxx.hpp"
#include "jlcxx/functions.hpp"
#include "jlcxx/stl.hpp"
#include "jlCirc.h"
#ifdef VERBOSE_IMPORT
# define DEBUG_MSG(a) std::cerr << a << "\n"
#else
# define DEBUG_MSG(a)
#endif
#define __HERE__ __FILE__ ":" QUOTE2(__LINE__)
#define QUOTE(arg) #arg
#define QUOTE2(arg) QUOTE(arg)
namespace jlcxx {
template<> struct IsMirroredType<Circle> : std::false_type { };
template<> struct DefaultConstructible<Circle> : std::false_type { };
}
JLCXX_MODULE define_julia_module(jlcxx::Module& types){
DEBUG_MSG("Adding wrapper for type Circle (" __HERE__ ")");
// defined in ./circle.hh:6:7
auto t0 = types.add_type<Circle>("Circle");
/**********************************************************************/
/* Wrappers for the methods of class Circle
*/
DEBUG_MSG("Adding wrapper for void Circle::Circle(int) (" __HERE__ ")");
// defined in ./circle.hh:8:5
t0.constructor<int>(/*finalize=*/true);
DEBUG_MSG("Adding wrapper for void Circle::Circle(const Circle &) (" __HERE__ ")");
// defined in ./circle.hh:14:5
t0.constructor<const Circle &>(/*finalize=*/true);
DEBUG_MSG("Adding wrapper for void Circle::Circle(Circle &&) (" __HERE__ ")");
// defined in ./circle.hh:20:5
t0.constructor<Circle &&>(/*finalize=*/true);
DEBUG_MSG("Adding wrapper for int Circle::radius() (" __HERE__ ")");
// signature to use in the veto list: int Circle::radius()
// defined in ./circle.hh:26:9
t0.method("radius", static_cast<int (Circle::*)() const>(&Circle::radius));
/* End of Circle class method wrappers
**********************************************************************/
/**********************************************************************
* Wrappers for global functions and variables including
* class static members
*/
DEBUG_MSG("Adding wrapper for void test() (" __HERE__ ")");
// signature to use in the veto list: void test()
// defined in ./circle.hh:34:6
types.method("test", static_cast<void (*)() >(&test));
/* End of global function wrappers
**********************************************************************/
DEBUG_MSG("End of wrapper definitions");
} error log
|
It's a CxxWrap limitation. When do you want the move constructor to be called? It is not clear to me how you'd like to map the copy and move constructors to Julia. |
Yes, it's unclear to me conceptually too how a move constructor would be called from the julia side, so it might be a dead end. However, I'm wrapping a library that I'm in no position of modifying its sources. |
I see. I'm adding @barche to get its opinion. It's not clear to me know the move-only class should be handled, and more general pass-by-rvalue function parameters. The std::uniq_ptr is one notorious example of move-only class. As @t-bltg highlighted, Wrapit currently skip move-constructor and any function with a T&& parameter. @t-bltg, if you give more insights on the class you want to wrap, this might help to understand use cases and how mapping to Julia should be done. Philippe. |
Thanks Philippe, I cannot disclose the sources, but here is a reduced example of what is intended to be wrapped (you were dead-on right about #include <memory>
struct Options;
enum class State
{
IDLE = 0,
RUNNING = 1,
};
class CurrentState
{
public:
explicit CurrentState(std::unique_ptr<Options> && Options);
~CurrentState();
CurrentState(CurrentState const &) = delete;
CurrentState(CurrentState &&) = delete;
CurrentState & operator=(CurrentState const &) = delete;
CurrentState & operator=(CurrentState &&) = delete;
State getState() const
{ return m_state; }
private:
State m_state;
std::unique_ptr<Options> m_Options;
}; |
Let's wait from @barche's inputs to see how to handle this case. If you need an immediate solution, here is a workaround, you can use in the meantime. Define a function in a header file you add to the WrapIt CurrentState createCurrentState(const Option& o){
return CurrentState(std::make_unique<Option>(o));
} Then, either require calling this function instead of the usual constructor or, for a more transparent use, define a constructor inside the julia module: CurrentState(o::Option) = createCurrentState(o) To customize the julia module, you can use the pattern of ex002-ROOT: export list is generated in a separate file and the generated master file (limited to few lines) is discarded and replaced by a custom file. This will also allow you customizing the shared library path and solve at the same time the Issue #18. Philippe. |
That's a nice workaround ! Regarding #18, I ended up writing my own module, however from a user point of view (a beginner using |
I think @grasph 's workaround is the only way for now. There is currently no way to directly wrap the move constructor, but it seems like it would be a nice feature to have. I think it should be possible to also provide a |
In
wrapit/src/FunctionWrapper.cpp
Lines 570 to 579 in 3cb7ace
The generated code does not compile, right, but where should this be fixed ?
Is it a limitation in
wrapit
,CxxWrap
orlibcxxwrap-julia
?I'd like to try to fix this, but I will need some pointers to start, so any comment would be very helpful.
The text was updated successfully, but these errors were encountered: