Skip to content

Commit 090f71e

Browse files
author
millucas
committed
Replace usage of bitflags with constants
Using bitflags for FFI is unsound in linux32, and it causes crashes like https://bugzilla.mozilla.org/show_bug.cgi?id=1406952. This is pretty similar to rust-lang/rust-bindgen#439. For this to be properly type safe we need to wait for rust-lang/rust#43036. Hopefully that's not for too long.
1 parent 14dd92a commit 090f71e

File tree

3 files changed

+32
-41
lines changed

3 files changed

+32
-41
lines changed

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ static = []
3838

3939
[dependencies]
4040

41-
bitflags = "0.9.1"
4241
glob = "0.2.11"
4342
libc = "0.2.14"
4443
libloading = { version = "0.4.0", optional = true }

src/lib.rs

+31-39
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
#![cfg_attr(feature="clippy", plugin(clippy))]
3131
#![cfg_attr(feature="clippy", warn(clippy))]
3232

33-
#[macro_use]
34-
extern crate bitflags;
35-
3633
extern crate glob;
3734
extern crate libc;
3835
#[cfg(feature="runtime")]
@@ -66,6 +63,13 @@ macro_rules! cenum {
6663
}) => (
6764
pub type $name = c_int;
6865

66+
$($(#[$vmeta])* pub const $variant: $name = $value;)+
67+
);
68+
($(#[$meta:meta])* enum $name:ident {
69+
$($(#[$vmeta:meta])* const $variant:ident = $value:expr); +;
70+
}) => (
71+
pub type $name = c_int;
72+
6973
$($(#[$vmeta])* pub const $variant: $name = $value;)+
7074
);
7175
}
@@ -890,18 +894,16 @@ cenum! {
890894
// Flags
891895
//================================================
892896

893-
bitflags! {
894-
#[repr(C)]
895-
pub struct CXCodeComplete_Flags: c_uint {
897+
cenum! {
898+
enum CXCodeComplete_Flags {
896899
const CXCodeComplete_IncludeMacros = 1;
897900
const CXCodeComplete_IncludeCodePatterns = 2;
898901
const CXCodeComplete_IncludeBriefComments = 4;
899902
}
900903
}
901904

902-
bitflags! {
903-
#[repr(C)]
904-
pub struct CXCompletionContext: c_uint {
905+
cenum! {
906+
enum CXCompletionContext {
905907
const CXCompletionContext_Unexposed = 0;
906908
const CXCompletionContext_AnyType = 1;
907909
const CXCompletionContext_AnyValue = 2;
@@ -929,9 +931,8 @@ bitflags! {
929931
}
930932
}
931933

932-
bitflags! {
933-
#[repr(C)]
934-
pub struct CXDiagnosticDisplayOptions: c_uint {
934+
cenum! {
935+
enum CXDiagnosticDisplayOptions {
935936
const CXDiagnostic_DisplaySourceLocation = 1;
936937
const CXDiagnostic_DisplayColumn = 2;
937938
const CXDiagnostic_DisplaySourceRanges = 4;
@@ -941,26 +942,23 @@ bitflags! {
941942
}
942943
}
943944

944-
bitflags! {
945-
#[repr(C)]
946-
pub struct CXGlobalOptFlags: c_uint {
945+
cenum! {
946+
enum CXGlobalOptFlags {
947947
const CXGlobalOpt_None = 0;
948948
const CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 1;
949949
const CXGlobalOpt_ThreadBackgroundPriorityForEditing = 2;
950950
const CXGlobalOpt_ThreadBackgroundPriorityForAll = 3;
951951
}
952952
}
953953

954-
bitflags! {
955-
#[repr(C)]
956-
pub struct CXIdxDeclInfoFlags: c_uint {
954+
cenum! {
955+
enum CXIdxDeclInfoFlags {
957956
const CXIdxDeclFlag_Skipped = 1;
958957
}
959958
}
960959

961-
bitflags! {
962-
#[repr(C)]
963-
pub struct CXIndexOptFlags: c_uint {
960+
cenum! {
961+
enum CXIndexOptFlags {
964962
const CXIndexOptNone = 0;
965963
const CXIndexOptSuppressRedundantRefs = 1;
966964
const CXIndexOptIndexFunctionLocalSymbols = 2;
@@ -970,18 +968,16 @@ bitflags! {
970968
}
971969
}
972970

973-
bitflags! {
974-
#[repr(C)]
975-
pub struct CXNameRefFlags: c_uint {
971+
cenum! {
972+
enum CXNameRefFlags {
976973
const CXNameRange_WantQualifier = 1;
977974
const CXNameRange_WantTemplateArgs = 2;
978975
const CXNameRange_WantSinglePiece = 4;
979976
}
980977
}
981978

982-
bitflags! {
983-
#[repr(C)]
984-
pub struct CXObjCDeclQualifierKind: c_uint {
979+
cenum! {
980+
enum CXObjCDeclQualifierKind {
985981
const CXObjCDeclQualifier_None = 0;
986982
const CXObjCDeclQualifier_In = 1;
987983
const CXObjCDeclQualifier_Inout = 2;
@@ -992,9 +988,8 @@ bitflags! {
992988
}
993989
}
994990

995-
bitflags! {
996-
#[repr(C)]
997-
pub struct CXObjCPropertyAttrKind: c_uint {
991+
cenum! {
992+
enum CXObjCPropertyAttrKind {
998993
const CXObjCPropertyAttr_noattr = 0;
999994
const CXObjCPropertyAttr_readonly = 1;
1000995
const CXObjCPropertyAttr_getter = 2;
@@ -1013,23 +1008,20 @@ bitflags! {
10131008
}
10141009
}
10151010

1016-
bitflags! {
1017-
#[repr(C)]
1018-
pub struct CXReparse_Flags: c_uint {
1011+
cenum! {
1012+
enum CXReparse_Flags {
10191013
const CXReparse_None = 0;
10201014
}
10211015
}
10221016

1023-
bitflags! {
1024-
#[repr(C)]
1025-
pub struct CXSaveTranslationUnit_Flags: c_uint {
1017+
cenum! {
1018+
enum CXSaveTranslationUnit_Flags {
10261019
const CXSaveTranslationUnit_None = 0;
10271020
}
10281021
}
10291022

1030-
bitflags! {
1031-
#[repr(C)]
1032-
pub struct CXTranslationUnit_Flags: c_uint {
1023+
cenum! {
1024+
enum CXTranslationUnit_Flags {
10331025
const CXTranslationUnit_None = 0;
10341026
const CXTranslationUnit_DetailedPreprocessingRecord = 1;
10351027
const CXTranslationUnit_Incomplete = 2;

tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn parse() {
1919
0,
2020
ptr::null_mut(),
2121
0,
22-
CXTranslationUnit_Flags::empty(),
22+
0,
2323
);
2424
assert!(!tu.is_null());
2525
}

0 commit comments

Comments
 (0)