intl/icu/source/common/utracimp.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 *******************************************************************************
michael@0 3 *
michael@0 4 * Copyright (C) 2003-2009, International Business Machines
michael@0 5 * Corporation and others. All Rights Reserved.
michael@0 6 *
michael@0 7 *******************************************************************************
michael@0 8 * file name: utracimp.h
michael@0 9 * encoding: US-ASCII
michael@0 10 * tab size: 8 (not used)
michael@0 11 * indentation:4
michael@0 12 *
michael@0 13 * created on: 2003aug06
michael@0 14 * created by: Markus W. Scherer
michael@0 15 *
michael@0 16 * Internal header for ICU tracing/logging.
michael@0 17 *
michael@0 18 *
michael@0 19 * Various notes:
michael@0 20 * - using a trace level variable to only call trace functions
michael@0 21 * when the level is sufficient
michael@0 22 * - using the same variable for tracing on/off to never make a function
michael@0 23 * call when off
michael@0 24 * - the function number is put into a local variable by the entry macro
michael@0 25 * and used implicitly to avoid copy&paste/typing mistakes by the developer
michael@0 26 * - the application must call utrace_setFunctions() and pass in
michael@0 27 * implementations for the trace functions
michael@0 28 * - ICU trace macros call ICU functions that route through the function
michael@0 29 * pointers if they have been set;
michael@0 30 * this avoids an indirection at the call site
michael@0 31 * (which would cost more code for another check and for the indirection)
michael@0 32 *
michael@0 33 * ### TODO Issues:
michael@0 34 * - Verify that va_list is portable among compilers for the same platform.
michael@0 35 * va_list should be portable because printf() would fail otherwise!
michael@0 36 * - Should enum values like UTraceLevel be passed into int32_t-type arguments,
michael@0 37 * or should enum types be used?
michael@0 38 */
michael@0 39
michael@0 40 #ifndef __UTRACIMP_H__
michael@0 41 #define __UTRACIMP_H__
michael@0 42
michael@0 43 #include "unicode/utrace.h"
michael@0 44 #include <stdarg.h>
michael@0 45
michael@0 46 U_CDECL_BEGIN
michael@0 47
michael@0 48 /**
michael@0 49 * \var utrace_level
michael@0 50 * Trace level variable. Negative for "off".
michael@0 51 * Use only via UTRACE_ macros.
michael@0 52 * @internal
michael@0 53 */
michael@0 54 #ifdef UTRACE_IMPL
michael@0 55 U_EXPORT int32_t
michael@0 56 #else
michael@0 57 U_CFUNC U_COMMON_API int32_t
michael@0 58 #endif
michael@0 59 utrace_level;
michael@0 60
michael@0 61
michael@0 62 /**
michael@0 63 * Traced Function Exit return types.
michael@0 64 * Flags indicating the number and types of varargs included in a call
michael@0 65 * to a UTraceExit function.
michael@0 66 * Bits 0-3: The function return type. First variable param.
michael@0 67 * Bit 4: Flag for presence of U_ErrorCode status param.
michael@0 68 * @internal
michael@0 69 */
michael@0 70 typedef enum UTraceExitVal {
michael@0 71 /** The traced function returns no value @internal */
michael@0 72 UTRACE_EXITV_NONE = 0,
michael@0 73 /** The traced function returns an int32_t, or compatible, type. @internal */
michael@0 74 UTRACE_EXITV_I32 = 1,
michael@0 75 /** The traced function returns a pointer @internal */
michael@0 76 UTRACE_EXITV_PTR = 2,
michael@0 77 /** The traced function returns a UBool @internal */
michael@0 78 UTRACE_EXITV_BOOL = 3,
michael@0 79 /** Mask to extract the return type values from a UTraceExitVal @internal */
michael@0 80 UTRACE_EXITV_MASK = 0xf,
michael@0 81 /** Bit indicating that the traced function includes a UErrorCode parameter @internal */
michael@0 82 UTRACE_EXITV_STATUS = 0x10
michael@0 83 } UTraceExitVal;
michael@0 84
michael@0 85 /**
michael@0 86 * Trace function for the entry point of a function.
michael@0 87 * Do not use directly, use UTRACE_ENTRY instead.
michael@0 88 * @param fnNumber The UTraceFunctionNumber for the current function.
michael@0 89 * @internal
michael@0 90 */
michael@0 91 U_CAPI void U_EXPORT2
michael@0 92 utrace_entry(int32_t fnNumber);
michael@0 93
michael@0 94 /**
michael@0 95 * Trace function for each exit point of a function.
michael@0 96 * Do not use directly, use UTRACE_EXIT* instead.
michael@0 97 * @param fnNumber The UTraceFunctionNumber for the current function.
michael@0 98 * @param returnType The type of the value returned by the function.
michael@0 99 * @param errorCode The UErrorCode value at function exit. See UTRACE_EXIT.
michael@0 100 * @internal
michael@0 101 */
michael@0 102 U_CAPI void U_EXPORT2
michael@0 103 utrace_exit(int32_t fnNumber, int32_t returnType, ...);
michael@0 104
michael@0 105
michael@0 106 /**
michael@0 107 * Trace function used inside functions that have a UTRACE_ENTRY() statement.
michael@0 108 * Do not use directly, use UTRACE_DATAX() macros instead.
michael@0 109 *
michael@0 110 * @param utraceFnNumber The number of the current function, from the local
michael@0 111 * variable of the same name.
michael@0 112 * @param level The trace level for this message.
michael@0 113 * @param fmt The trace format string.
michael@0 114 *
michael@0 115 * @internal
michael@0 116 */
michael@0 117 U_CAPI void U_EXPORT2
michael@0 118 utrace_data(int32_t utraceFnNumber, int32_t level, const char *fmt, ...);
michael@0 119
michael@0 120 U_CDECL_END
michael@0 121
michael@0 122 #if U_ENABLE_TRACING
michael@0 123
michael@0 124 /**
michael@0 125 * Boolean expression to see if ICU tracing is turned on
michael@0 126 * to at least the specified level.
michael@0 127 * @internal
michael@0 128 */
michael@0 129 #define UTRACE_LEVEL(level) (utrace_getLevel()>=(level))
michael@0 130
michael@0 131 /**
michael@0 132 * Flag bit in utraceFnNumber, the local variable added to each function
michael@0 133 * with tracing code to contains the function number.
michael@0 134 *
michael@0 135 * Set the flag if the function's entry is traced, which will cause the
michael@0 136 * function's exit to also be traced. utraceFnNumber is uncoditionally
michael@0 137 * set at entry, whether or not the entry is traced, so that it will
michael@0 138 * always be available for error trace output.
michael@0 139 * @internal
michael@0 140 */
michael@0 141 #define UTRACE_TRACED_ENTRY 0x80000000
michael@0 142
michael@0 143 /**
michael@0 144 * Trace statement for the entry point of a function.
michael@0 145 * Stores the function number in a local variable.
michael@0 146 * In C code, must be placed immediately after the last variable declaration.
michael@0 147 * Must be matched with UTRACE_EXIT() at all function exit points.
michael@0 148 *
michael@0 149 * Tracing should start with UTRACE_ENTRY after checking for
michael@0 150 * U_FAILURE at function entry, so that if a function returns immediately
michael@0 151 * because of a pre-existing error condition, it does not show up in the trace,
michael@0 152 * consistent with ICU's error handling model.
michael@0 153 *
michael@0 154 * @param fnNumber The UTraceFunctionNumber for the current function.
michael@0 155 * @internal
michael@0 156 */
michael@0 157 #define UTRACE_ENTRY(fnNumber) \
michael@0 158 int32_t utraceFnNumber=(fnNumber); \
michael@0 159 if(utrace_getLevel()>=UTRACE_INFO) { \
michael@0 160 utrace_entry(fnNumber); \
michael@0 161 utraceFnNumber |= UTRACE_TRACED_ENTRY; \
michael@0 162 }
michael@0 163
michael@0 164
michael@0 165 /**
michael@0 166 * Trace statement for the entry point of open and close functions.
michael@0 167 * Produces trace output at a less verbose setting than plain UTRACE_ENTRY
michael@0 168 * Stores the function number in a local variable.
michael@0 169 * In C code, must be placed immediately after the last variable declaration.
michael@0 170 * Must be matched with UTRACE_EXIT() at all function exit points.
michael@0 171 *
michael@0 172 * @param fnNumber The UTraceFunctionNumber for the current function.
michael@0 173 * @internal
michael@0 174 */
michael@0 175 #define UTRACE_ENTRY_OC(fnNumber) \
michael@0 176 int32_t utraceFnNumber=(fnNumber); \
michael@0 177 if(utrace_getLevel()>=UTRACE_OPEN_CLOSE) { \
michael@0 178 utrace_entry(fnNumber); \
michael@0 179 utraceFnNumber |= UTRACE_TRACED_ENTRY; \
michael@0 180 }
michael@0 181
michael@0 182 /**
michael@0 183 * Trace statement for each exit point of a function that has a UTRACE_ENTRY()
michael@0 184 * statement.
michael@0 185 *
michael@0 186 * @param errorCode The function's ICU UErrorCode value at function exit,
michael@0 187 * or U_ZERO_ERROR if the function does not use a UErrorCode.
michael@0 188 * 0==U_ZERO_ERROR indicates success,
michael@0 189 * positive values an error (see u_errorName()),
michael@0 190 * negative values an informational status.
michael@0 191 *
michael@0 192 * @internal
michael@0 193 */
michael@0 194 #define UTRACE_EXIT() \
michael@0 195 {if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \
michael@0 196 utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, UTRACE_EXITV_NONE); \
michael@0 197 }}
michael@0 198
michael@0 199 /**
michael@0 200 * Trace statement for each exit point of a function that has a UTRACE_ENTRY()
michael@0 201 * statement, and that returns a value.
michael@0 202 *
michael@0 203 * @param val The function's return value, int32_t or comatible type.
michael@0 204 *
michael@0 205 * @internal
michael@0 206 */
michael@0 207 #define UTRACE_EXIT_VALUE(val) \
michael@0 208 {if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \
michael@0 209 utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, UTRACE_EXITV_I32, val); \
michael@0 210 }}
michael@0 211
michael@0 212 #define UTRACE_EXIT_STATUS(status) \
michael@0 213 {if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \
michael@0 214 utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, UTRACE_EXITV_STATUS, status); \
michael@0 215 }}
michael@0 216
michael@0 217 #define UTRACE_EXIT_VALUE_STATUS(val, status) \
michael@0 218 {if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \
michael@0 219 utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (UTRACE_EXITV_I32 | UTRACE_EXITV_STATUS), val, status); \
michael@0 220 }}
michael@0 221
michael@0 222 #define UTRACE_EXIT_PTR_STATUS(ptr, status) \
michael@0 223 {if(utraceFnNumber & UTRACE_TRACED_ENTRY) { \
michael@0 224 utrace_exit(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (UTRACE_EXITV_PTR | UTRACE_EXITV_STATUS), ptr, status); \
michael@0 225 }}
michael@0 226
michael@0 227 /**
michael@0 228 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
michael@0 229 * Takes no data arguments.
michael@0 230 * The number of arguments for this macro must match the number of inserts
michael@0 231 * in the format string. Vector inserts count as two arguments.
michael@0 232 * Calls utrace_data() if the level is high enough.
michael@0 233 * @internal
michael@0 234 */
michael@0 235 #define UTRACE_DATA0(level, fmt) \
michael@0 236 if(UTRACE_LEVEL(level)) { \
michael@0 237 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt)); \
michael@0 238 }
michael@0 239
michael@0 240 /**
michael@0 241 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
michael@0 242 * Takes one data argument.
michael@0 243 * The number of arguments for this macro must match the number of inserts
michael@0 244 * in the format string. Vector inserts count as two arguments.
michael@0 245 * Calls utrace_data() if the level is high enough.
michael@0 246 * @internal
michael@0 247 */
michael@0 248 #define UTRACE_DATA1(level, fmt, a) \
michael@0 249 if(UTRACE_LEVEL(level)) { \
michael@0 250 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY , (level), (fmt), (a)); \
michael@0 251 }
michael@0 252
michael@0 253 /**
michael@0 254 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
michael@0 255 * Takes two data arguments.
michael@0 256 * The number of arguments for this macro must match the number of inserts
michael@0 257 * in the format string. Vector inserts count as two arguments.
michael@0 258 * Calls utrace_data() if the level is high enough.
michael@0 259 * @internal
michael@0 260 */
michael@0 261 #define UTRACE_DATA2(level, fmt, a, b) \
michael@0 262 if(UTRACE_LEVEL(level)) { \
michael@0 263 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY , (level), (fmt), (a), (b)); \
michael@0 264 }
michael@0 265
michael@0 266 /**
michael@0 267 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
michael@0 268 * Takes three data arguments.
michael@0 269 * The number of arguments for this macro must match the number of inserts
michael@0 270 * in the format string. Vector inserts count as two arguments.
michael@0 271 * Calls utrace_data() if the level is high enough.
michael@0 272 * @internal
michael@0 273 */
michael@0 274 #define UTRACE_DATA3(level, fmt, a, b, c) \
michael@0 275 if(UTRACE_LEVEL(level)) { \
michael@0 276 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c)); \
michael@0 277 }
michael@0 278
michael@0 279 /**
michael@0 280 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
michael@0 281 * Takes four data arguments.
michael@0 282 * The number of arguments for this macro must match the number of inserts
michael@0 283 * in the format string. Vector inserts count as two arguments.
michael@0 284 * Calls utrace_data() if the level is high enough.
michael@0 285 * @internal
michael@0 286 */
michael@0 287 #define UTRACE_DATA4(level, fmt, a, b, c, d) \
michael@0 288 if(UTRACE_LEVEL(level)) { \
michael@0 289 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d)); \
michael@0 290 }
michael@0 291
michael@0 292 /**
michael@0 293 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
michael@0 294 * Takes five data arguments.
michael@0 295 * The number of arguments for this macro must match the number of inserts
michael@0 296 * in the format string. Vector inserts count as two arguments.
michael@0 297 * Calls utrace_data() if the level is high enough.
michael@0 298 * @internal
michael@0 299 */
michael@0 300 #define UTRACE_DATA5(level, fmt, a, b, c, d, e) \
michael@0 301 if(UTRACE_LEVEL(level)) { \
michael@0 302 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e)); \
michael@0 303 }
michael@0 304
michael@0 305 /**
michael@0 306 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
michael@0 307 * Takes six data arguments.
michael@0 308 * The number of arguments for this macro must match the number of inserts
michael@0 309 * in the format string. Vector inserts count as two arguments.
michael@0 310 * Calls utrace_data() if the level is high enough.
michael@0 311 * @internal
michael@0 312 */
michael@0 313 #define UTRACE_DATA6(level, fmt, a, b, c, d, e, f) \
michael@0 314 if(UTRACE_LEVEL(level)) { \
michael@0 315 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f)); \
michael@0 316 }
michael@0 317
michael@0 318 /**
michael@0 319 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
michael@0 320 * Takes seven data arguments.
michael@0 321 * The number of arguments for this macro must match the number of inserts
michael@0 322 * in the format string. Vector inserts count as two arguments.
michael@0 323 * Calls utrace_data() if the level is high enough.
michael@0 324 * @internal
michael@0 325 */
michael@0 326 #define UTRACE_DATA7(level, fmt, a, b, c, d, e, f, g) \
michael@0 327 if(UTRACE_LEVEL(level)) { \
michael@0 328 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f), (g)); \
michael@0 329 }
michael@0 330
michael@0 331 /**
michael@0 332 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
michael@0 333 * Takes eight data arguments.
michael@0 334 * The number of arguments for this macro must match the number of inserts
michael@0 335 * in the format string. Vector inserts count as two arguments.
michael@0 336 * Calls utrace_data() if the level is high enough.
michael@0 337 * @internal
michael@0 338 */
michael@0 339 #define UTRACE_DATA8(level, fmt, a, b, c, d, e, f, g, h) \
michael@0 340 if(UTRACE_LEVEL(level)) { \
michael@0 341 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f), (g), (h)); \
michael@0 342 }
michael@0 343
michael@0 344 /**
michael@0 345 * Trace statement used inside functions that have a UTRACE_ENTRY() statement.
michael@0 346 * Takes nine data arguments.
michael@0 347 * The number of arguments for this macro must match the number of inserts
michael@0 348 * in the format string. Vector inserts count as two arguments.
michael@0 349 * Calls utrace_data() if the level is high enough.
michael@0 350 * @internal
michael@0 351 */
michael@0 352 #define UTRACE_DATA9(level, fmt, a, b, c, d, e, f, g, h, i) \
michael@0 353 if(UTRACE_LEVEL(level)) { \
michael@0 354 utrace_data(utraceFnNumber & ~UTRACE_TRACED_ENTRY, (level), (fmt), (a), (b), (c), (d), (e), (f), (g), (h), (i)); \
michael@0 355 }
michael@0 356
michael@0 357 #else
michael@0 358
michael@0 359 /*
michael@0 360 * When tracing is disabled, the following macros become empty
michael@0 361 */
michael@0 362
michael@0 363 #define UTRACE_LEVEL(level) 0
michael@0 364 #define UTRACE_ENTRY(fnNumber)
michael@0 365 #define UTRACE_ENTRY_OC(fnNumber)
michael@0 366 #define UTRACE_EXIT()
michael@0 367 #define UTRACE_EXIT_VALUE(val)
michael@0 368 #define UTRACE_EXIT_STATUS(status)
michael@0 369 #define UTRACE_EXIT_VALUE_STATUS(val, status)
michael@0 370 #define UTRACE_EXIT_PTR_STATUS(ptr, status)
michael@0 371 #define UTRACE_DATA0(level, fmt)
michael@0 372 #define UTRACE_DATA1(level, fmt, a)
michael@0 373 #define UTRACE_DATA2(level, fmt, a, b)
michael@0 374 #define UTRACE_DATA3(level, fmt, a, b, c)
michael@0 375 #define UTRACE_DATA4(level, fmt, a, b, c, d)
michael@0 376 #define UTRACE_DATA5(level, fmt, a, b, c, d, e)
michael@0 377 #define UTRACE_DATA6(level, fmt, a, b, c, d, e, f)
michael@0 378 #define UTRACE_DATA7(level, fmt, a, b, c, d, e, f, g)
michael@0 379 #define UTRACE_DATA8(level, fmt, a, b, c, d, e, f, g, h)
michael@0 380 #define UTRACE_DATA9(level, fmt, a, b, c, d, e, f, g, h, i)
michael@0 381
michael@0 382 #endif
michael@0 383
michael@0 384 #endif

mercurial