diff --git a/eth/db/kvstore.nim b/eth/db/kvstore.nim index e8fb294..3b54d37 100644 --- a/eth/db/kvstore.nim +++ b/eth/db/kvstore.nim @@ -8,7 +8,12 @@ ## Simple Key-Value store database interface that allows creating multiple ## tables within each store -{.push raises: [Defect].} +when (NimMajor, NimMinor) < (1, 4): + {.push raises: [Defect].} + {.pragma: callback, gcsafe, raises: [Defect].} +else: + {.push raises: [].} + {.pragma: callback, gcsafe, raises: [].} import std/[tables, hashes, sets], @@ -25,16 +30,16 @@ type KvResult*[T] = Result[T, string] - DataProc* = proc(val: openArray[byte]) {.gcsafe, raises: [Defect].} - KeyValueProc* = proc(key, val: openArray[byte]) {.gcsafe, raises: [Defect].} + DataProc* = proc(val: openArray[byte]) {.callback.} + KeyValueProc* = proc(key, val: openArray[byte]) {.callback.} - PutProc = proc (db: RootRef, key, val: openArray[byte]): KvResult[void] {.nimcall, gcsafe, raises: [Defect].} - GetProc = proc (db: RootRef, key: openArray[byte], onData: DataProc): KvResult[bool] {.nimcall, gcsafe, raises: [Defect].} - FindProc = proc (db: RootRef, prefix: openArray[byte], onFind: KeyValueProc): KvResult[int] {.nimcall, gcsafe, raises: [Defect].} - DelProc = proc (db: RootRef, key: openArray[byte]): KvResult[bool] {.nimcall, gcsafe, raises: [Defect].} - ClearProc = proc (db: RootRef): KvResult[bool] {.nimcall, gcsafe, raises: [Defect].} - ContainsProc = proc (db: RootRef, key: openArray[byte]): KvResult[bool] {.nimcall, gcsafe, raises: [Defect].} - CloseProc = proc (db: RootRef): KvResult[void] {.nimcall, gcsafe, raises: [Defect].} + PutProc = proc (db: RootRef, key, val: openArray[byte]): KvResult[void] {.nimcall, callback.} + GetProc = proc (db: RootRef, key: openArray[byte], onData: DataProc): KvResult[bool] {.nimcall, callback.} + FindProc = proc (db: RootRef, prefix: openArray[byte], onFind: KeyValueProc): KvResult[int] {.nimcall, callback.} + DelProc = proc (db: RootRef, key: openArray[byte]): KvResult[bool] {.nimcall, callback.} + ClearProc = proc (db: RootRef): KvResult[bool] {.nimcall, callback.} + ContainsProc = proc (db: RootRef, key: openArray[byte]): KvResult[bool] {.nimcall, callback.} + CloseProc = proc (db: RootRef): KvResult[void] {.nimcall, callback.} KvStoreRef* = ref object ## Key-Value store virtual interface diff --git a/eth/db/kvstore_sqlite3.nim b/eth/db/kvstore_sqlite3.nim index 0465d1e..9b3a67c 100644 --- a/eth/db/kvstore_sqlite3.nim +++ b/eth/db/kvstore_sqlite3.nim @@ -1,6 +1,11 @@ ## Implementation of KvStore based on sqlite3 -{.push raises: [Defect].} +when (NimMajor, NimMinor) < (1, 4): + {.push raises: [Defect].} + {.pragma: callback, gcsafe, raises: [Defect].} +else: + {.push raises: [Defect].} + {.pragma: callback, gcsafe, raises: [].} import std/[os, options, strformat, typetraits], @@ -22,7 +27,7 @@ type Sqlite* = ptr sqlite3 SqliteStmt*[Params; Result] = distinct RawStmtPtr NoParams* = tuple # this is the empty tuple - ResultHandler*[T] = proc(val: T) {.gcsafe, raises: [Defect].} + ResultHandler*[T] = proc(val: T) {.callback.} SqStoreRef* = ref object # Handle for a single database - from here, keyspaces and statements @@ -48,7 +53,7 @@ type proc ( a: openArray[byte], b: openArray[byte] - ): Result[seq[byte], cstring] {.noSideEffect, gcsafe, cdecl, raises: [Defect].} + ): Result[seq[byte], cstring] {.noSideEffect, cdecl, callback.} template dispose(db: Sqlite) = discard sqlite3_close(db) @@ -598,7 +603,7 @@ proc hasTable*(db: SqStoreRef, name: string): KvResult[bool] = let sql = "SELECT name FROM sqlite_master WHERE type='table' AND name='" & name & "';" - db.exec(sql, (), proc(_: openArray[byte]) = discard) + db.exec(sql, (), proc(_: openArray[byte]) {.callback.} = discard) proc openKvStore*( db: SqStoreRef, name = "kvstore", withoutRowid = false, diff --git a/tests/db/test_kvstore_sqlite3.nim b/tests/db/test_kvstore_sqlite3.nim index 9fbcc34..7feb9b3 100644 --- a/tests/db/test_kvstore_sqlite3.nim +++ b/tests/db/test_kvstore_sqlite3.nim @@ -249,7 +249,7 @@ procSuite "SqStoreRef": proc customSumFun( a: openArray[byte], - b: openArray[byte]): Result[seq[byte], cstring] {.noSideEffect, gcsafe, cdecl, raises: [Defect].} = + b: openArray[byte]): Result[seq[byte], cstring] {.cdecl.} = let num1 = uint32.fromBytesBE(a) let num2 = uint32.fromBytesBE(b) let sum = num1 + num2