fix gdbinit; postprocessing macros
[m6w6/ext-psi] / src / types / impl_val.h
1 /*******************************************************************************
2 Copyright (c) 2016, Michael Wallner <mike@php.net>.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *******************************************************************************/
25
26 #ifndef PSI_TYPES_IMPL_VAL_H
27 #define PSI_TYPES_IMPL_VAL_H
28
29 #include "Zend/zend_types.h"
30 #include "Zend/zend_API.h"
31
32 typedef struct zend_fcall {
33 zend_fcall_info fci;
34 zend_fcall_info_cache fcc;
35 } zend_fcall;
36
37 typedef union impl_val {
38 int8_t i8;
39 uint8_t u8;
40 int16_t i16;
41 uint16_t u16;
42 int32_t i32;
43 uint32_t u32;
44 int64_t i64;
45 uint64_t u64;
46 #if HAVE_INT128
47 int128_t i128;
48 uint128_t u128;
49 #endif
50 float fval;
51 double dval;
52 #ifdef HAVE_LONG_DOUBLE
53 long double ldval;
54 #endif
55 union {
56 zend_bool bval;
57 zend_long lval;
58 zend_string *str;
59 zend_fcall *cb;
60 } zend;
61 void *ptr;
62 #ifdef PHP_DEBUG
63 char _dbg[sizeof(void *)];
64 #endif
65 } impl_val;
66
67 #ifndef linux
68 # define isinfl isinf
69 # define isnanl isnan
70 #endif
71 #if HAVE_LONG_DOUBLE
72 # define CASE_IMPLVAL_LD_PRINTF(fun, to, ival, with_suffix) \
73 case PSI_T_LONG_DOUBLE: \
74 if (isinfl(ival.ldval)) { \
75 fun(to, "\\INF"); \
76 } else if (isnanl(ival.ldval)) { \
77 fun(to, "\\NAN"); \
78 } else { \
79 fun(to, "%" PRIldval "%s", ival.ldval, (with_suffix) ? "L" : ""); \
80 } \
81 break;
82 #else
83 # define CASE_IMPLVAL_LD_PRINTF(fun, to, ival, with_suffix)
84 #endif
85
86 #define CASE_IMPLVAL_FLOAT_PRINTF(fun, to, ival, with_suffix) \
87 CASE_IMPLVAL_LD_PRINTF(fun, to, ival, with_suffix); \
88 case PSI_T_FLOAT: \
89 if (isinf(ival.dval)) { \
90 fun(to, "\\INF"); \
91 } else if (isnan(ival.dval)) { \
92 fun(to, "\\NAN"); \
93 } else { \
94 fun(to, "%" PRIfval "%s", ival.dval, (with_suffix) ? "F" : ""); \
95 } \
96 break; \
97 case PSI_T_DOUBLE: \
98 if (isinf(ival.dval)) { \
99 fun(to, "\\INF"); \
100 } else if (isnan(ival.dval)) { \
101 fun(to, "\\NAN"); \
102 } else { \
103 fun(to, "%" PRIdval, ival.dval); \
104 } \
105 break
106
107 #define CASE_IMPLVAL_INT_PRINTF(fun, to, ival, with_suffix) \
108 case PSI_T_INT8: \
109 fun(to, "%" PRId8, ival.i8); \
110 break; \
111 case PSI_T_UINT8: \
112 fun(to, "%" PRIu8, ival.u8); \
113 break; \
114 case PSI_T_INT16: \
115 fun(to, "%" PRId16, ival.i16); \
116 break; \
117 case PSI_T_UINT16: \
118 fun(to, "%" PRIu16, ival.u16); \
119 break; \
120 case PSI_T_INT32: \
121 fun(to, "%" PRId32, ival.i32); \
122 break; \
123 case PSI_T_UINT32: \
124 fun(to, "%" PRIu32 "%s", ival.u32, (with_suffix) ? "U" : ""); \
125 break; \
126 case PSI_T_INT64: \
127 fun(to, "%" PRId64 "%s", ival.i64, (with_suffix) ? "L" : ""); \
128 break; \
129 case PSI_T_UINT64: \
130 fun(to, "%" PRIu64 "%s", ival.u64, (with_suffix) ? "UL" : ""); \
131 break
132
133 #define CASE_IMPLVAL_NUM_PRINTF(fun, to, ival, with_suffix) \
134 CASE_IMPLVAL_INT_PRINTF(fun, to, ival, with_suffix); \
135 CASE_IMPLVAL_FLOAT_PRINTF(fun, to, ival, with_suffix)
136
137 #endif