Commit 1d956615 authored by John Parent's avatar John Parent
Browse files

Prevent eigen ref pass by ref

parent 935f5d8a
Pipeline #230463 passed with stages
in 11 minutes and 32 seconds
......@@ -11,6 +11,7 @@ public:
Eigen::MatrixXd &getMatrix() { return big_mat; }
const Eigen::MatrixXd &viewMatrix() { return big_mat; }
void scale_by_2(Eigen::VectorXd v) { v *= 2;}
void scale_by_2(Eigen::VectorXd &v) {v *= 2;}
Eigen::MatrixXd getGivenMat(Eigen::MatrixXd const mat) {return mat;}
};
......
......@@ -912,6 +912,26 @@ class BindingsGenerator:
return not self.check_decl("Ref", x.decl_string)
return True
def check_type(self, decl, *conds, valid=True):
valid_type = valid
for cond in conds:
if not cond(decl):
valid_type = not valid
return valid_type
def supports_eigen_ref(self, decl):
base_conds = [self.eigen_is_not_ref, self.is_eigen_matrix]
support_conds = [
(dec.type_traits.is_reference, dec.type_traits.is_const),
(dec.type_traits.is_reference, dec.type_traits.is_pointer),
]
if self.check_type(decl, *base_conds):
if self.check_type(decl, *support_conds[0]):
return True
elif self.check_type(decl, *support_conds[1], valid=False):
return True
return False
def check_decl(self, check, decl_string):
return check in decl_string
......@@ -980,7 +1000,11 @@ class BindingsGenerator:
# return noraml string with added return
# value policy
rvp = self.set_eigen_return_policy(member_method)
if self.has_eigen_args(member_method) and self.opts.eigen_ref:
if (
self.has_eigen_args(member_method)
and self.supports_eigen_ref(member_method)
and self.opts.eigen_ref
):
eigen_str += self.generate_lambda_string(
member_method,
module=module,
......@@ -1941,8 +1965,7 @@ class BindingsGenerator:
)
for arg in constructorObj.arguments:
if (
self.is_eigen_matrix(arg.decl_type)
and self.eigen_is_not_ref(arg.decl_type)
self.supports_eigen_ref(arg.decl_type)
and self.opts.eigen_ref
):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment