Skip to content

fix: resolve anonymous enum #61

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

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/CPPDataMember.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ static PyObject* dm_get(CPPDataMember* dm, CPPInstance* pyobj, PyObject* /* kls
Py_INCREF(dm->fDescription);
return dm->fDescription;
}

if (Cppyy::IsEnumConstant(dm->fScope)) {
// anonymous enum
long long llval = Cppyy::GetEnumDataValue(dm->fScope);
const std::string& enum_type = Cppyy::ResolveEnum(dm->fScope);

PyObject* bval;
if (enum_type == "bool") {
bval = (bool)llval ? Py_True : Py_False;
Py_INCREF(bval);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment I would have is that this also enables test12_enum_scope on OS X with cling. Maybe there is something there that can also enable this test on other platforms.

} else if (enum_type == "char") {
char val = (char)llval;
bval = CPyCppyy_PyText_FromStringAndSize(&val, 1);
} else if (enum_type == "int" || enum_type == "unsigned int")
bval = PyInt_FromLong((long)llval);
else
bval = PyLong_FromLongLong(llval);

return bval;
}
}

// non-initialized or public data accesses through class (e.g. by help())
Expand Down