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

STL PMR data structures are not correctly parsed #283

Open
hexomethyl opened this issue Jan 13, 2025 · 2 comments
Open

STL PMR data structures are not correctly parsed #283

hexomethyl opened this issue Jan 13, 2025 · 2 comments

Comments

@hexomethyl
Copy link

Cppyy seems to fail to correctly handle the PMR type aliases for both Unordered and ordered STL maps when either the key or value also contains the PMR namespace. Below are test cases which seem to fail.

def test_cppyy_pmr():
    try:
        cppyy.gbl.__cppyy_testing.TestObjectPmr
    except:
        cppyy.cppdef(
        """
        #include <memory_resource>
        #include <string>
        #include <memory>
        #include <unordered_map>
        #include <map>
        #include <cstdint>
        
        namespace __cppyy_testing {
            struct TestObjectPmr {
                struct NestedDummyObject {
                    std::int32_t id;
                };
                
                std::pmr::unordered_map<std::pmr::string, std::unique_ptr<NestedDummyObject>> umap;
                std::pmr::unordered_map<std::string, std::shared_ptr<NestedDummyObject>> map;
            };
        }
        """
        )

    obj = cppyy.gbl.__cppyy_testing.TestObjectPmr()

umap ends up with the incorrect type of cppyy.gbl.std.unordered_map<std::stringtd::pmr::polymorphic_allocator<char>,std::unique_ptr<__cppyy_testing::TestObjectPmr::N...jectPmr::NestedDummyObject,std::default_delete<__cppyy_testing::TestObjectPmr::NestedDummyObject>>>>> where std::pmr::string is malformed.

map has the correct type but I cannot seem to insert any data into the map

@hexomethyl
Copy link
Author

namespace __cppyy_testing {
          struct TestObjectPmr {
              struct NestedDummyObject {
                  std::int32_t id;
              };
              
              std::pmr::unordered_map<std::pmr::string, std::int32_t> umap;
              std::pmr::unordered_map<std::string, std::int32_t> map;
          };
      }

For the code presented above, the map structure works as expected, however umap fails due to not receiving any of Cppyy STL pythonizations

@wlav
Copy link
Owner

wlav commented Jan 14, 2025

My bet is on the ROOT/meta legacy code. That code was written when upstream was still doing using namespace std everywhere. The meta code attempts to normalize type names by always representing std::basic_string<> as std::string, but b/c of that prior using namespace std, it may be going too eagerly after anything that is called string, then just removes parts of the name w/o checking.

With the normalized name messed up, I'm sure iterator, value types, etc. can't be found, so no pythonizations. (Aside, although the name ends up incorrect on Linux, on Mac the code actually segfaults.)

Meta is a maze (there's an on-going effort by upstream to get rid of it). May take a bit to find where things are going wrong.

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