From 90d86148b7a1847b4492e0c6fd892327400a0aba Mon Sep 17 00:00:00 2001
From: Isaac Woods <isaacwoods.home@gmail.com>
Date: Mon, 1 Oct 2018 21:55:16 +0100
Subject: [PATCH] De-duplicate c_cvoid definitions

---
 src/lib.rs    | 40 ++++++++++++++++++++++------------------
 src/switch.rs | 18 ------------------
 2 files changed, 22 insertions(+), 36 deletions(-)

diff --git a/src/lib.rs b/src/lib.rs
index 823d36c1..c997960a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -101,6 +101,28 @@ extern crate std as core;
 #[macro_use] mod macros;
 mod dox;
 
+/*
+ * `c_void` should be defined for all targets except wasm.
+ */
+#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
+cfg_if! {
+    if #[cfg(core_cvoid)] {
+        pub use core::ffi::c_void;
+    } else {
+        // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
+        // more optimization opportunities around it recognizing things like
+        // malloc/free.
+        #[repr(u8)]
+        pub enum c_void {
+            // Two dummy variants so the #[repr] attribute can be used.
+            #[doc(hidden)]
+            __variant1,
+            #[doc(hidden)]
+            __variant2,
+        }
+    }
+}
+
 cfg_if! {
     if #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] {
         // empty ...
@@ -108,24 +130,6 @@ cfg_if! {
         // On the Switch, we only define some useful universal types for
         // convenience. Those can be found in the switch.rs file.
     } else {
-        cfg_if! {
-            if #[cfg(core_cvoid)] {
-                pub use core::ffi::c_void;
-            } else {
-                // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
-                // more optimization opportunities around it recognizing things like
-                // malloc/free.
-                #[repr(u8)]
-                pub enum c_void {
-                    // Two dummy variants so the #[repr] attribute can be used.
-                    #[doc(hidden)]
-                    __variant1,
-                    #[doc(hidden)]
-                    __variant2,
-                }
-            }
-        }
-
         pub type int8_t = i8;
         pub type int16_t = i16;
         pub type int32_t = i32;
diff --git a/src/switch.rs b/src/switch.rs
index bb6df388..d47d41b1 100644
--- a/src/switch.rs
+++ b/src/switch.rs
@@ -34,21 +34,3 @@ pub type c_char = u8;
 pub type c_long = i64;
 pub type c_ulong = u64;
 pub type wchar_t = u32;
-
-cfg_if! {
-    if #[cfg(core_cvoid)] {
-        pub use core::ffi::c_void;
-    } else {
-        // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
-        // enable more optimization opportunities around it recognizing things
-        // like malloc/free.
-        #[repr(u8)]
-        pub enum c_void {
-            // Two dummy variants so the #[repr] attribute can be used.
-            #[doc(hidden)]
-            __variant1,
-            #[doc(hidden)]
-            __variant2,
-        }
-    }
-}
-- 
GitLab