-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
infinite print using warn on a recursive struct (sometimes) #1446
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
Comments
I think we'll probably resolve this by having it only print x levels, where x is probably 2. After the limit is reached the pointers are not followed and it just prints the address. |
Isn't that too simplistic a fix? |
Can you elaborate? |
Can the number of levels be configured? Is the actual problem some default choice of type in the union? Maybe Zig's printing magic is too simple for what amounts to human-readable serialization of arbitrary data structures. |
I may be misunderstanding something, but my actual concrete struct isn't self-referential, it's a tree that's only two levels deep, and is printed correctly once in the output:
I don't see why it wouldn't be printed like this in the case that goes infinite. |
My mistake, @cgag. It was my understanding that the struct was self-referential. If that is not this issue then it is another one, because I didn't try to handle self-referencing structs yet. I'll have another look after the shortly upcoming 0.3.0 release. |
I misunderstood too. Sorry. |
I believe the issue is that you're attempting to access invalid addresses. This is often the kind of behavior you see when referencing pointers to invalid locations on the stack, with the behavior differing wildly between release modes.
Here you return
|
Oh, good call, I guess I should have realized that. I just had all those literal values in there for testing and ran into errors as I started pulling things apart. My bad. |
@cgag I was playing with this to verify there weren't any other errors and discovered that:
Doesn't work on Windows. It probably works fine on POSIX OSs though because DirectAllocator doesn't need to keep any state for them.
Fixes it. |
Those 2 things should be the same. The first code snippet is doing the second code snippet, but with a hidden stack variable instead of an explicit one. |
It would be neat if we could have a runtime safety check that detected this that didn't come at too high of a speed cost. If anyone has a proposal for how that might work, file an issue. We could probably take inspiration from MemorySanitizer |
You would think, but I assure you that the first one crashes on alloc in Windows. |
code here: https://gist.github.com/cgag/04e2e921cb54474fcee0a6f20a1e3d98
So, it seems if I build this with build-exe, and run it It segfaults during the warn on the e1:
If I build with release-fast, it prints e1 correctly, then basically prints a million recursive binary structs and segfaults:
The only difference between the functions that produce the value that prints successfully (if built with release-fast), is the on that prints infinitely, is the first one is first rendered to a string by a function that doesn't modify the Expr.
The text was updated successfully, but these errors were encountered: