CastXML / pygccxml

pygccxml is a specialized XML reader that reads the output from CastXML. It provides a simple framework to navigate C++ declarations, using Python classes.
Boost Software License 1.0
133 stars 46 forks source link

Multiple Declaration Errors for namespace std in ARM #197

Open FireBoyAJ24 opened 1 month ago

FireBoyAJ24 commented 1 month ago

Description

When building the OMPL make update_bindings on ARM, we get an error: pygccxml.declarations.runtime_errors.multiple_declarations_found_t: Multiple declarations have been found. Matcher: [(decl type==namespace_t) and (name==std)]. Context of this issue comes from https://github.com/ompl/ompl/issues/1116.

Is it possible that the standard C++ library headers are treated differently (unexpectedly) in ARM compared to X86_64 in PygccXML?

I placed this issue in pygccxml as the error comes from this package compared to py++ and OMPL.

Expected Behavior

In X86_64, we are able to make the Python bindings with no errors. However, in ARM, we get the error stated in the description.

Example Code to Test the Error

from pygccxml import utils
from pygccxml import declarations
from pygccxml import parser
from pyplusplus import module_builder, messages
from pyplusplus.module_builder import call_policies

# Find the location of the xml generator (castxml or gccxml)
generator_path, generator_name = utils.find_xml_generator()

# Configure the xml generator
xml_generator_config = parser.xml_generator_configuration_t(
    xml_generator_path=generator_path,
    xml_generator=generator_name)

print(generator_name, generator_path)

name = "util"

mb = module_builder.module_builder_t(
            files=['util.h'],
            # cache is not used with compilation_mode = parser.COMPILATION_MODE.ALL_AT_ONCE
            # cache = '/workspaces/ompl_workspace/build/Release/pyplusplus_'+name+'.cache',
            xml_generator_config=xml_generator_config,
            compilation_mode=parser.COMPILATION_MODE.ALL_AT_ONCE,
            indexing_suite_version=2)
mb.classes().always_expose_using_scope = True
std_ns_decls = mb.namespace("std")

declarations.print_declarations(std_ns_decls)

Example util.h file:

``` // Copyright 2004-2006 Roman Yakovenko. // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef __hello_world_hpp__ #define __hello_world_hpp__ #include //I want to rename color to Color enum color{ red, green, blue }; struct genealogical_tree{/*...*/}; struct animal{ explicit animal( const std::string& name="" ) : m_name( name ) {} //I need to set call policies to the function genealogical_tree& genealogical_tree_ref() { return m_genealogical_tree; } std::string name() const { return m_name; } private: std::string m_name; genealogical_tree m_genealogical_tree; }; //I want to exclude next declarations: struct impl1{}; struct impl2{}; inline int* get_int_ptr(){ return 0;} inline int* get_int_ptr(int){ return 0;} inline int* get_int_ptr(double){ return 0;} #endif//__hello_world_hpp__ ```

Error:

Traceback (most recent call last):
  File "/workspaces/ompl_workspace/pyplusplus_test/generate_bindings.py", line 28, in <module>
    std_ns_decls = mb.namespace("std")
  File "/usr/local/lib/python3.10/dist-packages/pyplusplus/module_builder/module_builder.py", line 265, in namespace
    return self.global_ns.namespace( name=name
  File "/usr/local/lib/python3.10/dist-packages/pygccxml/declarations/namespace.py", line 117, in namespace
    self._find_single(
  File "/usr/local/lib/python3.10/dist-packages/pygccxml/declarations/scopedef.py", line 464, in _find_single
    found = matcher.get_single(decl_matcher, decls, False)
  File "/usr/local/lib/python3.10/dist-packages/pygccxml/declarations/scopedef.py", line 92, in get_single
    raise runtime_errors.multiple_declarations_found_t(decl_matcher)
pygccxml.declarations.runtime_errors.multiple_declarations_found_t: Multiple declarations have been found. Matcher: [(decl type==namespace_t) and (name==std)]

Tried Potential Solutions

Resources

iMichka commented 1 month ago

Hey. Thanks for letting me know.

I think the best thing to do would be to have a minimal c/c++ code example to be able to reproduce this outside of the OMPL build context. So I can try to write a test case for it and debug it.

I do not have an ARM machine right now (might buy a ARM Mac next year though). I need to check if I can set ARM CI on Github, I think they announced ARM machines lately.

The bug might also be in CastXML. Another solution would be to provide the xml files that have been generated, because I think I can also explore their content and see what is going on.