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

[BUG]: Binding two maps with two different integer key types failues due to duplicate KeyViews #4529

Closed
2 of 3 tasks
gatecat opened this issue Feb 24, 2023 · 4 comments
Closed
2 of 3 tasks
Labels
triage New bug, unverified

Comments

@gatecat
Copy link

gatecat commented Feb 24, 2023

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

3cc7e42

Problem description

The attached example code binds two map types: std::map<uint16_t, uint16_t> and std::map<uint32_t, uint16_t>.

With recent pybind11 this fails when importing with:

ImportError: generic_type: cannot initialize type "KeysView[int]": an object with that name is already defined

Looking at the relevant code:

if (!detail::get_type_info(typeid(KeysView))) {

checks whether a matching key typeid has been wrapped already; but in this case two different typeids have the same string name in pybind11.

This is breaking a project that happens to use this; if there's a workaround other than unifying the map key types that fixes things with recent pybind11 releases that would also be useful to know.

Thanks for your help!

Reproducible example code

#include <pybind11/pybind11.h>
#include <pybind11/stl_bind.h>
#include <map>

namespace py = pybind11;

PYBIND11_MODULE(python_example, m) {
    py::bind_map<std::map<uint16_t, uint16_t>>(m, "u16u16map");
    py::bind_map<std::map<uint32_t, uint16_t>>(m, "u32u16map");
}

Is this a regression? Put the last known working version here if it is.

Believe this was broken by 9db9880. 2.10.0 was known working.

@gatecat gatecat added the triage New bug, unverified label Feb 24, 2023
@lyskov
Copy link
Contributor

lyskov commented Mar 31, 2023

The same issue also appear if one attempts to bind both map to float and double. Minimal code to replicate:

#include <map>
#include <pybind11/pybind11.h>
#include <pybind11/stl_bind.h>

PYBIND11_MODULE(example, m)
{
	// leads to ImportError: generic_type: cannot initialize type "ValuesView[float]": an object with that name is already defined
	pybind11::bind_map< std::map<std::string,float> >(m, "map_string_float" );
	pybind11::bind_map< std::map<std::string,double> >(m, "map_string_double" );
}

@mika-fischer
Copy link

I think this was broken by 9db9880 first released in v2.10.2, from #4353

@mika-fischer
Copy link

And needless to say this also breaks our build, so this is a real issue.

Interrestingly we also run into this:

ImportError: generic_type: cannot initialize type "ArrayInt2": an object with that name is already defined

ArrayInt2 is a binding for std::array<int, 2>. Not entirely sure if it's the same issue, but it also appears with 2.10.2...

Everything works fine in 2.10.1.

@Tobias-Fischer
Copy link

Are there any updates on this? It also breaks a few of my projects, see https://github.com/conda-forge/pycolmap-feedstock/issues

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

No branches or pull requests

4 participants