X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Fmarshal.c;h=d0c7f125152e271ae89d153c275b9a7b52081cad;hp=9804fe09ffb7a6b5162dfb3df4e553198530e8fb;hb=16e375c9503246b179550cd97c0739c916dc802a;hpb=2fa436074ca9a5e87f39b696de832fa2188fcfc6 diff --git a/src/marshal.c b/src/marshal.c index 9804fe0..d0c7f12 100644 --- a/src/marshal.c +++ b/src/marshal.c @@ -23,7 +23,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ -#include "php_psi_stdinc.h" +#ifdef HAVE_CONFIG_H +# include "config.h" +#else +# include "php_config.h" +#endif #include "data.h" #include "calc.h" @@ -96,7 +100,7 @@ zend_internal_arg_info *psi_internal_arginfo(struct psi_impl *impl) zend_internal_function_info *fi; struct psi_impl_arg *iarg; - aip = calloc(argc + 1 + !!impl->func->vararg, sizeof(*aip)); + aip = pecalloc(argc + 1 + !!impl->func->vararg, sizeof(*aip), 1); fi = (zend_internal_function_info *) &aip[0]; #ifdef ZEND_TYPE_ENCODE @@ -226,52 +230,6 @@ impl_val *psi_let_boolval(impl_val *tmp, struct psi_decl_arg *spec, token_t impl return psi_val_boolval(tmp, real_type, boolval); } -#if HAVE_INT128 -static inline char *psi_u128_to_buf(char *buf, unsigned __int128 u128) -{ - for (*buf = 0; u128 > 0; u128 /= 10) { - *--buf = ((u128 % 10) + '0') & 0xff; - } - return buf; -} - -static inline char *psi_i128_to_buf(char *buf, __int128 i128) -{ - if (i128 < 0) { - char *res = psi_u128_to_buf(buf, ~((unsigned __int128) i128) + 1); - - *--res = '-'; - return res; - } - return psi_u128_to_buf(buf, i128); -} - -# define RETVAL_LONG_STR(V, s) do {\ - char buf[0x30] = {0}; \ - if (s && V >= ZEND_LONG_MIN && V <= ZEND_LONG_MAX) { \ - RETVAL_LONG(V); \ - } else if (!s && V <= ZEND_LONG_MAX) { \ - RETVAL_LONG(V); \ - } else if (!s && V <= ZEND_ULONG_MAX) { \ - RETVAL_STRING(zend_print_ulong_to_buf(&buf[sizeof(buf) - 1], V)); \ - } else if (s && V >= INT128_MIN && V <= INT128_MAX) { \ - RETVAL_STRING(psi_i128_to_buf(&buf[sizeof(buf) - 1], V)); \ - } else { \ - RETVAL_STRING(psi_u128_to_buf(&buf[sizeof(buf) - 1], V)); \ - } \ - } while (0) -#else -# define RETVAL_LONG_STR(V, s) do {\ - char buf[0x20] = {0}; \ - if (s && V >= ZEND_LONG_MIN && V <= ZEND_LONG_MAX) { \ - RETVAL_LONG(V); \ - } else if (!s && V <= ZEND_LONG_MAX) { \ - RETVAL_LONG(V); \ - } else { \ - RETVAL_STRING(zend_print_ulong_to_buf(&buf[sizeof(buf) - 1], V)); \ - } \ - } while (0) -#endif /* * set $ivar = to_int(*dvar) */ @@ -290,10 +248,10 @@ void psi_set_to_int(zval *return_value, struct psi_set_exp *set, impl_val *ret_v case PSI_T_INT32: RETVAL_LONG(v->i32); break; case PSI_T_UINT32: RETVAL_LONG(v->u32); break; case PSI_T_INT64: RETVAL_LONG(v->i64); break; - case PSI_T_UINT64: RETVAL_LONG_STR(v->u64, 0); break; + case PSI_T_UINT64: RETVAL_LONG_DOUBLE_STR(v->u64,); break; #ifdef HAVE_INT128 - case PSI_T_INT128: RETVAL_LONG_STR(v->i128, 1); break; - case PSI_T_UINT128: RETVAL_LONG_STR(v->u128, 0); break; + case PSI_T_INT128: RETVAL_LONG_DOUBLE_STR(v->i128, is_signed=true); break; + case PSI_T_UINT128: RETVAL_LONG_DOUBLE_STR(v->u128,); break; #endif case PSI_T_FLOAT: RETVAL_DOUBLE((double) v->fval); @@ -340,7 +298,7 @@ static inline impl_val *psi_val_intval(impl_val *tmp, token_t real_type, zend_lo } #if HAVE_INT128 -void psi_strto_i128(char *ptr, char *end, token_t real_type, impl_val *val) { +static void psi_strto_i128(char *ptr, char *end, token_t real_type, impl_val *val) { unsigned __int128 i = 0; bool oct = false, hex = false, sign = false; @@ -732,7 +690,7 @@ void psi_set_to_array(zval *return_value, struct psi_set_exp *set, impl_val *r_v ZVAL_NULL(&ele); psi_set_exp_exec_ex(sub_exp, &ele, sym->ptr, frame); - add_assoc_zval(return_value, ivar->name->val + 1, &ele); + add_assoc_zval_ex(return_value, ivar->name->val + 1, ivar->name->len - 1, &ele); } }