[niepce: 24/29] library+rust: fix a crash from the sqlite callback



commit 4a9cbd9f52fcd4e9f3a7e33fc290c2d058decfdd
Author: Hubert Figuière <hub figuiere net>
Date:   Sat Sep 16 21:06:34 2017 -0400

    library+rust: fix a crash from the sqlite callback

 src/engine/db/library.rs |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
---
diff --git a/src/engine/db/library.rs b/src/engine/db/library.rs
index 739339b..df44a48 100644
--- a/src/engine/db/library.rs
+++ b/src/engine/db/library.rs
@@ -89,8 +89,9 @@ impl Library {
     fn init(&mut self) -> bool {
         let conn_attempt = rusqlite::Connection::open(self.dbpath.clone());
         if let Ok(conn) = conn_attempt {
+            let notif_id = self.notif_id;
             conn.create_scalar_function("rewrite_xmp", 0, false, |_| {
-                self.notify(Box::new(LibNotification::XmpNeedsUpdate));
+                Library::notify_by_id(notif_id, Box::new(LibNotification::XmpNeedsUpdate));
                 Ok(true)
             });
             self.dbconn = Some(conn);
@@ -199,6 +200,10 @@ impl Library {
         unsafe { engine_library_notify(self.notif_id, Box::into_raw(notif) as *mut c_void); }
     }
 
+    pub fn notify_by_id(id: u64,  notif: Box<LibNotification>) {
+        unsafe { engine_library_notify(id, Box::into_raw(notif) as *mut c_void); }
+    }
+
     pub fn add_jpeg_file_to_bundle(&self, file_id: LibraryId, fsfile_id: LibraryId) -> bool {
         if let Some(ref conn) = self.dbconn {
             let filetype: i32 = libfile::FileType::RAW_JPEG.into();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]