From df04cb8a97da5c1de8a5cc14d6a0cfedb168e569 Mon Sep 17 00:00:00 2001 From: cgmossa Date: Tue, 28 Nov 2023 22:55:18 +0100 Subject: [PATCH] don't protect r `NULL` --- extendr-api/src/ownership.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/extendr-api/src/ownership.rs b/extendr-api/src/ownership.rs index 9115c161de..a70b529526 100644 --- a/extendr-api/src/ownership.rs +++ b/extendr-api/src/ownership.rs @@ -20,13 +20,17 @@ use libR_sys::{ static OWNERSHIP: Lazy> = Lazy::new(|| Mutex::new(Ownership::new())); pub(crate) unsafe fn protect(sexp: SEXP) { - let mut own = OWNERSHIP.lock().expect("protect failed"); - own.protect(sexp); + if sexp != R_NilValue { + let mut own = OWNERSHIP.lock().expect("protect failed"); + own.protect(sexp); + } } pub(crate) unsafe fn unprotect(sexp: SEXP) { - let mut own = OWNERSHIP.lock().expect("unprotect failed"); - own.unprotect(sexp); + if sexp != R_NilValue { + let mut own = OWNERSHIP.lock().expect("unprotect failed"); + own.unprotect(sexp); + } } pub const INITIAL_PRESERVATION_SIZE: usize = 100000;