-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes for
cabi_realloc
when new_size = 0 (#465)
* gen-guest-c: Fix cabi_realloc behavior when new_size is zero Match the behavior of the Rust guest cabi_realloc by returning `align` if new_size == 0. * guest-rust: Add an assert to cabi_realloc The code generator is expected not to emit calls that might have `old_size == 0 && new_size == 0`, but if that condition is not met the resulting call to `alloc::realloc` is documented as having undefined behavior. * Add test exercising cabi_realloc new_size = 0
- Loading branch information
Showing
5 changed files
with
12 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -418,14 +418,15 @@ impl C { | |
// Note that these intrinsics are declared as `weak` so they can be | ||
// overridden from some other symbol. | ||
self.src.c_fns( | ||
" | ||
__attribute__((weak, export_name(\"cabi_realloc\"))) | ||
void *cabi_realloc(void *ptr, size_t orig_size, size_t org_align, size_t new_size) { | ||
r#" | ||
__attribute__((weak, export_name("cabi_realloc"))) | ||
void *cabi_realloc(void *ptr, size_t old_size, size_t align, size_t new_size) { | ||
if (new_size == 0) return (void*) align; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
alexcrichton
Member
|
||
void *ret = realloc(ptr, new_size); | ||
if (!ret) abort(); | ||
return ret; | ||
} | ||
", | ||
"#, | ||
); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This will cause memory leaks in c++?