Skip to content

Talk about merging in the possibility of secure allocator on strings #415

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

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0804322
Merge pull request #1 from open-source-parsers/master
Feb 5, 2016
7f1d334
Add eclipse ignore settings
dawesc Feb 5, 2016
fbe5f2f
Copy all cpp files to inl files to convert into templates
dawesc Feb 5, 2016
1f2e9d1
Remove from the cpp file anything that has to be templated
dawesc Feb 5, 2016
614a5c3
Remove from the inl files the code that remains in cpp
dawesc Feb 5, 2016
8e7fb04
Definition of templates
dawesc Feb 5, 2016
96ce895
Forward declarations also need the template declaration
dawesc Feb 5, 2016
75b3de3
Fix compilation scripts for new paths
dawesc Feb 5, 2016
5804843
Add template in front of every method in the template implementation
dawesc Feb 5, 2016
0092dd7
typedef's for classes that have been made templated
dawesc Feb 5, 2016
027ee3d
Fix up code to execute
dawesc Feb 5, 2016
1ae3e95
Move std::string -> String from value type
dawesc Feb 5, 2016
fc8897a
Uses the appropriate allocator instead of malloc/free
dawesc Feb 5, 2016
1729e9c
Fix some compilation errors
flatwhatson Feb 6, 2016
ecf832b
Fix issue with incorrect clone causing seg fault
Feb 6, 2016
30d4cf0
All tests fixed, issue with missing swap of string value
Feb 6, 2016
2968ced
Merge pull request #2 from open-source-parsers/master
Feb 6, 2016
06d95c6
Merge remote-tracking branch 'origin/master' into secure_allocator_clean
dawesc Feb 6, 2016
b905735
Fix up merge
dawesc Feb 6, 2016
6147e59
isfinite global declaration conflicted with boost
dawesc Feb 6, 2016
eb9a949
Added typedef alias Value_ for a type with accessible allocator
Feb 7, 2016
74147f7
Added typedef aliases to Writer & Reader
Feb 7, 2016
ce5b9f7
Revert "Added typedef aliases to Writer & Reader"
dawesc Feb 7, 2016
70f323e
Revert "Added typedef alias Value_ for a type with accessible allocator"
dawesc Feb 7, 2016
32ffc7f
addError needs to use String
Feb 7, 2016
0a3d8ee
More String uses
Feb 7, 2016
8140a0f
Compilation fix
Feb 7, 2016
1f2d46d
Fixes for allocators that aren't std::allocator<char>
dawesc Feb 7, 2016
2872f44
Add support for easy creation fetching of Json in any allocator format
dawesc Feb 7, 2016
56256c3
Support parse from just const char* rather than copying into string
dawesc Feb 7, 2016
d75f879
Document was incorrectly typed
dawesc Feb 7, 2016
d296cce
toStyledString to support an output in a specific format
dawesc Feb 7, 2016
08df258
SecureAllocator needs a operator == to compile on ubuntu
dawesc Feb 7, 2016
f6e89d4
Commit gitattributes enforced line endings
flatwhatson Feb 8, 2016
580f92e
Fix string constructor template
flatwhatson Feb 8, 2016
5cdb42c
Accept any basic_string as key in operator[] and get()
flatwhatson Feb 8, 2016
f49f248
Merge pull request #3 from open-source-parsers/master
Feb 12, 2016
2d6b688
Merge remote-tracking branch 'origin/master' into secure_allocator_clean
dawesc Feb 12, 2016
ecbc0ac
Remove IsIntegral compiler warning about not used
dawesc Feb 12, 2016
4f8eb03
Fix travis, the override added has caused compilation to fail on clang
dawesc Feb 12, 2016
09a70c6
Another virtual in clang++ causing issues
dawesc Feb 12, 2016
b27a16e
More override on clang++ fixes
dawesc Feb 12, 2016
3933c84
Implicit string conversion reported by travis clang++
dawesc Feb 12, 2016
7ee007e
Attempt to fix the travis error about max_size
Feb 12, 2016
3f5a69f
Also support address for fuller compliance with allocator
Feb 12, 2016
e920567
Not installing enough files
Feb 13, 2016
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
*.tlog/
*.pdb

# eclipse project files
.project
.cproject
/.settings/

# CMake-generated files:
CMakeFiles/
CTestTestFile.cmake
Expand Down
5 changes: 3 additions & 2 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
FILE(GLOB INCLUDE_FILES "json/*.h")
INSTALL(FILES ${INCLUDE_FILES} DESTINATION ${INCLUDE_INSTALL_DIR}/json)
FILE(GLOB HEADER_FILES "json/*.h")
FILE(GLOB INCLUDE_FILES "json/*.inl")
INSTALL(FILES ${HEADER_FILES} ${INCLUDE_FILES} DESTINATION ${INCLUDE_INSTALL_DIR}/json)
22 changes: 17 additions & 5 deletions include/json/forwards.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,38 @@

namespace Json {

// features.h
class Features;
class StaticString;
typedef unsigned int ArrayIndex;

namespace detail {

// writer.h
template<class _Value>
class FastWriter;
template<class _Value>
class StyledWriter;

// reader.h
template<class _Value>
class Reader;

// features.h
class Features;

// value.h
typedef unsigned int ArrayIndex;
class StaticString;
template<class _Value>
class Path;
template<class _Value>
class PathArgument;
template<class _Alloc, class _String>
class Value;
template<class _Value>
class ValueIteratorBase;
template<class _Value>
class ValueIterator;
template<class _Value>
class ValueConstIterator;

} // namespace detail
} // namespace Json

#endif // JSON_FORWARDS_H_INCLUDED
6 changes: 3 additions & 3 deletions include/json/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#define JSON_JSON_H_INCLUDED

#include "autolink.h"
#include "value.h"
#include "reader.h"
#include "writer.h"
#include "value.inl"
#include "reader.inl"
#include "writer.inl"
#include "features.h"

#endif // JSON_JSON_H_INCLUDED
92 changes: 63 additions & 29 deletions include/json/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)

namespace Json {
namespace detail {

/** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a
*Value.
*
* \deprecated Use CharReader and CharReaderBuilder.
*/
template<class _Value>
class JSON_API Reader {
public:
typedef typename _Value::String String;
typedef char Char;
typedef const Char* Location;

Expand Down Expand Up @@ -71,8 +74,28 @@ class JSON_API Reader {
* \return \c true if the document was successfully parsed, \c false if an
* error occurred.
*/
template<class CharT, class Traits, class BSAllocator, template<class, class, class> class BasicString>
bool
parse(const std::string& document, Value& root, bool collectComments = true);
parse(const BasicString<CharT, Traits, BSAllocator>& document, _Value& root, bool collectComments = true);

/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
document.
* \param doc Pointer on the beginning of the UTF-8 encoded string of the
document to read.
* \param root [out] Contains the root value of the document if it was
* successfully parsed.
* \param collectComments \c true to collect comment and allow writing them
back during
* serialization, \c false to discard comments.
* This parameter is ignored if
Features::allowComments_
* is \c false.
* \return \c true if the document was successfully parsed, \c false if an
error occurred.
*/
bool parse(const char* doc,
_Value& root,
bool collectComments = true);

/** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
document.
Expand All @@ -94,12 +117,12 @@ class JSON_API Reader {
*/
bool parse(const char* beginDoc,
const char* endDoc,
Value& root,
_Value& root,
bool collectComments = true);

/// \brief Parse from input stream.
/// \see Json::operator>>(std::istream&, Json::Value&).
bool parse(std::istream& is, Value& root, bool collectComments = true);
bool parse(std::istream& is, _Value& root, bool collectComments = true);

/** \brief Returns a user friendly string that list errors in the parsed
* document.
Expand Down Expand Up @@ -138,7 +161,7 @@ class JSON_API Reader {
* \return \c true if the error was successfully added, \c false if the
* Value offset exceeds the document size.
*/
bool pushError(const Value& value, const std::string& message);
bool pushError(const _Value& value, const std::string& message);

/** \brief Add a semantic error message with extra context.
* \param value JSON Value location associated with the error
Expand All @@ -147,7 +170,7 @@ class JSON_API Reader {
* \return \c true if the error was successfully added, \c false if either
* Value offset exceeds the document size.
*/
bool pushError(const Value& value, const std::string& message, const Value& extra);
bool pushError(const _Value& value, const std::string& message, const _Value& extra);

/** \brief Return whether there are any errors.
* \return \c true if there are no errors to report \c false if
Expand Down Expand Up @@ -183,7 +206,7 @@ class JSON_API Reader {
class ErrorInfo {
public:
Token token_;
std::string message_;
String message_;
Location extra_;
};

Expand All @@ -201,11 +224,11 @@ class JSON_API Reader {
bool readObject(Token& token);
bool readArray(Token& token);
bool decodeNumber(Token& token);
bool decodeNumber(Token& token, Value& decoded);
bool decodeNumber(Token& token, _Value& decoded);
bool decodeString(Token& token);
bool decodeString(Token& token, std::string& decoded);
bool decodeString(Token& token, String& decoded);
bool decodeDouble(Token& token);
bool decodeDouble(Token& token, Value& decoded);
bool decodeDouble(Token& token, _Value& decoded);
bool decodeUnicodeCodePoint(Token& token,
Location& current,
Location end,
Expand All @@ -214,36 +237,37 @@ class JSON_API Reader {
Location& current,
Location end,
unsigned int& unicode);
bool addError(const std::string& message, Token& token, Location extra = 0);
bool addError(String message, Token& token, Location extra = 0);
bool recoverFromError(TokenType skipUntilToken);
bool addErrorAndRecover(const std::string& message,
bool addErrorAndRecover(const String& message,
Token& token,
TokenType skipUntilToken);
void skipUntilSpace();
Value& currentValue();
_Value& currentValue();
Char getNextChar();
void
getLocationLineAndColumn(Location location, int& line, int& column) const;
std::string getLocationLineAndColumn(Location location) const;
String getLocationLineAndColumn(Location location) const;
void addComment(Location begin, Location end, CommentPlacement placement);
void skipCommentTokens(Token& token);

typedef std::stack<Value*> Nodes;
typedef std::stack<_Value*> Nodes;
Nodes nodes_;
Errors errors_;
std::string document_;
String document_;
Location begin_;
Location end_;
Location current_;
Location lastValueEnd_;
Value* lastValue_;
std::string commentsBefore_;
_Value* lastValue_;
String commentsBefore_;
Features features_;
bool collectComments_;
}; // Reader

/** Interface for reading JSON from a char array.
*/
template<class _Value>
class JSON_API CharReader {
public:
virtual ~CharReader() {}
Expand All @@ -266,7 +290,7 @@ class JSON_API CharReader {
*/
virtual bool parse(
char const* beginDoc, char const* endDoc,
Value* root, std::string* errs) = 0;
_Value* root, std::string* errs) = 0;

class JSON_API Factory {
public:
Expand All @@ -290,8 +314,10 @@ class JSON_API CharReader {
bool ok = parseFromStream(builder, std::cin, &value, &errs);
\endcode
*/
class JSON_API CharReaderBuilder : public CharReader::Factory {
template<class _Value>
class JSON_API CharReaderBuilder : public CharReader<_Value>::Factory {
public:
typedef typename _Value::String String;
// Note: We use a Json::Value so that we can add data-members to this class
// without a major version bump.
/** Configuration of this builder.
Expand Down Expand Up @@ -330,44 +356,45 @@ class JSON_API CharReaderBuilder : public CharReader::Factory {
JSON Value.
\sa setDefaults()
*/
Json::Value settings_;
_Value settings_;

CharReaderBuilder();
~CharReaderBuilder() override;
virtual ~CharReaderBuilder() override;

CharReader* newCharReader() const override;
virtual CharReader<_Value>* newCharReader() const override;

/** \return true if 'settings' are legal and consistent;
* otherwise, indicate bad settings via 'invalid'.
*/
bool validate(Json::Value* invalid) const;
bool validate(_Value* invalid) const;

/** A simple way to update a specific setting.
*/
Value& operator[](std::string key);
_Value& operator[](String key);

/** Called by ctor, but you can use this to reset settings_.
* \pre 'settings' != NULL (but Json::null is fine)
* \remark Defaults:
* \snippet src/lib_json/json_reader.cpp CharReaderBuilderDefaults
*/
static void setDefaults(Json::Value* settings);
static void setDefaults(_Value* settings);
/** Same as old Features::strictMode().
* \pre 'settings' != NULL (but Json::null is fine)
* \remark Defaults:
* \snippet src/lib_json/json_reader.cpp CharReaderBuilderStrictMode
*/
static void strictMode(Json::Value* settings);
static void strictMode(_Value* settings);
};

/** Consume entire stream and use its begin/end.
* Someday we might have a real StreamReader, but for now this
* is convenient.
*/
template<class _Value>
bool JSON_API parseFromStream(
CharReader::Factory const&,
typename CharReader<_Value>::Factory const&,
std::istream&,
Value* root, std::string* errs);
_Value* root, std::string* errs);

/** \brief Read from 'sin' into 'root'.

Expand All @@ -393,7 +420,14 @@ bool JSON_API parseFromStream(
\throw std::exception on parse error.
\see Json::operator<<()
*/
JSON_API std::istream& operator>>(std::istream&, Value&);
template<class _Value>
JSON_API std::istream& operator>>(std::istream&, _Value&);

} // namespace detail

typedef detail::CharReader<detail::Value<>> CharReader; // class Json::CharReader
typedef detail::CharReaderBuilder<detail::Value<>> CharReaderBuilder; // class Json::CharReaderBuilder
typedef detail::Reader<detail::Value<>> Reader; // class Json::Reader

} // namespace Json

Expand Down
Loading