void *ws_f_calloc(WsFastMalloc *pool, size_t num, size_t size) { void *p = ws_f_malloc(pool, num * size); if (p == NULL) return p; memset(p, 0, num * size); return p; }
void *ws_f_memdup(WsFastMalloc *pool, const void *ptr, size_t size) { unsigned char *d = ws_f_malloc(pool, size + 1); if (d == NULL) return NULL; memcpy(d, ptr, size); d[size] = '\0'; return d; }
WsFormalParm *ws_formal_parameter(WsCompilerPtr compiler, WsUInt32 line, char *name) { WsFormalParm *parm = ws_f_malloc(compiler->pool_stree, sizeof(*parm)); if (parm == NULL) ws_error_memory(compiler); else { parm->line = line; parm->name = name; } return parm; }
WsVarDec *ws_variable_declaration(WsCompilerPtr compiler, char *name, WsExpression *expr) { WsVarDec *vardec = ws_f_malloc(compiler->pool_stree, sizeof(*vardec)); if (vardec == NULL) ws_error_memory(compiler); else { vardec->name = name; vardec->expr = expr; } return vardec; }
void *ws_f_strdup(WsFastMalloc *pool, const char *str) { size_t len; char *s; if (str == NULL) return NULL; len = strlen(str) + 1; s = ws_f_malloc(pool, len); if (s == NULL) return NULL; memcpy(s, str, len); return s; }