Skip to content

Commit

Permalink
added a callback for reference policy detection
Browse files Browse the repository at this point in the history
  • Loading branch information
jnastarot authored and pthom committed Dec 2, 2024
1 parent de3a455 commit ea33c52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/litgen/internal/adapted_types/adapted_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,10 @@ def find_return_policy_in_comments(rv_policy_token: str) -> str | None:

if (matches_regex_pointer and returns_pointer) or (matches_regex_reference and returns_reference):
self.return_value_policy = "reference"


if options.fn_return_force_policy_reference__callback:
options.fn_return_force_policy_reference__callback(self)

def _pydef_fill_call_policy_from_function_comment(self, call_policy_token: str) -> str | None:
function_comment = self.cpp_element().cpp_element_comments.comments_as_str()
if call_policy_token in function_comment:
Expand Down
6 changes: 5 additions & 1 deletion src/litgen/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from litgen.internal.template_options import TemplateFunctionsOptions, TemplateClassOptions
from litgen.internal.class_iterable_info import ClassIterablesInfos
from litgen.internal.adapted_types import AdaptedFunction


class BindLibraryType(Enum):
Expand Down Expand Up @@ -210,7 +211,10 @@ class LitgenOptions:
# See packages/litgen/integration_tests/mylib/include/mylib/return_value_policy_test.h as an example
fn_return_force_policy_reference_for_pointers__regex: str = ""
fn_return_force_policy_reference_for_references__regex: str = ""

#
# The callback provides a flexible way to enforce the reference return policy for functions
fn_return_force_policy_reference__callback: Callable[[AdaptedFunction]] | None = None

# ------------------------------------------------------------------------------
# Force overload
# ------------------------------------------------------------------------------
Expand Down

0 comments on commit ea33c52

Please sign in to comment.