From 773c5468811b1a2c13dfd777ef25a13a616a3b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 10 Oct 2017 00:10:12 +0200 Subject: [PATCH 1/2] lib: Stop using bitflags to declare FFI definitions. 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 https://github.com/rust-lang-nursery/rust-bindgen/issues/439. For this to be properly type safe we need to wait for https://github.com/rust-lang/rust/issues/43036. Hopefully that's not for too long. --- Cargo.toml | 1 - src/lib.rs | 70 +++++++++++++++++++++++----------------------------- tests/lib.rs | 2 +- 3 files changed, 32 insertions(+), 41 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0c109253e..0eacbc0f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,6 @@ static = [] [dependencies] -bitflags = "0.9.1" glob = "0.2.11" libc = "0.2.14" libloading = { version = "0.4.0", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 3b9fd55e9..991a8be53 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,9 +30,6 @@ #![cfg_attr(feature="clippy", plugin(clippy))] #![cfg_attr(feature="clippy", warn(clippy))] -#[macro_use] -extern crate bitflags; - extern crate glob; extern crate libc; #[cfg(feature="runtime")] @@ -66,6 +63,13 @@ macro_rules! cenum { }) => ( pub type $name = c_int; + $($(#[$vmeta])* pub const $variant: $name = $value;)+ + ); + ($(#[$meta:meta])* enum $name:ident { + $($(#[$vmeta:meta])* const $variant:ident = $value:expr); +; + }) => ( + pub type $name = c_int; + $($(#[$vmeta])* pub const $variant: $name = $value;)+ ); } @@ -890,18 +894,16 @@ cenum! { // Flags //================================================ -bitflags! { - #[repr(C)] - pub struct CXCodeComplete_Flags: c_uint { +cenum! { + enum CXCodeComplete_Flags { const CXCodeComplete_IncludeMacros = 1; const CXCodeComplete_IncludeCodePatterns = 2; const CXCodeComplete_IncludeBriefComments = 4; } } -bitflags! { - #[repr(C)] - pub struct CXCompletionContext: c_uint { +cenum! { + enum CXCompletionContext { const CXCompletionContext_Unexposed = 0; const CXCompletionContext_AnyType = 1; const CXCompletionContext_AnyValue = 2; @@ -929,9 +931,8 @@ bitflags! { } } -bitflags! { - #[repr(C)] - pub struct CXDiagnosticDisplayOptions: c_uint { +cenum! { + enum CXDiagnosticDisplayOptions { const CXDiagnostic_DisplaySourceLocation = 1; const CXDiagnostic_DisplayColumn = 2; const CXDiagnostic_DisplaySourceRanges = 4; @@ -941,9 +942,8 @@ bitflags! { } } -bitflags! { - #[repr(C)] - pub struct CXGlobalOptFlags: c_uint { +cenum! { + enum CXGlobalOptFlags { const CXGlobalOpt_None = 0; const CXGlobalOpt_ThreadBackgroundPriorityForIndexing = 1; const CXGlobalOpt_ThreadBackgroundPriorityForEditing = 2; @@ -951,16 +951,14 @@ bitflags! { } } -bitflags! { - #[repr(C)] - pub struct CXIdxDeclInfoFlags: c_uint { +cenum! { + enum CXIdxDeclInfoFlags { const CXIdxDeclFlag_Skipped = 1; } } -bitflags! { - #[repr(C)] - pub struct CXIndexOptFlags: c_uint { +cenum! { + enum CXIndexOptFlags { const CXIndexOptNone = 0; const CXIndexOptSuppressRedundantRefs = 1; const CXIndexOptIndexFunctionLocalSymbols = 2; @@ -970,18 +968,16 @@ bitflags! { } } -bitflags! { - #[repr(C)] - pub struct CXNameRefFlags: c_uint { +cenum! { + enum CXNameRefFlags { const CXNameRange_WantQualifier = 1; const CXNameRange_WantTemplateArgs = 2; const CXNameRange_WantSinglePiece = 4; } } -bitflags! { - #[repr(C)] - pub struct CXObjCDeclQualifierKind: c_uint { +cenum! { + enum CXObjCDeclQualifierKind { const CXObjCDeclQualifier_None = 0; const CXObjCDeclQualifier_In = 1; const CXObjCDeclQualifier_Inout = 2; @@ -992,9 +988,8 @@ bitflags! { } } -bitflags! { - #[repr(C)] - pub struct CXObjCPropertyAttrKind: c_uint { +cenum! { + enum CXObjCPropertyAttrKind { const CXObjCPropertyAttr_noattr = 0; const CXObjCPropertyAttr_readonly = 1; const CXObjCPropertyAttr_getter = 2; @@ -1013,23 +1008,20 @@ bitflags! { } } -bitflags! { - #[repr(C)] - pub struct CXReparse_Flags: c_uint { +cenum! { + enum CXReparse_Flags { const CXReparse_None = 0; } } -bitflags! { - #[repr(C)] - pub struct CXSaveTranslationUnit_Flags: c_uint { +cenum! { + enum CXSaveTranslationUnit_Flags { const CXSaveTranslationUnit_None = 0; } } -bitflags! { - #[repr(C)] - pub struct CXTranslationUnit_Flags: c_uint { +cenum! { + enum CXTranslationUnit_Flags { const CXTranslationUnit_None = 0; const CXTranslationUnit_DetailedPreprocessingRecord = 1; const CXTranslationUnit_Incomplete = 2; diff --git a/tests/lib.rs b/tests/lib.rs index 6c82a4e6e..a3481cccb 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -19,7 +19,7 @@ fn parse() { 0, ptr::null_mut(), 0, - CXTranslationUnit_Flags::empty(), + 0, ); assert!(!tu.is_null()); } From 093728586d8c25d7b05a3d76e41f7e6a2663a68c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 10 Oct 2017 00:12:46 +0200 Subject: [PATCH 2/2] Bump version. --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0512c83ed..4e6f51f07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [0.21.0] - 2017-10-10 + +### Fixed +* Fixed soundness of flags in Linux32. + ## [0.20.1] - 2017-09-16 ### Fixed diff --git a/Cargo.toml b/Cargo.toml index 0eacbc0f5..6ea2b93d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "clang-sys" authors = ["Kyle Mayes "] -version = "0.20.1" +version = "0.21.0" readme = "README.md" license = "Apache-2.0"