diff options
Diffstat (limited to 'src/3rdparty/tinycbor/src')
-rw-r--r-- | src/3rdparty/tinycbor/src/cbor.h | 10 | ||||
-rw-r--r-- | src/3rdparty/tinycbor/src/cborencoder.c | 74 | ||||
-rw-r--r-- | src/3rdparty/tinycbor/src/cborerrorstrings.c | 2 | ||||
-rw-r--r-- | src/3rdparty/tinycbor/src/cborinternal_p.h | 14 | ||||
-rw-r--r-- | src/3rdparty/tinycbor/src/cborparser.c | 8 | ||||
-rw-r--r-- | src/3rdparty/tinycbor/src/compilersupport_p.h | 2 |
6 files changed, 56 insertions, 54 deletions
diff --git a/src/3rdparty/tinycbor/src/cbor.h b/src/3rdparty/tinycbor/src/cbor.h index 3672bd0d98..be5bbc77a3 100644 --- a/src/3rdparty/tinycbor/src/cbor.h +++ b/src/3rdparty/tinycbor/src/cbor.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2018 Intel Corporation +** Copyright (C) 2021 Intel Corporation ** ** Permission is hereby granted, free of charge, to any person obtaining a copy ** of this software and associated documentation files (the "Software"), to deal @@ -263,10 +263,10 @@ CBOR_INLINE_API CborError cbor_encode_float(CborEncoder *encoder, float value) CBOR_INLINE_API CborError cbor_encode_double(CborEncoder *encoder, double value) { return cbor_encode_floating_point(encoder, CborDoubleType, &value); } -CBOR_API CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEncoder, size_t length); -CBOR_API CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder, size_t length); -CBOR_API CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *containerEncoder); -CBOR_API CborError cbor_encoder_close_container_checked(CborEncoder *encoder, const CborEncoder *containerEncoder); +CBOR_API CborError cbor_encoder_create_array(CborEncoder *parentEncoder, CborEncoder *arrayEncoder, size_t length); +CBOR_API CborError cbor_encoder_create_map(CborEncoder *parentEncoder, CborEncoder *mapEncoder, size_t length); +CBOR_API CborError cbor_encoder_close_container(CborEncoder *parentEncoder, const CborEncoder *containerEncoder); +CBOR_API CborError cbor_encoder_close_container_checked(CborEncoder *parentEncoder, const CborEncoder *containerEncoder); CBOR_INLINE_API uint8_t *_cbor_encoder_get_buffer_pointer(const CborEncoder *encoder) { diff --git a/src/3rdparty/tinycbor/src/cborencoder.c b/src/3rdparty/tinycbor/src/cborencoder.c index 38804cfa6f..a51f445159 100644 --- a/src/3rdparty/tinycbor/src/cborencoder.c +++ b/src/3rdparty/tinycbor/src/cborencoder.c @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2018 Intel Corporation +** Copyright (C) 2021 Intel Corporation ** ** Permission is hereby granted, free of charge, to any person obtaining a copy ** of this software and associated documentation files (the "Software"), to deal @@ -65,7 +65,7 @@ * \code * uint8_t buf[16]; * CborEncoder encoder; - * cbor_encoder_init(&encoder, &buf, sizeof(buf), 0); + * cbor_encoder_init(&encoder, buf, sizeof(buf), 0); * cbor_encode_int(&encoder, some_value); * \endcode * @@ -117,16 +117,16 @@ * CborEncoder encoder, mapEncoder; * cbor_encoder_init(&encoder, buf, sizeof(buf), 0); * err = cbor_encoder_create_map(&encoder, &mapEncoder, 1); - * if (!err) + * if (err) * return err; * err = cbor_encode_text_stringz(&mapEncoder, "foo"); - * if (!err) + * if (err) * return err; * err = cbor_encode_boolean(&mapEncoder, some_value); - * if (!err) + * if (err) * return err; * err = cbor_encoder_close_container_checked(&encoder, &mapEncoder); - * if (!err) + * if (err) * return err; * * size_t len = cbor_encoder_get_buffer_size(&encoder, buf); @@ -157,7 +157,7 @@ * * cbor_encoder_init(&encoder, buf, size, 0); * err = cbor_encoder_create_array(&encoder, &arrayEncoder, n); - * cbor_assert(err); // can't fail, the buffer is always big enough + * cbor_assert(!err); // can't fail, the buffer is always big enough * * for (i = 0; i < n; ++i) { * err = cbor_encode_text_stringz(&arrayEncoder, strings[i]); @@ -166,7 +166,7 @@ * } * * err = cbor_encoder_close_container_checked(&encoder, &arrayEncoder); - * cbor_assert(err); // shouldn't fail! + * cbor_assert(!err); // shouldn't fail! * * more_bytes = cbor_encoder_get_extra_bytes_needed(encoder); * if (more_size) { @@ -222,8 +222,8 @@ void cbor_encoder_init_writer(CborEncoder *encoder, CborEncoderWriteFunction wri static inline void put16(void *where, uint16_t v) { - v = cbor_htons(v); - memcpy(where, &v, sizeof(v)); + uint16_t v_be = cbor_htons(v); + memcpy(where, &v_be, sizeof(v_be)); } /* Note: Since this is currently only used in situations where OOM is the only @@ -243,14 +243,14 @@ static inline bool isOomError(CborError err) static inline void put32(void *where, uint32_t v) { - v = cbor_htonl(v); - memcpy(where, &v, sizeof(v)); + uint32_t v_be = cbor_htonl(v); + memcpy(where, &v_be, sizeof(v_be)); } static inline void put64(void *where, uint64_t v) { - v = cbor_htonll(v); - memcpy(where, &v, sizeof(v)); + uint64_t v_be = cbor_htonll(v); + memcpy(where, &v_be, sizeof(v_be)); } static inline bool would_overflow(CborEncoder *encoder, size_t len) @@ -462,11 +462,10 @@ static CborError encode_string(CborEncoder *encoder, size_t length, uint8_t shif */ /** - * Appends the text string \a string of length \a length to the CBOR stream - * provided by \a encoder. CBOR requires that \a string be valid UTF-8, but - * TinyCBOR makes no verification of correctness. + * Appends the byte string \a string of length \a length to the CBOR stream + * provided by \a encoder. CBOR byte strings are arbitrary raw data. * - * \sa CborError cbor_encode_text_stringz, cbor_encode_byte_string + * \sa cbor_encode_text_stringz, cbor_encode_text_string */ CborError cbor_encode_byte_string(CborEncoder *encoder, const uint8_t *string, size_t length) { @@ -474,10 +473,11 @@ CborError cbor_encode_byte_string(CborEncoder *encoder, const uint8_t *string, s } /** - * Appends the byte string \a string of length \a length to the CBOR stream - * provided by \a encoder. CBOR byte strings are arbitrary raw data. + * Appends the text string \a string of length \a length to the CBOR stream + * provided by \a encoder. CBOR requires that \a string be valid UTF-8, but + * TinyCBOR makes no verification of correctness. * - * \sa cbor_encode_text_stringz, cbor_encode_text_string + * \sa CborError cbor_encode_text_stringz, cbor_encode_byte_string */ CborError cbor_encode_text_string(CborEncoder *encoder, const char *string, size_t length) { @@ -514,7 +514,7 @@ static CborError create_container(CborEncoder *encoder, CborEncoder *container, } /** - * Creates a CBOR array in the CBOR stream provided by \a encoder and + * Creates a CBOR array in the CBOR stream provided by \a parentEncoder and * initializes \a arrayEncoder so that items can be added to the array using * the CborEncoder functions. The array must be terminated by calling either * cbor_encoder_close_container() or cbor_encoder_close_container_checked() @@ -523,17 +523,17 @@ static CborError create_container(CborEncoder *encoder, CborEncoder *container, * The number of items inserted into the array must be exactly \a length items, * otherwise the stream is invalid. If the number of items is not known when * creating the array, the constant \ref CborIndefiniteLength may be passed as - * length instead. + * length instead, and an indefinite length array is created. * * \sa cbor_encoder_create_map */ -CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEncoder, size_t length) +CborError cbor_encoder_create_array(CborEncoder *parentEncoder, CborEncoder *arrayEncoder, size_t length) { - return create_container(encoder, arrayEncoder, length, ArrayType << MajorTypeShift); + return create_container(parentEncoder, arrayEncoder, length, ArrayType << MajorTypeShift); } /** - * Creates a CBOR map in the CBOR stream provided by \a encoder and + * Creates a CBOR map in the CBOR stream provided by \a parentEncoder and * initializes \a mapEncoder so that items can be added to the map using * the CborEncoder functions. The map must be terminated by calling either * cbor_encoder_close_container() or cbor_encoder_close_container_checked() @@ -542,7 +542,7 @@ CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEnco * The number of pair of items inserted into the map must be exactly \a length * items, otherwise the stream is invalid. If the number is not known * when creating the map, the constant \ref CborIndefiniteLength may be passed as - * length instead. + * length instead, and an indefinite length map is created. * * \b{Implementation limitation:} TinyCBOR cannot encode more than SIZE_MAX/2 * key-value pairs in the stream. If the length \a length is larger than this @@ -551,11 +551,11 @@ CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEnco * * \sa cbor_encoder_create_array */ -CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder, size_t length) +CborError cbor_encoder_create_map(CborEncoder *parentEncoder, CborEncoder *mapEncoder, size_t length) { if (length != CborIndefiniteLength && length > SIZE_MAX / 2) return CborErrorDataTooLarge; - return create_container(encoder, mapEncoder, length, MapType << MajorTypeShift); + return create_container(parentEncoder, mapEncoder, length, MapType << MajorTypeShift); } /** @@ -570,21 +570,21 @@ CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder, * * \sa cbor_encoder_create_array(), cbor_encoder_create_map() */ -CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *containerEncoder) +CborError cbor_encoder_close_container(CborEncoder *parentEncoder, const CborEncoder *containerEncoder) { - if (encoder->end && !(encoder->flags & CborIteratorFlag_WriterFunction)) - encoder->data.ptr = containerEncoder->data.ptr; - else - encoder->data.bytes_needed = containerEncoder->data.bytes_needed; - encoder->end = containerEncoder->end; + // synchronise buffer state with that of the container + parentEncoder->end = containerEncoder->end; + parentEncoder->data = containerEncoder->data; + if (containerEncoder->flags & CborIteratorFlag_UnknownLength) - return append_byte_to_buffer(encoder, BreakByte); + return append_byte_to_buffer(parentEncoder, BreakByte); if (containerEncoder->remaining != 1) return containerEncoder->remaining == 0 ? CborErrorTooManyItems : CborErrorTooFewItems; - if (!encoder->end) + if (!parentEncoder->end) return CborErrorOutOfMemory; /* keep the state */ + return CborNoError; } diff --git a/src/3rdparty/tinycbor/src/cborerrorstrings.c b/src/3rdparty/tinycbor/src/cborerrorstrings.c index 1dd8ae25bd..44f766a3c4 100644 --- a/src/3rdparty/tinycbor/src/cborerrorstrings.c +++ b/src/3rdparty/tinycbor/src/cborerrorstrings.c @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2018 Intel Corporation +** Copyright (C) 2021 Intel Corporation ** ** Permission is hereby granted, free of charge, to any person obtaining a copy ** of this software and associated documentation files (the "Software"), to deal diff --git a/src/3rdparty/tinycbor/src/cborinternal_p.h b/src/3rdparty/tinycbor/src/cborinternal_p.h index c5fe63003f..16269e6301 100644 --- a/src/3rdparty/tinycbor/src/cborinternal_p.h +++ b/src/3rdparty/tinycbor/src/cborinternal_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2018 Intel Corporation +** Copyright (C) 2021 Intel Corporation ** ** Permission is hereby granted, free of charge, to any person obtaining a copy ** of this software and associated documentation files (the "Software"), to deal @@ -37,15 +37,17 @@ #endif #ifndef CBOR_NO_HALF_FLOAT_TYPE -# ifdef __F16C__ +# if defined(__F16C__) || defined(__AVX2__) # include <immintrin.h> -static inline unsigned short encode_half(double val) +static inline unsigned short encode_half(float val) { - return _cvtss_sh((float)val, 3); + __m128i m = _mm_cvtps_ph(_mm_set_ss(val), _MM_FROUND_CUR_DIRECTION); + return _mm_extract_epi16(m, 0); } -static inline double decode_half(unsigned short half) +static inline float decode_half(unsigned short half) { - return _cvtsh_ss(half); + __m128i m = _mm_cvtsi32_si128(half); + return _mm_cvtss_f32(_mm_cvtph_ps(m)); } # else /* software implementation of float-to-fp16 conversions */ diff --git a/src/3rdparty/tinycbor/src/cborparser.c b/src/3rdparty/tinycbor/src/cborparser.c index 2019e7b808..80c44c7e13 100644 --- a/src/3rdparty/tinycbor/src/cborparser.c +++ b/src/3rdparty/tinycbor/src/cborparser.c @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2018 Intel Corporation +** Copyright (C) 2021 Intel Corporation ** ** Permission is hereby granted, free of charge, to any person obtaining a copy ** of this software and associated documentation files (the "Software"), to deal @@ -232,7 +232,7 @@ static CborError preparse_value(CborValue *it) case SinglePrecisionFloat: case DoublePrecisionFloat: it->flags |= CborIteratorFlag_IntegerValueTooLarge; - /* fall through */ + Q_FALLTHROUGH(); case TrueValue: case NullValue: case UndefinedValue: @@ -913,7 +913,7 @@ CborError cbor_value_get_int_checked(const CborValue *value, int *result) /** * \fn bool cbor_value_is_byte_string(const CborValue *value) * - * Returns true if the iterator \a value is valid and points to a CBOR text + * Returns true if the iterator \a value is valid and points to a CBOR byte * string. CBOR byte strings are binary data with no specified encoding or * format. * @@ -1147,7 +1147,7 @@ static CborError get_string_chunk(CborValue *it, const void **bufferptr, size_t */ CborError _cbor_value_get_string_chunk(const CborValue *value, const void **bufferptr, - size_t *len, CborValue *next) + size_t *len, CborValue *next) { CborValue tmp; if (!next) diff --git a/src/3rdparty/tinycbor/src/compilersupport_p.h b/src/3rdparty/tinycbor/src/compilersupport_p.h index bd10efc9c7..0879801611 100644 --- a/src/3rdparty/tinycbor/src/compilersupport_p.h +++ b/src/3rdparty/tinycbor/src/compilersupport_p.h @@ -44,7 +44,7 @@ # include <stdbool.h> #endif -#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L || __cpp_static_assert >= 200410 +#if __STDC_VERSION__ >= 201112L || (defined(__cplusplus) && __cplusplus >= 201103L) || (defined(__cpp_static_assert) && __cpp_static_assert >= 200410) # define cbor_static_assert(x) static_assert(x, #x) #elif !defined(__cplusplus) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) && (__STDC_VERSION__ > 199901L) # define cbor_static_assert(x) _Static_assert(x, #x) |