File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -942,7 +942,10 @@ def find_return_policy_in_comments(rv_policy_token: str) -> str | None:
942942
943943 if (matches_regex_pointer and returns_pointer ) or (matches_regex_reference and returns_reference ):
944944 self .return_value_policy = "reference"
945-
945+
946+ if options .fn_return_force_policy_reference__callback :
947+ options .fn_return_force_policy_reference__callback (self )
948+
946949 def _pydef_fill_call_policy_from_function_comment (self , call_policy_token : str ) -> str | None :
947950 function_comment = self .cpp_element ().cpp_element_comments .comments_as_str ()
948951 if call_policy_token in function_comment :
Original file line number Diff line number Diff line change 1010
1111from litgen .internal .template_options import TemplateFunctionsOptions , TemplateClassOptions
1212from litgen .internal .class_iterable_info import ClassIterablesInfos
13+ from litgen .internal .adapted_types import AdaptedFunction
1314
1415
1516class BindLibraryType (Enum ):
@@ -210,7 +211,10 @@ class LitgenOptions:
210211 # See packages/litgen/integration_tests/mylib/include/mylib/return_value_policy_test.h as an example
211212 fn_return_force_policy_reference_for_pointers__regex : str = ""
212213 fn_return_force_policy_reference_for_references__regex : str = ""
213-
214+ #
215+ # The callback provides a flexible way to enforce the reference return policy for functions
216+ fn_return_force_policy_reference__callback : Callable [[AdaptedFunction ]] | None = None
217+
214218 # ------------------------------------------------------------------------------
215219 # Force overload
216220 # ------------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments