Skip to content

Commit

Permalink
Bug#30898701 UPGRADE THE RAPIDJSON LIBRARY [1/2, upgrade rapidjson]
Browse files Browse the repository at this point in the history
Upgrade the rapidjson library to the latest version.
This gives us better error reporting, and allows us to
remove two backports from upstream.

Since there has not been any official release in the last
four years, we have included the latest available commit
from https://github.com/Tencent/rapidjson/

Change-Id: I7a80693b108a1f3327a09bf138812c9f1aaa5bc9
  • Loading branch information
Erik Froseth committed Feb 20, 2020
1 parent 651b4d5 commit dd748e9
Show file tree
Hide file tree
Showing 33 changed files with 2,268 additions and 774 deletions.
12 changes: 3 additions & 9 deletions extra/RAPIDJSON-README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
Expand All @@ -23,14 +23,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
----

The rapidjson library included in this directory is based on
https://github.com/miloyip/rapidjson, version 1.1.0.
https://github.com/Tencent/rapidjson/,
commit 418331e99f859f00bdc8306f69eba67e8693c55e

We only include the contents of the folder "include/" so that we don't include
any code licensed under the JSON License.

Pull request 1161 has been backported from upstream rapidjson in order to be
able to use std::regex instead of the internal rapidjson regex in JSON Schema
validation.

Pull request 1413 has been backported from upstream rapidjson that fixes a
memory leak in case of invalid regex patterns.
17 changes: 15 additions & 2 deletions extra/rapidjson/include/rapidjson/allocators.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ concept Allocator {
\endcode
*/


/*! \def RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY
\ingroup RAPIDJSON_CONFIG
\brief User-defined kDefaultChunkCapacity definition.
User can define this as any \c size that is a power of 2.
*/

#ifndef RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY
#define RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY (64 * 1024)
#endif


///////////////////////////////////////////////////////////////////////////////
// CrtAllocator

Expand Down Expand Up @@ -236,7 +249,7 @@ class MemoryPoolAllocator {
*/
bool AddChunk(size_t capacity) {
if (!baseAllocator_)
ownBaseAllocator_ = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator());
ownBaseAllocator_ = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator)();
if (ChunkHeader* chunk = reinterpret_cast<ChunkHeader*>(baseAllocator_->Malloc(RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + capacity))) {
chunk->capacity = capacity;
chunk->size = 0;
Expand All @@ -248,7 +261,7 @@ class MemoryPoolAllocator {
return false;
}

static const int kDefaultChunkCapacity = 64 * 1024; //!< Default chunk capacity.
static const int kDefaultChunkCapacity = RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY; //!< Default chunk capacity.

//! Chunk header for perpending to each chunk.
/*! Chunks are stored as a singly linked list.
Expand Down
78 changes: 78 additions & 0 deletions extra/rapidjson/include/rapidjson/cursorstreamwrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Tencent is pleased to support the open source community by making RapidJSON available.
//
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
//
// Licensed under the MIT License (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// http://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.

#ifndef RAPIDJSON_CURSORSTREAMWRAPPER_H_
#define RAPIDJSON_CURSORSTREAMWRAPPER_H_

#include "stream.h"

#if defined(__GNUC__)
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(effc++)
#endif

#if defined(_MSC_VER) && _MSC_VER <= 1800
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(4702) // unreachable code
RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
#endif

RAPIDJSON_NAMESPACE_BEGIN


//! Cursor stream wrapper for counting line and column number if error exists.
/*!
\tparam InputStream Any stream that implements Stream Concept
*/
template <typename InputStream, typename Encoding = UTF8<> >
class CursorStreamWrapper : public GenericStreamWrapper<InputStream, Encoding> {
public:
typedef typename Encoding::Ch Ch;

CursorStreamWrapper(InputStream& is):
GenericStreamWrapper<InputStream, Encoding>(is), line_(1), col_(0) {}

// counting line and column number
Ch Take() {
Ch ch = this->is_.Take();
if(ch == '\n') {
line_ ++;
col_ = 0;
} else {
col_ ++;
}
return ch;
}

//! Get the error line number, if error exists.
size_t GetLine() const { return line_; }
//! Get the error column number, if error exists.
size_t GetColumn() const { return col_; }

private:
size_t line_; //!< Current Line
size_t col_; //!< Current Column
};

#if defined(_MSC_VER) && _MSC_VER <= 1800
RAPIDJSON_DIAG_POP
#endif

#if defined(__GNUC__)
RAPIDJSON_DIAG_POP
#endif

RAPIDJSON_NAMESPACE_END

#endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_
Loading

0 comments on commit dd748e9

Please sign in to comment.