diff --git a/pybindgen/container.py b/pybindgen/container.py index 7da4be4..1aa39b4 100644 --- a/pybindgen/container.py +++ b/pybindgen/container.py @@ -475,6 +475,7 @@ static PyObject* 'CONTAINER_CONVERTER_FUNC_NAME': this_type_converter, 'ADD_VALUE': self.container_traits.add_value_method, } + code_sink.writeln(r''' int %(CONTAINER_CONVERTER_FUNC_NAME)s(PyObject *arg, %(CTYPE)s *container) { diff --git a/pybindgen/gccxmlparser.py b/pybindgen/gccxmlparser.py index fd84c75..a52ef5a 100644 --- a/pybindgen/gccxmlparser.py +++ b/pybindgen/gccxmlparser.py @@ -898,7 +898,7 @@ pybindgen.settings.error_handler = ErrorHandler() allow_empty=True, recursive=False): if fun.name.startswith('__'): continue - for dependency in fun.i_depend_on_them(recursive=False): + for dependency in fun.i_depend_on_them(recursive=True): type_info = dependency.depend_on_it traits = container_traits.find_container_traits(type_info) if traits is None: @@ -1109,10 +1109,10 @@ pybindgen.settings.error_handler = ErrorHandler() ## detect use of unregistered container types: need to look at ## all parameters and return values of all functions in this namespace... - for meth in cls.get_members(): - if meth.name.startswith('__') or not isinstance(meth, calldef.calldef_t): + for member in cls.get_members(access='public'): + if member.name.startswith('__'): continue - for dependency in meth.i_depend_on_them(recursive=False): + for dependency in member.i_depend_on_them(recursive=True): type_info = dependency.depend_on_it traits = container_traits.find_container_traits(type_info) if traits is None: @@ -1122,7 +1122,7 @@ pybindgen.settings.error_handler = ErrorHandler() # all classes are registered, because we may # depend on one of those classes for the element # type. - self._containers_to_register.append((traits, type_info, outer_class, name)) + self._containers_to_register.append((traits, type_info, None, name)) class_wrapper = module.add_class(cls_name, **kwargs) class_wrapper.gccxml_definition = cls @@ -1332,7 +1332,6 @@ pybindgen.settings.error_handler = ErrorHandler() kwargs['container_type'] = container_type pygen_sink = self._get_pygen_sink_for_definition(element_decl) - ## pygen... if pygen_sink: pygen_sink.writeln("module.add_container(%s)" % ", ".join([repr(name), _pygen_retval(*return_type_spec)] + _pygen_kwargs(kwargs))) diff --git a/pybindgen/typehandlers/codesink.py b/pybindgen/typehandlers/codesink.py index f3d085f..39d3336 100644 --- a/pybindgen/typehandlers/codesink.py +++ b/pybindgen/typehandlers/codesink.py @@ -83,6 +83,9 @@ class FileCodeSink(CodeSink): CodeSink.__init__(self) self.file = file_ + def __repr__(self): + return "" % (self.file.name,) + def writeln(self, line=''): """Write one or more lines of code""" self.file.write('\n'.join(self._format_code(line))) diff --git a/tests/foo.h b/tests/foo.h index 74ad74c..9029409 100644 --- a/tests/foo.h +++ b/tests/foo.h @@ -750,7 +750,10 @@ int set_simple_list (SimpleStructList list); class TestContainer { public: - TestContainer () {} + + std::set m_floatSet; + + TestContainer () { m_floatSet.insert (1.0); m_floatSet.insert (2.0); m_floatSet.insert (3.0); } virtual SimpleStructList get_simple_list (); virtual int set_simple_list (SimpleStructList list); @@ -769,4 +772,5 @@ std::map get_map (); std::set get_set (); + #endif /* !FOO_H_ */ diff --git a/tests/foomodulegen-auto-split.py b/tests/foomodulegen-auto-split.py index 64bd31f..df5dce5 100644 --- a/tests/foomodulegen-auto-split.py +++ b/tests/foomodulegen-auto-split.py @@ -31,6 +31,7 @@ def my_module_gen(): 'foomodulegen_module2_local'), ] module_parser = ModuleParser('foo4', '::') + module_parser.enable_anonymous_containers = True gccxml_options = dict( include_paths=eval(sys.argv[2]), diff --git a/tests/foomodulegen-auto.py b/tests/foomodulegen-auto.py index eb8f92b..0729faf 100644 --- a/tests/foomodulegen-auto.py +++ b/tests/foomodulegen-auto.py @@ -17,6 +17,7 @@ def my_module_gen(): out = FileCodeSink(sys.stdout) pygen_file = open(sys.argv[3], "wt") module_parser = ModuleParser('foo2', '::') + module_parser.enable_anonymous_containers = True print >> sys.stderr, "PYTHON_INCLUDES:", repr(sys.argv[2]) gccxml_options = dict( diff --git a/tests/foomodulegen.py b/tests/foomodulegen.py index c46ddcf..64749e6 100755 --- a/tests/foomodulegen.py +++ b/tests/foomodulegen.py @@ -396,8 +396,11 @@ int %s::custom_method_added_by_a_hook(int x) mod.add_function('get_simple_list', ReturnValue.new('SimpleStructList'), []) mod.add_function('set_simple_list', 'int', [Parameter.new('SimpleStructList', 'list')]) + mod.add_container('std::set', 'float', 'set') + TestContainer = mod.add_class('TestContainer', allow_subclassing=True) TestContainer.add_constructor([]) + TestContainer.add_instance_attribute('m_floatSet', 'std::set') TestContainer.add_method('get_simple_list', ReturnValue.new('SimpleStructList'), [], is_virtual=True) TestContainer.add_method('set_simple_list', 'int', [Parameter.new('SimpleStructList', 'list')], is_virtual=True) TestContainer.add_method('set_simple_list_by_ref', 'int', [Parameter.new('SimpleStructList&', 'inout_list', diff --git a/tests/foomodulegen4.py b/tests/foomodulegen4.py index 86a5c75..68db8d3 100644 --- a/tests/foomodulegen4.py +++ b/tests/foomodulegen4.py @@ -22,6 +22,8 @@ class MyMultiSectionFactory(MultiSectionFactory): self.section_sinks = {} def get_section_code_sink(self, section_name): + if section_name == '__main__': + return self.main_sink try: return self.section_sinks[section_name] except KeyError: diff --git a/tests/footest.py b/tests/footest.py index 3585329..8e2c5a2 100644 --- a/tests/footest.py +++ b/tests/footest.py @@ -985,5 +985,11 @@ class TestFoo(unittest.TestCase): self.assertEqual(zbr_count_after, zbr_count_before) + def test_scan_containers_in_attributes(self): + t = foo.TestContainer() + v = list(t.m_floatSet) + self.assertEqual(v, [1,2,3]) + + if __name__ == '__main__': unittest.main()