X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Ftoken.c;h=7b303e712fa0c44ebdea49cc1d3227b8b064bc3f;hb=35060621f2fd5079502543d17942127c1a602f72;hp=df7d2e8592905062cd82ae1025e5fdbc0a5350e8;hpb=f854ff4c520183dbd820f61b958c9794cfd3a1fd;p=m6w6%2Fext-psi diff --git a/src/token.c b/src/token.c index df7d2e8..7b303e7 100644 --- a/src/token.c +++ b/src/token.c @@ -32,29 +32,33 @@ #include "token.h" #include "parser.h" -size_t psi_token_alloc_size(size_t token_len, size_t fname_len) { - return sizeof(struct psi_token) + token_len + fname_len + 2; -} +#ifndef PSI_DEBUG_TOKEN_ALLOC +# define PSI_DEBUG_TOKEN_ALLOC 0 +#endif struct psi_token *psi_token_init(token_t token_typ, const char *token_txt, size_t token_len, unsigned col, unsigned line, zend_string *file) { 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; T->file = zend_string_copy(file); - T->text = zend_string_init(token_txt, token_len, 1); - + T->text = zend_string_init_interned(token_txt, token_len, 1); +#if PSI_DEBUG_TOKEN_ALLOC + fprintf(stderr, "PSI: token_init %p\n", T); +#endif return T; } void psi_token_free(struct psi_token **token_ptr) { if (*token_ptr) { struct psi_token *token = *token_ptr; - +#if PSI_DEBUG_TOKEN_ALLOC + fprintf(stderr, "PSI: token_free %p\n", token); +#endif *token_ptr = NULL; zend_string_release(token->text); zend_string_release(token->file); @@ -63,10 +67,12 @@ 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 + fprintf(stderr, "PSI: token_copy %p <= %p\n", ptr, src); +#endif ptr->text = zend_string_copy(ptr->text); ptr->file = zend_string_copy(ptr->file); @@ -82,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); @@ -103,6 +109,9 @@ struct psi_token *psi_token_cat(const char *sep, unsigned argc, ...) { T->text = smart_str_extract(&text); +#if PSI_DEBUG_TOKEN_ALLOC + fprintf(stderr, "PSI: token_cat %p\n", T); +#endif return T; }