From: Michael Wallner Date: Fri, 2 Nov 2018 09:20:38 +0000 (+0100) Subject: pe*alloc X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=216e7ac3b97aed5a5d65c511dc061c78be90e79d;p=m6w6%2Fext-psi pe*alloc --- diff --git a/src/context.c b/src/context.c index 22fd915..1d5e230 100644 --- a/src/context.c +++ b/src/context.c @@ -113,7 +113,7 @@ PHP_MSHUTDOWN_FUNCTION(psi_context) struct psi_context *psi_context_init(struct psi_context *C, struct psi_context_ops *ops, psi_error_cb error, unsigned flags) { if (!C) { - C = malloc(sizeof(*C)); + C = pemalloc(sizeof(*C), 1); } memset(C, 0, sizeof(*C)); @@ -144,7 +144,7 @@ static bool psi_context_add(struct psi_context *C, struct psi_parser *P) struct psi_data *D; struct psi_validate_scope scope = {0}; - C->data = realloc(C->data, (C->count + 1) * sizeof(*C->data)); + C->data = safe_perealloc(C->data, (C->count + 1), sizeof(*C->data), 0, 1); D = psi_data_exchange(&C->data[C->count++], PSI_DATA(P)); psi_validate_scope_ctor(&scope); diff --git a/src/cpp.c b/src/cpp.c index 0f048b4..e01c3e6 100644 --- a/src/cpp.c +++ b/src/cpp.c @@ -98,7 +98,7 @@ static void free_cpp_def(zval *p) struct psi_cpp *psi_cpp_init(struct psi_parser *P) { - struct psi_cpp *cpp = calloc(1, sizeof(*cpp)); + struct psi_cpp *cpp = pecalloc(1, sizeof(*cpp), 1); cpp->parser = P; zend_hash_init(&cpp->once, 0, NULL, NULL, 1); diff --git a/src/cpp_tokiter.c b/src/cpp_tokiter.c index f2b468e..5611d3a 100644 --- a/src/cpp_tokiter.c +++ b/src/cpp_tokiter.c @@ -290,7 +290,7 @@ static size_t psi_cpp_tokiter_expand_tokens(struct psi_cpp *cpp, if (tokens && psi_plist_count(tokens)) { size_t i = 0, n = 0; bool stringify = false, paste = false; - struct psi_token *tok, **exp_tokens = calloc(psi_plist_count(tokens), sizeof(*exp_tokens)); + struct psi_token *tok, **exp_tokens = pecalloc(psi_plist_count(tokens), sizeof(*exp_tokens), 1); while (psi_plist_get(tokens, i++, &tok)) { struct psi_token *new_tok; @@ -367,7 +367,7 @@ static struct psi_plist **psi_cpp_tokiter_read_call_tokens( struct psi_cpp *cpp, size_t arg_count) { size_t arg_index = 0, lparens = 1, rparens = 0; - struct psi_plist **arg_tokens = calloc(arg_count, sizeof(*arg_tokens)); + struct psi_plist **arg_tokens = pecalloc(arg_count, sizeof(*arg_tokens), 1); struct psi_plist *free_tokens = psi_plist_init((psi_plist_dtor) psi_token_free); struct psi_token *tok; diff --git a/src/data.c b/src/data.c index f9e0e5f..b1fbc49 100644 --- a/src/data.c +++ b/src/data.c @@ -35,7 +35,7 @@ struct psi_data *psi_data_ctor_with_dtors(struct psi_data *data, psi_error_cb error, unsigned flags) { if (!data) { - data = calloc(1, sizeof(*data)); + data = pecalloc(1, sizeof(*data), 1); } data->error = error; @@ -78,7 +78,7 @@ struct psi_data *psi_data_ctor(struct psi_data *data, psi_error_cb error, unsigned flags) { if (!data) { - data = calloc(1, sizeof(*data)); + data = pecalloc(1, sizeof(*data), 1); } data->error = error; @@ -121,7 +121,7 @@ struct psi_data *psi_data_ctor(struct psi_data *data, psi_error_cb error, struct psi_data *psi_data_exchange(struct psi_data *dest, struct psi_data *src) { if (!dest) { - dest = malloc(sizeof(*dest)); + dest = pemalloc(sizeof(*dest), 1); } *dest = *src; memset(src, 0, sizeof(*src)); diff --git a/src/libffi.c b/src/libffi.c index fbd79b0..30210cf 100644 --- a/src/libffi.c +++ b/src/libffi.c @@ -218,7 +218,7 @@ static size_t psi_ffi_struct_type_pad(ffi_type **els, size_t padding) { size_t i; for (i = 0; i < padding; ++i) { - ffi_type *pad = malloc(sizeof(*pad)); + ffi_type *pad = pemalloc(sizeof(*pad), 1); memcpy(pad, &ffi_type_schar, sizeof(*pad)); *els++ = pad; @@ -240,7 +240,7 @@ static inline void psi_ffi_struct_type_element( struct psi_ffi_struct_element_storage *s, struct psi_decl_arg *darg, ffi_type *darg_type) { - ffi_type *type, **tmp; + ffi_type *type; size_t padding; if (darg->layout->pos == s->last_arg_pos) { @@ -249,7 +249,7 @@ static inline void psi_ffi_struct_type_element( } s->last_arg_pos = darg->layout->pos; - type = malloc(sizeof(*type)); + type = pemalloc(sizeof(*type), 1); *type = *darg_type; if (type->alignment > s->max_align) { @@ -260,13 +260,7 @@ static inline void psi_ffi_struct_type_element( if ((padding = psi_offset_padding(darg->layout->pos - s->offset, type->alignment))) { if (s->nels + padding + 1 > s->argc) { s->argc += padding; - tmp = realloc(s->els, (s->argc + 1) * sizeof(*s->els)); - if (tmp) { - s->els = tmp; - } else { - free(s->els); - abort(); - } + s->els = safe_perealloc(s->els, (s->argc + 1), sizeof(*s->els), 0, 1); s->els[s->argc] = NULL; } psi_ffi_struct_type_pad(&s->els[s->nels], padding); @@ -281,13 +275,12 @@ static inline void psi_ffi_struct_type_element( static ffi_type **psi_ffi_struct_type_elements(struct psi_decl_struct *strct) { size_t i = 0; - ffi_type **tmp; struct psi_decl_arg *darg; struct psi_ffi_struct_element_storage s = {0}; s.last_arg_pos = -1; s.argc = psi_plist_count(strct->args); - s.els = calloc(s.argc + 1, sizeof(*s.els)); + s.els = pecalloc(s.argc + 1, sizeof(*s.els), 1); while (psi_plist_get(strct->args, i++, &darg)) { psi_ffi_struct_type_element(&s, darg, psi_ffi_decl_arg_type(darg)); @@ -300,13 +293,7 @@ static ffi_type **psi_ffi_struct_type_elements(struct psi_decl_struct *strct) { if (s.offset < strct->size) { /* WTF? */ size_t padding = strct->size - s.offset; - tmp = realloc(s.els, (padding + s.argc + 1) * sizeof(*s.els)); - if (tmp) { - s.els = tmp; - } else { - free(s.els); - return NULL; - } + s.els = safe_perealloc(s.els, (padding + s.argc + 1), sizeof(*s.els), 0, 1); psi_ffi_struct_type_pad(&s.els[s.nels], padding); s.els[s.argc + padding] = NULL; } @@ -324,7 +311,7 @@ static inline ffi_type *psi_ffi_decl_type(struct psi_decl_type *type) { switch (real->type) { case PSI_T_STRUCT: if (!real->real.strct->engine.type) { - ffi_type *strct = calloc(1, sizeof(ffi_type)); + ffi_type *strct = pecalloc(1, sizeof(ffi_type), 1); strct->type = FFI_TYPE_STRUCT; strct->size = 0; @@ -363,9 +350,9 @@ static inline ffi_type *psi_ffi_decl_func_array_type(struct psi_decl *fn) { s.last_arg_pos = -1; s.argc = fn->func->var->array_size; - s.els = calloc(s.argc + 1, sizeof(*s.els)); + s.els = pecalloc(s.argc + 1, sizeof(*s.els), 1); - info->rv_array = calloc(1, sizeof(ffi_type)); + info->rv_array = pecalloc(1, sizeof(ffi_type), 1); info->rv_array->type = FFI_TYPE_STRUCT; info->rv_array->size = 0; info->rv_array->elements = s.els; @@ -434,7 +421,7 @@ static inline struct psi_ffi_decl_info *psi_ffi_decl_init(struct psi_decl *decl) int rc; size_t i, c = psi_plist_count(decl->args); struct psi_decl_arg *arg; - struct psi_ffi_decl_info *info = calloc(1, sizeof(*info) + 2 * c * sizeof(void *)); + struct psi_ffi_decl_info *info = pecalloc(1, sizeof(*info) + 2 * c * sizeof(void *), 1); decl->info = info; @@ -507,7 +494,7 @@ static inline void psi_ffi_callback_init(struct psi_ffi_impl_info *impl_info, decl_info = psi_ffi_decl_init(cb->decl); } - cb_info = calloc(1, sizeof(*cb_info)); + cb_info = pecalloc(1, sizeof(*cb_info), 1); cb_info->impl_info = impl_info; cb_info->let_exp = let_exp; rc = psi_ffi_prep_closure(&cb_info->closure, &cb_info->code, @@ -585,7 +572,7 @@ static inline void psi_ffi_callback_dtor(struct psi_let_exp *let_exp) { static inline struct psi_ffi_impl_info *psi_ffi_impl_init(struct psi_impl *impl, struct psi_context *C) { struct psi_ffi_context *context = C->context; - struct psi_ffi_impl_info *info = calloc(1, sizeof(*info)); + struct psi_ffi_impl_info *info = pecalloc(1, sizeof(*info), 1); struct psi_let_stmt *let; ffi_status rc; size_t l = 0; @@ -652,7 +639,7 @@ struct psi_ffi_extvar_info { }; static inline ffi_status psi_ffi_extvar_init(struct psi_decl_extvar *evar) { - struct psi_ffi_extvar_info *info = calloc(1, sizeof(*info)); + struct psi_ffi_extvar_info *info = pecalloc(1, sizeof(*info), 1); ffi_status rc; evar->info = info; @@ -700,7 +687,7 @@ static inline struct psi_ffi_context *psi_ffi_context_init(struct psi_ffi_contex ffi_status rc; if (!L) { - L = malloc(sizeof(*L)); + L = pemalloc(sizeof(*L), 1); } memset(L, 0, sizeof(*L)); @@ -770,7 +757,7 @@ static zend_function_entry *psi_ffi_compile(struct psi_context *C) } if (C->impls) { - zfe = calloc(psi_plist_count(C->impls) + 1, sizeof(*zfe)); + zfe = pecalloc(psi_plist_count(C->impls) + 1, sizeof(*zfe), 1); while (psi_plist_get(C->impls, i++, &impl)) { zend_function_entry *zf = &zfe[nf]; @@ -885,7 +872,7 @@ static ZEND_RESULT_CODE psi_ffi_load() #if HAVE_INT128 ffi_type *i128, *u128; - i128 = calloc(1, 3*sizeof(ffi_type)); + i128 = pecalloc(1, 3*sizeof(ffi_type), 1); i128->type = FFI_TYPE_STRUCT; i128->size = 0; i128->elements = (ffi_type **) (i128 + 1); @@ -894,7 +881,7 @@ static ZEND_RESULT_CODE psi_ffi_load() ffi_type_sint128 = i128; - u128 = calloc(1, 3*sizeof(ffi_type)); + u128 = pecalloc(1, 3*sizeof(ffi_type), 1); u128->type = FFI_TYPE_STRUCT; u128->size = 0; u128->elements = (ffi_type **) (u128 + 1); diff --git a/src/marshal.c b/src/marshal.c index cb0aa10..14f0dca 100644 --- a/src/marshal.c +++ b/src/marshal.c @@ -96,7 +96,7 @@ zend_internal_arg_info *psi_internal_arginfo(struct psi_impl *impl) zend_internal_function_info *fi; struct psi_impl_arg *iarg; - aip = calloc(argc + 1 + !!impl->func->vararg, sizeof(*aip)); + aip = pecalloc(argc + 1 + !!impl->func->vararg, sizeof(*aip), 1); fi = (zend_internal_function_info *) &aip[0]; #ifdef ZEND_TYPE_ENCODE diff --git a/src/parser.c b/src/parser.c index 719c551..50bfa31 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,4 +1,4 @@ -/* Generated by re2c 1.1.1 on Fri Nov 2 08:39:44 2018 */ +/* Generated by re2c 1.1.1 on Fri Nov 2 10:19:25 2018 */ #line 1 "src/parser.re" /******************************************************************************* Copyright (c) 2016, Michael Wallner . @@ -44,7 +44,7 @@ struct psi_parser *psi_parser_init(struct psi_parser *P, psi_error_cb error, unsigned flags) { if (!P) { - P = malloc(sizeof(*P)); + P = pemalloc(sizeof(*P), 1); } memset(P, 0, sizeof(*P)); @@ -70,7 +70,7 @@ struct psi_parser_input *psi_parser_open_file(struct psi_parser *P, const char * return NULL; } - if (!(fb = malloc(sizeof(*fb) + sb.st_size + YYMAXFILL))) { + if (!(fb = pemalloc(sizeof(*fb) + sb.st_size + YYMAXFILL, 1))) { if (report_errors) { P->error(PSI_DATA(P), NULL, PSI_WARNING, "Could not allocate %zu bytes for reading '%s': %s", @@ -110,7 +110,7 @@ struct psi_parser_input *psi_parser_open_string(struct psi_parser *P, const char { struct psi_parser_input *sb; - if (!(sb = malloc(sizeof(*sb) + length + YYMAXFILL))) { + if (!(sb = pemalloc(sizeof(*sb) + length + YYMAXFILL, 1))) { P->error(PSI_DATA(P), NULL, PSI_WARNING, "Could not allocate %zu bytes: %s", length + YYMAXFILL, strerror(errno)); diff --git a/src/parser.re b/src/parser.re index ab3cdad..ebd1e16 100644 --- a/src/parser.re +++ b/src/parser.re @@ -41,7 +41,7 @@ struct psi_parser *psi_parser_init(struct psi_parser *P, psi_error_cb error, unsigned flags) { if (!P) { - P = malloc(sizeof(*P)); + P = pemalloc(sizeof(*P), 1); } memset(P, 0, sizeof(*P)); @@ -67,7 +67,7 @@ struct psi_parser_input *psi_parser_open_file(struct psi_parser *P, const char * return NULL; } - if (!(fb = malloc(sizeof(*fb) + sb.st_size + YYMAXFILL))) { + if (!(fb = pemalloc(sizeof(*fb) + sb.st_size + YYMAXFILL, 1))) { if (report_errors) { P->error(PSI_DATA(P), NULL, PSI_WARNING, "Could not allocate %zu bytes for reading '%s': %s", @@ -107,7 +107,7 @@ struct psi_parser_input *psi_parser_open_string(struct psi_parser *P, const char { struct psi_parser_input *sb; - if (!(sb = malloc(sizeof(*sb) + length + YYMAXFILL))) { + if (!(sb = pemalloc(sizeof(*sb) + length + YYMAXFILL, 1))) { P->error(PSI_DATA(P), NULL, PSI_WARNING, "Could not allocate %zu bytes: %s", length + YYMAXFILL, strerror(errno)); diff --git a/src/plist.c b/src/plist.c index 699db2c..048305a 100644 --- a/src/plist.c +++ b/src/plist.c @@ -60,7 +60,7 @@ struct psi_plist *psi_plist_init_ex(size_t size, void (*dtor)(void *)) { size = sizeof(void*); } - list = calloc(1, sizeof(*list) + size); + list = pecalloc(1, sizeof(*list) + size, 1); list->size = size; list->dtor = dtor; @@ -88,7 +88,7 @@ void psi_plist_free(struct psi_plist *list) { struct psi_plist *psi_plist_copy(struct psi_plist *list, void (*ctor)(void *)) { size_t i; - struct psi_plist *copy = calloc(1, sizeof(*list) + list->size + list->count * list->size); + struct psi_plist *copy = pecalloc(1, sizeof(*list) + list->size + list->count * list->size, 1); *copy = *list; if (list->count) { @@ -113,7 +113,7 @@ void **psi_plist_eles(struct psi_plist *list) { struct psi_plist *psi_plist_add(struct psi_plist *list, void *ptr) { if (list && list->count) { - list = realloc(list, sizeof(*list) + list->size + list->count * list->size); + list = safe_perealloc(list, list->count + 1, list->size, sizeof(*list), 1); } if (list) { PLIST_CPY(list, PLIST_ELE(list, list->count++), ptr); @@ -123,7 +123,7 @@ struct psi_plist *psi_plist_add(struct psi_plist *list, void *ptr) { struct psi_plist *psi_plist_add_r(struct psi_plist *list, size_t num_eles, void **eles) { if (list) { - list = realloc(list, sizeof(*list) + list->size + (num_eles + list->count) * list->size); + list = safe_perealloc(list, list->count + num_eles + 1, list->size, sizeof(*list), 1); } if (list) { memcpy(PLIST_ELE(list, list->count), eles, num_eles * list->size); @@ -190,7 +190,7 @@ struct psi_plist *psi_plist_ins(struct psi_plist *list, size_t index, void *ptr) if (list) { new_count = MAX(list->count + 1, index); if (new_count) { - list = realloc(list, sizeof(*list) + list->size + new_count * list->size); + list = safe_perealloc(list, new_count + 1, list->size, sizeof(*list), 1); } if (list) { PLIST_MOV_EXPAND(list, index); @@ -207,11 +207,9 @@ struct psi_plist *psi_plist_ins_r(struct psi_plist *list, size_t offset_start, s if (list) { new_count = MAX(offset_start, list->count) + num_eles; if (new_count) { - list = realloc(list, sizeof(*list) + list->size + new_count * list->size); + list = safe_perealloc(list, new_count + 1, list->size, sizeof(*list), 1); } if (list) { - size_t e; - PLIST_MOV_EXPAND_EX(list, offset_start, num_eles); PLIST_CPY_R(list, PLIST_ELE(list, offset_start), eles, num_eles); list->count = new_count; diff --git a/src/token.c b/src/token.c index 316c734..7b303e7 100644 --- a/src/token.c +++ b/src/token.c @@ -41,7 +41,7 @@ struct psi_token *psi_token_init(token_t token_typ, const char *token_txt, { struct psi_token *T; - T = calloc(1, sizeof(*T)); + T = pecalloc(1, sizeof(*T), 1); T->type = token_typ; T->col = col; T->line = line; @@ -67,7 +67,7 @@ void psi_token_free(struct psi_token **token_ptr) { } struct psi_token *psi_token_copy(struct psi_token *src) { - struct psi_token *ptr = malloc(sizeof(*ptr)); + struct psi_token *ptr = pemalloc(sizeof(*ptr), 1); *ptr = *src; #if PSI_DEBUG_TOKEN_ALLOC @@ -88,7 +88,7 @@ struct psi_token *psi_token_cat(const char *sep, unsigned argc, ...) { va_list argv; unsigned i; size_t sep_len = sep ? strlen(sep) : 0; - struct psi_token *T = malloc(sizeof(*T)); + struct psi_token *T = pemalloc(sizeof(*T), 1); smart_str text = {0}; va_start(argv, argc); diff --git a/src/types.h b/src/types.h index df267a0..e0c4b07 100644 --- a/src/types.h +++ b/src/types.h @@ -85,39 +85,4 @@ static inline impl_val *deref_impl_val(impl_val *ret_val, struct psi_decl_var *v return ret_val; } -static inline impl_val *enref_impl_val(void *ptr, struct psi_decl_var *var) { - impl_val *val, *val_ptr; - unsigned i; - - ZEND_ASSERT(var->arg->var == var); -#if 0 - fprintf(stderr, "enref: %s pl=%u:%u as=%u:%u\n", - var->name->val, var->pointer_level, var->arg->var->pointer_level, - var->array_size, var->arg->var->array_size); -#endif - if (!var->pointer_level ){//&& real_decl_type(var->arg->type)->type != PSI_T_STRUCT) { - return ptr; - } - - val = calloc(var->pointer_level + 1, sizeof(void *)); - val_ptr = val; - for (i = !var->arg->var->array_size; i < var->pointer_level; ++i) { -#if 0 - fprintf(stderr, "++\n"); -#endif - val_ptr->ptr = (void **) val_ptr + 1; - val_ptr = val_ptr->ptr; - } - val_ptr->ptr = ptr; - return val; -} - -static inline impl_val *struct_member_ref(struct psi_decl_arg *set_arg, impl_val *struct_ptr, impl_val **to_free) { - void *ptr = (char *) struct_ptr + set_arg->layout->pos; -#if 0 - fprintf(stderr, "struct member %s: %p\n", set_arg->var->name->val, ptr); -#endif - return ptr; -} - #endif diff --git a/src/types/assert_stmt.c b/src/types/assert_stmt.c index 9ded0ee..e65efae 100644 --- a/src/types/assert_stmt.c +++ b/src/types/assert_stmt.c @@ -30,7 +30,7 @@ struct psi_assert_stmt *psi_assert_stmt_init(enum psi_assert_kind kind, struct psi_num_exp *exp) { - struct psi_assert_stmt *stmt = calloc(1, sizeof(*stmt)); + struct psi_assert_stmt *stmt = pecalloc(1, sizeof(*stmt), 1); stmt->kind = kind; stmt->exp = exp; @@ -91,7 +91,7 @@ char *psi_assert_stmt_message(struct psi_assert_stmt *stmt) dprintf(fd, "Failed asserting that "); psi_num_exp_dump(fd, stmt->exp); fstat(fd, &sb); - message = malloc(sb.st_size + 1); + message = pemalloc(sb.st_size + 1, 1); lseek(fd, 0, SEEK_SET); read(fd, message, sb.st_size); close(fd); diff --git a/src/types/const.c b/src/types/const.c index 1a06e43..1afbac0 100644 --- a/src/types/const.c +++ b/src/types/const.c @@ -29,7 +29,7 @@ struct psi_const *psi_const_init(struct psi_impl_type *type, zend_string *name, struct psi_impl_def_val *val) { - struct psi_const *c = calloc(1, sizeof(*c)); + struct psi_const *c = pecalloc(1, sizeof(*c), 1); if (name->val[0] == '\\') { c->name = zend_string_init(&name->val[1], name->len-1, 1); diff --git a/src/types/cpp_exp.c b/src/types/cpp_exp.c index 6f0fff0..89a8f0e 100644 --- a/src/types/cpp_exp.c +++ b/src/types/cpp_exp.c @@ -32,7 +32,7 @@ struct psi_cpp_exp *psi_cpp_exp_init(token_t type, void *data) { - struct psi_cpp_exp *exp = calloc(1, sizeof(*exp)); + struct psi_cpp_exp *exp = pecalloc(1, sizeof(*exp), 1); switch ((exp->type = type)) { case PSI_T_WARNING: diff --git a/src/types/cpp_macro_call.c b/src/types/cpp_macro_call.c index 8d7dc23..fb32bc0 100644 --- a/src/types/cpp_macro_call.c +++ b/src/types/cpp_macro_call.c @@ -31,7 +31,7 @@ struct psi_cpp_macro_call *psi_cpp_macro_call_init(zend_string *name, struct psi_plist *args) { - struct psi_cpp_macro_call *call = calloc(1, sizeof(*call)); + struct psi_cpp_macro_call *call = pecalloc(1, sizeof(*call), 1); call->name = zend_string_copy(name); call->args = args; return call; @@ -40,7 +40,7 @@ struct psi_cpp_macro_call *psi_cpp_macro_call_init(zend_string *name, struct psi_cpp_macro_call *psi_cpp_macro_call_copy( struct psi_cpp_macro_call *call) { - struct psi_cpp_macro_call *copy = calloc(1, sizeof(*copy)); + struct psi_cpp_macro_call *copy = pecalloc(1, sizeof(*copy), 1); copy->name = zend_string_copy(call->name); if (call->token) { copy->token = psi_token_copy(call->token); diff --git a/src/types/cpp_macro_decl.c b/src/types/cpp_macro_decl.c index c26b708..4f21d60 100644 --- a/src/types/cpp_macro_decl.c +++ b/src/types/cpp_macro_decl.c @@ -31,7 +31,7 @@ struct psi_cpp_macro_decl *psi_cpp_macro_decl_init(struct psi_plist *sig, struct psi_plist *tokens, struct psi_num_exp *exp) { - struct psi_cpp_macro_decl *macro = calloc(1, sizeof(*macro)); + struct psi_cpp_macro_decl *macro = pecalloc(1, sizeof(*macro), 1); macro->exp = exp; macro->sig = sig; macro->tokens = tokens; diff --git a/src/types/decl.c b/src/types/decl.c index 581eadd..5872a32 100644 --- a/src/types/decl.c +++ b/src/types/decl.c @@ -38,7 +38,7 @@ struct psi_decl *psi_decl_init(struct psi_decl_arg *func, struct psi_plist *args) { - struct psi_decl *d = calloc(1, sizeof(*d)); + struct psi_decl *d = pecalloc(1, sizeof(*d), 1); d->func = func; d->args = args; diff --git a/src/types/decl_abi.c b/src/types/decl_abi.c index 794005b..7efa2ef 100644 --- a/src/types/decl_abi.c +++ b/src/types/decl_abi.c @@ -28,7 +28,7 @@ struct psi_decl_abi *psi_decl_abi_init(zend_string *convention) { - struct psi_decl_abi *abi = calloc(1, sizeof(*abi)); + struct psi_decl_abi *abi = pecalloc(1, sizeof(*abi), 1); abi->convention = convention ? zend_string_copy(convention) : zend_string_init_interned(ZEND_STRL("default"), 1); diff --git a/src/types/decl_arg.c b/src/types/decl_arg.c index 9f487c3..91a5366 100644 --- a/src/types/decl_arg.c +++ b/src/types/decl_arg.c @@ -31,7 +31,7 @@ struct psi_decl_arg *psi_decl_arg_init(struct psi_decl_type *type, struct psi_decl_var *var) { - struct psi_decl_arg *arg = calloc(1, sizeof(*arg)); + struct psi_decl_arg *arg = pecalloc(1, sizeof(*arg), 1); arg->token = var->token; arg->type = type; arg->var = var; diff --git a/src/types/decl_enum.c b/src/types/decl_enum.c index f060bf3..310b7e3 100644 --- a/src/types/decl_enum.c +++ b/src/types/decl_enum.c @@ -28,7 +28,7 @@ struct psi_decl_enum *psi_decl_enum_init(zend_string *name, struct psi_plist *l) { - struct psi_decl_enum *e = calloc(1, sizeof(*e)); + struct psi_decl_enum *e = pecalloc(1, sizeof(*e), 1); e->name = zend_string_copy(name); e->items = l; return e; diff --git a/src/types/decl_enum_item.c b/src/types/decl_enum_item.c index 7c49142..f20eaa6 100644 --- a/src/types/decl_enum_item.c +++ b/src/types/decl_enum_item.c @@ -29,7 +29,7 @@ struct psi_decl_enum_item *psi_decl_enum_item_init(zend_string *name, struct psi_num_exp *num) { - struct psi_decl_enum_item *i = calloc(1, sizeof(*i)); + struct psi_decl_enum_item *i = pecalloc(1, sizeof(*i), 1); i->name = zend_string_copy(name); i->num = num; return i; diff --git a/src/types/decl_extvar.c b/src/types/decl_extvar.c index c6a77aa..4490a0a 100644 --- a/src/types/decl_extvar.c +++ b/src/types/decl_extvar.c @@ -36,7 +36,7 @@ struct psi_decl_extvar *psi_decl_extvar_init(struct psi_decl_arg *arg) { - struct psi_decl_extvar *evar = calloc(1, sizeof(*evar)); + struct psi_decl_extvar *evar = pecalloc(1, sizeof(*evar), 1); evar->arg = arg; return evar; diff --git a/src/types/decl_struct.c b/src/types/decl_struct.c index c2b8cc1..14076c6 100644 --- a/src/types/decl_struct.c +++ b/src/types/decl_struct.c @@ -31,7 +31,7 @@ struct psi_decl_struct* psi_decl_struct_init(zend_string *name, struct psi_plist *args) { - struct psi_decl_struct *s = calloc(1, sizeof(*s)); + struct psi_decl_struct *s = pecalloc(1, sizeof(*s), 1); s->name = zend_string_copy(name); s->args = args; return s; diff --git a/src/types/decl_type.c b/src/types/decl_type.c index 31c49b4..51795b0 100644 --- a/src/types/decl_type.c +++ b/src/types/decl_type.c @@ -32,7 +32,7 @@ struct psi_decl_type *psi_decl_type_init(token_t type, zend_string *name) { - struct psi_decl_type *t = calloc(1, sizeof(*t)); + struct psi_decl_type *t = pecalloc(1, sizeof(*t), 1); t->type = type; t->name = zend_string_copy(name); return t; @@ -55,7 +55,7 @@ void psi_decl_type_free(struct psi_decl_type **type_ptr) struct psi_decl_type *psi_decl_type_copy(struct psi_decl_type *src) { - struct psi_decl_type *dst = calloc(1, sizeof(*dst)); + struct psi_decl_type *dst = pecalloc(1, sizeof(*dst), 1); dst->type = src->type; if (src->name) { diff --git a/src/types/decl_union.c b/src/types/decl_union.c index 826dc48..3ab8f69 100644 --- a/src/types/decl_union.c +++ b/src/types/decl_union.c @@ -31,7 +31,7 @@ struct psi_decl_union* psi_decl_union_init(zend_string *name, struct psi_plist *args) { - struct psi_decl_union *u = calloc(1, sizeof(*u)); + struct psi_decl_union *u = pecalloc(1, sizeof(*u), 1); u->name = zend_string_copy(name); u->args = args; return u; diff --git a/src/types/decl_var.c b/src/types/decl_var.c index 56c525c..49bc58f 100644 --- a/src/types/decl_var.c +++ b/src/types/decl_var.c @@ -33,7 +33,7 @@ struct psi_decl_var *psi_decl_var_init(zend_string *name, unsigned pl, unsigned as) { - struct psi_decl_var *v = calloc(1, sizeof(*v)); + struct psi_decl_var *v = pecalloc(1, sizeof(*v), 1); if (name) { v->name = zend_string_copy(name); v->fqn = zend_string_copy(name); @@ -45,7 +45,7 @@ struct psi_decl_var *psi_decl_var_init(zend_string *name, unsigned pl, struct psi_decl_var *psi_decl_var_copy(struct psi_decl_var *src) { - struct psi_decl_var *dest = calloc(1, sizeof(*dest)); + struct psi_decl_var *dest = pecalloc(1, sizeof(*dest), 1); *dest = *src; diff --git a/src/types/free_exp.c b/src/types/free_exp.c index 115da91..7d17756 100644 --- a/src/types/free_exp.c +++ b/src/types/free_exp.c @@ -29,7 +29,7 @@ struct psi_free_exp *psi_free_exp_init(zend_string *func, struct psi_plist *vars) { - struct psi_free_exp *f = calloc(1, sizeof(*f)); + struct psi_free_exp *f = pecalloc(1, sizeof(*f), 1); f->func = zend_string_copy(func); f->vars = vars; return f; @@ -99,7 +99,7 @@ bool psi_free_exp_validate(struct psi_data *data, struct psi_free_exp *exp, } /* now check for known vars */ - exp->let = calloc(psi_plist_count(exp->vars), sizeof(*exp->let)); + exp->let = pecalloc(psi_plist_count(exp->vars), sizeof(*exp->let), 1); for (i = 0; psi_plist_get(exp->vars, i, &free_var); ++i) { if (!psi_impl_get_decl_arg(scope->impl, free_var)) { data->error(data, free_var->token, PSI_WARNING, diff --git a/src/types/free_stmt.c b/src/types/free_stmt.c index 18677af..526f22d 100644 --- a/src/types/free_stmt.c +++ b/src/types/free_stmt.c @@ -28,7 +28,7 @@ struct psi_free_stmt *psi_free_stmt_init(struct psi_plist *exps) { - struct psi_free_stmt *f = calloc(1, sizeof(*f)); + struct psi_free_stmt *f = pecalloc(1, sizeof(*f), 1); f->exps = exps; return f; } diff --git a/src/types/impl.c b/src/types/impl.c index d2c87b9..84bff97 100644 --- a/src/types/impl.c +++ b/src/types/impl.c @@ -31,7 +31,7 @@ struct psi_impl *psi_impl_init(struct psi_impl_func *func, struct psi_plist *stmts) { - struct psi_impl *impl = calloc(1, sizeof(*impl)); + struct psi_impl *impl = pecalloc(1, sizeof(*impl), 1); size_t i = 0; struct psi_token **abstract_stmt; diff --git a/src/types/impl_arg.c b/src/types/impl_arg.c index adbc021..5de6161 100644 --- a/src/types/impl_arg.c +++ b/src/types/impl_arg.c @@ -29,7 +29,7 @@ struct psi_impl_arg *psi_impl_arg_init(struct psi_impl_type *type, struct psi_impl_var *var, struct psi_impl_def_val *def) { - struct psi_impl_arg *arg = calloc(1, sizeof(*arg)); + struct psi_impl_arg *arg = pecalloc(1, sizeof(*arg), 1); arg->type = type; arg->var = var; arg->var->arg = arg; diff --git a/src/types/impl_def_val.c b/src/types/impl_def_val.c index f78a6b9..fc3bc60 100644 --- a/src/types/impl_def_val.c +++ b/src/types/impl_def_val.c @@ -31,7 +31,7 @@ struct psi_impl_def_val *psi_impl_def_val_init(token_t t, void *data) { - struct psi_impl_def_val *def = calloc(1, sizeof(*def)); + struct psi_impl_def_val *def = pecalloc(1, sizeof(*def), 1); switch ((def->type = t)) { case PSI_T_TRUE: diff --git a/src/types/impl_func.c b/src/types/impl_func.c index d160448..a6f45e6 100644 --- a/src/types/impl_func.c +++ b/src/types/impl_func.c @@ -29,7 +29,7 @@ struct psi_impl_func *psi_impl_func_init(zend_string *name, struct psi_plist *args, struct psi_impl_type *type) { - struct psi_impl_func *func = calloc(1, sizeof(*func)); + struct psi_impl_func *func = pecalloc(1, sizeof(*func), 1); func->name = zend_string_copy(name); func->args = args ? : psi_plist_init((psi_plist_dtor) psi_impl_arg_free); diff --git a/src/types/impl_type.c b/src/types/impl_type.c index 3517727..be173aa 100644 --- a/src/types/impl_type.c +++ b/src/types/impl_type.c @@ -28,7 +28,7 @@ struct psi_impl_type *psi_impl_type_init(token_t type, zend_string *name) { - struct psi_impl_type *t = calloc(1, sizeof(*t)); + struct psi_impl_type *t = pecalloc(1, sizeof(*t), 1); t->type = type; t->name = zend_string_copy(name); diff --git a/src/types/impl_var.c b/src/types/impl_var.c index 1fa4173..d3ab4f8 100644 --- a/src/types/impl_var.c +++ b/src/types/impl_var.c @@ -30,7 +30,7 @@ struct psi_impl_var *psi_impl_var_init(zend_string *name, bool is_reference) { - struct psi_impl_var *var = calloc(1, sizeof(*var)); + struct psi_impl_var *var = pecalloc(1, sizeof(*var), 1); var->name = zend_string_copy(name); var->fqn = zend_string_copy(name); @@ -41,7 +41,7 @@ struct psi_impl_var *psi_impl_var_init(zend_string *name, bool is_reference) struct psi_impl_var *psi_impl_var_copy(struct psi_impl_var *var) { - struct psi_impl_var *cpy = malloc(sizeof(*cpy)); + struct psi_impl_var *cpy = pemalloc(sizeof(*cpy), 1); *cpy = *var; diff --git a/src/types/layout.c b/src/types/layout.c index 1a7dcb6..c462120 100644 --- a/src/types/layout.c +++ b/src/types/layout.c @@ -30,7 +30,7 @@ struct psi_layout *psi_layout_init(size_t pos, size_t len, struct psi_layout *bfw) { - struct psi_layout *l = calloc(1, sizeof(*l)); + struct psi_layout *l = pecalloc(1, sizeof(*l), 1); assert(pos + len + (intptr_t) bfw); diff --git a/src/types/let_callback.c b/src/types/let_callback.c index 7126b12..4d65df4 100644 --- a/src/types/let_callback.c +++ b/src/types/let_callback.c @@ -29,7 +29,7 @@ struct psi_let_callback *psi_let_callback_init(struct psi_let_func *func, struct psi_plist *args, struct psi_plist *cb_args) { - struct psi_let_callback *cb = calloc(1, sizeof(*cb)); + struct psi_let_callback *cb = pecalloc(1, sizeof(*cb), 1); cb->func = func; cb->args = args; cb->cb_args = cb_args; diff --git a/src/types/let_calloc.c b/src/types/let_calloc.c index 8b26431..152e5c8 100644 --- a/src/types/let_calloc.c +++ b/src/types/let_calloc.c @@ -29,7 +29,7 @@ struct psi_let_calloc *psi_let_calloc_init(struct psi_num_exp *nmemb, struct psi_num_exp *size) { - struct psi_let_calloc *alloc = calloc(1, sizeof(*alloc)); + struct psi_let_calloc *alloc = pecalloc(1, sizeof(*alloc), 1); alloc->nmemb = nmemb; alloc->size = size; diff --git a/src/types/let_exp.c b/src/types/let_exp.c index fa74b16..97eec8f 100644 --- a/src/types/let_exp.c +++ b/src/types/let_exp.c @@ -42,7 +42,7 @@ struct psi_let_exp *psi_let_exp_init_ex(struct psi_decl_var *var, struct psi_let_exp *psi_let_exp_init(enum psi_let_exp_kind kind, void *data) { - struct psi_let_exp *let = calloc(1, sizeof(*let)); + struct psi_let_exp *let = pecalloc(1, sizeof(*let), 1); switch (let->kind = kind) { case PSI_LET_NULL: assert(!data); diff --git a/src/types/let_func.c b/src/types/let_func.c index ea2f371..fd8b49f 100644 --- a/src/types/let_func.c +++ b/src/types/let_func.c @@ -35,7 +35,7 @@ struct psi_let_func *psi_let_func_init(token_t type, zend_string *name, struct psi_impl_var *var) { - struct psi_let_func *func = calloc(1, sizeof(*func)); + struct psi_let_func *func = pecalloc(1, sizeof(*func), 1); func->type = type; func->name = zend_string_copy(name); func->var = var; diff --git a/src/types/let_stmt.c b/src/types/let_stmt.c index b85f0ce..c64856b 100644 --- a/src/types/let_stmt.c +++ b/src/types/let_stmt.c @@ -28,7 +28,7 @@ struct psi_let_stmt *psi_let_stmt_init(struct psi_let_exp *exp) { - struct psi_let_stmt *let = calloc(1, sizeof(*let)); + struct psi_let_stmt *let = pecalloc(1, sizeof(*let), 1); let->exp = exp; return let; diff --git a/src/types/num_exp.c b/src/types/num_exp.c index 72f374e..36be5f3 100644 --- a/src/types/num_exp.c +++ b/src/types/num_exp.c @@ -36,7 +36,7 @@ struct psi_num_exp *psi_num_exp_init_ternary(token_t op, struct psi_num_exp *cond, struct psi_num_exp *truthy, struct psi_num_exp *falsy) { - struct psi_num_exp *exp = calloc(1, sizeof(*exp)); + struct psi_num_exp *exp = pecalloc(1, sizeof(*exp), 1); exp->op = op; exp->data.t.cond = cond; @@ -49,7 +49,7 @@ struct psi_num_exp *psi_num_exp_init_ternary(token_t op, struct psi_num_exp *psi_num_exp_init_binary(token_t op, struct psi_num_exp *lhs, struct psi_num_exp *rhs) { - struct psi_num_exp *exp = calloc(1, sizeof(*exp)); + struct psi_num_exp *exp = pecalloc(1, sizeof(*exp), 1); exp->op = op; exp->data.b.lhs = lhs; @@ -61,7 +61,7 @@ struct psi_num_exp *psi_num_exp_init_binary(token_t op, struct psi_num_exp *psi_num_exp_init_unary(token_t op, struct psi_num_exp *u) { - struct psi_num_exp *exp = calloc(1, sizeof(*exp)); + struct psi_num_exp *exp = pecalloc(1, sizeof(*exp), 1); exp->op = op; exp->data.u = u; @@ -71,7 +71,7 @@ struct psi_num_exp *psi_num_exp_init_unary(token_t op, struct psi_num_exp *psi_num_exp_init_num(struct psi_number *n) { - struct psi_num_exp *exp = calloc(1, sizeof(*exp)); + struct psi_num_exp *exp = pecalloc(1, sizeof(*exp), 1); exp->op = PSI_T_NUMBER; exp->data.n = n; @@ -82,7 +82,7 @@ struct psi_num_exp *psi_num_exp_init_num(struct psi_number *n) struct psi_num_exp *psi_num_exp_init_cast(struct psi_decl_type *typ, struct psi_num_exp *num) { - struct psi_num_exp *exp = calloc(1, sizeof(*exp)); + struct psi_num_exp *exp = pecalloc(1, sizeof(*exp), 1); exp->op = PSI_T_CAST; exp->data.c.typ = typ; @@ -99,7 +99,7 @@ struct psi_num_exp *psi_num_exp_copy(struct psi_num_exp *exp) return NULL; } - cpy = malloc(sizeof(*cpy)); + cpy = pemalloc(sizeof(*cpy), 1); *cpy = *exp; switch (exp->op) { diff --git a/src/types/number.c b/src/types/number.c index 15505e2..5483196 100644 --- a/src/types/number.c +++ b/src/types/number.c @@ -39,7 +39,7 @@ struct psi_number *psi_number_init(token_t t, void *num, unsigned flags) { - struct psi_number *exp = calloc(1, sizeof(*exp)); + struct psi_number *exp = pecalloc(1, sizeof(*exp), 1); exp->flags = flags; switch (exp->type = t) { @@ -104,7 +104,7 @@ struct psi_number *psi_number_init(token_t t, void *num, unsigned flags) struct psi_number *psi_number_copy(struct psi_number *exp) { - struct psi_number *num = calloc(1, sizeof(*num)); + struct psi_number *num = pecalloc(1, sizeof(*num), 1); *num = *exp; diff --git a/src/types/return_exp.c b/src/types/return_exp.c index 375f096..d66c55c 100644 --- a/src/types/return_exp.c +++ b/src/types/return_exp.c @@ -30,7 +30,7 @@ struct psi_return_exp *psi_return_exp_init(struct psi_decl_var *func, struct psi_plist *args, struct psi_set_exp *set) { - struct psi_return_exp *exp = calloc(1, sizeof(*exp)); + struct psi_return_exp *exp = pecalloc(1, sizeof(*exp), 1); exp->func = func; exp->args = args; diff --git a/src/types/return_stmt.c b/src/types/return_stmt.c index 8ff646d..0c4df36 100644 --- a/src/types/return_stmt.c +++ b/src/types/return_stmt.c @@ -29,7 +29,7 @@ struct psi_return_stmt *psi_return_stmt_init(struct psi_return_exp *exp) { - struct psi_return_stmt *ret = calloc(1, sizeof(*ret)); + struct psi_return_stmt *ret = pecalloc(1, sizeof(*ret), 1); ret->exp = exp; return ret; } diff --git a/src/types/set_exp.c b/src/types/set_exp.c index ef4173a..aea0747 100644 --- a/src/types/set_exp.c +++ b/src/types/set_exp.c @@ -33,7 +33,7 @@ struct psi_set_exp *psi_set_exp_init(enum psi_set_exp_kind kind, void *data) { - struct psi_set_exp *val = calloc(1, sizeof(*val)); + struct psi_set_exp *val = pecalloc(1, sizeof(*val), 1); switch (val->kind = kind) { case PSI_SET_FUNC: diff --git a/src/types/set_func.c b/src/types/set_func.c index 7ac2ed5..caf32ff 100644 --- a/src/types/set_func.c +++ b/src/types/set_func.c @@ -29,7 +29,7 @@ struct psi_set_func *psi_set_func_init(token_t type, zend_string *name, struct psi_decl_var *var) { - struct psi_set_func *func = calloc(1, sizeof(*func)); + struct psi_set_func *func = pecalloc(1, sizeof(*func), 1); func->type = type; func->name = zend_string_copy(name); diff --git a/src/types/set_stmt.c b/src/types/set_stmt.c index 5d31aca..1917571 100644 --- a/src/types/set_stmt.c +++ b/src/types/set_stmt.c @@ -29,7 +29,7 @@ struct psi_set_stmt *psi_set_stmt_init(struct psi_set_exp *exp) { - struct psi_set_stmt *set = calloc(1, sizeof(*set)); + struct psi_set_stmt *set = pecalloc(1, sizeof(*set), 1); set->exp = exp; return set; }