Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tinycbor mynewt upstream #83

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
half/full-FP support changes
- Make half float encode/decode conditional
- Change defaults for CBOR_WITHOUT_OPEN_MEMSTREAM,
  CBOR_NO_HALF_FLOAT_TYPE and CBOR_NO_FLOATING_POINT
  to y so that half float, float and open
  memstream support along with newlib libc does not
  get compiled in
- 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 <vipulrahane@apache.org>
  • Loading branch information
vrahane committed Feb 8, 2018
commit c45469b402f1b559b68236312ec1bbe9a5e7e2e3
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ endif
# version using funopen or fopencookie
ifeq ($(open_memstream-pass),)
ifeq ($(funopen-pass)$(fopencookie-pass),)
CFLAGS += -DWITHOUT_OPEN_MEMSTREAM
CFLAGS += -DCBOR_WITHOUT_OPEN_MEMSTREAM
$(warning warning: funopen and fopencookie unavailable, open_memstream can not be implemented and conversion to JSON will not work properly!)
else
TINYCBOR_SOURCES += src/open_memstream.c
Expand Down
8 changes: 4 additions & 4 deletions src/cbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ struct CborEncoder
{
cbor_encoder_writer *writer;
void *writer_arg;
#ifndef NO_DFLT_WRITER
#ifndef CBOR_NO_DFLT_WRITER
struct cbor_buf_writer wr;
#endif
size_t remaining;
Expand All @@ -219,7 +219,7 @@ typedef struct CborEncoder CborEncoder;

static const size_t CborIndefiniteLength = SIZE_MAX;

#ifndef NO_DFLT_WRITER
#ifndef CBOR_NO_DFLT_WRITER
CBOR_API void cbor_encoder_init(CborEncoder *encoder, uint8_t *buffer, size_t size, int flags);
#endif
CBOR_API void cbor_encoder_cust_writer_init(CborEncoder *encoder, struct cbor_encoder_writer *w, int flags);
Expand Down Expand Up @@ -267,7 +267,7 @@ enum CborParserIteratorFlags

struct CborParser
{
#ifndef NO_DFLT_READER
#ifndef CBOR_NO_DFLT_READER
struct cbor_buf_reader br;
#endif
struct cbor_decoder_reader *d;
Expand All @@ -288,7 +288,7 @@ struct CborValue
};
typedef struct CborValue CborValue;

#ifndef NO_DFLT_READER
#ifndef CBOR_NO_DFLT_READER
CBOR_API CborError cbor_parser_init(const uint8_t *buffer, size_t size, int flags, CborParser *parser, CborValue *it);
#endif
CBOR_API CborError cbor_parser_cust_reader_init(struct cbor_decoder_reader *r, int flags, CborParser *parser, CborValue *it);
Expand Down
12 changes: 6 additions & 6 deletions src/cborencoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
* Structure used to encode to CBOR.
*/

#ifndef NO_DFLT_WRITER
#ifndef CBOR_NO_DFLT_WRITER
/**
* Initializes a CborEncoder structure \a encoder by pointing it to buffer \a
* buffer of size \a size. The \a flags field is currently unused and must be
Expand All @@ -223,7 +223,7 @@ void cbor_encoder_cust_writer_init(CborEncoder *encoder, struct cbor_encoder_wri
}


#ifndef NO_FLOAT_SUPPORT
#ifndef CBOR_NO_FLOATING_POINT
static inline void put16(void *where, uint16_t v)
{
v = cbor_htons(v);
Expand All @@ -242,7 +242,7 @@ static inline bool isOomError(CborError err)
return true;
}

#ifndef NO_FLOAT_SUPPORT
#ifndef CBOR_NO_FLOATING_POINT
static inline void put32(void *where, uint32_t v)
{
v = cbor_htonl(v);
Expand Down Expand Up @@ -363,7 +363,7 @@ CborError cbor_encode_simple_value(CborEncoder *encoder, uint8_t value)
return encode_number(encoder, value, SimpleTypesType << MajorTypeShift);
}

#ifndef NO_FLOAT_SUPPORT
#ifndef CBOR_NO_FLOATING_POINT
/**
* Appends the floating-point value of type \a fpType and pointed to by \a
* value to the CBOR stream provided by \a encoder. The value of \a fpType must
Expand Down Expand Up @@ -453,7 +453,7 @@ static CborError create_container(CborEncoder *encoder, CborEncoder *container,
{
CborError err;
container->writer = encoder->writer;
#ifndef NO_DFLT_WRITER
#ifndef CBOR_NO_DFLT_WRITER
container->wr.end = encoder->wr.end;
#endif
saturated_decrement(encoder);
Expand Down Expand Up @@ -540,7 +540,7 @@ CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *
if (containerEncoder->remaining != 1)
return containerEncoder->remaining == 0 ? CborErrorTooManyItems : CborErrorTooFewItems;

#ifndef NO_DFLT_WRITER
#ifndef CBOR_NO_DFLT_WRITER
if (!encoder->wr.end) {
return CborErrorOutOfMemory;
}
Expand Down
5 changes: 3 additions & 2 deletions src/cborparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ static CborError preparse_next_value(CborValue *it)
static CborError advance_internal(CborValue *it)
{
uint64_t length;
CborError err = _cbor_value_extract_number(it->parser, &it->offset, &length);
CborError err;
err = _cbor_value_extract_number(it->parser, &it->offset, &length);
cbor_assert(err == CborNoError);

if (it->type == CborByteStringType || it->type == CborTextStringType) {
Expand Down Expand Up @@ -342,7 +343,7 @@ uint64_t _cbor_value_decode_int64_internal(const CborValue *value)
return value->parser->d->get64(value->parser->d, value->offset + 1);
}

#ifndef NO_DFLT_READER
#ifndef CBOR_NO_DFLT_READER
/**
* Initializes the CBOR parser for parsing \a size bytes beginning at \a
* buffer. Parsing will use flags set in \a flags. The iterator to the first
Expand Down
8 changes: 6 additions & 2 deletions src/cborpretty.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
#include "cborinternal_p.h"
#include "utf8_p.h"

#include <float.h>
#include <inttypes.h>
#include <float.h>
#ifndef CBOR_NO_FLOATING_POINT
#include <math.h>
#endif
#include <string.h>

/**
Expand Down Expand Up @@ -457,7 +459,7 @@ static CborError value_to_pretty(CborStreamFunction stream, void *out, CborValue
err = stream(out, val ? "true" : "false");
break;
}
#ifndef NO_FLOAT_SUPPORT
#ifndef CBOR_NO_FLOATING_POINT
case CborDoubleType: {
const char *suffix;
double val;
Expand All @@ -468,12 +470,14 @@ static CborError value_to_pretty(CborStreamFunction stream, void *out, CborValue
cbor_value_get_float(it, &f);
val = f;
suffix = flags & CborPrettyNumericEncodingIndicators ? "_2" : "f";
#ifndef CBOR_NO_HALF_FLOAT_TYPE
} else if (false) {
uint16_t f16;
case CborHalfFloatType:
cbor_value_get_half_float(it, &f16);
val = decode_half(f16);
suffix = flags & CborPrettyNumericEncodingIndicators ? "_1" : "f16";
#endif
} else {
cbor_value_get_double(it, &val);
suffix = "";
Expand Down
8 changes: 6 additions & 2 deletions src/cbortojson.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@

#include <float.h>
#include <inttypes.h>
#ifndef CBOR_NO_FLOATING_POINT
#include <math.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -401,7 +403,7 @@ static CborError stringify_map_key(char **key, CborValue *it, int flags, CborTyp
{
(void)flags; /* unused */
(void)type; /* unused */
#ifdef WITHOUT_OPEN_MEMSTREAM
#ifdef CBOR_WITHOUT_OPEN_MEMSTREAM
(void)key; /* unused */
(void)it; /* unused */
return CborErrorJsonNotImplemented;
Expand Down Expand Up @@ -592,7 +594,7 @@ static CborError value_to_json(FILE *out, CborValue *it, int flags, CborType typ
return CborErrorIO;
break;
}
#ifndef NO_FLOAT_SUPPORT
#ifndef CBOR_NO_FLOATING_POINT
case CborDoubleType: {
double val;
if (false) {
Expand All @@ -601,12 +603,14 @@ static CborError value_to_json(FILE *out, CborValue *it, int flags, CborType typ
status->flags = TypeWasNotNative;
cbor_value_get_float(it, &f);
val = f;
#ifndef CBOR_NO_HALF_FLOAT_TYPE
} else if (false) {
uint16_t f16;
case CborHalfFloatType:
status->flags = TypeWasNotNative;
cbor_value_get_half_float(it, &f16);
val = decode_half(f16);
#endif
} else {
cbor_value_get_double(it, &val);
}
Expand Down
4 changes: 2 additions & 2 deletions src/cborvalidation.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@

#include <string.h>

#include <float.h>
#ifndef CBOR_NO_FLOATING_POINT
# include <float.h>
# include <math.h>
#include <math.h>
#endif


Expand Down
5 changes: 5 additions & 0 deletions src/compilersupport_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ extern "C" {
# include <assert.h>
#endif
#include <float.h>
#ifndef CBOR_NO_FLOATING_TYPE

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CBOR_NO_FLOATING_POINT?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or CBOR_NO_HALF_FLOAT_TYPE?

#include <math.h>
#endif
#include <stddef.h>
#include <stdint.h>
#include <string.h>
Expand Down Expand Up @@ -203,6 +205,7 @@ static inline bool add_check_overflow(size_t v1, size_t v2, size_t *r)
#endif
}

#ifndef CBOR_NO_HALF_FLOAT_TYPE
static inline unsigned short encode_half(double val)
{
#ifdef __F16C__
Expand Down Expand Up @@ -255,6 +258,8 @@ static inline double decode_half(unsigned short half)
#endif
}

#endif

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/open_memstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define _DEFAULT_SOURCE 1
#define _GNU_SOURCE 1

#ifndef WITHOUT_OPEN_MEMSTREAM
#ifndef CBOR_WITHOUT_OPEN_MEMSTREAM

#include <sys/types.h>
#include <errno.h>
Expand Down