diff --git a/src/anonimongo/collections.nim b/src/anonimongo/collections.nim index 0e85949..19a22b8 100644 --- a/src/anonimongo/collections.nim +++ b/src/anonimongo/collections.nim @@ -44,7 +44,7 @@ import multisock ## .. _items: #items.i,Cursor ## .. _getMore: dbops/crud.html#getMore,Database,int64,string,int -proc one*(q: Query[AsyncSocket]): Future[BsonDocument] {.multisock.} = +proc one*(q: Query[AsyncSocket]): Future[BsonDocument] {.multisock, gcsafe.} = let doc = await q.collection.db.find(q.collection.name, q.query, q.sort, q.projection, skip = q.skip, limit = 1, singleBatch = true) let batch = doc["cursor"]["firstBatch"].ofArray @@ -106,7 +106,7 @@ proc find*(c: Collection[AsyncSocket], query = bson(), projection = bsonNull()): result.projection = projection proc findOne*(c: Collection[AsyncSocket], query = bson(), projection = bsonNull(), - sort = bsonNull()): Future[BsonDocument] {.multisock.} = + sort = bsonNull()): Future[BsonDocument] {.multisock, gcsafe.} = var q = await c.find(query, projection) q.sort = sort result = await q.one diff --git a/src/anonimongo/core/bson.nim b/src/anonimongo/core/bson.nim index ea5d569..e8b1a0c 100644 --- a/src/anonimongo/core/bson.nim +++ b/src/anonimongo/core/bson.nim @@ -678,7 +678,7 @@ proc writeKey(s: var Streamable, key: string, kind: BsonKind): int32 = s.write 0x00.byte result = int32(1 + key.len + 1) -proc encode*(doc: BsonDocument): (int, string) +proc encode*(doc: BsonDocument): (int, string) {.gcsafe.} proc encode(s: var Streamable, key: string, doc: BsonInt32): int = result = s.writeKey(key, bkInt32) + doc.value.sizeof @@ -742,7 +742,7 @@ proc encode(s: var Streamable, key: string, doc: BsonBinary): int = for b in doc.value: s.writeLE b -proc encode(s: var Streamable, key: string, doc: BsonTimestamp): int = +proc encode(s: var Streamable, key: string, doc: BsonTimestamp): int {.gcsafe.} = result = s.writeKey(key, bkTimestamp) + uint64.sizeof s.writeLE doc.value[0] s.writeLE doc.value[1] @@ -904,7 +904,7 @@ proc decodeKey(s: var Streamable): (string, BsonKind) = buff &= achar result = (buff, kind) -proc decode*(strbytes: string): BsonDocument +proc decode*(strbytes: string): BsonDocument {.gcsafe.} proc decodeArray(s: var Streamable): seq[BsonBase] = let length = s.peekInt32LE @@ -954,7 +954,7 @@ proc decodeBinary(s: var Streamable): (BsonSubtype, seq[byte]) = thebytes.add s.readChar.byte result = (subtype, thebytes) -proc decode(s: var Streamable): (string, BsonBase) = +proc decode(s: var Streamable): (string, BsonBase) {.gcsafe.} = let (key, kind) = s.decodeKey var val: BsonBase case kind diff --git a/src/anonimongo/core/utils.nim b/src/anonimongo/core/utils.nim index 713019b..1230653 100644 --- a/src/anonimongo/core/utils.nim +++ b/src/anonimongo/core/utils.nim @@ -14,7 +14,7 @@ func flags*(d: Database): int32 = d.db.flags as int32 proc sendOps*(q: BsonDocument, db: Database[AsyncSocket], name = "", cmd = ckRead, compression = cidNoop): - Future[ReplyFormat]{.multisock.} = + Future[ReplyFormat]{.multisock, gcsafe.} = ## A helper utility which greatly simplify actual Database command ## queries. Any new command implementation usually use this ## helper proc. Cmd argument is needed to recognize what kind @@ -93,7 +93,7 @@ proc proceed*(db: Database[AsyncSocket], q: BsonDocument, dbname = "", cmd = ckR #template crudops(db: Database, q: BsonDocument): untyped {.multisock.} = proc crudops*(db: Database[AsyncSocket], q: BsonDocument, dbname = "", cmd = ckRead): - Future[BsonDocument]{.multisock.} = + Future[BsonDocument]{.multisock, gcsafe.} = ## About the same as ``proceed`` but this will return a BsonDocument ## compared to ``proceed`` that return ``WriteResult``. let compressions = db.db.compressions diff --git a/src/anonimongo/core/wire.nim b/src/anonimongo/core/wire.nim index 973125d..e00ab87 100644 --- a/src/anonimongo/core/wire.nim +++ b/src/anonimongo/core/wire.nim @@ -74,7 +74,7 @@ type const msgDefaultFlags = 0 -proc serialize(s: var Streamable, doc: BsonDocument): int = +proc serialize(s: var Streamable, doc: BsonDocument): int {.gcsafe.} = let (doclen, docstr) = encode doc result = doclen s.write docstr @@ -108,7 +108,7 @@ proc replyParse*(s: var Streamable): ReplyFormat = result.documents[i] = s.readStr(doclen).decode if s.atEnd or s.peekChar.byte == 0: break -proc msgParse*(s: var Streamable, rest = 0): ReplyFormat = +proc msgParse*(s: var Streamable, rest = 0): ReplyFormat {.gcsafe.} = ## Get the message in the ReplyFormat from given data stream. ## This is adapted to older type ReplyFormat from newer wire ## protocol OP_MSG. @@ -130,7 +130,7 @@ proc msgParse*(s: var Streamable, rest = 0): ReplyFormat = proc prepareQuery*(s: var Streamable, reqId, target, opcode, flags: int32, collname: string, nskip, nreturn: int32, - query = newbson(), selector = newbson(), compression = cidNoop): int = + query = newbson(), selector = newbson(), compression = cidNoop): int {.gcsafe.} = ## Convert and encode the query into stream to be ready for sending ## onto TCP wire socket. var query = query @@ -244,7 +244,7 @@ proc look*(reply: ReplyFormat) = for d in reply.documents: dump d -proc getReply*(socket: AsyncSocket): Future[ReplyFormat] {.multisock.} = +proc getReply*(socket: AsyncSocket): Future[ReplyFormat] {.multisock, gcsafe.} = ## Get data from socket and apply the replyParse into the result. var bstrhead = newStringStream(await socket.recv(size = 16)) let msghdr = msgHeaderFetch bstrhead diff --git a/src/anonimongo/dbops/crud.nim b/src/anonimongo/dbops/crud.nim index cedf2bf..1e43a4c 100644 --- a/src/anonimongo/dbops/crud.nim +++ b/src/anonimongo/dbops/crud.nim @@ -36,7 +36,7 @@ proc find*(db: Database[AsyncSocket], coll: string,query = bson(), max = bsonNull(), min = bsonNull(), returnKey = false, showRecordId = false, tailable = false, awaitData = false, oplogReplay = false, noCursorTimeout = false, partial = false, - collation = bsonNull(), explain = ""): Future[BsonDocument]{.multisock.} = + collation = bsonNull(), explain = ""): Future[BsonDocument]{.multisock, gcsafe.} = var q = bson({ find: coll, filter: query }) for field, val in { "sort": sort,