Adding exception to the main section fails when using MultiSectionFactory

Bug #838255 reported by Riyaz Haque
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PyBindGen
New
Undecided
Unassigned

Bug Description

Hi,

I am using MultiSectionFactory to split the generated code. However there is one common exception across all sections that I intend to add to the main section.

mod = Module(module_name)
section_list = ["foo", "bar", "baz"]
out = GeomMultiSectionFactory(module_name, section_list)

# Common exception
excp = mod.add_exception(name="exception", custom_name = "PyExc_RuntimeError", foreign_cpp_namespace="std", message_rvalue="%(EXC)s.what()")

for section in section_list:
mod.begin_section(section)
# do something
mod.end_section(section)

mod.generate(out, module_name)

This gives me the following pybindgen error:
Traceback (most recent call last):
  File "Main.py", line 83, in <module>
    mod.generate(out, module_name)
  File "pybindgen/pybindgen/module.py", line 894, in generate
    self.do_generate(sink_manager, module_file_base_name)
  File "pybindgen/pybindgen/module.py", line 779, in do_generate
    sink, header_sink = out.get_code_sink_for_wrapper(exc)
  File "pybindgen/pybindgen/module.py", line 147, in get_code_sink_for_wrapper
    section_sink = self.multi_section_factory.get_section_code_sink(section)
  File "/home/utils.py", line 49, in get_section_code_sink
    return self.section_sinks[section_name]
KeyError: '__main__'

Changing the if-check
'if section is None' in the method get_code_sink_for_wrapper(self, wrapper) in module.py
to
'if section == "__main__"' fixes the problem

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.