Skip to content

Commit

Permalink
Debug function pointer tripping up python bindings compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
SamFlt committed Jun 19, 2024
1 parent 24c0770 commit 657aa7b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion modules/python/generator/visp_python_bindgen/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def define_method(method: types.Method, method_config: Dict, is_class_method, sp
method_name = get_name(method.name)
py_method_name = method_config.get('custom_name') or method_name
return_type = get_type(method.return_type, specs, header_env.mapping)
param_is_function_ptr = [is_function_pointer(param.type) for param in method.parameters]

method_signature = get_method_signature(method_name,
get_type(method.return_type, {}, header_env.mapping),
Expand Down Expand Up @@ -353,7 +354,15 @@ def make_keep_alive_str(values) -> str:

# Arguments that are inputs to the lambda function that wraps the ViSP function
input_param_types = [params_strs[i] for i in range(len(param_is_input)) if param_is_input[i]]
params_with_names = [t + ' ' + name for t, name in zip(input_param_types, input_param_names)]

def to_argument_name(type: str, name: str) -> str:
if '(*)' in type:
return type.replace('(*)', f'(*{name})', 1)
else:
return type + ' ' + name


params_with_names = [to_argument_name(t, name) for t, name in zip(input_param_types, input_param_names)]

# Params that are only outputs: they should be declared in function. Assume that they are default constructible
param_is_only_output = [not is_input and is_output for is_input, is_output in zip(param_is_input, param_is_output)]
Expand Down
10 changes: 10 additions & 0 deletions modules/python/generator/visp_python_bindgen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ def segment_repr(segment: types.PQNameSegment) -> str:

return '::'.join(final_segment_reprs)



def get_type(param: Union[types.FunctionType, types.DecoratedType, types.Value], owner_specs: Dict[str, str], header_env_mapping: Dict[str, str]) -> Optional[str]:
'''
Get the type of a parameter. Compared to get_typename, this function resolves the parameter's constness, whether it is a ref, moveref or pointer.
Expand Down Expand Up @@ -350,6 +352,14 @@ def is_pointer_to_const_cstr(param: types.Pointer) -> bool:

return False

def is_function_pointer(param: types.DecoratedType) -> bool:
'''
Whether the typed is a function pointer
'''
if not isinstance(param, types.Pointer):
return False
return isinstance(param.ptr_to, types.FunctionType)

def is_non_const_ref_to_immutable_type(param: types.DecoratedType) -> bool:
'''
Returns true if the parameter is a mutable reference to an immutable type in Python.
Expand Down

0 comments on commit 657aa7b

Please sign in to comment.