Merge pull request #1120 from mrdomino/calloc-cleanup

Clean up allocator defs
This commit is contained in:
Joe Bryan 2019-01-02 15:39:37 -05:00 committed by GitHub
commit c3fe60db4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 30 deletions

View File

@ -91,27 +91,23 @@
cnt_w = (cnt_w + 1) % (n); \
} while (0)
/* c3_malloc(): asserting malloc
*/
#define c3_malloc(s) ({ \
void* rut = malloc(s); \
if ( 0 == rut ) { \
c3_assert(!"memory lost"); \
} \
rut;})
/* c3_calloc(): asserting calloc
*/
#define c3_calloc(s) ({ \
void* rut = c3_malloc(s); \
memset(rut, 0, s); \
rut;})
/* c3_realloc(): asserting realloc
*/
#define c3_realloc(a, b) ({ \
void* rut = realloc(a, b); \
if ( 0 == rut ) { \
c3_assert(!"memory lost"); \
} \
rut;})
/* Asserting allocators.
*/
# define c3_malloc(s) ({ \
void* rut = malloc(s); \
if ( 0 == rut ) { \
c3_assert(!"memory lost"); \
} \
rut;})
# define c3_calloc(s) ({ \
void* rut = calloc(1,s); \
if ( 0 == rut ) { \
c3_assert(!"memory lost"); \
} \
rut;})
# define c3_realloc(a, b) ({ \
void* rut = realloc(a, b); \
if ( 0 == rut ) { \
c3_assert(!"memory lost"); \
} \
rut;})

View File

@ -75,7 +75,7 @@ _raft_rnam_free(u3_rnam* nam_u)
static u3_rnam*
_raft_readname(const c3_c* str_c, c3_w siz_w)
{
u3_rnam* nam_u = calloc(1, sizeof(*nam_u));
u3_rnam* nam_u = c3_calloc(sizeof(*nam_u));
c3_c* col_c;
c3_w nam_w;
@ -520,8 +520,8 @@ _raft_rmsg_read(const u3_rbuf* buf_u, u3_rmsg* msg_u)
memcpy(&msg_u->rest.apen.ent_d, buf_u->buf_y + red_i, sizeof(c3_d));
red_i += sizeof(c3_d);
msg_u->rest.apen.ent_u = calloc(
1, msg_u->rest.apen.ent_d * sizeof(u3_rent));
msg_u->rest.apen.ent_u = c3_calloc(
msg_u->rest.apen.ent_d * sizeof(u3_rent));
{
c3_d i_d;
u3_rent* ent_u = msg_u->rest.apen.ent_u;
@ -1152,7 +1152,7 @@ _raft_write_rest(u3_rcon* ron_u, c3_d lai_d, c3_w lat_w, u3_rmsg* msg_u)
msg_u->rest.lai_d = lai_d;
msg_u->rest.lat_w = lat_w;
msg_u->rest.nam_w = 1 + strlen(raf_u->str_c) / 4;
msg_u->rest.nam_c = calloc(1, 4 * msg_u->rest.nam_w);
msg_u->rest.nam_c = c3_calloc(4 * msg_u->rest.nam_w);
strncpy(msg_u->rest.nam_c, raf_u->str_c, 4 * msg_u->rest.nam_w + 1);
msg_u->len_d += 4 + msg_u->rest.nam_w;
}

View File

@ -272,7 +272,7 @@ _sist_cask(c3_c* dir_c, u3_noun nun)
{
c3_c paw_c[60];
u3_noun key;
u3_utty* uty_u = calloc(1, sizeof(u3_utty));
u3_utty* uty_u = c3_calloc(sizeof(u3_utty));
uty_u->fid_i = 0;
uH;

View File

@ -95,7 +95,7 @@ _term_close_cb(uv_handle_t* han_t)
void
u3_term_io_init()
{
u3_utty* uty_u = calloc(1, sizeof(u3_utty));
u3_utty* uty_u = c3_calloc(sizeof(u3_utty));
if ( c3y == u3_Host.ops_u.dem ) {
uty_u->fid_i = 1;