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));
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);
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);
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;
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;
psi_error_cb error, unsigned flags)
{
if (!data) {
- data = calloc(1, sizeof(*data));
+ data = pecalloc(1, sizeof(*data), 1);
}
data->error = error;
unsigned flags)
{
if (!data) {
- data = calloc(1, sizeof(*data));
+ data = pecalloc(1, sizeof(*data), 1);
}
data->error = 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));
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;
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) {
}
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) {
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);
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));
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;
}
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;
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;
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;
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,
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;
};
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;
ffi_status rc;
if (!L) {
- L = malloc(sizeof(*L));
+ L = pemalloc(sizeof(*L), 1);
}
memset(L, 0, sizeof(*L));
}
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];
#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);
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);
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
-/* 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 <mike@php.net>.
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));
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",
{
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));
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));
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",
{
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));
size = sizeof(void*);
}
- list = calloc(1, sizeof(*list) + size);
+ list = pecalloc(1, sizeof(*list) + size, 1);
list->size = size;
list->dtor = dtor;
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) {
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);
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);
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);
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;
{
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;
}
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
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);
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
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;
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);
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);
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:
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;
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);
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;
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;
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);
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;
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;
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;
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;
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;
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;
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) {
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;
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);
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;
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;
}
/* 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,
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;
}
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;
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;
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:
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);
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);
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);
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;
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);
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;
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;
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);
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;
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;
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;
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;
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;
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;
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;
return NULL;
}
- cpy = malloc(sizeof(*cpy));
+ cpy = pemalloc(sizeof(*cpy), 1);
*cpy = *exp;
switch (exp->op) {
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) {
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;
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;
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;
}
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:
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);
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;
}