From c0e445be73021264c9f936bd02fe38f917d7cd6c Mon Sep 17 00:00:00 2001 From: radu Date: Sun, 23 Jun 2024 07:30:02 +0300 Subject: [PATCH] handle case when we munlock 2 times the same page on windows --- src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ed9b97f..ea547c3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ #![deny(warnings)] + use numpy::{PyArray1, PyArrayMethods}; use pyo3::buffer::PyBuffer; use pyo3::prelude::*; @@ -108,8 +109,13 @@ unsafe fn _mlock(ptr: *mut u8, len: usize) -> bool { /// Calls the platform's underlying `munlock(2)` implementation. unsafe fn _munlock(ptr: *mut u8, len: usize) -> bool { - println!("munlock len {len}"); - memsec::munlock(ptr, len) + let r = memsec::munlock(ptr, len); + if r == false && cfg!(target_os = "windows") { + // On windows if we munlock 2 times on the same page we get an error. + // This can happen if we munlock 2 vars that are in the same page. + return true; + } + r } #[cfg(test)]