define pst_alloc & pst_free macro to use global allocator

This commit is contained in:
2020-02-01 17:57:43 +04:00
parent e27f0c5c18
commit 7c13dfa9e1
8 changed files with 50 additions and 46 deletions
+14 -1
View File
@@ -152,7 +152,7 @@ bool print_expr_block (pst_context* ctx, Dwarf_Op *exprs, int exprlen, Dwarf_Att
return true;
}
void pst_context_init(pst_context* ctx, pst_allocator* alloc, ucontext_t* hctx)
void pst_context_init(pst_context* ctx, ucontext_t* hctx)
{
// global
pst_alloc_init(&allocator);
@@ -194,3 +194,16 @@ void pst_context_fini(pst_context* ctx)
pst_log_fini(&logger);
pst_alloc_fini(&allocator);
}
char* pst_dup(const char* str)
{
pst_assert(str);
uint32_t len = strlen(str);
char* dst = (char*)allocator.alloc(len + 1);
memcpy(dst, str, len);
dst[len] = 0;
return dst;
}