damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 6ae326d193806728e3bee64c7429218479feea3d
parent 851bffed0f8ef0ea29fcad82e5bac8f537ee8632
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 26 Jan 2024 14:02:03 -0800

ndb: use is_closed which also check nil ptrs

not an issue atm, but maybe in the future

Diffstat:
Mdamus/ContentView.swift | 2+-
Mnostrdb/Ndb.swift | 16++++++++++------
Mnostrdb/NdbTxn.swift | 2+-
3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -466,7 +466,7 @@ struct ContentView: View { if damus_state.ndb.reopen() { print("txn: NOSTRDB REOPENED") } else { - print("txn: NOSTRDB FAILED TO REOPEN closed:\(damus_state.ndb.closed)") + print("txn: NOSTRDB FAILED TO REOPEN closed:\(damus_state.ndb.is_closed)") } } .onChange(of: scenePhase) { (phase: ScenePhase) in diff --git a/nostrdb/Ndb.swift b/nostrdb/Ndb.swift @@ -32,7 +32,11 @@ class Ndb { let path: String? let owns_db: Bool var generation: Int - var closed: Bool + private var closed: Bool + + var is_closed: Bool { + self.closed || self.ndb.ndb == nil + } static func safemode() -> Ndb? { guard let path = db_path ?? old_db_path else { return nil } @@ -179,7 +183,7 @@ class Ndb { } func close() { - guard !self.closed else { return } + guard !self.is_closed else { return } self.closed = true print("txn: CLOSING NOSTRDB") ndb_destroy(self.ndb.ndb) @@ -187,7 +191,7 @@ class Ndb { } func reopen() -> Bool { - guard self.closed, + guard self.is_closed, let db = Self.open(path: self.path, owns_db_file: self.owns_db) else { return false } @@ -381,7 +385,7 @@ class Ndb { } func process_client_event(_ str: String) -> Bool { - guard !self.closed else { return false } + guard !self.is_closed else { return false } return str.withCString { cstr in return ndb_process_client_event(ndb.ndb, cstr, Int32(str.utf8.count)) != 0 } @@ -407,14 +411,14 @@ class Ndb { } func process_event(_ str: String) -> Bool { - guard !closed else { return false } + guard !is_closed else { return false } return str.withCString { cstr in return ndb_process_event(ndb.ndb, cstr, Int32(str.utf8.count)) != 0 } } func process_events(_ str: String) -> Bool { - guard !closed else { return false } + guard !is_closed else { return false } return str.withCString { cstr in return ndb_process_events(ndb.ndb, cstr, str.utf8.count) != 0 } diff --git a/nostrdb/NdbTxn.swift b/nostrdb/NdbTxn.swift @@ -35,7 +35,7 @@ class NdbTxn<T> { self.generation = Thread.current.threadDictionary["txn_generation"] as! Int } else { self.txn = ndb_txn() - guard !ndb.closed else { return nil } + guard !ndb.is_closed else { return nil } self.generation = ndb.generation let ok = ndb_begin_query(ndb.ndb.ndb, &self.txn) != 0 if !ok {