Skip to content

Commit c8b7a88

Browse files
committed
enable gcsafe
1 parent d78cca9 commit c8b7a88

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

src/msgpack4nim.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ type
4040
MsgStream* = ref object of StringStreamObj
4141
encodingMode: EncodingMode
4242

43+
{.push gcsafe.}
44+
4345
proc init*(x: typedesc[MsgStream], data: sink string, encodingMode = MSGPACK_OBJ_TO_DEFAULT): MsgStream =
4446
result = new x
4547
# Initialize StringStream base by copying fields from a new StringStream:
@@ -1284,3 +1286,5 @@ proc stringify*(data: string): string =
12841286
stringify(s, zz)
12851287
zz.write(" ")
12861288
result = zz.data
1289+
1290+
{.pop.}

src/msgpack4nim/msgpack2any.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type
2626
of msgUint: uintVal*: uint64
2727
of msgNull: nil
2828

29+
{.push gcsafe.}
30+
2931
proc newMsgAny*(kind: AnyType): MsgAny =
3032
result = MsgAny(kind: kind)
3133

@@ -473,3 +475,5 @@ proc toPretty(result: var string, n: MsgAny, indent = 2, ml = true,
473475
proc pretty*(n: MsgAny, indent = 2): string =
474476
result = ""
475477
toPretty(result, n, indent)
478+
479+
{.pop.}

src/msgpack4nim/msgpack2json.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import ../msgpack4nim, json, tables, math, base64, streams
22

3+
{.push gcsafe.}
4+
35
proc toJsonNode*(s: Stream): JsonNode =
46
let c = ord(s.peekChar)
57
case c
@@ -94,3 +96,5 @@ proc fromJsonNode*(n: JsonNode): string =
9496
var s = MsgStream.init()
9597
fromJsonNode(s, n)
9698
result = s.data
99+
100+
{.pop.}

src/msgpack4nim/msgpack4collection.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import sequtils, math, ../msgpack4nim
22
import tables, intsets, lists, deques, sets, strtabs, critbits, streams
33

4+
{.push gcsafe.}
5+
46
proc pack_type*(s: Stream, val: IntSet) =
57
var ss = MsgStream.init()
68
var count = 0
@@ -201,3 +203,5 @@ proc unpack_type*(s: Stream, val: var IntSet) =
201203
for i in 0..len-1:
202204
x = s.unpack_imp_int32()
203205
val.incl(x)
206+
207+
{.pop.}

tests/test_codec.nim

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import std/[algorithm, critbits, deques, endians, hashes, intsets, lists,
1+
import std/[algorithm, critbits, deques, hashes, intsets, lists,
22
math, sequtils, sets, streams, strtabs, strutils, tables, unittest]
33

44
import msgpack4nim
@@ -991,3 +991,15 @@ suite "msgpack encoder-decoder":
991991
for sub in nodes:
992992
check sub.name notin names
993993
names.add(sub.name)
994+
995+
test "unpack in gcsafe proc":
996+
proc gcsafeProc(): carrier {.gcsafe.} =
997+
let cc = initCarrier()
998+
let buf = pack(cc)
999+
var dd: carrier
1000+
unpack(buf, dd)
1001+
result = dd
1002+
1003+
let cc = initCarrier()
1004+
let dd = gcsafeProc()
1005+
check $cc == $dd

0 commit comments

Comments
 (0)