@@ -23,24 +23,24 @@ enum { LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_FATAL };
23
23
#define LOG_MAX_LEN 4096 /* max number of chars to output */
24
24
#define LOG_MAX_NUM 128 /* max number of elements to output */
25
25
26
- #define MIN (x , y ) ((x) > (y) ? y : x )
26
+ #define MIN (x , y ) ((x) > (y) ? (y) : (x) )
27
27
28
28
/* Construct string of up to LOG_MAX_NUM elements of an array of C type
29
29
* To avoid variable name clash, prefix with double underscores.
30
30
*/
31
31
#define LOG_BUF_C_TYPE (type , format , buf , data , n ) \
32
32
do { \
33
- char *__p = buf; \
33
+ char *__p = ( buf); \
34
34
/* Reserve 5 char at the end for " ... \0". Note the first \
35
35
* space will come from the '\0' of the previous string. \
36
36
*/ \
37
- int __i = 0 , __j = sizeof (buf ) - 5 , __k , __l = MIN (n , LOG_MAX_NUM ); \
37
+ int __i = 0 , __j = sizeof (buf ) - 5 , __k , __l = MIN (( n ) , LOG_MAX_NUM ); \
38
38
/* j is the available number of chars including '\0'. k is the \
39
39
* number of chars printed without '\0'. So as long as k < j, \
40
40
* it means the output, with a trailing '\0', fits in the buffer. \
41
41
*/ \
42
42
while (__i < __l && \
43
- (__k = snprintf (__p , __j , format , ((type * )data )[__i ])) < __j ) { \
43
+ (__k = snprintf (__p , __j , ( format ) , ((type * )( data )) [__i ])) < __j ) {\
44
44
assert (__k >= 0 && "snprintf write error to __p" ); \
45
45
__p += __k ; \
46
46
__j -= __k ; \
@@ -69,66 +69,69 @@ enum { LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_FATAL };
69
69
switch (type) { \
70
70
case ONNX_TYPE_UINT8: \
71
71
case ONNX_TYPE_INT8: \
72
- LOG_BUF_C_TYPE(const char, hex ? " %02x" : "%c", buf, data, n); \
72
+ LOG_BUF_C_TYPE(const char, ( hex) ? " %02x" : "%c", ( buf), ( data), (n)); \
73
73
break; \
74
74
case ONNX_TYPE_UINT16: \
75
75
case ONNX_TYPE_INT16: \
76
- LOG_BUF_C_TYPE(const short, hex ? " %04x" : " %d", buf, data, n); \
76
+ LOG_BUF_C_TYPE(const short, ( hex) ? " %04x" : " %d", ( buf), ( data), (n)); \
77
77
break; \
78
78
case ONNX_TYPE_UINT32: \
79
79
case ONNX_TYPE_INT32: \
80
- LOG_BUF_C_TYPE(const int, hex ? " %08x" : " %d", buf, data, n); \
80
+ LOG_BUF_C_TYPE(const int, ( hex) ? " %08x" : " %d", ( buf), ( data), (n)); \
81
81
break; \
82
82
case ONNX_TYPE_UINT64: \
83
83
case ONNX_TYPE_INT64: \
84
- LOG_BUF_C_TYPE(const long, hex ? " %016x" : " %ld", buf, data, n); \
84
+ LOG_BUF_C_TYPE(const long, ( hex) ? " %016x" : " %ld", ( buf), ( data), (n)); \
85
85
break; \
86
86
case ONNX_TYPE_FLOAT16: \
87
- LOG_BUF_C_TYPE(const short, " %04x", buf, data, n); \
87
+ LOG_BUF_C_TYPE(const short, " %04x", ( buf), ( data), (n)); \
88
88
break; \
89
89
case ONNX_TYPE_FLOAT: \
90
- LOG_BUF_C_TYPE(const float, hex ? " %08x" : " %f", buf, data, n); \
90
+ LOG_BUF_C_TYPE(const float, ( hex) ? " %08x" : " %f", ( buf), ( data), (n)); \
91
91
break; \
92
92
case ONNX_TYPE_DOUBLE: \
93
- LOG_BUF_C_TYPE(const double, hex ? " %016x" : " %lf", buf, data, n); \
93
+ LOG_BUF_C_TYPE(const double, ( hex) ? " %016x" : " %lf", ( buf), ( data), (n)); \
94
94
break; \
95
95
default: { \
96
- int __a = sprintf(buf, " unsupported data type %d ", type); \
96
+ int __a = sprintf(( buf) , " unsupported data type %d ", ( type)); \
97
97
assert(__a >= 0 && "sprintf write error to buf"); \
98
98
} \
99
99
} \
100
100
} while (0)
101
101
102
- #define LOG_BUF (type , buf , data , n ) LOG_BUF_ONNX_TYPE(type, buf, data, n, 0)
103
- #define LOG_XBUF (type , buf , data , n ) LOG_BUF_ONNX_TYPE(type, buf, data, n, 1)
102
+ #define LOG_BUF (type , buf , data , n ) \
103
+ LOG_BUF_ONNX_TYPE((type), (buf), (data), (n), 0)
104
+ #define LOG_XBUF (type , buf , data , n ) \
105
+ LOG_BUF_ONNX_TYPE((type),(buf), (data), (n), 1)
104
106
105
107
#define LOG_CHAR_BUF (buf , data , n ) \
106
- LOG_BUF_C_TYPE(const char, "%c", buf, data, n )
108
+ LOG_BUF_C_TYPE(const char, "%c", ( buf), ( data), (n) )
107
109
#define LOG_CHAR_XBUF (buf , data , n ) \
108
- LOG_BUF_C_TYPE(const char, " %02x", buf, data, n )
110
+ LOG_BUF_C_TYPE(const char, " %02x", ( buf), ( data), (n) )
109
111
#define LOG_SHORT_BUF (buf , data , n ) \
110
- LOG_BUF_C_TYPE(const short, " %d", buf, data, n )
112
+ LOG_BUF_C_TYPE(const short, " %d", ( buf), ( data), (n) )
111
113
#define LOG_SHORT_XBUF (buf , data , n ) \
112
- LOG_BUF_C_TYPE(const short, " %04x", buf, data, n)
113
- #define LOG_INT_BUF (buf , data , n ) LOG_BUF_C_TYPE(const int, " %d", buf, data, n)
114
+ LOG_BUF_C_TYPE(const short, " %04x", (buf), (data), (n))
115
+ #define LOG_INT_BUF (buf , data , n ) \
116
+ LOG_BUF_C_TYPE(const int, " %d", (buf), (data), (n))
114
117
#define LOG_INT_XBUF (buf , data , n ) \
115
- LOG_BUF_C_TYPE(const int, " %08x", buf, data, n )
118
+ LOG_BUF_C_TYPE(const int, " %08x", ( buf), ( data), (n) )
116
119
#define LOG_LONG_BUF (buf , data , n ) \
117
- LOG_BUF_C_TYPE(const long, " %ld", buf, data, n )
120
+ LOG_BUF_C_TYPE(const long, " %ld", ( buf), ( data), (n) )
118
121
#define LOG_LONG_XBUF (buf , data , n ) \
119
- LOG_BUF_C_TYPE(const long, " %016x", buf, data, n )
122
+ LOG_BUF_C_TYPE(const long, " %016x", ( buf), ( data), (n) )
120
123
#define LOG_FLOAT_BUF (buf , data , n ) \
121
- LOG_BUF_C_TYPE(const float, " %f", buf, data, n )
124
+ LOG_BUF_C_TYPE(const float, " %f", ( buf), ( data), (n) )
122
125
#define LOG_FLOAT_XBUF (buf , data , n ) \
123
- LOG_BUF_C_TYPE(const float, " %08x", buf, data, n )
126
+ LOG_BUF_C_TYPE(const float, " %08x", ( buf), ( data), (n) )
124
127
#define LOG_DOUBLE_BUF (buf , data , n ) \
125
- LOG_BUF_C_TYPE(const double, " %lf", buf, data, n )
128
+ LOG_BUF_C_TYPE(const double, " %lf", ( buf), ( data), (n) )
126
129
#define LOG_DOUBLE_XBUF (buf , data , n ) \
127
- LOG_BUF_C_TYPE(const double, " %016x", buf, data, n )
130
+ LOG_BUF_C_TYPE(const double, " %016x", ( buf), ( data),(n) )
128
131
129
132
/* Main macro for log output */
130
133
#define LOG_PRINTF (level , ...) \
131
- log_printf(level, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
134
+ log_printf(( level) , __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
132
135
133
136
/* Generic log routine */
134
137
extern void log_init (void );
0 commit comments