From: Michael Wallner Date: Tue, 20 Nov 2018 15:20:42 +0000 (+0100) Subject: dump fixes X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=commitdiff_plain;h=2d34b0c215608bc3eae007ce5f4e80eae3c1e147;hp=a0f437f26cd0f121ee911a55327a68a3544bf15f dump fixes --- diff --git a/src/calc.h b/src/calc.h index 0c2678c..6361ce8 100644 --- a/src/calc.h +++ b/src/calc.h @@ -29,9 +29,9 @@ #include "token.h" #include "types/impl_val.h" -#define PRIfval ".13gF" -#define PRIdval ".53g" -#define PRIldval ".64LgL" +#define PRIfval ".6g" +#define PRIdval ".16g" +#define PRIldval ".29Lg" typedef token_t (*psi_calc)(token_t t1, impl_val *v1, token_t t2, impl_val *v2, impl_val *res); diff --git a/src/context.c b/src/context.c index febe0bb..7b48c92 100644 --- a/src/context.c +++ b/src/context.c @@ -235,7 +235,7 @@ zend_function_entry *psi_context_compile(struct psi_context *C) } zc.name = zend_string_copy(c->name); - psi_impl_def_val_get_zval(c->val, c->type ? c->type->type : PSI_T_MIXED , &zc.value); + psi_impl_def_val_get_zval(c->val, c->type ? c->type->type : PSI_T_MIXED, &zc.value); zend_register_constant(&zc); } diff --git a/src/data.c b/src/data.c index fb94d30..9bcd493 100644 --- a/src/data.c +++ b/src/data.c @@ -24,6 +24,7 @@ *******************************************************************************/ #include "php_psi_stdinc.h" +#include "php_psi.h" #include "data.h" #include "php_globals.h" diff --git a/src/data.h b/src/data.h index ca7bf90..6ab3490 100644 --- a/src/data.h +++ b/src/data.h @@ -31,8 +31,6 @@ #include "plist.h" #include "validate.h" -#include "php_network.h" - #include #include diff --git a/src/marshal.h b/src/marshal.h index a7777d3..9880f52 100644 --- a/src/marshal.h +++ b/src/marshal.h @@ -72,9 +72,19 @@ static inline char *psi_i128_to_buf(char *buf, __int128 i128) } else if (V >= -(1L<<52) && V <= (1L<<53)) { \ ZVAL_DOUBLE(z, V); \ } else if (V < ZEND_LONG_MIN || V > ZEND_LONG_MAX) { \ - ZVAL_STRING(z, psi_i128_to_buf(&buf[sizeof(buf) - 1], V)); \ + char *str = psi_i128_to_buf(&buf[sizeof(buf) - 1], V); \ + if (persistent) { \ + ZVAL_PSTRING(z, str); \ + } else { \ + ZVAL_STRING(z, str); \ + } \ } else { \ - ZVAL_STRING(z, zend_print_long_to_buf(&buf[sizeof(buf) - 1], V)); \ + char *str = zend_print_long_to_buf(&buf[sizeof(buf) - 1], V); \ + if (persistent) { \ + ZVAL_PSTRING(z, str); \ + } else { \ + ZVAL_STRING(z, str); \ + } \ } \ } else { \ if (V <= ZEND_LONG_MAX) { \ @@ -82,9 +92,19 @@ static inline char *psi_i128_to_buf(char *buf, __int128 i128) } else if (V <= (1L<<53)) { \ ZVAL_DOUBLE(z, V); \ } else if (V > ZEND_ULONG_MAX) { \ - ZVAL_STRING(z, psi_u128_to_buf(&buf[sizeof(buf) - 1], V)); \ + char *str = psi_u128_to_buf(&buf[sizeof(buf) - 1], V); \ + if (persistent) { \ + ZVAL_PSTRING(z, str); \ + } else { \ + ZVAL_STRING(z, str); \ + } \ } else { \ - ZVAL_STRING(z, zend_print_ulong_to_buf(&buf[sizeof(buf) - 1], V)); \ + char *str = zend_print_ulong_to_buf(&buf[sizeof(buf) - 1], V); \ + if (persistent) { \ + ZVAL_PSTRING(z, str); \ + } else { \ + ZVAL_STRING(z, str); \ + } \ } \ } \ } while (0) diff --git a/src/module.c b/src/module.c index 08db814..c369dc6 100644 --- a/src/module.c +++ b/src/module.c @@ -166,7 +166,7 @@ static PHP_FUNCTION(psi_dump) { php_stream *s; zval *r = NULL; - struct psi_dump dump = {.fun = php_stream_printf}; + struct psi_dump dump = {.fun = (psi_dump_cb) php_stream_printf}; if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "|r!", &r)) { return; diff --git a/src/parser.c b/src/parser.c index 9475ff9..9d3395c 100644 --- a/src/parser.c +++ b/src/parser.c @@ -151,7 +151,7 @@ static inline zend_string *macro_to_constant(struct psi_parser *parser, token_t typ = psi_num_exp_exec(scope->macro->exp, &res, NULL, scope->cpp); switch (typ) { - CASE_IMPLVAL_NUM_PRINTF(smart_str_append_printf, &str, res); + CASE_IMPLVAL_NUM_PRINTF(smart_str_append_printf, &str, res, true); default: assert(0); } diff --git a/src/parser_scan.c b/src/parser_scan.c index 1a0e4d3..62fe215 100644 --- a/src/parser_scan.c +++ b/src/parser_scan.c @@ -1,4 +1,4 @@ -/* Generated by re2c 1.1.1 on Tue Nov 13 09:05:21 2018 */ +/* Generated by re2c 1.1.1 on Tue Nov 20 15:59:31 2018 */ #line 1 "src/parser_scan.re" /******************************************************************************* Copyright (c) 2016, Michael Wallner . diff --git a/src/types/assert_stmt.c b/src/types/assert_stmt.c index 6909191..916c96e 100644 --- a/src/types/assert_stmt.c +++ b/src/types/assert_stmt.c @@ -89,7 +89,6 @@ void psi_assert_stmt_throw(struct psi_assert_stmt *stmt) { struct psi_dump dump; smart_str str = {0}; - zend_string *message; dump.ctx.hn = &str; dump.fun = (psi_dump_cb) smart_str_append_printf; diff --git a/src/types/const.c b/src/types/const.c index fd1a165..6277070 100644 --- a/src/types/const.c +++ b/src/types/const.c @@ -69,22 +69,6 @@ void psi_const_dump(struct psi_dump *dump, struct psi_const *cnst) bool psi_const_validate(struct psi_data *data, struct psi_const *c, struct psi_validate_scope *scope) { - if (c->type) { - switch (c->type->type) { - case PSI_T_BOOL: - case PSI_T_INT: - case PSI_T_FLOAT: - case PSI_T_DOUBLE: - case PSI_T_STRING: - break; - default: - data->error(data, val->token, PSI_WARNING, - "Invalid default value type '%s', " - "expected one of bool, int, float/double or string.", - type->name->val); - return false; - } - } if (!psi_impl_def_val_validate(data, c->val, c->type, scope)) { return false; } diff --git a/src/types/decl_struct.c b/src/types/decl_struct.c index 44f8b4c..d17895a 100644 --- a/src/types/decl_struct.c +++ b/src/types/decl_struct.c @@ -60,7 +60,7 @@ void psi_decl_struct_dump(struct psi_dump *dump, struct psi_decl_struct *strct) PSI_DUMP(dump, "struct %s::(%zu, %zu)", strct->name->val, strct->align, strct->size); if (psi_plist_count(strct->args)) { - psi_decl_type_dump_args_with_layout(fd, strct->args, 0); + psi_decl_type_dump_args_with_layout(dump, strct->args, 0); } else { PSI_DUMP(dump, ";"); } diff --git a/src/types/decl_type.c b/src/types/decl_type.c index 164f33f..9db6de1 100644 --- a/src/types/decl_type.c +++ b/src/types/decl_type.c @@ -289,7 +289,7 @@ bool psi_decl_type_validate(struct psi_data *data, struct psi_decl_type *type, return true; } -void psi_decl_type_dump_args_with_layout(int fd, struct psi_plist *args, +void psi_decl_type_dump_args_with_layout(struct psi_dump *dump, struct psi_plist *args, unsigned level) { size_t i = 0; @@ -349,7 +349,7 @@ void psi_decl_type_dump(struct psi_dump *dump, struct psi_decl_type *t, unsigned case PSI_T_STRUCT: PSI_DUMP(dump, "struct "); if (psi_decl_type_is_anon(t->name, "struct")) { - psi_decl_type_dump_args_with_layout(fd, t->real.strct->args, level); + psi_decl_type_dump_args_with_layout(dump, t->real.strct->args, level); return; } break; @@ -357,7 +357,7 @@ void psi_decl_type_dump(struct psi_dump *dump, struct psi_decl_type *t, unsigned case PSI_T_UNION: PSI_DUMP(dump, "union "); if (psi_decl_type_is_anon(t->name, "union")) { - psi_decl_type_dump_args_with_layout(fd, t->real.unn->args, level); + psi_decl_type_dump_args_with_layout(dump, t->real.unn->args, level); return; } break; diff --git a/src/types/decl_type.h b/src/types/decl_type.h index d51220d..e929651 100644 --- a/src/types/decl_type.h +++ b/src/types/decl_type.h @@ -69,7 +69,7 @@ int psi_decl_type_is_weak(struct psi_decl_type *type); struct psi_decl_type *psi_decl_type_get_real(struct psi_decl_type *type); struct psi_plist *psi_decl_type_get_args(struct psi_decl_type *dtyp, struct psi_decl_type **real_typ_ptr); -void psi_decl_type_dump_args_with_layout(int fd, struct psi_plist *args, unsigned level); +void psi_decl_type_dump_args_with_layout(struct psi_dump *dump, struct psi_plist *args, unsigned level); size_t psi_decl_type_get_args_align(struct psi_plist *args); diff --git a/src/types/decl_union.c b/src/types/decl_union.c index a2daf2c..146bc62 100644 --- a/src/types/decl_union.c +++ b/src/types/decl_union.c @@ -56,7 +56,7 @@ void psi_decl_union_dump(struct psi_dump *dump, struct psi_decl_union *unn) { PSI_DUMP(dump, "union %s::(%zu, %zu)", unn->name->val, unn->align, unn->size); if (psi_plist_count(unn->args)) { - psi_decl_type_dump_args_with_layout(fd, unn->args, 0); + psi_decl_type_dump_args_with_layout(dump, unn->args, 0); } else { PSI_DUMP(dump, ";"); } diff --git a/src/types/impl_def_val.h b/src/types/impl_def_val.h index 1345005..360ebb6 100644 --- a/src/types/impl_def_val.h +++ b/src/types/impl_def_val.h @@ -48,5 +48,5 @@ void psi_impl_def_val_free(struct psi_impl_def_val **def_ptr); void psi_impl_def_val_dump(struct psi_dump *dump, struct psi_impl_def_val *val); bool psi_impl_def_val_validate(struct psi_data *data, struct psi_impl_def_val *def, struct psi_impl_type *cmp, struct psi_validate_scope *scope); -token_t psi_impl_def_val_get_zend(struct psi_impl_def_val *val, impl_val *res); +void psi_impl_def_val_get_zval(struct psi_impl_def_val *val, token_t typ, zval *z); #endif diff --git a/src/types/impl_val.h b/src/types/impl_val.h index 186a080..0e52318 100644 --- a/src/types/impl_val.h +++ b/src/types/impl_val.h @@ -80,7 +80,7 @@ typedef union impl_val { } \ break; #else -# define CASE_IMPLVAL_LD_PRINTF(fun, to, ival) +# define CASE_IMPLVAL_LD_PRINTF(fun, to, ival, with_suffix) #endif #define CASE_IMPLVAL_FLOAT_PRINTF(fun, to, ival, with_suffix) \