Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rhathaway2 opened this issue Feb 22, 2024 · 3 comments
Open

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

rhathaway2 opened this issue Feb 22, 2024 · 3 comments

Comments

@rhathaway2
Copy link

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
Copy link
Member

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 added a commit that referenced this issue Mar 6, 2024
This was an oversight.  bool is handled differently than other native
types in some cases such as int since additional conversions are
needed for both Fortran and Python.

#343
@ltaylor16
Copy link
Member

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

@rhathaway2
Copy link
Author

Sounds good. Thanks for the fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants