Skip to content

Commit

Permalink
added trivial abi attribute to date, time, time_offset
Browse files Browse the repository at this point in the history
also:
- included <cassert> directly in 'debug' builds when TOML_ASSERT isn't defined
- minor preprocessor cleanup
- minor documentation fixes
  • Loading branch information
marzer committed Mar 23, 2020
1 parent 60853e2 commit b2f36e3
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 75 deletions.
1 change: 1 addition & 0 deletions include/toml++/toml.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
#undef TOML_INLINE_FUNC_IMPL
#undef TOML_COMPILER_EXCEPTIONS
#undef TOML_LAUNDER
#undef TOML_TRIVIAL_ABI
#endif

/// \mainpage toml++
Expand Down
37 changes: 22 additions & 15 deletions include/toml++/toml_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,12 @@
#define TOML_LARGE_FILES 0
#endif

#ifndef TOML_ASSERT
#ifdef assert
#define TOML_ASSERT(expr) assert(expr)
#else
#define TOML_ASSERT(expr) (void)0
#endif
#endif

#ifndef TOML_UNDEF_MACROS
#define TOML_UNDEF_MACROS 1
#endif

//TOML_ASSERT

////////// COMPILER & ENVIRONMENT STUFF

#ifndef __cplusplus
Expand All @@ -66,8 +60,9 @@
#define TOML_POP_WARNINGS _Pragma("clang diagnostic pop")
#define TOML_ASSUME(cond) __builtin_assume(cond)
#define TOML_UNREACHABLE __builtin_unreachable()
#define TOML_GNU_ATTR(attr) __attribute__((attr))
#if defined(_MSC_VER) // msvc compat mode
#if defined(__has_declspec_attribute)
#ifdef __has_declspec_attribute
#if __has_declspec_attribute(novtable)
#define TOML_INTERFACE __declspec(novtable)
#endif
Expand All @@ -76,12 +71,13 @@
#endif
#define TOML_ALWAYS_INLINE __forceinline
#endif
#else // regular ol' clang
#define TOML_GNU_ATTR(attr) __attribute__((attr))
#ifdef __has_attribute
#if __has_attribute(always_inline)
#define TOML_ALWAYS_INLINE __attribute__((__always_inline__)) inline
#endif
#endif
#ifdef __has_attribute
#if !defined(TOML_ALWAYS_INLINE) && __has_attribute(always_inline)
#define TOML_ALWAYS_INLINE __attribute__((__always_inline__)) inline
#endif
#if !defined(TOML_TRIVIAL_ABI) && __has_attribute(trivial_abi)
#define TOML_TRIVIAL_ABI __attribute__((__trivial_abi__))
#endif
#endif
#ifdef __EXCEPTIONS
Expand Down Expand Up @@ -244,6 +240,9 @@
#ifndef TOML_UNLIKELY
#define TOML_UNLIKELY
#endif
#ifndef TOML_TRIVIAL_ABI
#define TOML_TRIVIAL_ABI
#endif
#ifndef TOML_NODISCARD_CTOR
#define TOML_NODISCARD_CTOR
#endif
Expand Down Expand Up @@ -338,6 +337,14 @@ TOML_DISABLE_ALL_WARNINGS
#include <map>
#include <iosfwd>
#include <charconv>
#ifndef TOML_ASSERT
#if !defined(NDEBUG) || defined(_DEBUG) || defined(DEBUG)
#include <cassert>
#define TOML_ASSERT(expr) assert(expr)
#else
#define TOML_ASSERT(expr) (void)0
#endif
#endif
#ifndef TOML_OPTIONAL_TYPE
#include <optional>
#endif
Expand Down
6 changes: 3 additions & 3 deletions include/toml++/toml_date_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
TOML_START
{
/// \brief A local date.
struct date final
struct TOML_TRIVIAL_ABI date final
{
/// \brief The year component.
uint16_t year;
Expand Down Expand Up @@ -92,7 +92,7 @@ TOML_START
}

/// \brief A local time-of-day.
struct time final
struct TOML_TRIVIAL_ABI time final
{
/// \brief The hour component, from 0 - 23.
uint8_t hour;
Expand Down Expand Up @@ -180,7 +180,7 @@ TOML_START
}

/// \brief A timezone offset.
struct time_offset final
struct TOML_TRIVIAL_ABI time_offset final
{
/// \brief Offset from UTC+0, in minutes.
int16_t minutes;
Expand Down
7 changes: 3 additions & 4 deletions include/toml++/toml_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,9 @@ TOML_START

/// \brief Gets a raw reference to a value node's underlying data.
///
/// \warning This function is dangerous if used carelessly and **WILL** break your code if the chosen value type
/// doesn't match the node's actual type. If you provide a definition for `TOML_ASSERT`
/// (explicitly or indirectly by including `<cassert>`) an assertion will fire when
/// invalid accesses are attempted: \cpp
/// \warning This function is dangerous if used carelessly and **WILL** break your code if the
/// chosen value type doesn't match the node's actual type. In debug builds an assertion
/// will fire when invalid accesses are attempted: \cpp
///
/// auto tbl = toml::parse(R"(
///
Expand Down
3 changes: 1 addition & 2 deletions include/toml++/toml_node_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ TOML_START
///
/// \warning This function is dangerous if used carelessly and **WILL** break your code if the
/// node_view didn't reference a node, or the chosen value type doesn't match the node's
/// actual type. If you provide a definition for TOML_ASSERT (explicitly or indirectly
/// by including `<cassert>`) an assertion will fire when invalid accesses are attempted: \cpp
/// actual type. In debug builds an assertion will fire when invalid accesses are attempted: \cpp
///
/// auto tbl = toml::parse(R"(
///
Expand Down
2 changes: 1 addition & 1 deletion include/toml++/toml_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#define TOML_LIB_MAJOR 0
#define TOML_LIB_MINOR 5
#define TOML_LIB_PATCH 1
#define TOML_LIB_PATCH 2

#define TOML_LANG_MAJOR 0
#define TOML_LANG_MINOR 5
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(
'tomlplusplus',
'cpp',
version : '0.5.1',
version : '0.5.2',
license : 'MIT',
default_options : [
'cpp_std=c++17',
Expand Down
57 changes: 36 additions & 21 deletions python/generate_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,7 @@
inline_namespace_explainer = 'All members of this namespace are automatically members of the parent namespace. ' \
+ 'It does not require an explicit \'using\' statement.'
type_names = [
'table',
'array',
'value',
'date',
'time',
'date_time',
'time_offset',
'string',
'string_view',
'string_char',
'parse_result',
'parse_error',
'json_formatter',
'default_formatter',
'format_flags',
#------ standard types
'size_t',
'uint8_t',
'uint16_t',
Expand Down Expand Up @@ -71,7 +57,24 @@
'ofstream',
'stringstream',
'istringstream',
'ostringstream'
'ostringstream',
'string_view',
'string',
'byte',
#------ toml++ types
'table',
'array',
'value',
'date',
'time',
'date_time',
'time_offset',
'string_char',
'parse_result',
'parse_error',
'json_formatter',
'default_formatter',
'format_flags'
]
all_namespaces = [
'std',
Expand Down Expand Up @@ -657,16 +660,13 @@ class ExtDocLinksFix(object):
(r'std::(?:basic_|w)?ostringstreams?', 'https://en.cppreference.com/w/cpp/io/basic_ostringstream'),
(r'std::(?:basic_|w)?stringstreams?', 'https://en.cppreference.com/w/cpp/io/basic_stringstream'),
(r'std::(?:basic_|w|u8)?string_views?', 'https://en.cppreference.com/w/cpp/string/basic_string_view'),
(r'std::(?:basic_|w|u8)?strings?', 'https://en.cppreference.com/w/cpp/string/basic_string'),

(r'std::(?:basic_|w|u8)?strings?', 'https://en.cppreference.com/w/cpp/string/basic_string'),
(r'\s(?:<|&lt;)fstream(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/fstream'),
(r'\s(?:<|&lt;)sstream(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/sstream'),
(r'\s(?:<|&lt;)iostream(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/iostream'),
(r'\s(?:<|&lt;)iosfwd(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/iosfwd'),
(r'\s(?:<|&lt;)string(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/string'),
(r'\s(?:<|&lt;)string_view(?:>|&gt;)', 'https://en.cppreference.com/w/cpp/header/string_view'),


(r'char(?:8|16|32)_ts?', 'https://en.cppreference.com/w/cpp/language/types'),
(r'std::is_(?:nothrow_)?convertible(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_convertible'),
(r'std::is_same(?:_v)?', 'https://en.cppreference.com/w/cpp/types/is_same'),
Expand All @@ -683,8 +683,15 @@ class ExtDocLinksFix(object):
(r'std::add_[lr]value_reference(?:_t)?', 'https://en.cppreference.com/w/cpp/types/add_reference'),
(r'std::remove_reference(?:_t)?', 'https://en.cppreference.com/w/cpp/types/remove_reference'),
(r'std::remove_cv(?:_t)?', 'https://en.cppreference.com/w/cpp/types/remove_cv'),
(r'std::underlying_type(?:_t)?', 'https://en.cppreference.com/w/cpp/types/underlying_type'),
(r'std::exceptions?', 'https://en.cppreference.com/w/cpp/error/exception'),
(r'std::runtime_errors?', 'https://en.cppreference.com/w/cpp/error/runtime_error'),
(r'std::is_constant_evaluated', 'https://en.cppreference.com/w/cpp/types/is_constant_evaluated'),
(r'std::launder', 'https://en.cppreference.com/w/cpp/utility/launder'),
(r'std::bit_width', 'https://en.cppreference.com/w/cpp/numeric/bit_width'),
(r'std::bit_ceil', 'https://en.cppreference.com/w/cpp/numeric/bit_ceil'),
(r'std::bit_floor', 'https://en.cppreference.com/w/cpp/numeric/bit_floor'),
(r'std::bit_cast', 'https://en.cppreference.com/w/cpp/numeric/bit_cast'),
(r'std::initializer_lists?', 'https://en.cppreference.com/w/cpp/utility/initializer_list'),
(
r'(?:L?P)?(?:'
Expand All @@ -704,7 +711,15 @@ class ExtDocLinksFix(object):
(r'(?:Legacy)?BidirectionalIterators?', 'https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator'),
(r'(?:Legacy)?RandomAccessIterators?', 'https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator'),
(r'(?:Legacy)?ContiguousIterators?', 'https://en.cppreference.com/w/cpp/named_req/ContiguousIterator'),
#(r'(?:Legacy)?Iterators?', 'https://en.cppreference.com/w/cpp/named_req/Iterator'),
(
r'(?:'
+ r'__cplusplus|__STDC_HOSTED__'
+ r'|__FILE__|__LINE__'
+ r'|__DATE__|__TIME__'
+ r'|__STDCPP_DEFAULT_NEW_ALIGNMENT__'
+ r')',
'https://en.cppreference.com/w/cpp/preprocessor/replace'
),
# toml-specific
(r'toml::values?', 'classtoml_1_1value.html'),
(r'(toml::)?date_times?', 'structtoml_1_1date__time.html'),
Expand Down
8 changes: 4 additions & 4 deletions tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#endif
#define TOML_OPTIONAL_TYPE tl::optional
#endif

#include <cassert> //so TOML_ASSERT() maps to assert()
#define TOML_ALL_INLINE 0
#define TOML_IMPLEMENTATION
#if !defined(_MSC_VER) || !defined(_M_IX86)
#define TOML_ALL_INLINE 0
#define TOML_IMPLEMENTATION
#endif
#include "../include/toml++/toml.h"

#define CATCH_CONFIG_RUNNER
Expand Down
5 changes: 3 additions & 2 deletions tests/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
#endif
#include "catch2.h"
#include <sstream>
#include <cassert> //so TOML_ASSERT() maps to assert()
#define TOML_UNDEF_MACROS 0
#define TOML_ALL_INLINE 0
#if !defined(_MSC_VER) || !defined(_M_IX86)
#define TOML_ALL_INLINE 0
#endif
#include "../include/toml++/toml.h"

#if TOML_COMPILER_EXCEPTIONS
Expand Down
Loading

0 comments on commit b2f36e3

Please sign in to comment.