picow-http 0.12.1-4-g9d4fd13
HTTP server for the Raspberry Pi PicoW
assertion.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Geoff Simmons <geoff@simmons.de>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 * See LICENSE
6 */
7
63#include <string.h>
64
65#include "pico/platform.h"
66
88#if defined (NDEBUG) && !defined(__DOXYGEN__)
89#define PICOW_HTTP_ASSERT(c) ((void)(c))
90#else
91#define PICOW_HTTP_ASSERT(c) do { \
92 if (!(c)) \
93 panic("%s(): " #c " false", __func__); \
94 } while (0)
95#endif
96
118#define AZ(x) do { PICOW_HTTP_ASSERT((x) == 0); } while (0)
119
141#define AN(x) do { PICOW_HTTP_ASSERT((x) != 0); } while (0)
142
143/*
144 * The following does not include ALLOC_OBJ and FREE_OBJ from Varnish
145 * miniobj.h, because we may want to use LWIP custom memory pools.
146 */
147
167#define ZERO_OBJ(to, sz) \
168 do { \
169 void *(*volatile z_obj)(void *, int, size_t) = memset; \
170 (void)z_obj(to, 0, sz); \
171 } while (0)
172
200#define INIT_OBJ(to, type_magic) \
201 do { \
202 ZERO_OBJ(to, sizeof *(to)); \
203 (to)->magic = (type_magic); \
204 } while (0)
205
240#define FINI_OBJ(to) \
241 do { \
242 ZERO_OBJ(&(to)->magic, sizeof (to)->magic); \
243 to = NULL; \
244 } while (0)
245
280#define VALID_OBJ(ptr, type_magic) \
281 ((ptr) != NULL && (ptr)->magic == (type_magic))
282
321#define CHECK_OBJ(ptr, type_magic) \
322 do { \
323 PICOW_HTTP_ASSERT((ptr)->magic == type_magic); \
324 } while (0)
325
362#define CHECK_OBJ_NOTNULL(ptr, type_magic) \
363 do { \
364 PICOW_HTTP_ASSERT((ptr) != NULL); \
365 PICOW_HTTP_ASSERT((ptr)->magic == type_magic); \
366 } while (0)
367
408#define CHECK_OBJ_ORNULL(ptr, type_magic) \
409 do { \
410 if ((ptr) != NULL) \
411 PICOW_HTTP_ASSERT((ptr)->magic == type_magic); \
412 } while (0)
413
459#define CAST_OBJ(to, from, type_magic) \
460 do { \
461 (to) = (from); \
462 if ((to) != NULL) \
463 CHECK_OBJ((to), (type_magic)); \
464 } while (0)
465
506#define CAST_OBJ_NOTNULL(to, from, type_magic) \
507 do { \
508 (to) = (from); \
509 AN((to)); \
510 CHECK_OBJ((to), (type_magic)); \
511 } while (0)