Skip to content

Commit 717ad15

Browse files
committed
ext: lib: tinycbor: half/full-FP support changes
- Make half float encode/decode conditional - src/cborpretty.c, src/cbortojson.c and src/cborvalidation.c conditionally include math.h and half float type support - Conditionally include math.h in src/compilersupport_p.h to avoid newlib libc from getting compiled in - Conditionally compile src/cborparser_dup_string.c if newlib libc is compiled in Signed-off-by: Vipul Rahane <[email protected]>
1 parent bc0a91d commit 717ad15

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

ext/lib/encoding/tinycbor/src/cborpretty.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
#include "cborinternal_p.h"
3434
#include "utf8_p.h"
3535

36-
#include <float.h>
3736
#include <inttypes.h>
37+
#include <float.h>
38+
#ifndef CBOR_NO_FLOATING_POINT
3839
#include <math.h>
40+
#endif
3941
#include <string.h>
4042

4143
/**
@@ -468,12 +470,14 @@ static CborError value_to_pretty(CborStreamFunction stream, void *out, CborValue
468470
cbor_value_get_float(it, &f);
469471
val = f;
470472
suffix = flags & CborPrettyNumericEncodingIndicators ? "_2" : "f";
473+
#ifndef CBOR_NO_HALF_FLOAT_TYPE
471474
} else if (false) {
472475
uint16_t f16;
473476
case CborHalfFloatType:
474477
cbor_value_get_half_float(it, &f16);
475478
val = decode_half(f16);
476479
suffix = flags & CborPrettyNumericEncodingIndicators ? "_1" : "f16";
480+
#endif
477481
} else {
478482
cbor_value_get_double(it, &val);
479483
suffix = "";

ext/lib/encoding/tinycbor/src/cbortojson.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636

3737
#include <float.h>
3838
#include <inttypes.h>
39+
#ifndef CBOR_NO_FLOATING_POINT
3940
#include <math.h>
41+
#endif
4042
#include <stdio.h>
4143
#include <stdlib.h>
4244
#include <string.h>
@@ -601,12 +603,14 @@ static CborError value_to_json(FILE *out, CborValue *it, int flags, CborType typ
601603
status->flags = TypeWasNotNative;
602604
cbor_value_get_float(it, &f);
603605
val = f;
606+
#ifndef CBOR_NO_HALF_FLOAT_TYPE
604607
} else if (false) {
605608
uint16_t f16;
606609
case CborHalfFloatType:
607610
status->flags = TypeWasNotNative;
608611
cbor_value_get_half_float(it, &f16);
609612
val = decode_half(f16);
613+
#endif
610614
} else {
611615
cbor_value_get_double(it, &val);
612616
}

ext/lib/encoding/tinycbor/src/cborvalidation.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939

4040
#include <string.h>
4141

42+
#include <float.h>
4243
#ifndef CBOR_NO_FLOATING_POINT
43-
# include <float.h>
44-
# include <math.h>
44+
#include <math.h>
4545
#endif
4646

4747

ext/lib/encoding/tinycbor/src/compilersupport_p.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ extern "C" {
4141
# include <assert.h>
4242
#endif
4343
#include <float.h>
44+
#ifndef CBOR_NO_FLOATING_TYPE
4445
#include <math.h>
46+
#endif
4547
#include <stddef.h>
4648
#include <stdint.h>
4749
#include <string.h>
@@ -203,6 +205,7 @@ static inline bool add_check_overflow(size_t v1, size_t v2, size_t *r)
203205
#endif
204206
}
205207

208+
#ifndef CBOR_NO_HALF_FLOAT_TYPE
206209
static inline unsigned short encode_half(double val)
207210
{
208211
#ifdef __F16C__
@@ -255,6 +258,8 @@ static inline double decode_half(unsigned short half)
255258
#endif
256259
}
257260

261+
#endif
262+
258263
#ifdef __cplusplus
259264
}
260265
#endif

0 commit comments

Comments
 (0)