Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/cborencoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
#endif
#define __STDC_WANT_IEC_60559_TYPES_EXT__

#include "cbor.h"
#include "cborinternal_p.h"
Expand Down
1 change: 1 addition & 0 deletions src/cborencoder_close_container_checked.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
#endif
#define __STDC_WANT_IEC_60559_TYPES_EXT__

#include "cbor.h"

Expand Down
1 change: 1 addition & 0 deletions src/cborencoder_float.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
#endif
#define __STDC_WANT_IEC_60559_TYPES_EXT__

#include "cbor.h"

Expand Down
29 changes: 28 additions & 1 deletion src/cborinternal_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,46 @@
#ifndef CBORINTERNAL_P_H
#define CBORINTERNAL_P_H

/* Dependent source files (*.c) must define __STDC_WANT_IEC_60559_TYPES_EXT__
* before <float.h> is (transitively) first included.
*/
#if !defined(__STDC_WANT_IEC_60559_TYPES_EXT__)
# error __STDC_WANT_IEC_60559_TYPES_EXT__ not defined
#endif

#include "compilersupport_p.h"

#ifndef CBOR_NO_FLOATING_POINT
# include <float.h>
# include <math.h>
# include <string.h>
#else
# ifndef CBOR_NO_HALF_FLOAT_TYPE
# define CBOR_NO_HALF_FLOAT_TYPE 1
# endif
#endif

#ifndef CBOR_NO_HALF_FLOAT_TYPE
# if defined(__F16C__) || defined(__AVX2__)
/* 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).
*/
# if FLT16_MANT_DIG > 0 || __FLT16_MANT_DIG__ > 0
static inline unsigned short encode_half(float x)
{
unsigned short h;
_Float16 f = (_Float16)x;
memcpy(&h, &f, 2);
return h;
}

static inline float decode_half(unsigned short x)
{
_Float16 f;
memcpy(&f, &x, 2);
return (float)f;
}
# elif defined(__F16C__) || defined(__AVX2__)
# include <immintrin.h>
static inline unsigned short encode_half(float val)
{
Expand Down
1 change: 1 addition & 0 deletions src/cborparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
#endif
#define __STDC_WANT_IEC_60559_TYPES_EXT__

#include "cbor.h"
#include "cborinternal_p.h"
Expand Down
1 change: 1 addition & 0 deletions src/cborparser_dup_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
#endif
#define __STDC_WANT_IEC_60559_TYPES_EXT__

#include "cbor.h"
#include "compilersupport_p.h"
Expand Down
1 change: 1 addition & 0 deletions src/cborparser_float.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
#endif
#define __STDC_WANT_IEC_60559_TYPES_EXT__

#include "cbor.h"

Expand Down
1 change: 1 addition & 0 deletions src/cborpretty.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
#endif
#define __STDC_WANT_IEC_60559_TYPES_EXT__

#include "cbor.h"
#include "cborinternal_p.h"
Expand Down
1 change: 1 addition & 0 deletions src/cbortojson.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
#endif
#define __STDC_WANT_IEC_60559_TYPES_EXT__

#include "cbor.h"
#include "cborjson.h"
Expand Down
1 change: 1 addition & 0 deletions src/cborvalidation.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
#endif
#define __STDC_WANT_IEC_60559_TYPES_EXT__

#include "cbor.h"
#include "cborinternal_p.h"
Expand Down
1 change: 1 addition & 0 deletions tools/json2cbor/json2cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
****************************************************************************/

#define _GNU_SOURCE
#define __STDC_WANT_IEC_60559_TYPES_EXT__
#include "cbor.h"
#include "cborinternal_p.h"
#include "compilersupport_p.h"
Expand Down