Skip to content

Commit e6f2972

Browse files
committed
update
1 parent d9685a0 commit e6f2972

25 files changed

+651
-642
lines changed

module/lib/jsoncons/basic_json.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,10 @@ namespace jsoncons {
895895
return ptr_->get_allocator();
896896
}
897897
};
898+
#if defined(__GNUC__) && JSONCONS_GCC_AVAILABLE(13,0,0)
899+
#pragma GCC diagnostic push
900+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
901+
#endif
898902

899903
// array_storage
900904
class array_storage final
@@ -1209,6 +1213,10 @@ namespace jsoncons {
12091213
std::allocator_traits<object_allocator>::deallocate(alloc, ptr_,1);
12101214
}
12111215
};
1216+
#if defined(__GNUC__) && JSONCONS_GCC_AVAILABLE(13,0,0)
1217+
#pragma GCC diagnostic pop
1218+
#endif
1219+
12121220
private:
12131221
class json_const_pointer_storage final
12141222
{

module/lib/jsoncons/config/compiler_support.hpp

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,26 @@
1313
#include <exception>
1414
#include <ostream>
1515

16-
#if defined (__clang__)
17-
#define JSONCONS_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
16+
#if defined(__GNUC__)
17+
# if defined(__GNUC_PATCHLEVEL__)
18+
# define JSONCONS_GCC_AVAILABLE(major, minor, patch) \
19+
((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \
20+
>= (major * 10000 + minor * 100 + patch))
21+
# else
22+
# define JSONCONS_GCC_AVAILABLE(major, minor, patch) \
23+
((__GNUC__ * 10000 + __GNUC_MINOR__ * 100) \
24+
>= (major * 10000 + minor * 100 + patch))
25+
# endif
26+
# else
27+
# define JSONCONS_GCC_AVAILABLE(major, minor, patch) 0
28+
#endif
29+
30+
#if defined(__clang__)
31+
# define JSONCONS_CLANG_AVAILABLE(major, minor, patch) \
32+
((__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) \
33+
>= (major * 10000 + minor * 100 + patch))
34+
# else
35+
# define JSONCONS_CLANG_AVAILABLE(major, minor, patch) 0
1836
#endif
1937

2038
// Uncomment the following line to suppress deprecated names (recommended for new code)
@@ -24,11 +42,6 @@
2442
// MIT license
2543

2644
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54577
27-
#if defined(__clang__)
28-
#elif defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ < 9)
29-
#define JSONCONS_NO_VECTOR_ERASE_TAKES_CONST_ITERATOR 1
30-
#define JSONCONS_NO_MAP_CONS_TAKES_ALLOCATOR 1
31-
#endif
3245

3346
#if defined(__clang__)
3447
# define JSONCONS_FALLTHROUGH [[clang::fallthrough]]
@@ -189,8 +202,8 @@
189202
# if (defined JSONCONS_HAS_2017)
190203
# if defined(__clang__)
191204
# if defined(__APPLE__)
192-
# if JSONCONS_CLANG_VERSION >= 100001
193-
# define JSONCONS_HAS_STD_VARIANT 1
205+
# if JSONCONS_CLANG_AVAILABLE(10,0,1)
206+
# define JSONCONS_HAS_STD_VARIANT 1
194207
# endif
195208
# elif __has_include(<variant>)
196209
# define JSONCONS_HAS_STD_VARIANT 1
@@ -287,6 +300,7 @@
287300
// Follows boost
288301

289302
// gcc and clang
303+
#if !defined(__CUDA_ARCH__)
290304
#if (defined(__clang__) || defined(__GNUC__)) && defined(__cplusplus)
291305
#if defined(__SIZEOF_INT128__) && !defined(_MSC_VER)
292306
# define JSONCONS_HAS_INT128
@@ -316,6 +330,7 @@
316330
#endif
317331
#endif
318332
#endif
333+
#endif // __CUDA_ARCH__
319334

320335
// Follows boost config/detail/suffix.hpp
321336
#if defined(JSONCONS_HAS_INT128) && defined(__cplusplus)
@@ -345,10 +360,10 @@ namespace jsoncons {
345360
#define JSONCONS_COPY(first,last,d_first) std::copy(first, last, d_first)
346361
#endif
347362

348-
#if defined(_MSC_VER) && _MSC_VER <= 1900
349-
#define JSONCONS_CONSTEXPR
350-
#else
363+
#if defined(JSONCONS_HAS_CP14)
351364
#define JSONCONS_CONSTEXPR constexpr
365+
#else
366+
#define JSONCONS_CONSTEXPR
352367
#endif
353368

354369
#if !defined(JSONCONS_HAS_STD_REGEX)
@@ -362,11 +377,8 @@ namespace jsoncons {
362377
#endif
363378

364379
#if !defined(JSONCONS_HAS_STATEFUL_ALLOCATOR)
365-
#if defined(__clang__)
366-
#define JSONCONS_HAS_STATEFUL_ALLOCATOR 1
367-
#elif (defined(__GNUC__) && (__GNUC__ == 4)) && (defined(__GNUC__) && __GNUC_MINOR__ < 9)
368-
// gcc 4.8 basic_string doesn't satisfy C++11 allocator requirements
369-
// and gcc doesn't support allocators with no default constructor
380+
#if defined(__clang__) && !JSONCONS_CLANG_AVAILABLE(11,0,0)
381+
#elif defined(__GNUC__) && !JSONCONS_GCC_AVAILABLE(10,0,0)
370382
#else
371383
#define JSONCONS_HAS_STATEFUL_ALLOCATOR 1
372384
#endif

module/lib/jsoncons/config/version.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <iostream>
1111

1212
#define JSONCONS_VERSION_MAJOR 0
13-
#define JSONCONS_VERSION_MINOR 175
13+
#define JSONCONS_VERSION_MINOR 176
1414
#define JSONCONS_VERSION_PATCH 0
1515

1616
namespace jsoncons {

module/lib/jsoncons/decode_traits.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ namespace jsoncons {
151151
template <class T, class CharT>
152152
struct decode_traits<T,CharT,
153153
typename std::enable_if<!is_json_type_traits_declared<T>::value &&
154-
extension_traits::is_list_like<T>::value &&
154+
extension_traits::is_array_like<T>::value &&
155155
extension_traits::is_back_insertable<T>::value &&
156156
!extension_traits::is_typed_array<T>::value
157157
>::type>
@@ -310,7 +310,7 @@ namespace jsoncons {
310310
template <class T, class CharT>
311311
struct decode_traits<T,CharT,
312312
typename std::enable_if<!is_json_type_traits_declared<T>::value &&
313-
extension_traits::is_list_like<T>::value &&
313+
extension_traits::is_array_like<T>::value &&
314314
extension_traits::is_back_insertable_byte_container<T>::value &&
315315
extension_traits::is_typed_array<T>::value
316316
>::type>
@@ -383,7 +383,7 @@ namespace jsoncons {
383383
template <class T, class CharT>
384384
struct decode_traits<T,CharT,
385385
typename std::enable_if<!is_json_type_traits_declared<T>::value &&
386-
extension_traits::is_list_like<T>::value &&
386+
extension_traits::is_array_like<T>::value &&
387387
extension_traits::is_back_insertable<T>::value &&
388388
!extension_traits::is_back_insertable_byte_container<T>::value &&
389389
extension_traits::is_typed_array<T>::value
@@ -436,7 +436,7 @@ namespace jsoncons {
436436
template <class T, class CharT>
437437
struct decode_traits<T,CharT,
438438
typename std::enable_if<!is_json_type_traits_declared<T>::value &&
439-
extension_traits::is_list_like<T>::value &&
439+
extension_traits::is_array_like<T>::value &&
440440
!extension_traits::is_back_insertable<T>::value &&
441441
extension_traits::is_insertable<T>::value
442442
>::type>

module/lib/jsoncons/detail/heap_string.hpp

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <memory> // std::allocator
1616
#include <jsoncons/config/compiler_support.hpp>
1717

18-
namespace jsoncons {
18+
namespace jsoncons {
1919
namespace detail {
2020

2121
inline char*
@@ -30,8 +30,8 @@ namespace detail {
3030
{
3131
Extra extra_;
3232
Allocator alloc_;
33-
34-
Allocator& get_allocator()
33+
34+
Allocator& get_allocator()
3535
{
3636
return alloc_;
3737
}
@@ -53,15 +53,16 @@ namespace detail {
5353
struct heap_string : public heap_string_base<Extra,Allocator>
5454
{
5555
using char_type = CharT;
56-
using allocator_type = typename std::allocator_traits<Allocator>::template rebind_alloc<CharT>;
56+
using allocator_type = typename std::allocator_traits<Allocator>::template rebind_alloc<CharT>;
5757
using allocator_traits_type = std::allocator_traits<allocator_type>;
5858
using pointer = typename allocator_traits_type::pointer;
5959

6060
pointer p_;
6161
std::size_t length_;
6262
uint8_t offset_;
63+
uint8_t align_pad_;
6364

64-
~heap_string() noexcept = default;
65+
~heap_string() noexcept = default;
6566

6667
const char_type* c_str() const { return extension_traits::to_plain_pointer(p_); }
6768
const char_type* data() const { return extension_traits::to_plain_pointer(p_); }
@@ -110,10 +111,10 @@ namespace detail {
110111
using heap_string_type = heap_string<CharT,Extra,Allocator>;
111112
private:
112113

113-
using byte_allocator_type = typename std::allocator_traits<Allocator>::template rebind_alloc<char>;
114+
using byte_allocator_type = typename std::allocator_traits<Allocator>::template rebind_alloc<char>;
114115
using byte_pointer = typename std::allocator_traits<byte_allocator_type>::pointer;
115116

116-
using heap_string_allocator_type = typename std::allocator_traits<Allocator>::template rebind_alloc<heap_string_type>;
117+
using heap_string_allocator_type = typename std::allocator_traits<Allocator>::template rebind_alloc<heap_string_type>;
117118
public:
118119
using pointer = typename std::allocator_traits<heap_string_allocator_type>::pointer;
119120

@@ -136,27 +137,41 @@ namespace detail {
136137
std::size_t len = aligned_size(length*sizeof(char_type));
137138

138139
std::size_t align = alignof(storage_type);
139-
std::size_t mem_len = (align-1)+len;
140-
140+
char* q = nullptr;
141+
char* storage = nullptr;
141142
byte_allocator_type byte_alloc(alloc);
142-
byte_pointer ptr = byte_alloc.allocate(mem_len);
143+
uint8_t align_pad = 0;
143144

144-
char* q = extension_traits::to_plain_pointer(ptr);
145+
if (align <= 8) {
146+
byte_pointer ptr = byte_alloc.allocate(len);
147+
q = extension_traits::to_plain_pointer(ptr);
145148

146-
char* storage = align_up(q, align);
149+
if (reinterpret_cast<uintptr_t>(q) % align == 0) {
150+
storage = q;
151+
} else {
152+
byte_alloc.deallocate(ptr, len);
153+
}
154+
}
147155

148-
JSONCONS_ASSERT(storage >= q);
156+
if (storage == nullptr) {
157+
align_pad = uint8_t(align-1);
158+
byte_pointer ptr = byte_alloc.allocate(align_pad+len);
159+
q = extension_traits::to_plain_pointer(ptr);
160+
storage = align_up(q, align);
161+
JSONCONS_ASSERT(storage >= q);
162+
}
149163

150164
heap_string_type* ps = new(storage)heap_string_type(extra, byte_alloc);
151165

152-
auto psa = launder_cast<storage_t*>(storage);
166+
auto psa = launder_cast<storage_t*>(storage);
153167

154168
CharT* p = new(&psa->c)char_type[length + 1];
155169
std::memcpy(p, s, length*sizeof(char_type));
156170
p[length] = 0;
157171
ps->p_ = std::pointer_traits<typename heap_string_type::pointer>::pointer_to(*p);
158172
ps->length_ = length;
159173
ps->offset_ = (uint8_t)(storage - q);
174+
ps->align_pad_ = align_pad;
160175
return std::pointer_traits<pointer>::pointer_to(*ps);
161176
}
162177

@@ -170,7 +185,7 @@ namespace detail {
170185

171186
char* p = q - ptr->offset_;
172187

173-
std::size_t mem_size = (alignof(storage_type)-1)+ aligned_size(ptr->length_*sizeof(char_type));
188+
std::size_t mem_size = ptr->align_pad_ + aligned_size(ptr->length_*sizeof(char_type));
174189
byte_allocator_type byte_alloc(ptr->get_allocator());
175190
byte_alloc.deallocate(p,mem_size + ptr->offset_);
176191
}

module/lib/jsoncons/detail/optional.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,20 @@ namespace detail
250250

251251
T& value() &
252252
{
253-
return static_cast<bool>(*this)
254-
? get()
255-
: JSONCONS_THROW(std::runtime_error("Bad optional access")), get();
253+
if (has_value_)
254+
{
255+
return get();
256+
}
257+
JSONCONS_THROW(std::runtime_error("Bad optional access"));
256258
}
257259

258-
constexpr const T& value() const &
260+
JSONCONS_CONSTEXPR const T& value() const &
259261
{
260-
return static_cast<bool>(*this)
261-
? get()
262-
: JSONCONS_THROW(std::runtime_error("Bad optional access")), get();
262+
if (has_value_)
263+
{
264+
return get();
265+
}
266+
JSONCONS_THROW(std::runtime_error("Bad optional access"));
263267
}
264268

265269
template <typename U>
@@ -298,7 +302,7 @@ namespace detail
298302
return std::addressof(this->value_);
299303
}
300304

301-
constexpr const T& operator*() const&
305+
JSONCONS_CONSTEXPR const T& operator*() const&
302306
{
303307
return value();
304308
}

0 commit comments

Comments
 (0)