fix access of stat.st_mtime
[m6w6/ext-psi] / src / marshal.h
index 6fe15c67f3606899a658d1f899ce40d9d7ae5da8..9880f522f5f975b7b7e0e701687627d654eed0f8 100644 (file)
 #ifndef PSI_MARSHAL_H
 #define PSI_MARSHAL_H
 
-#include "impl_val.h"
+#include "types/impl_val.h"
 #include "Zend/zend_types.h"
 
 struct psi_let_exp;
 struct psi_set_exp;
-struct psi_decl_type;
+struct psi_decl_arg;
 struct psi_call_frame;
 struct psi_impl;
 struct psi_impl_type;
 
+#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);
+}
+#else
+# define psi_u128_to_buf(b,u) zend_print_ulong_to_buf(b,u)
+# define psi_i128_to_buf(b,i) zend_print_long_to_buf(b,i)
+#endif
+
+
+#define RETVAL_LONG_DOUBLE_STR(V, flags) ZVAL_LONG_DOUBLE_STR(return_value, V, flags)
+# define ZVAL_LONG_DOUBLE_STR(z, V, flags) do { \
+       char buf[0x20] = {0}; \
+       bool is_signed = false, persistent = false; \
+       flags; \
+       if (is_signed) { \
+               if (V >= ZEND_LONG_MIN && V <= ZEND_LONG_MAX) { \
+                       ZVAL_LONG(z, V); \
+               } else if (V >= -(1L<<52) && V <= (1L<<53)) { \
+                       ZVAL_DOUBLE(z, V); \
+               } else if (V < ZEND_LONG_MIN || V > ZEND_LONG_MAX) { \
+                       char *str = psi_i128_to_buf(&buf[sizeof(buf) - 1], V); \
+                       if (persistent) { \
+                               ZVAL_PSTRING(z, str); \
+                       } else { \
+                               ZVAL_STRING(z, str); \
+                       } \
+               } else { \
+                       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) { \
+                       ZVAL_LONG(z, V); \
+               } else if (V <= (1L<<53)) { \
+                       ZVAL_DOUBLE(z, V); \
+               } else if (V > ZEND_ULONG_MAX) { \
+                       char *str = psi_u128_to_buf(&buf[sizeof(buf) - 1], V); \
+                       if (persistent) { \
+                               ZVAL_PSTRING(z, str); \
+                       } else { \
+                               ZVAL_STRING(z, str); \
+                       } \
+               } else { \
+                       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)
+
+
 zend_long psi_zval_count(zval *zvalue);
 zend_internal_arg_info *psi_internal_arginfo(struct psi_impl *impl);
 int psi_internal_type(struct psi_impl_type *type);
 
 typedef void (*psi_marshal_set)(zval *return_value, struct psi_set_exp *set, impl_val *ret_val, struct psi_call_frame *frame);
-typedef impl_val *(*psi_marshal_let)(impl_val *tmp, struct psi_decl_type *psi_decl_type, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
+typedef impl_val *(*psi_marshal_let)(impl_val *tmp, struct psi_decl_arg *type_spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
 
 void psi_set_void(zval *return_value, struct psi_set_exp *set, impl_val *ret_val, struct psi_call_frame *frame);
 void psi_set_to_bool(zval *return_value, struct psi_set_exp *set, impl_val *ret_val, struct psi_call_frame *frame);
@@ -56,15 +130,15 @@ void psi_set_to_array(zval *return_value, struct psi_set_exp *set, impl_val *ret
 void psi_set_to_object(zval *return_value, struct psi_set_exp *set, impl_val *ret_val, struct psi_call_frame *frame);
 void psi_set_zval(zval *return_value, struct psi_set_exp *set, impl_val *ret_val, struct psi_call_frame *frame);
 
-impl_val *psi_let_void(impl_val *tmp, struct psi_decl_type *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
-impl_val *psi_let_boolval(impl_val *tmp, struct psi_decl_type *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
-impl_val *psi_let_intval(impl_val *tmp, struct psi_decl_type *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
-impl_val *psi_let_floatval(impl_val *tmp, struct psi_decl_type *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
-impl_val *psi_let_strval(impl_val *tmp, struct psi_decl_type *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
-impl_val *psi_let_pathval(impl_val *tmp, struct psi_decl_type *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
-impl_val *psi_let_strlen(impl_val *tmp, struct psi_decl_type *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
-impl_val *psi_let_objval(impl_val *tmp, struct psi_decl_type *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
-impl_val *psi_let_zval(impl_val *tmp, struct psi_decl_type *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
-impl_val *psi_let_count(impl_val *tmp, struct psi_decl_type *spec, token_t impl_type, impl_val *ival, zval *zvalue, void **to_free);
+impl_val *psi_let_void(impl_val *tmp, struct psi_decl_arg *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
+impl_val *psi_let_boolval(impl_val *tmp, struct psi_decl_arg *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
+impl_val *psi_let_intval(impl_val *tmp, struct psi_decl_arg *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
+impl_val *psi_let_floatval(impl_val *tmp, struct psi_decl_arg *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
+impl_val *psi_let_strval(impl_val *tmp, struct psi_decl_arg *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
+impl_val *psi_let_pathval(impl_val *tmp, struct psi_decl_arg *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
+impl_val *psi_let_strlen(impl_val *tmp, struct psi_decl_arg *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
+impl_val *psi_let_objval(impl_val *tmp, struct psi_decl_arg *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
+impl_val *psi_let_zval(impl_val *tmp, struct psi_decl_arg *spec, token_t impl_type, impl_val *ivalue, zval *zvalue, void **to_free);
+impl_val *psi_let_count(impl_val *tmp, struct psi_decl_arg *spec, token_t impl_type, impl_val *ival, zval *zvalue, void **to_free);
 
 #endif