LLNL / shroud

Shroud: generate Fortran and Python wrappers for C and C++ libraries
BSD 3-Clause "New" or "Revised" License
90 stars 7 forks source link

Error generating python bindings for C++ bool variable #343

Open rhathaway2 opened 7 months ago

rhathaway2 commented 7 months ago

I am getting a Python NameError when trying to generate python bindings for a boolean variable in a C++ class. I have created a simple reproducer shown below:

example.hpp

#ifndef EXAMPLE_H
#define EXAMPLE_H

class Example{
    public:
        bool example_flag = true;
}

#endif

with the yaml file reproducer.yaml:

options:
  wrap_fortran: False
  wrap_c: False
  wrap_python: True

declarations:

- decl: class Example
  cxx_header: example.hpp
  declarations:
  - decl: Example(void);
  - decl: bool require_example_flag;

When I run shroud-0.13.0 reproducer.yaml I get the following error:

Wrote library_types.yaml
Traceback (most recent call last):
  File "/collab/usr/gapps/python/build/spack-toss4.2/var/spack/environments/python310/._view/i74j3perqsso644fvgbrjnzhyuvpn42l/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/collab/usr/gapps/python/build/spack-toss4.2/var/spack/environments/python310/._view/i74j3perqsso644fvgbrjnzhyuvpn42l/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/gapps/shroud/public/toss_4_x86_64_ib/bin/shroud-0.13.0/__main__.py", line 3, in <module>
  File "/usr/gapps/shroud/public/toss_4_x86_64_ib/bin/shroud-0.13.0/_bootstrap/__init__.py", line 253, in bootstrap
  File "/usr/gapps/shroud/public/toss_4_x86_64_ib/bin/shroud-0.13.0/_bootstrap/__init__.py", line 38, in run
  File "/g/g16/rhathaw/.shiv/shroud-0.13.0.pyz_acfbdc8350559952ecaebb807395b07c2a838cb4aad878fbbda80f02ad07859b/site-packages/shroud/main.py", line 311, in main
    main_with_args(args)
  File "/g/g16/rhathaw/.shiv/shroud-0.13.0.pyz_acfbdc8350559952ecaebb807395b07c2a838cb4aad878fbbda80f02ad07859b/site-packages/shroud/main.py", line 537, in main_with_args
    wrapp.Wrapp(newlibrary, config, splicers["py"]).wrap_library()
  File "/g/g16/rhathaw/.shiv/shroud-0.13.0.pyz_acfbdc8350559952ecaebb807395b07c2a838cb4aad878fbbda80f02ad07859b/site-packages/shroud/wrapp.py", line 191, in wrap_library
    self.wrap_namespace(newlibrary.wrap_namespace, top=True)
  File "/g/g16/rhathaw/.shiv/shroud-0.13.0.pyz_acfbdc8350559952ecaebb807395b07c2a838cb4aad878fbbda80f02ad07859b/site-packages/shroud/wrapp.py", line 261, in wrap_namespace
    self.wrap_class(cls, modinfo)
  File "/g/g16/rhathaw/.shiv/shroud-0.13.0.pyz_acfbdc8350559952ecaebb807395b07c2a838cb4aad878fbbda80f02ad07859b/site-packages/shroud/wrapp.py", line 453, in wrap_class
    self.wrap_class_variable(node, var, fileinfo)
  File "/g/g16/rhathaw/.shiv/shroud-0.13.0.pyz_acfbdc8350559952ecaebb807395b07c2a838cb4aad878fbbda80f02ad07859b/site-packages/shroud/wrapp.py", line 829, in wrap_class_variable
    .format(stmts0))
NameError: name 'stmts0' is not defined. Did you mean: 'stmts'?
ltaylor16 commented 7 months ago

Thanks for the report. I was able to reproduce the problem with your example. It'll be next week before I can start on a fix.

ltaylor16 commented 7 months ago

This is fixed in the develop branch. The next release is probably a few months off.

rhathaway2 commented 7 months ago

Sounds good. Thanks for the fix