Skip to content

Commit

Permalink
fix: resolve anonymous enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Vipul-Cariappa authored and aaronj0 committed Sep 24, 2024
1 parent 098f455 commit b1c76d0
Showing 1 changed file with 20 additions and 0 deletions.
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);
} 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

0 comments on commit b1c76d0

Please sign in to comment.