Commit 4c0e8d1c authored by John Parent's avatar John Parent
Browse files

Prevent illegal bindings of unique ptrs

 Add flag to prevent all binding of unique ptrs

 Unique ptrs need more nuanced handling, but for now this will work
parent 4ef80761
Pipeline #232299 failed with stages
in 13 minutes and 51 seconds
......@@ -15,6 +15,11 @@ UniqueHolder::UniqueHolder(std::unique_ptr<AbBase> b)
this->b= std::make_unique<int>(0);
};
void UniqueHolder::reseat(u_int_ptr &a)
{
a.reset(new int(*a.get()+1));
};
void UniqueHolder::take(std::unique_ptr<int> new_b)
{
this->b = std::move(new_b);
......
......@@ -27,6 +27,7 @@ public:
UniqueHolder(std::unique_ptr<AbBase> b);
std::unique_ptr<Base2> give();
void take(std::unique_ptr<int> new_b);
void reseat(u_int_ptr &a);
u_int_ptr give_back_int(u_int_ptr a) {return a;}
ub2 give_back_u_base(ub2 a) {return a;}
......
......@@ -393,9 +393,13 @@ class BindingsGenerator:
)
elif self.check_unique_ptr(member_function):
signature = self.lambda_abstract_unique_member(
member_function, member=not is_free_function
)
if self.opts.bind_unique and self.check_unique_abstr(
member_function
):
signature = self.lambda_abstract_unique_member(
member_function, member=not is_free_function
)
elif self.has_ref_args(member_function) and pass_by_ref:
arg_string = ""
signature = self.enable_pbr_immutable(
......@@ -487,7 +491,8 @@ class BindingsGenerator:
return_policy=return_value_policy,
)
member_string.strip(",")
if not signature:
return ""
return member_string
def find_getter(self, var_data, class_data):
......@@ -861,10 +866,11 @@ class BindingsGenerator:
return True
return False
def get_templ_dep_includes(self, dep):
extra_includes = set()
# We know type is non-primative
if not self.is_primative(dep) and not self.check_decl("std", dep):
def _get_decl_from_str(self, dec_str):
found_dep = None
if not self.is_primative(dec_str) and not self.check_decl(
"std", dec_str
):
# need .h file if we do not already include it
......@@ -875,7 +881,7 @@ class BindingsGenerator:
# Then get requisite #include, by querying location attribute
# if non templated class
# dep is string value, find associated class_t object
qualified_dep = self.add_namespace(" ", dep).strip(" ")
qualified_dep = self.add_namespace(" ", dec_str).strip(" ")
found_dep = self.name_data.classes(
lambda x: qualified_dep == x.decl_string, recursive=True
)
......@@ -883,17 +889,29 @@ class BindingsGenerator:
# TODO add typedef search support
if not found_dep.declarations:
found_dep = self.name_data.enumerations(
lambda x: self.search_enum_values(x, dep)
lambda x: self.search_enum_values(x, dec_str)
)
if len(found_dep):
found_dep = found_dep[0]
if self.is_templated(dep):
extra_includes.add(
found_dep.constructors()[0].location.file_name
)
else:
extra_includes.add(found_dep.location.file_name)
# and by querying constructor location if templ
return found_dep
def template_decl(self, dec_str):
decs = self._get_decl_from_str(dec_str)
if decs:
return decs[0]
return None
def get_templ_dep_includes(self, dep):
extra_includes = set()
# We know type is non-primative
found_dep = self._get_decl_from_str(dep)
if found_dep and len(found_dep):
found_dep = found_dep[0]
if self.is_templated(dep):
extra_includes.add(
found_dep.constructors()[0].location.file_name
)
else:
extra_includes.add(found_dep.location.file_name)
# and by querying constructor location if templ
return extra_includes
def is_stl(self, x):
......@@ -1096,6 +1114,19 @@ class BindingsGenerator:
def check_unique_ptr(self, decl):
return self.check_ptr_type(decl, "unique_ptr")
def check_unique_abstr(self, decl):
for arg in decl.arguments:
dec_type = dec.templates.split(
dec.type_traits.base_type(arg.decl_type).decl_string
)[1][0]
found_dec = self.template_decl(dec_type)
if found_dec and (
found_dec.is_abstract
or not dec.type_traits_classes.has_copy_constructor(found_dec)
):
return False
return True
def check_shared_ptr(self, decl):
return self.check_ptr_type(decl, "shared_ptr")
......@@ -1123,33 +1154,25 @@ class BindingsGenerator:
).decl_string
if dec.templates.is_instantiation(base_decl_string):
dec_type = dec.templates.split(base_decl_string)
if "unique_ptr" in dec_type[0] and self.opts.cxx14_flag:
# so if a type is going to be the dependency of another type and
# is either in our TU or added by another mdx
# we know it's in our yaml or that other yaml so maybe we can walk though that way??
# need to look at cross loading data
# for now tho
# does pygccxml skip templates in the start with thing?
type_ = dec_type[1][0]
dec = self.name_data.decls(
name=type_, decl_type=dec.class_t, recursive=True
)[0]
if dec.is_abstract:
pass
# instead of the copy constructor new thing, rather we used move semantics or just a reference
# to construct the unique ptr
lambda_return += (
self.opts.make_unique_fmt.format(type=type_, var=name)
+ ","
)
elif "unique_ptr" in dec_type[0] and not self.opts.cxx14_flag:
if "unique_ptr" in dec_type[0]:
type_ = dec_type[1][0]
# dcl = self.name_data.decls(name=type_,decl_type=dec.class_t, recursive=True)
lambda_return += (
self.opts.compose_unique.format(type=type_, var=name)
+ ","
)
# check if type is abstract here? Still will need to resolve the type
# then clear all vars and return, or just return, return null string, cause
# we cant bind (as of now)
if self.opts.cxx14_flag:
lambda_return += (
self.opts.make_unique_fmt.format(
type=type_, var=name
)
+ ","
)
else:
lambda_return += (
self.opts.compose_unique.format(
type=type_, var=name
)
+ ","
)
else:
type_ = arg.decl_type.decl_string
lambda_return += name + ", "
......@@ -1946,9 +1969,13 @@ class BindingsGenerator:
constructorObj
)
if self.check_unique_ptr(constructorObj):
constructor_str += self.constructor_unique_lambda(
constructorObj
)
if (
self.opts.bind_unique
and self.check_unique_abstr(constructorObj)
):
constructor_str += self.constructor_unique_lambda(
constructorObj
)
else:
arg_string = ""
arg_name_string = ","
......@@ -2102,7 +2129,12 @@ class BindingsGenerator:
member_string += eigen_str
elif self.check_unique_ptr(member_function):
member_string += self.member_unique_lambda(member_function)
if self.opts.bind_unique and self.check_unique_abstr(
member_function
):
member_string += self.member_unique_lambda(
member_function
)
else:
keep_alive_str = self.generate_keep_alive_string(
member_function, keep_alive_dict
......@@ -3428,8 +3460,8 @@ def main(argv=None):
help="Specify additional compiler arguments to be passed to Clang/LLVM via CastXML",
)
arg.add(
"--pass_eigen_by_ref",
"-epbr",
"--pass_eigen_by_ref",
dest="eigen_ref",
action="store",
type=lambda x: bool(distutils.util.strtobool(x)),
......@@ -3437,8 +3469,8 @@ def main(argv=None):
help="Toogle the use of Eigen PBR via Eigen::Ref<MarixType>",
)
arg.add(
"--use_eigen_return_policy",
"-erp",
"--use_eigen_return_policy",
dest="eigen_ret_pol",
action="store",
type=lambda x: bool(distutils.util.strtobool(x)),
......@@ -3446,8 +3478,17 @@ def main(argv=None):
help="Toggle use of return policy for returning Eigen types",
)
arg.add(
"--use_cxx_14",
"-bup",
"--bind-unique-ptr",
dest="bind_unique",
action="store",
type=lambda x: bool(distutils.util.strtobool(x)),
default=True,
help="Enable binding of unique_ptrs not pbr in function arguments",
)
arg.add(
"-cxx14",
"--use_cxx_14",
dest="cxx14_flag",
action="store",
type=lambda x: bool(distutils.util.strtobool(x)),
......
Supports Markdown
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