pantor / ruckig

Motion Generation for Robots and Machines. Real-time. Jerk-constrained. Time-optimal.
https://ruckig.com
MIT License
690 stars 162 forks source link

Python bindings function PerDOF::append returns pointer to temporary variable data #37

Closed paolo-mastrapasqua closed 3 years ago

paolo-mastrapasqua commented 3 years ago

I'm trying to play with the library on windows using the bindings for python. Building was straightforward, but executing examples/position.py, I ran into this error message: "ImporteError: generic_type: cannot initialize type "": an object with that name"

It ended up being the following function:

template<size_t MAX>
struct PerDOF {
    static const char* append(std::string name, size_t DOFs) {
        return (name.append(std::to_string(DOFs))).c_str();
    }
//...
};

as you can see the variable name is temporary, and the function returns a pointer to its internal storage, that is temporary too, and it get deallocated by the time it gets used.

pantor commented 3 years ago

Hi @paolo-mastrapasqua, thanks for pointing that out! With the latest commit, this issue should be fixed. Can you confirm?

paolo-mastrapasqua commented 3 years ago

👍, I did the same.