Skip to content

Commit b082633

Browse files
Python: Spell * as ptr when converting C++ names to Python style, instead of ignoring this symbol.
1 parent c511bcc commit b082633

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

  • include/mrbind/targets/pybind11

include/mrbind/targets/pybind11/core.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,19 @@ namespace MRBind::pb11
21022102
std::size_t last_good_size = 0;
21032103
for (char ch : name)
21042104
{
2105+
auto AddSpecialString = [&](std::string_view str)
2106+
{
2107+
if (!prev_char_is_special)
2108+
{
2109+
ret += '_';
2110+
prev_char_is_special = true;
2111+
}
2112+
2113+
ret += str;
2114+
last_good_size = ret.size();
2115+
ret += '_';
2116+
};
2117+
21052118
// Somewhat in doubt here. I don't want to treat `_` as a special character, because I want to be able to use this to add
21062119
// custom functions like `__call__` and stuff.
21072120
if (std::isalnum((unsigned char)ch) || ch == '_')
@@ -2112,9 +2125,14 @@ namespace MRBind::pb11
21122125
}
21132126
else if (ch == '-')
21142127
{
2115-
prev_char_is_special = false;
2116-
ret += "minus";
2117-
last_good_size = ret.size();
2128+
AddSpecialString("minus");
2129+
}
2130+
else if (ch == '*')
2131+
{
2132+
// Need this to disambiguate e.g. `std::vector<T>` vs `std::vector<T *>`.
2133+
// For now we don't support `&`. One reason for that is that it causes `A_ref` and `A_refref` to be defined as aliases for `A`.
2134+
// Supporting `&` would require filtering out those aliases.
2135+
AddSpecialString("ptr");
21182136
}
21192137
else
21202138
{

0 commit comments

Comments
 (0)