Skip to content

Commit

Permalink
fix tuple return issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SamFlt committed Nov 22, 2023
1 parent f589716 commit 191663f
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 9 deletions.
8 changes: 7 additions & 1 deletion modules/python/config/dnn_tracker.json
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
{"ignored_headers": [], "ignored_classes": [], "user_defined_headers": [], "classes": {}, "enums": {}}
{
"ignored_headers": [],
"ignored_classes": [],
"user_defined_headers": [],
"classes": {},
"enums": {}
}
8 changes: 7 additions & 1 deletion modules/python/config/gui.json
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
{}
{
"ignored_headers": [],
"ignored_classes": [],
"user_defined_headers": [],
"classes": {},
"enums": {}
}
8 changes: 6 additions & 2 deletions modules/python/config/imgproc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{

}
"ignored_headers": [],
"ignored_classes": [],
"user_defined_headers": [],
"classes": {},
"enums": {}
}
8 changes: 7 additions & 1 deletion modules/python/config/tt.json
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
{"ignored_headers": [], "ignored_classes": [], "user_defined_headers": [], "classes": {}, "enums": {}}
{
"ignored_headers": [],
"ignored_classes": [],
"user_defined_headers": [],
"classes": {},
"enums": {}
}
12 changes: 11 additions & 1 deletion modules/python/config/tt_mi.json
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
{"ignored_headers": [], "ignored_classes": [], "user_defined_headers": [], "classes": {}, "enums": {}}
{
"ignored_headers": [],
"ignored_classes": [],
"user_defined_headers": [],
"classes": {
"vpTemplateTrackerMI": {
"is_virtual": true
}
},
"enums": {}
}
12 changes: 12 additions & 0 deletions modules/python/docs/todos.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ To be written:
* In code documentation for the generator
* Document config files

* Failure cases

* If you have this error:
error: invalid new-expression of abstract class type ‘vpTemplateTrackerMI’
return new Class{std::forward<Args>(args)...};
In file included from /home/sfelton/software/visp_build/modules/python/bindings/src/tt_mi.cpp:13:0:
/home/sfelton/software/visp-sfelton/modules/tracker/tt_mi/include/visp3/tt_mi/vpTemplateTrackerMI.h:46:19: note: because the following virtual functions are pure within ‘vpTemplateTrackerMI’:
class VISP_EXPORT vpTemplateTrackerMI : public vpTemplateTracker
You should define the class (here vpTemplaterMI) as pure virtual in the config file (via the flag is_virtual)
This error occurs because some methods are defined as pure virtual in a parent class and are not defined in the class this class: Pure virtual class detection does not look in the class hierarchy but only at the present class



Packaging
------------------
Expand Down
14 changes: 11 additions & 3 deletions modules/python/generator/visp_python_bindgen/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,16 @@ def define_method(method: types.Method, method_config: Dict, is_class_method, sp
else:
self_param_with_name = None
method_caller = bound_object.cpp_name + '::' if is_class_method else bound_object.cpp_name
output_param_symbols = []
if return_type is None or return_type == 'void':
maybe_get_return = ''
maybe_return_in_tuple = ''
output_param_symbols.append('')
else:
maybe_get_return = f'{return_type} res = '
maybe_return_in_tuple = 'res, '
if '&' in return_type:
output_param_symbols.append('&res')
else:
output_param_symbols.append('res')

if len(output_param_names) == 0 and (return_type is None or return_type == 'void'):
return_str = ''
Expand All @@ -270,7 +274,11 @@ def define_method(method: types.Method, method_config: Dict, is_class_method, sp
elif len(output_param_names) == 1 and (return_type is None or return_type == 'void'):
return_str = output_param_names[0]
else:
return_str = f'std::make_tuple({maybe_return_in_tuple}{", ".join(output_param_names)})'
# When returning a tuple we need to explicitely convert references to pointer.
# This is required since std::tuple will upcast the ref to its base class and try to store a copy of the object
# If a class is pure virtual, this is not possible and will a compilation error!
output_param_symbols.extend(['&' + name for name in output_param_names if '&' in name])
return_str = f'std::make_tuple({", ".join(output_param_symbols)})'

lambda_body = f'''
{param_declarations}
Expand Down

0 comments on commit 191663f

Please sign in to comment.