-
Notifications
You must be signed in to change notification settings - Fork 14
For c2py of stl types take argument by value and move elements #35
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,12 @@ namespace cpp2py { | |
|
||
template <typename T> struct py_converter<std::optional<T>> { | ||
|
||
using conv = py_converter<T>; | ||
using conv = py_converter<std::decay_t<T>>; | ||
parcollet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
static PyObject *c2py(std::optional<T> &op) { | ||
if (!bool(op)) Py_RETURN_NONE; | ||
return conv::c2py(*op); | ||
} | ||
static PyObject *c2py(std::optional<T> op) { | ||
if (!bool(op)) Py_RETURN_NONE; | ||
return conv::c2py(std::move(*op)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't rather There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be no problem with the syntax. std::move(*op) We invoke T& operator*() &; and then move from the |
||
} | ||
|
||
static bool is_convertible(PyObject *ob, bool raise_exception) { | ||
return ((ob == Py_None) or conv::is_convertible(ob, raise_exception)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,9 @@ namespace cpp2py { | |
|
||
template <typename T1, typename T2> struct py_converter<std::pair<T1, T2>> { | ||
|
||
static PyObject *c2py(std::pair<T1, T2> const &p) { | ||
pyref x1 = py_converter<T1>::c2py(std::get<0>(p)); | ||
pyref x2 = py_converter<T2>::c2py(std::get<1>(p)); | ||
static PyObject *c2py(std::pair<T1, T2> p) { | ||
pyref x1 = py_converter<std::decay_t<T1>>::c2py(std::move(std::get<0>(p))); | ||
parcollet marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even if its safe this will most definitely trigger false-positives for static analyzers / warnings that warn about use after move!? |
||
pyref x2 = py_converter<std::decay_t<T2>>::c2py(std::move(std::get<1>(p))); | ||
if (x1.is_null() or x2.is_null()) return NULL; | ||
return PyTuple_Pack(2, (PyObject *)x1, (PyObject *)x2); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,10 @@ namespace cpp2py { | |
template <typename T, size_t R> struct py_converter<std::array<T, R>> { | ||
// -------------------------------------- | ||
|
||
static PyObject *c2py(std::array<T, R> const &v) { | ||
static PyObject *c2py(std::array<T, R> v) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah wait... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, this will in fact lead to an additional unnecessary stack copy. c2py(std::array<T, R> &v)
c2py(std::array<T, R> const &v)
c2py(std::array<T, R> &&v) |
||
PyObject *list = PyList_New(0); | ||
for (auto const &x : v) { | ||
pyref y = py_converter<T>::c2py(x); | ||
for (auto &x : v) { | ||
pyref y = py_converter<std::decay_t<T>>::c2py(std::move(x)); | ||
if (y.is_null() or (PyList_Append(list, y) == -1)) { | ||
Py_DECREF(list); | ||
return NULL; | ||
|
Uh oh!
There was an error while loading. Please reload this page.