Skip to content

Fix BareExcept warnings on Nim 2.0rc1 #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/jsony.nim
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ proc parseHook*(s: string, i: var int, v: var bool) =
else:
error("Boolean true or false expected.", i)
else:
# Its faster to do char by char scan:
# It's faster to do char by char scan:
eatSpace(s, i)
if i + 3 < s.len and s[i+0] == 't' and s[i+1] == 'r' and s[i+2] == 'u' and s[i+3] == 'e':
i += 4
Expand Down Expand Up @@ -116,8 +116,8 @@ proc parseHook*(s: string, i: var int, v: var SomeSignedInt) =
parseHook(s, i, v2)
try:
v = type(v)(v2)
except:
error("Number type to small to contain the number.", i)
except CatchableError:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this error actually CatchableError? I have not tested.

Could you make a test case for this and see what the behavior is?

error("Number type too small to contain the number.", i)

proc parseHook*(s: string, i: var int, v: var SomeFloat) =
## Will parse float32 and float64.
Expand Down Expand Up @@ -394,13 +394,13 @@ proc parseHook*[T: enum](s: string, i: var int, v: var T) =
else:
try:
v = parseEnum[T](strV)
except:
except CatchableError:
error("Can't parse enum.", i)
else:
try:
strV = parseSymbol(s, i)
v = T(parseInt(strV))
except:
except CatchableError:
error("Can't parse enum.", i)

proc parseHook*[T: object|ref object](s: string, i: var int, v: var T) =
Expand Down Expand Up @@ -606,17 +606,17 @@ proc dumpNumberSlow(s: var string, v: uint|uint8|uint16|uint32|uint64) =
s.add $v.uint64

proc dumpNumberFast(s: var string, v: uint|uint8|uint16|uint32|uint64) =
# Its faster to not allocate a string for a number,
# but to write it out the digits directly.
# It's faster to not allocate a string for a number,
# but to write out the digits directly.
if v == 0:
s.add '0'
return
# Max size of a uin64 number is 20 digits.
# Max size of a uint64 number is 20 digits.
var digits: array[20, char]
var v = v
var p = 0
while v != 0:
# Its faster to look up 2 digits at a time, less int divisions.
# It's faster to look up 2 digits at a time, less int divisions.
let idx = v mod 100
digits[p] = lookup[idx*2+1]
inc p
Expand Down Expand Up @@ -668,7 +668,7 @@ proc dumpStrSlow(s: var string, v: string) =
s.add '"'

proc dumpStrFast(s: var string, v: string) =
# Its faster to grow the string only once.
# It's faster to grow the string only once.
# Then fill the string with pointers.
# Then cap it off to right length.
var at = s.len
Expand Down