8#ifndef LIBCBOR_COMMON_H
9#define LIBCBOR_COMMON_H
17#include "cbor/cbor_export.h"
18#include "cbor/configuration.h"
31#define CBOR_RESTRICT_POINTER
36#define CBOR_RESTRICT_POINTER CBOR_RESTRICT_SPECIFIER
40static const uint8_t cbor_major_version = CBOR_MAJOR_VERSION;
41static const uint8_t cbor_minor_version = CBOR_MINOR_VERSION;
42static const uint8_t cbor_patch_version = CBOR_PATCH_VERSION;
45 _CBOR_TO_STR(CBOR_MAJOR_VERSION) \
46 "." _CBOR_TO_STR(CBOR_MINOR_VERSION) "." _CBOR_TO_STR(CBOR_PATCH_VERSION)
47#define CBOR_HEX_VERSION \
48 ((CBOR_MAJOR_VERSION << 16) | (CBOR_MINOR_VERSION << 8) | CBOR_PATCH_VERSION)
54#define _cbor_debug_print(fmt, ...) \
57 fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, \
60extern bool _cbor_enable_assert;
63#define CBOR_ASSERT(e) assert(!_cbor_enable_assert || (e))
64#define _CBOR_TEST_DISABLE_ASSERT(block) \
66 _cbor_enable_assert = false; \
67 block _cbor_enable_assert = true; \
70#define debug_print(fmt, ...) \
74#define _CBOR_TEST_DISABLE_ASSERT(block) \
80#define _CBOR_TO_STR_(x) #x
81#define _CBOR_TO_STR(x) _CBOR_TO_STR_(x)
84#define _CBOR_UNUSED __attribute__((__unused__))
87#define _CBOR_NODISCARD __attribute__((warn_unused_result))
88#elif defined(_MSC_VER)
89#define _CBOR_UNUSED __pragma(warning(suppress : 4100 4101))
90#define _CBOR_NODISCARD
93#define _CBOR_NODISCARD
96#ifdef CBOR_HAS_BUILTIN_UNREACHABLE
97#define _CBOR_UNREACHABLE __builtin_unreachable()
99#define _CBOR_UNREACHABLE
102typedef void* (*_cbor_malloc_t)(size_t);
103typedef void* (*_cbor_realloc_t)(
void*, size_t);
111#define _CBOR_NOTNULL(cbor_item) \
113 if (cbor_item == NULL) { \
119#define _CBOR_DEPENDENT_NOTNULL(cbor_item, pointer) \
121 if (pointer == NULL) { \
122 _cbor_free(cbor_item); \
_cbor_malloc_t _cbor_malloc
_cbor_realloc_t _cbor_realloc
bool cbor_isa_string(const cbor_item_t *item)
Does the item have the appropriate major type?
bool cbor_isa_negint(const cbor_item_t *item)
Does the item have the appropriate major type?
bool cbor_isa_tag(const cbor_item_t *item)
Does the item have the appropriate major type?
void(* _cbor_free_t)(void *)
cbor_item_t * cbor_move(cbor_item_t *item)
Provides CPP-like move construct.
void *(* _cbor_malloc_t)(size_t)
void cbor_set_allocs(_cbor_malloc_t custom_malloc, _cbor_realloc_t custom_realloc, _cbor_free_t custom_free)
Sets the memory management routines to use.
bool cbor_is_float(const cbor_item_t *item)
Is the item an a floating point number?
bool cbor_is_int(const cbor_item_t *item)
Is the item an integer, either positive or negative?
void cbor_intermediate_decref(cbor_item_t *item)
Decreases the item's reference count by one, deallocating the item if needed.
bool cbor_is_bool(const cbor_item_t *item)
Is the item an a boolean?
void *(* _cbor_realloc_t)(void *, size_t)
bool cbor_isa_uint(const cbor_item_t *item)
Does the item have the appropriate major type?
bool cbor_isa_float_ctrl(const cbor_item_t *item)
Does the item have the appropriate major type?
bool cbor_isa_array(const cbor_item_t *item)
Does the item have the appropriate major type?
cbor_item_t * cbor_incref(cbor_item_t *item)
Increases the item's reference count by one.
void cbor_decref(cbor_item_t **item)
Decreases the item's reference count by one, deallocating the item if needed.
size_t cbor_refcount(const cbor_item_t *item)
Get the item's reference count.
cbor_type cbor_typeof(const cbor_item_t *item)
Get the type of the item.
bool cbor_is_null(const cbor_item_t *item)
Does this item represent null
bool cbor_isa_bytestring(const cbor_item_t *item)
Does the item have the appropriate major type?
bool cbor_isa_map(const cbor_item_t *item)
Does the item have the appropriate major type?
bool cbor_is_undef(const cbor_item_t *item)
Does this item represent undefined
cbor_type
Specifies the Major type of cbor_item_t.