Skip to content

Commit 510ac84

Browse files
ringaboutAraq
andauthored
implements quirky for functions (#24700)
ref #24686 With this PR ```nim import std/streams proc foo() = var name = newStringStream("2r2") raise newException(ValueError, "sh") try: foo() except: discard echo 123 ``` this example no longer leaks --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
1 parent b7d8896 commit 510ac84

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

compiler/pragmas.nim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,8 +1318,12 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
13181318
pragmaProposition(c, it)
13191319
of wEnsures:
13201320
pragmaEnsures(c, it)
1321-
of wEnforceNoRaises, wQuirky:
1321+
of wEnforceNoRaises:
13221322
sym.flags.incl sfNeverRaises
1323+
of wQuirky:
1324+
sym.flags.incl sfNeverRaises
1325+
if sym.kind in {skProc, skMethod, skConverter, skFunc, skIterator}:
1326+
sym.options.incl optQuirky
13231327
of wSystemRaisesDefect:
13241328
sym.flags.incl sfSystemRaisesDefect
13251329
of wVirtual:

lib/system/arc.nim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ else:
8787
template count(x: Cell): untyped =
8888
x.rc shr rcShift
8989
90+
when not defined(nimHasQuirky):
91+
{.pragma: quirky.}
92+
9093
proc nimNewObj(size, alignment: int): pointer {.compilerRtl.} =
9194
let hdrSize = align(sizeof(RefHeader), alignment)
9295
let s = size + hdrSize
@@ -190,7 +193,7 @@ proc nimRawDispose(p: pointer, alignment: int) {.compilerRtl.} =
190193
template `=dispose`*[T](x: owned(ref T)) = nimRawDispose(cast[pointer](x), T.alignOf)
191194
#proc dispose*(x: pointer) = nimRawDispose(x)
192195
193-
proc nimDestroyAndDispose(p: pointer) {.compilerRtl, raises: [].} =
196+
proc nimDestroyAndDispose(p: pointer) {.compilerRtl, quirky, raises: [].} =
194197
let rti = cast[ptr PNimTypeV2](p)
195198
if rti.destructor != nil:
196199
cast[DestructorProc](rti.destructor)(p)

tests/arc/tvalgrind.nim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
discard """
2+
cmd: "nim c --mm:orc -d:useMalloc $file"
3+
valgrind: "true"
4+
"""
5+
6+
import std/streams
7+
8+
9+
proc foo() =
10+
var name = newStringStream("2r2")
11+
raise newException(ValueError, "sh")
12+
13+
try:
14+
foo()
15+
except:
16+
discard

0 commit comments

Comments
 (0)