-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Messed up output when using -d:useMalloc on program with block statement, options, and json-parsing #21540
Comments
Simplified a bit (x2, edited), seems to be related to get of Option returning a lent + copyMem type
Option = object
val: string
has: bool
proc some(val: string): Option =
result.has = true
result.val = val
# Remove lent and it works
proc get(self: Option): lent string =
result = self.val
type
StringStream = ref object
data: string
pos: int
proc readAll(s: StringStream): string =
result = newString(s.data.len)
copyMem(addr(result[0]), addr(s.data[0]), s.data.len)
proc newStringStream(s: string = ""): StringStream =
new(result)
result.data = s
proc parseJson(s: string): string =
let stream = newStringStream(s)
result = stream.readAll()
proc main =
let initialFEN = block:
let initialFEN = some parseJson("startpos")
initialFEN.get
echo initialFEN
main() |
Here is what the valgrind says
|
related: #20107 |
var
initialFEN
:tmpD
try:
`=copy`(initialFEN, block :tmp:
var
seed
:tmpD_1
:tmpD =
seed = some do:
:tmpD_1 = parseJson("startpos")
:tmpD_1
get(seed)
`=destroy`(:tmpD_1)
`=destroy_1`(seed)
:tmpD)
echo [initialFEN]
finally:
`=destroy`(initialFEN) The problem is that |
A possible soultion I have in mind is somehow to deref the block at the sempass/transf, not in the codegen phase so that the tmp will get the derefed value without worrying about the borrowed objects. |
…uctors function properly (nim-lang#21688) * fixes nim-lang#21540; deref block at transf phase to make injectdestructors function properly * add a test case * add one more test * fixes the type of block * transform block
…uctors function properly (nim-lang#21688) * fixes nim-lang#21540; deref block at transf phase to make injectdestructors function properly * add a test case * add one more test * fixes the type of block * transform block
…uctors function properly (nim-lang#21688) * fixes nim-lang#21540; deref block at transf phase to make injectdestructors function properly * add a test case * add one more test * fixes the type of block * transform block
Description
When running the following program with
nim r -d:useMalloc main.nim
it produces unexpected results with the newest version, but it works fine with Nim 1.6.12.Nim Version
Nim Compiler Version 1.9.1 [Linux: amd64]
Compiled at 2023-03-17
Copyright (c) 2006-2023 by Andreas Rumpf
git hash: b5ee81f
active boot switches: -d:release
Current Output
Expected Output
Possible Solution
No response
Additional Information
Workaround:
The text was updated successfully, but these errors were encountered: