-
-
Notifications
You must be signed in to change notification settings - Fork 13
add struct support #54
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
base: master
Are you sure you want to change the base?
Conversation
|
Wow, not bad!
That might be because the load/store sequence is broken, but i'm not sure. must perform a I'm fine with this, we can just say it's a problem and we're fine with it for now. |
|
|
||
| var iter = self.contents.iterator(); | ||
| while (iter.next()) |entry| { | ||
| arr.contents.putAssumeCapacity(try arr.allocator.dupe(u8, entry.key_ptr.*), try entry.value_ptr.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential memory leak here when arr.allocator.dupe fails to clone the key.
You gotta construct both locally first and errdefer-free them, then put the key/value pair
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
putAssumeCapacity can't fail. You would just need to errdefer duped_key.deinit() before adding the key and value to arr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even then, it's a bug right now :)
i'd just use two errdefers, and make it so that future expansions dont have to think about the cleanup.
the compiler won't emit the second errdefer anyways until there's an error
|
|
||
| var iter = self.contents.iterator(); | ||
| while (iter.next()) |entry| { | ||
| arr.contents.putAssumeCapacity(try arr.allocator.dupe(u8, entry.key_ptr.*), try entry.value_ptr.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| arr.contents.putAssumeCapacity(try arr.allocator.dupe(u8, entry.key_ptr.*), try entry.value_ptr.clone()); | |
| const duped_key = try arr.allocator.dupe(u8, entry.key_ptr.*); | |
| errdefer arr.allocator.free(duped_key); | |
| arr.contents.putAssumeCapacity(duped_key, try entry.value_ptr.clone()); |
uses
var a = [ .foo = bar ];syntax. Nested structs give a segfault for some reason though. #39