Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions gtwrap/matlab_wrapper/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1750,11 +1750,14 @@ def generate_collector_function(self, func_id):

# Setter
if "_set_" in method_name:
is_ptr_type = not self.is_optional(extra.ctype) and \
is_wrapped_value = not self.is_optional(extra.ctype) and \
self.can_be_pointer(extra.ctype) and \
not extra.ctype.is_shared_ptr and \
not extra.ctype.is_ptr and \
not extra.ctype.is_ref and \
not self.is_enum(extra.ctype, collector_func[1])
return_body = ' obj->{0} = {1}{0};'.format(
extra.name, '*' if is_ptr_type else '')
extra.name, '*' if is_wrapped_value else '')

setter = ' checkArguments("{property_name}",nargout,nargin{min1},' \
'{num_args});\n' \
Expand Down
2 changes: 1 addition & 1 deletion tests/expected/matlab/class_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ void Test_set_model_ptr_47(int nargout, mxArray *out[], int nargin, const mxArra
checkArguments("model_ptr",nargout,nargin-1,1);
auto obj = unwrap_shared_ptr<Test>(in[0], "ptr_Test");
std::shared_ptr<gtsam::noiseModel::Base> model_ptr = unwrap_shared_ptr< gtsam::noiseModel::Base >(in[1], "ptr_gtsamnoiseModelBase");
obj->model_ptr = *model_ptr;
obj->model_ptr = model_ptr;
}

void Test_get_value_48(int nargout, mxArray *out[], int nargin, const mxArray *in[])
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/pointer_properties.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class PointerProperties {
gtsam::noiseModel::Base* shared;
gtsam::Pose3 value;
};
21 changes: 21 additions & 0 deletions tests/test_matlab_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import os.path as osp
import sys
import tempfile
import unittest

sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
Expand Down Expand Up @@ -351,6 +352,26 @@ def test_class(self):
actual = osp.join(self.MATLAB_ACTUAL_DIR, file)
self.compare_and_diff(file, actual)

def test_shared_pointer_property_setter(self):
"""Shared-pointer properties assign handles; value properties copy."""
interface = osp.join(self.INTERFACE_DIR, 'pointer_properties.i')
wrapper = MatlabWrapper(
module_name='pointer_properties',
top_module_namespace=['gtsam'],
ignore_classes=[''],
)

with tempfile.TemporaryDirectory() as output_dir:
wrapper.wrap([interface], path=output_dir)
cpp_file = osp.join(output_dir,
'pointer_properties_wrapper.cpp')
with open(cpp_file, 'r', encoding='UTF-8') as generated_file:
cpp_content = generated_file.read()

self.assertIn('obj->shared = shared;', cpp_content)
self.assertNotIn('obj->shared = *shared;', cpp_content)
self.assertIn('obj->value = *value;', cpp_content)

def test_size_t_round_trip(self):
"""Generated size_t wrappers use alias-safe scalar conversions."""
file = osp.join(self.INTERFACE_DIR, 'matlab_integer_aliases.i')
Expand Down
Loading