From 08e0fd81bc3fb77cef19a6a33eb5b667624d8e2c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= <kornel@geekhood.net>
Date: Wed, 10 Jul 2019 16:57:32 +0100
Subject: [PATCH] GlobalContext is not affected by panics

It has plenty of thread-safety problems, but not this one
---
 src/context.rs | 5 +++++
 src/profile.rs | 8 ++++++++
 2 files changed, 13 insertions(+)

diff --git a/src/context.rs b/src/context.rs
index 29bc53b..3867f5a 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -5,6 +5,8 @@ use std::ffi::CStr;
 use std::os::raw::c_void;
 use std::cell::UnsafeCell;
 use std::collections::HashMap;
+use std::panic::UnwindSafe;
+use std::panic::RefUnwindSafe;
 
 /// A special case for non-thread-aware functions.
 ///
@@ -14,6 +16,9 @@ pub struct GlobalContext {
     _not_thread_safe: UnsafeCell<YouMustUseThreadContextToShareBetweenThreads>,
 }
 
+impl UnwindSafe for GlobalContext {}
+impl RefUnwindSafe for GlobalContext {}
+
 #[doc(hidden)]
 pub trait Context {
     fn as_ptr(&self) -> ffi::Context;
diff --git a/src/profile.rs b/src/profile.rs
index ac14c4f..de29608 100644
--- a/src/profile.rs
+++ b/src/profile.rs
@@ -530,3 +530,11 @@ fn bad_icc() {
     let err = Profile::new_icc(&[1, 2, 3]);
     assert!(err.is_err());
 }
+
+#[test]
+fn unwind_safety() {
+    let ref profile = Profile::new_xyz();
+    std::panic::catch_unwind(|| {
+        profile.clone()
+    }).unwrap();
+}
-- 
GitLab