From: Michael Wallner Date: Mon, 6 Feb 2017 19:39:44 +0000 (+0100) Subject: close #1: do not check for constants value X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=commitdiff_plain;h=91f2f40eee4e1d1dd62ad5de06517f9b27b4aaee;hp=9a01d0b6658e90781eb27117e44727dca70b1aa5 close #1: do not check for constants value --- diff --git a/m4/psi/psi_const.m4 b/m4/psi/psi_const.m4 index 6210ef9..57edff4 100644 --- a/m4/psi/psi_const.m4 +++ b/m4/psi/psi_const.m4 @@ -2,46 +2,31 @@ # Add a pre-defined string constant to $PSI_CONSTS_H psi_add_str_const() { PSI_CONSTS="$PSI_CONSTS - {PSI_T_STRING, \"string\", \"psi\\\\$1\", $2, PSI_T_QUOTED_STRING}," + {PSI_T_STRING, \"string\", \"psi\\\\$1\", {.ptr = $1}}," } # psi_add_int_const(name, value) # Add a pre-defined int constant to $PSI_CONSTS_H psi_add_int_const() { PSI_CONSTS="$PSI_CONSTS - {PSI_T_INT, \"int\", \"psi\\\\$1\", \"$2\", PSI_T_NUMBER}," + {PSI_T_INT, \"int\", \"psi\\\\$1\", {.zend.lval = (zend_long) $1}}," } dnl PSI_CONST(const name, type) dnl Check the value of a str/int constant and add it to the list of pre-defined dnl constants. AC_DEFUN(PSI_CONST, [ - AC_CACHE_CHECK(value of $1, psi_cv_const_$1, [ - psi_const_val= - case $2 in - str*) - if test "$cross_compiling" = "yes" - then - AC_TRY_CPP(PSI_INCLUDES $1, psi_const_val=`eval "$ac_try|tail -n1"`, psi_const_val=) - else - PSI_COMPUTE_STR(psi_const_val, $1, PSI_INCLUDES) - fi - ;; - int) - AC_COMPUTE_INT(psi_const_val, $1, PSI_INCLUDES) - ;; - esac - psi_cv_const_$1=$psi_const_val - ]) - if test "$psi_cv_const_$1" - then - case $2 in - str*) - psi_add_str_const "$1" "$psi_cv_const_$1" - ;; - int) - psi_add_int_const "$1" "$psi_cv_const_$1" - ;; - esac - fi + AC_CHECK_DECL($1, [ + if test "$psi_cv_const_$1" + then + case $2 in + str*) + psi_add_str_const "$1" + ;; + int) + psi_add_int_const "$1" + ;; + esac + fi + ],, [PSI_INCLUDES]) ]) diff --git a/php_psi_posix.h.in b/php_psi_posix.h.in index 4cd316c..1b2f07a 100644 --- a/php_psi_posix.h.in +++ b/php_psi_posix.h.in @@ -54,8 +54,7 @@ static struct psi_predef_const { token_t type_tag; const char *type_name; const char *var_name; - const char *val_text; - token_t val_type_tag; + impl_val value; } psi_predef_consts[] = { @PSI_CONSTS@ {0} diff --git a/src/context.c b/src/context.c index 11b2abd..f10f4c4 100644 --- a/src/context.c +++ b/src/context.c @@ -97,10 +97,25 @@ struct psi_context *psi_context_init(struct psi_context *C, struct psi_context_o T.types = psi_plist_add(T.types, &def); } for (predef_const = &psi_predef_consts[0]; predef_const->type_tag; ++predef_const) { - struct psi_impl_def_val *val = psi_impl_def_val_init(predef_const->val_type_tag, predef_const->val_text); struct psi_const_type *type = psi_const_type_init(predef_const->type_tag, predef_const->type_name); - struct psi_const *constant = psi_const_init(type, predef_const->var_name, val); + struct psi_impl_def_val *val; + struct psi_const *constant; + switch (type->type) { + case PSI_T_INT: + val = psi_impl_def_val_init(PSI_T_INT, NULL); + val->ival.zend.lval = predef_const->value.lval; + break; + case PSI_T_STRING: + val = psi_impl_def_val_init(PSI_T_STRING, NULL); + val->ival.zend.str = zend_string_init(predef_const->value.ptr, strlen(predef_const->value.ptr), 1); + break; + default: + assert(0); + break; + } + + constant = psi_const_init(type, predef_const->var_name, val); T.consts = psi_plist_add(T.consts, &constant); } for (predef_composite = &psi_predef_composites[0]; predef_composite->type_tag; ++predef_composite) { @@ -289,7 +304,7 @@ zend_function_entry *psi_context_compile(struct psi_context *C) continue; } - zc.name = zend_string_init(c->name + (c->name[0] == '\\'), strlen(c->name) - (c->name[0] == '\\'), 1); + zc.name = zend_string_init(c->name, strlen(c->name), 1); switch (c->type->type) { case PSI_T_BOOL: @@ -303,7 +318,7 @@ zend_function_entry *psi_context_compile(struct psi_context *C) break; case PSI_T_STRING: case PSI_T_QUOTED_STRING: - ZVAL_NEW_STR(&zc.value, zend_string_init(c->val->text, strlen(c->val->text), 1)); + ZVAL_NEW_STR(&zc.value, zend_string_copy(c->val->ival.zend.str)); break; default: assert(0); diff --git a/src/types/impl_def_val.c b/src/types/impl_def_val.c index efbd793..e24b4c2 100644 --- a/src/types/impl_def_val.c +++ b/src/types/impl_def_val.c @@ -33,7 +33,7 @@ struct psi_impl_def_val *psi_impl_def_val_init(token_t t, const char *text) struct psi_impl_def_val *def = calloc(1, sizeof(*def)); def->type = t; - def->text = strdup(text); + def->text = text ? strdup(text) : NULL; return def; } @@ -49,15 +49,15 @@ void psi_impl_def_val_free(struct psi_impl_def_val **def_ptr) } switch (def->type) { case PSI_T_STRING: - assert(0); - /* no break */ case PSI_T_QUOTED_STRING: if (def->ival.zend.str) { zend_string_release(def->ival.zend.str); } break; } - free(def->text); + if (def->text) { + free(def->text); + } free(def); } } @@ -79,7 +79,8 @@ bool psi_impl_def_val_validate(struct psi_data *data, break; case PSI_T_STRING: /* used for consts */ - /* no break */ + def->ival.zend.str = zend_string_init(def->text, strlen(def->text), 1); + break; case PSI_T_QUOTED_STRING: def->ival.zend.str = zend_string_init(&def->text[1], strlen(def->text) - 2, 1); break; @@ -95,13 +96,25 @@ bool psi_impl_def_val_validate(struct psi_data *data, void psi_impl_def_val_dump(int fd, struct psi_impl_def_val *val) { switch (val->type) { + case PSI_T_INT: + dprintf(fd, "%ld", val->ival.zend.lval); + break; + case PSI_T_FLOAT: + case PSI_T_DOUBLE: + dprintf(fd, "%f", val->ival.dval); + break; case PSI_T_STRING: - assert(0); - /* no break */ + dprintf(fd, "\"%s\"", val->ival.zend.str->val); + break; case PSI_T_QUOTED_STRING: dprintf(fd, "\"%s\"", val->text); break; default: - dprintf(fd, "%s", val->text); + if (val->text) { + dprintf(fd, "%s", val->text); + } else { + assert(0); + } + break; } }