Archived
Compare commits
10
Commits
3982a3e853
...
ff7a23a8f1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff7a23a8f1 | ||
|
|
91d1c50d60 | ||
|
|
0cd8b054a1 | ||
|
|
7a3b6ab7bc | ||
|
|
64da0f471a | ||
|
|
ef6f92349f | ||
|
|
9487c1b3b4 | ||
|
|
09496c6432 | ||
|
|
17362494e2 | ||
|
|
48a22bddfc |
@@ -63,7 +63,7 @@ jobs:
|
||||
-DCMAKE_CXX_COMPILER=g++
|
||||
-DCMAKE_CXX_FLAGS_DEBUG="-Werror"
|
||||
include:
|
||||
- os: macos-13
|
||||
- os: macos-latest
|
||||
build_cfg:
|
||||
name: clang-small
|
||||
cmakeflags: >-
|
||||
@@ -72,7 +72,8 @@ jobs:
|
||||
-DCMAKE_C_FLAGS="-Oz -g -Werror"
|
||||
-DCMAKE_CXX_COMPILER=clang++
|
||||
-DCMAKE_CXX_FLAGS="-O2 -g -Werror"
|
||||
- os: macos-13
|
||||
-DWITH_TOOLS=OFF
|
||||
- os: macos-15-intel
|
||||
build_cfg:
|
||||
name: clang
|
||||
cmakeflags: >-
|
||||
@@ -92,7 +93,7 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Clone tinycbor
|
||||
uses: actions/checkout@v5
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: install Linux software
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
|
||||
+9
-4
@@ -31,10 +31,10 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
|
||||
|
||||
set(TARGETS_EXPORT_NAME "TinyCBOR-targets")
|
||||
|
||||
option(WITH_CBOR2JSON "Compile code to convert from CBOR to JSON" ON)
|
||||
option(WITH_FLOATING_POINT "Use floating point code in TinyCBOR" ON)
|
||||
option(WITH_FREESTANDING "Compile TinyCBOR in C freestanding mode" OFF)
|
||||
if(WITH_FLOATING_POINT AND NOT WITH_FREESTANDING)
|
||||
option(WITH_FLOATING_POINT "Use floating point code in TinyCBOR" ON)
|
||||
option(WITH_CBOR2JSON "Compile code to convert from CBOR to JSON" ON)
|
||||
option(WITH_TOOLS "Compile the TinyCBOR tools" ON)
|
||||
endif()
|
||||
|
||||
@@ -131,8 +131,13 @@ check_symbol_exists(funopen stdio.h HAVE_OPEN_FUNOPEN)
|
||||
check_symbol_exists(fopencookie stdio.h HAVE_OPEN_FOPENCOOKIE)
|
||||
|
||||
if(NOT HAVE_OPEN_MEMSTREAM)
|
||||
if (HAVE_OPEN_FUNOPEN AND HAVE_OPEN_FOPENCOOKIE)
|
||||
message(STATUS "using open_memstream implementation")
|
||||
if (HAVE_OPEN_FUNOPEN)
|
||||
message(STATUS "implementing open_memstream using funopen()")
|
||||
target_compile_definitions(tinycbor PRIVATE HAVE_OPEN_FUNOPEN)
|
||||
target_sources(tinycbor PRIVATE src/open_memstream.c)
|
||||
elseif (HAVE_OPEN_FOPENCOOKIE)
|
||||
message(STATUS "implementing open_memstream using fopencookie()")
|
||||
target_compile_definitions(tinycbor PRIVATE HAVE_OPEN_FOPENCOOKIE)
|
||||
target_sources(tinycbor PRIVATE src/open_memstream.c)
|
||||
else()
|
||||
target_compile_definitions(tinycbor PRIVATE WITHOUT_OPEN_MEMSTREAM)
|
||||
|
||||
@@ -174,12 +174,13 @@ int main(int argc, char **argv)
|
||||
CborError err = cbor_parser_init(buf, length, 0, &parser, &it);
|
||||
if (!err)
|
||||
err = dumprecursive(&it, 0);
|
||||
free(buf);
|
||||
|
||||
if (err) {
|
||||
fprintf(stderr, "CBOR parsing failure at offset %ld: %s\n",
|
||||
cbor_value_get_next_byte(&it) - buf, cbor_error_string(err));
|
||||
free(buf);
|
||||
return 1;
|
||||
}
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -48,8 +48,12 @@
|
||||
/* Check for FLT16_MANT_DIG using integer comparison. Clang headers incorrectly
|
||||
* define this macro unconditionally when __STDC_WANT_IEC_60559_TYPES_EXT__
|
||||
* is defined (regardless of actual support for _Float16).
|
||||
*
|
||||
* GCC defines these macros but doesn't support arithmetic including
|
||||
* conversions on x86 without SSE2.
|
||||
*/
|
||||
# if FLT16_MANT_DIG > 0 || __FLT16_MANT_DIG__ > 0
|
||||
# if (FLT16_MANT_DIG > 0 || __FLT16_MANT_DIG__ > 0) && \
|
||||
!(defined(__i386__) && !defined(__SSE2__))
|
||||
static inline unsigned short encode_half(float x)
|
||||
{
|
||||
unsigned short h;
|
||||
|
||||
+5
-35
@@ -644,28 +644,11 @@ static CborError value_to_json(FILE *out, CborValue *it, int flags, CborType typ
|
||||
return CborNoError;
|
||||
}
|
||||
|
||||
case CborIntegerType: {
|
||||
double num; /* JS numbers are IEEE double precision */
|
||||
uint64_t val;
|
||||
cbor_value_get_raw_integer(it, &val); /* can't fail */
|
||||
num = (double)val;
|
||||
|
||||
if (cbor_value_is_negative_integer(it)) {
|
||||
num = -num - 1; /* convert to negative */
|
||||
if ((uint64_t)(-num - 1) != val) {
|
||||
status->flags = NumberPrecisionWasLost | NumberWasNegative;
|
||||
status->originalNumber = val;
|
||||
}
|
||||
} else {
|
||||
if ((uint64_t)num != val) {
|
||||
status->flags = NumberPrecisionWasLost;
|
||||
status->originalNumber = val;
|
||||
}
|
||||
}
|
||||
if (fprintf(out, "%.0f", num) < 0) /* this number has no fraction, so no decimal points please */
|
||||
return CborErrorIO;
|
||||
break;
|
||||
}
|
||||
case CborIntegerType:
|
||||
case CborNullType:
|
||||
case CborBooleanType:
|
||||
/* just use cborpretty.c */
|
||||
return cbor_value_to_pretty_advance(out, it);
|
||||
|
||||
case CborByteStringType:
|
||||
case CborTextStringType: {
|
||||
@@ -696,25 +679,12 @@ static CborError value_to_json(FILE *out, CborValue *it, int flags, CborType typ
|
||||
break;
|
||||
}
|
||||
|
||||
case CborNullType:
|
||||
if (fprintf(out, "null") < 0)
|
||||
return CborErrorIO;
|
||||
break;
|
||||
|
||||
case CborUndefinedType:
|
||||
status->flags = TypeWasNotNative;
|
||||
if (fprintf(out, "\"undefined\"") < 0)
|
||||
return CborErrorIO;
|
||||
break;
|
||||
|
||||
case CborBooleanType: {
|
||||
bool val;
|
||||
cbor_value_get_boolean(it, &val); /* can't fail */
|
||||
if (fprintf(out, val ? "true" : "false") < 0)
|
||||
return CborErrorIO;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef CBOR_NO_FLOATING_POINT
|
||||
case CborDoubleType: {
|
||||
double val;
|
||||
|
||||
+17
-17
@@ -52,14 +52,10 @@
|
||||
# define cbor_static_assert(x) ((void)sizeof(char[2*!!(x) - 1]))
|
||||
#endif
|
||||
|
||||
#if defined(__has_cpp_attribute) && defined(__cplusplus) // C++17
|
||||
#if defined(__has_cpp_attribute) // C23 and C++17
|
||||
# if __has_cpp_attribute(fallthrough)
|
||||
# define CBOR_FALLTHROUGH [[fallthrough]]
|
||||
# endif
|
||||
#elif defined(__has_c_attribute) && !defined(__cplusplus) // C23
|
||||
# if __has_c_attribute(fallthrough)
|
||||
# define CBOR_FALLTHROUGH [[fallthrough]]
|
||||
# endif
|
||||
#endif
|
||||
#ifndef CBOR_FALLTHROUGH
|
||||
# ifdef __GNUC__
|
||||
@@ -202,29 +198,33 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define CONST_CAST(t, v) const_cast<t>(v)
|
||||
# define CBOR_NULLPTR nullptr
|
||||
#else
|
||||
/* C-style const_cast without triggering a warning with -Wcast-qual */
|
||||
# define CONST_CAST(t, v) (t)(uintptr_t)(v)
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus) || __STDC_VERSION__ >= 202311
|
||||
# define CBOR_NULLPTR nullptr
|
||||
#else
|
||||
# define CBOR_NULLPTR NULL
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#ifndef likely
|
||||
#ifdef likely
|
||||
/* something has already defined likely(), accept it */
|
||||
#elif defined(__GNUC__)
|
||||
# define likely(x) __builtin_expect(!!(x), 1)
|
||||
#endif
|
||||
#ifndef unlikely
|
||||
# define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
#endif
|
||||
# define unreachable() __builtin_unreachable()
|
||||
#elif defined(_MSC_VER)
|
||||
# define likely(x) (x)
|
||||
# define unlikely(x) (x)
|
||||
# define unreachable() __assume(0)
|
||||
#else
|
||||
# define likely(x) (x)
|
||||
# define unlikely(x) (x)
|
||||
# define unreachable() do {} while (0)
|
||||
#endif
|
||||
|
||||
#ifdef unreachable
|
||||
/* C23 has unreachable() */
|
||||
#elif defined(__GNUC__)
|
||||
# define unreachable() __builtin_unreachable()
|
||||
#elif defined(_MSC_VER)
|
||||
# define unreachable() __assume(0)
|
||||
#endif
|
||||
|
||||
static inline bool add_check_overflow(size_t v1, size_t v2, size_t *r)
|
||||
|
||||
@@ -35,10 +35,10 @@
|
||||
#if defined(__unix__) || defined(__APPLE__)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
#if defined(HAVE_OPEN_FUNOPEN)
|
||||
typedef int RetType;
|
||||
typedef int LenType;
|
||||
#elif __linux__
|
||||
#elif defined(HAVE_OPEN_FOPENCOOKIE)
|
||||
typedef ssize_t RetType;
|
||||
typedef size_t LenType;
|
||||
#else
|
||||
@@ -99,9 +99,9 @@ FILE *open_memstream(char **bufptr, size_t *lenptr)
|
||||
*bufptr = NULL;
|
||||
*lenptr = 0;
|
||||
|
||||
#ifdef __APPLE__
|
||||
#if defined(HAVE_OPEN_FUNOPEN)
|
||||
return funopen(b, NULL, write_to_buffer, NULL, close_buffer);
|
||||
#elif __linux__
|
||||
#elif defined(HAVE_OPEN_FOPENCOOKIE)
|
||||
static const cookie_io_functions_t vtable = {
|
||||
NULL,
|
||||
write_to_buffer,
|
||||
|
||||
@@ -100,13 +100,20 @@ void addFixedData()
|
||||
QTest::newRow("0") << raw("\x00") << "0";
|
||||
QTest::newRow("1") << raw("\x01") << "1";
|
||||
QTest::newRow("2^53-1") << raw("\x1b\0\x1f\xff\xff""\xff\xff\xff\xff") << "9007199254740991";
|
||||
QTest::newRow("2^64-epsilon") << raw("\x1b\xff\xff\xff\xff""\xff\xff\xf8\x00") << "18446744073709549568";
|
||||
QTest::newRow("2^53+1") << raw("\x1b\0\x20\0\0""\0\0\0\1") << "9007199254740993";
|
||||
QTest::newRow("2^63-1") << raw("\x1b\x7f\xff\xff\xff""\xff\xff\xff\xff") << "9223372036854775807";
|
||||
QTest::newRow("2^64-1") << raw("\x1b\xff\xff\xff\xff""\xff\xff\xff\xff") << "18446744073709551615";
|
||||
|
||||
// negative integers
|
||||
QTest::newRow("-1") << raw("\x20") << "-1";
|
||||
QTest::newRow("-2") << raw("\x21") << "-2";
|
||||
QTest::newRow("-2^53+1") << raw("\x3b\0\x1f\xff\xff""\xff\xff\xff\xfe") << "-9007199254740991";
|
||||
QTest::newRow("-2^64+epsilon") << raw("\x3b\xff\xff\xff\xff""\xff\xff\xf8\x00") << "-18446744073709549568";
|
||||
QTest::newRow("-2^53-1") << raw("\x3b\0\x20\0\0""\0\0\0\0") << "-9007199254740993";
|
||||
QTest::newRow("-2^63+1") << raw("\x3b\x7f\xff\xff\xff""\xff\xff\xff\xfe") << "-9223372036854775807";
|
||||
QTest::newRow("-2^63") << raw("\x3b\x7f\xff\xff\xff""\xff\xff\xff\xff") << "-9223372036854775808";
|
||||
QTest::newRow("-2^63-1") << raw("\x3b\x80\0\0\0""\0\0\0\0") << "-9223372036854775809";
|
||||
QTest::newRow("-2^64+1") << raw("\x3b\xff\xff\xff\xff""\xff\xff\xff\xfe") << "-18446744073709551615";
|
||||
QTest::newRow("-2^64") << raw("\x3b\xff\xff\xff\xff""\xff\xff\xff\xff") << "-18446744073709551616";
|
||||
|
||||
QTest::newRow("false") << raw("\xf4") << "false";
|
||||
QTest::newRow("true") << raw("\xf5") << "true";
|
||||
@@ -618,16 +625,6 @@ void tst_ToJson::metaData_data()
|
||||
QTest::newRow("2.^53-1") << raw("\xfb\x43\x3f\xff\xff""\xff\xff\xff\xff") << "\"t\":251";
|
||||
QTest::newRow("2.^64-epsilon") << raw("\xfb\x43\xef\xff\xff""\xff\xff\xff\xff") << "\"t\":251";
|
||||
|
||||
// integers that are too precise for double
|
||||
QTest::newRow("2^53+1") << raw("\x1b\0\x20\0\0""\0\0\0\1")
|
||||
<< "\"t\":0,\"v\":\"+20000000000001\"";
|
||||
QTest::newRow("INT64_MAX-1") << raw("\x1b\x7f\xff\xff\xff""\xff\xff\xff\xfe")
|
||||
<< "\"t\":0,\"v\":\"+7ffffffffffffffe\"";
|
||||
QTest::newRow("INT64_MAX+1") << raw("\x1b\x80\0\0\0""\0\0\0\1")
|
||||
<< "\"t\":0,\"v\":\"+8000000000000001\"";
|
||||
QTest::newRow("-2^53-1") << raw("\x3b\0\x20\0\0""\0\0\0\0")
|
||||
<< "\"t\":0,\"v\":\"-20000000000000\"";
|
||||
|
||||
// simple values
|
||||
QTest::newRow("simple0") << raw("\xe0") << "\"t\":224,\"v\":0";
|
||||
QTest::newRow("simple19") << raw("\xf3") << "\"t\":224,\"v\":19";
|
||||
|
||||
Reference in New Issue
Block a user