make exception handling use owned refs

This commit is contained in:
Andreas Rumpf 2019-03-05 05:54:42 +01:00
commit 9a9c002abe

View file

@ -1341,7 +1341,7 @@ proc `is`*[T, S](x: T, y: S): bool {.magic: "Is", noSideEffect.}
template `isnot`*(x, y: untyped): untyped = not (x is y) template `isnot`*(x, y: untyped): untyped = not (x is y)
## Negated version of `is`. Equivalent to ``not(x is y)``. ## Negated version of `is`. Equivalent to ``not(x is y)``.
when defined(nimV2): when defined(nimV2) and not defined(nimscript):
type owned*{.magic: "BuiltinType".}[T] type owned*{.magic: "BuiltinType".}[T]
proc new*[T](a: var owned(ref T)) {.magic: "New", noSideEffect.} proc new*[T](a: var owned(ref T)) {.magic: "New", noSideEffect.}
@ -3022,8 +3022,10 @@ template newException*(exceptn: typedesc, message: string;
parentException: ref Exception = nil): untyped = parentException: ref Exception = nil): untyped =
## creates an exception object of type ``exceptn`` and sets its ``msg`` field ## creates an exception object of type ``exceptn`` and sets its ``msg`` field
## to `message`. Returns the new exception object. ## to `message`. Returns the new exception object.
var when declared(owned):
e: ref exceptn var e: owned(ref exceptn)
else:
var e: ref exceptn
new(e) new(e)
e.msg = message e.msg = message
e.parent = parentException e.parent = parentException
@ -3062,12 +3064,18 @@ when not declared(sysFatal):
sysFatal(exceptn, message, "") sysFatal(exceptn, message, "")
else: else:
proc sysFatal(exceptn: typedesc, message: string) {.inline, noReturn.} = proc sysFatal(exceptn: typedesc, message: string) {.inline, noReturn.} =
when declared(owned):
var e: owned(ref exceptn)
else:
var e: ref exceptn var e: ref exceptn
new(e) new(e)
e.msg = message e.msg = message
raise e raise e
proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noReturn.} = proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noReturn.} =
when declared(owned):
var e: owned(ref exceptn)
else:
var e: ref exceptn var e: ref exceptn
new(e) new(e)
e.msg = message & arg e.msg = message & arg