default init when init template is not used

This commit is contained in:
kdeme 2019-10-01 18:11:28 +02:00 committed by zah
parent 035b7eda24
commit 2b8921690c
2 changed files with 24 additions and 15 deletions

View File

@ -27,7 +27,31 @@ proc readStdin*(): seq[byte] =
proc NimMain() {.importc: "NimMain".}
# The default init, gets redefined when init template is used.
template initImpl(): untyped =
when defined(standalone):
discard
else:
proc fuzzerInit(): cint {.exportc: "LLVMFuzzerInitialize".} =
NimMain()
return 0
template init*(body: untyped) =
when defined(standalone):
template initImpl(): untyped = fuzz: `body`
else:
template initImpl() =
proc fuzzerInit(): cint {.exportc: "LLVMFuzzerInitialize".} =
NimMain()
`body`
return 0
template test*(body: untyped): untyped =
mixin initImpl
initImpl()
when defined(standalone):
var payload {.inject.} = readStdin()
@ -39,14 +63,3 @@ template test*(body: untyped): untyped =
makeOpenArray(data, len)
`body`
template init*(body: untyped): untyped =
when defined(standalone):
fuzz: `body`
else:
proc fuzzerInit(): cint {.exportc: "LLVMFuzzerInitialize".} =
NimMain()
`body`
return 0

View File

@ -1,9 +1,5 @@
import chronicles, eth/rlp, ../fuzztest
# TODO: have a default init as such
init:
discard
test:
try:
var rlp = rlpFromBytes(@payload.toRange)