X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Ftoken.c;h=01c45f10e0b1932e5a5bbcdf5920c290c0fe6fab;hp=4860afd3a43cae9276ca4ec6ed7e96fc46bbd2e8;hb=52ed5940ed0ab3cafd36fbded2e83c92563e7b2b;hpb=2f5af21b263403997e154658635d6b6e6eaab453 diff --git a/src/token.c b/src/token.c index 4860afd..01c45f1 100644 --- a/src/token.c +++ b/src/token.c @@ -23,19 +23,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ -#ifdef HAVE_CONFIG_H -# include "config.h" -#else -# include "php_config.h" -#endif - -#include -#include -#include -#include -#include - -#include "parser_proc.h" +#include "php_psi_stdinc.h" + #include "token.h" #include "parser.h" @@ -54,7 +43,7 @@ struct psi_token *psi_token_alloc(struct psi_parser *P) { token_typ = P->num; token_len = P->cur - P->tok; - fname_len = strlen(P->psi.file.fn); + fname_len = strlen(P->file.fn); T = calloc(1, psi_token_alloc_size(token_len, fname_len)); T->type = token_typ; @@ -65,7 +54,7 @@ struct psi_token *psi_token_alloc(struct psi_parser *P) { T->col = P->col; memcpy(T->text, P->tok, token_len); - memcpy(T->file, P->psi.file.fn, fname_len); + memcpy(T->file, P->file.fn, fname_len); return T; } @@ -93,8 +82,16 @@ struct psi_token *psi_token_cat(unsigned argc, ...) { if (T) { size_t token_len = T->size, fname_len = strlen(T->file); + struct psi_token *tmp = realloc(T, psi_token_alloc_size(T->size += arg->size + 1, fname_len)); + + if (tmp) { + T = tmp; + } else { + free(T); + va_end(argv); + return NULL; + } - T = realloc(T, psi_token_alloc_size(T->size += arg->size + 1, fname_len)); T->text = &T->buf[0]; T->file = &T->buf[T->size + 1]; T->buf[token_len] = ' '; @@ -139,29 +136,29 @@ struct psi_token *psi_token_translit(struct psi_token *T, char *from, char *to) static inline uint64_t psi_hash(char *digest_buf, ...) { - uint64_t hash = 5381; - uint8_t c; - const uint8_t *ptr; - va_list argv; + uint64_t hash = 5381; + uint8_t c; + const uint8_t *ptr; + va_list argv; - va_start(argv, digest_buf); - while ((ptr = va_arg(argv, const uint8_t *))) { + va_start(argv, digest_buf); + while ((ptr = va_arg(argv, const uint8_t *))) { while ((c = *ptr++)) { hash = ((hash << 5) + hash) + c; } - } - va_end(argv); + } + va_end(argv); - if (digest_buf) { - sprintf(digest_buf, "%" PRIx64, hash); - } + if (digest_buf) { + sprintf(digest_buf, "%" PRIx64, hash); + } - return hash; + return hash; } uint64_t psi_token_hash(struct psi_token *t, char *digest_buf) { char loc_buf[48]; sprintf(loc_buf, "%u%u", t->line, t->col); - return psi_hash(digest_buf, t->file, loc_buf, NULL); + return psi_hash(digest_buf, t->file, loc_buf, (char *) NULL); }