From c8b7a8800532c8211244ee71719b42a822707b81 Mon Sep 17 00:00:00 2001 From: jangko Date: Tue, 1 Aug 2023 10:14:10 +0700 Subject: [PATCH] enable gcsafe --- src/msgpack4nim.nim | 4 ++++ src/msgpack4nim/msgpack2any.nim | 4 ++++ src/msgpack4nim/msgpack2json.nim | 4 ++++ src/msgpack4nim/msgpack4collection.nim | 4 ++++ tests/test_codec.nim | 14 +++++++++++++- 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/msgpack4nim.nim b/src/msgpack4nim.nim index 33b8c5f..df6631c 100644 --- a/src/msgpack4nim.nim +++ b/src/msgpack4nim.nim @@ -40,6 +40,8 @@ type MsgStream* = ref object of StringStreamObj encodingMode: EncodingMode +{.push gcsafe.} + proc init*(x: typedesc[MsgStream], data: sink string, encodingMode = MSGPACK_OBJ_TO_DEFAULT): MsgStream = result = new x # Initialize StringStream base by copying fields from a new StringStream: @@ -1284,3 +1286,5 @@ proc stringify*(data: string): string = stringify(s, zz) zz.write(" ") result = zz.data + +{.pop.} diff --git a/src/msgpack4nim/msgpack2any.nim b/src/msgpack4nim/msgpack2any.nim index 570fb81..48625b7 100644 --- a/src/msgpack4nim/msgpack2any.nim +++ b/src/msgpack4nim/msgpack2any.nim @@ -26,6 +26,8 @@ type of msgUint: uintVal*: uint64 of msgNull: nil +{.push gcsafe.} + proc newMsgAny*(kind: AnyType): MsgAny = result = MsgAny(kind: kind) @@ -473,3 +475,5 @@ proc toPretty(result: var string, n: MsgAny, indent = 2, ml = true, proc pretty*(n: MsgAny, indent = 2): string = result = "" toPretty(result, n, indent) + +{.pop.} diff --git a/src/msgpack4nim/msgpack2json.nim b/src/msgpack4nim/msgpack2json.nim index 8bad4f9..cc6b5c2 100644 --- a/src/msgpack4nim/msgpack2json.nim +++ b/src/msgpack4nim/msgpack2json.nim @@ -1,5 +1,7 @@ import ../msgpack4nim, json, tables, math, base64, streams +{.push gcsafe.} + proc toJsonNode*(s: Stream): JsonNode = let c = ord(s.peekChar) case c @@ -94,3 +96,5 @@ proc fromJsonNode*(n: JsonNode): string = var s = MsgStream.init() fromJsonNode(s, n) result = s.data + +{.pop.} diff --git a/src/msgpack4nim/msgpack4collection.nim b/src/msgpack4nim/msgpack4collection.nim index b841e96..03370f7 100644 --- a/src/msgpack4nim/msgpack4collection.nim +++ b/src/msgpack4nim/msgpack4collection.nim @@ -1,6 +1,8 @@ import sequtils, math, ../msgpack4nim import tables, intsets, lists, deques, sets, strtabs, critbits, streams +{.push gcsafe.} + proc pack_type*(s: Stream, val: IntSet) = var ss = MsgStream.init() var count = 0 @@ -201,3 +203,5 @@ proc unpack_type*(s: Stream, val: var IntSet) = for i in 0..len-1: x = s.unpack_imp_int32() val.incl(x) + +{.pop.} diff --git a/tests/test_codec.nim b/tests/test_codec.nim index 4855861..30f0096 100644 --- a/tests/test_codec.nim +++ b/tests/test_codec.nim @@ -1,4 +1,4 @@ -import std/[algorithm, critbits, deques, endians, hashes, intsets, lists, +import std/[algorithm, critbits, deques, hashes, intsets, lists, math, sequtils, sets, streams, strtabs, strutils, tables, unittest] import msgpack4nim @@ -991,3 +991,15 @@ suite "msgpack encoder-decoder": for sub in nodes: check sub.name notin names names.add(sub.name) + + test "unpack in gcsafe proc": + proc gcsafeProc(): carrier {.gcsafe.} = + let cc = initCarrier() + let buf = pack(cc) + var dd: carrier + unpack(buf, dd) + result = dd + + let cc = initCarrier() + let dd = gcsafeProc() + check $cc == $dd