diff options
author | Ben Smith <binjimin@gmail.com> | 2017-03-06 11:34:37 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-06 11:34:37 -0800 |
commit | e4dda12b17a5323a56b6782a6787f258ed2d8c81 (patch) | |
tree | c47e34928fc9b48f5b8dd1579e4c0213074b6494 /src/common.h | |
parent | b6e5735f3bfbb66d76142fc2f404da796289fc76 (diff) | |
download | wabt-e4dda12b17a5323a56b6782a6787f258ed2d8c81.tar.gz wabt-e4dda12b17a5323a56b6782a6787f258ed2d8c81.tar.bz2 wabt-e4dda12b17a5323a56b6782a6787f258ed2d8c81.zip |
Use new/delete instead of malloc/free (#332)
Also switch some void* -> char*, because it removes some unnecessary
casts. C++ does not like void*.
Diffstat (limited to 'src/common.h')
-rw-r--r-- | src/common.h | 23 |
1 files changed, 2 insertions, 21 deletions
diff --git a/src/common.h b/src/common.h index 36bc3d8f..620b8f0e 100644 --- a/src/common.h +++ b/src/common.h @@ -403,25 +403,6 @@ struct Literal { StringSlice text; }; -static WABT_INLINE void* wabt_alloc(size_t size) { - return malloc(size); -} - -static WABT_INLINE void* wabt_alloc_zero(size_t size) { - return calloc(size, 1); -} - -static WABT_INLINE void* wabt_realloc(void* p, size_t size) { - /* Realloc normally frees if size is 0, but we don't want that behavior. */ - if (size == 0) - return p; - return realloc(p, size); -} - -static WABT_INLINE void wabt_free(void* p) { - free(p); -} - static WABT_INLINE char* wabt_strndup(const char* s, size_t len) { size_t real_len = 0; const char* p = s; @@ -430,7 +411,7 @@ static WABT_INLINE char* wabt_strndup(const char* s, size_t len) { real_len++; } - char* new_s = static_cast<char*>(wabt_alloc(real_len + 1)); + char* new_s = new char[real_len + 1]; memcpy(new_s, s, real_len); new_s[real_len] = 0; return new_s; @@ -458,7 +439,7 @@ StringSlice string_slice_from_cstr(const char* string); bool string_slice_is_empty(const StringSlice*); bool string_slices_are_equal(const StringSlice*, const StringSlice*); void destroy_string_slice(StringSlice*); -Result read_file(const char* filename, void** out_data, size_t* out_size); +Result read_file(const char* filename, char** out_data, size_t* out_size); void default_source_error_callback(const Location*, const char* error, |