summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/clang.rs14
-rw-r--r--src/ir/enum_ty.rs2
2 files changed, 10 insertions, 6 deletions
diff --git a/src/clang.rs b/src/clang.rs
index 0bfd78ef..a11e2924 100755
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -362,11 +362,15 @@ impl Cursor {
/// Get the unsigned constant value for this cursor's enum variant referent.
///
- /// Returns `ULLONG_MAX` if the cursor's referent is not an enum variant,
- /// which is also a valid enum value, so callers should check the cursor
- /// kind before calling this method (see issue #128).
- pub fn enum_val_unsigned(&self) -> u64 {
- unsafe { clang_getEnumConstantDeclUnsignedValue(self.x) as u64 }
+ /// Returns None if the cursor's referent is not an enum variant.
+ pub fn enum_val_unsigned(&self) -> Option<u64> {
+ unsafe {
+ if self.kind() == CXCursor_EnumConstantDecl {
+ Some(clang_getEnumConstantDeclUnsignedValue(self.x) as u64)
+ } else {
+ None
+ }
+ }
}
/// Given that this cursor's referent is a `typedef`, get the `Type` that is
diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs
index 1bcd5b14..8efd9e3b 100644
--- a/src/ir/enum_ty.rs
+++ b/src/ir/enum_ty.rs
@@ -75,7 +75,7 @@ impl Enum {
let value = if is_signed {
cursor.enum_val_signed().map(EnumVariantValue::Signed)
} else {
- Some(EnumVariantValue::Unsigned(cursor.enum_val_unsigned()))
+ cursor.enum_val_unsigned().map(EnumVariantValue::Unsigned)
};
if let Some(val) = value {
let name = cursor.spelling();