From a7075f3b9dc7abc40992b395baaf3fa769245e5a Mon Sep 17 00:00:00 2001 From: Colin Rofls Date: Mon, 29 Jun 2020 15:06:27 -0400 Subject: [PATCH] Use wrap_under_get_rule where expected I had initially thought I could skip a retain in these cases since we can trivially track the lifetime of the reference, but I ran into a segfault in a test that used the empty string, which I tracked down to here. I'm not totally sure what's actually going on under the hood, but I do know that this fixes my crash and also that I was being overly clever anyway. --- core-text/src/frame.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core-text/src/frame.rs b/core-text/src/frame.rs index fed9bce..95b97c8 100644 --- a/core-text/src/frame.rs +++ b/core-text/src/frame.rs @@ -41,8 +41,7 @@ impl CTFrame { pub fn get_lines(&self) -> Vec { unsafe { let array_ref = CTFrameGetLines(self.as_concrete_TypeRef()); - // not strictly correct but saves an unnecessary retain call - let array: CFArray = CFArray::wrap_under_create_rule(array_ref); + let array: CFArray = CFArray::wrap_under_get_rule(array_ref); array.iter().map(|l| CTLine::wrap_under_get_rule(l.as_concrete_TypeRef())).collect() } } @@ -64,7 +63,7 @@ impl CTFrame { // range length of 0 means 'all remaining lines' 0 => unsafe { let array_ref = CTFrameGetLines(self.as_concrete_TypeRef()); - let array: CFArray = CFArray::wrap_under_create_rule(array_ref); + let array: CFArray = CFArray::wrap_under_get_rule(array_ref); array.len() - range.location } n => n,