From e8be21dc663fca5d1773ad5432ba8f3d9244f486 Mon Sep 17 00:00:00 2001 From: Alex Fabijanic Date: Wed, 31 Jan 2018 18:32:15 -0600 Subject: [PATCH] Poco1.8.1 compilation error for C++98 mode #2121 --- JSON/CMakeLists.txt | 4 +- JSON/JSON_CE_vs90.vcproj | 6 +- JSON/JSON_WEC2013_vs110.vcxproj | 6 +- JSON/JSON_WEC2013_vs110.vcxproj.filters | 7 +- JSON/JSON_WEC2013_vs120.vcxproj | 6 +- JSON/JSON_WEC2013_vs120.vcxproj.filters | 7 +- JSON/JSON_vs100.vcxproj | 6 +- JSON/JSON_vs100.vcxproj.filters | 7 +- JSON/JSON_vs110.vcxproj | 6 +- JSON/JSON_vs110.vcxproj.filters | 7 +- JSON/JSON_vs120.vcxproj | 6 +- JSON/JSON_vs120.vcxproj.filters | 7 +- JSON/JSON_vs140.vcxproj | 6 +- JSON/JSON_vs140.vcxproj.filters | 7 +- JSON/JSON_vs150.vcxproj | 6 +- JSON/JSON_vs150.vcxproj.filters | 7 +- JSON/JSON_vs90.vcproj | 477 ++++++++++++++++-------- JSON/JSON_x64_vs100.vcxproj | 6 +- JSON/JSON_x64_vs100.vcxproj.filters | 7 +- JSON/JSON_x64_vs110.vcxproj | 6 +- JSON/JSON_x64_vs110.vcxproj.filters | 7 +- JSON/JSON_x64_vs120.vcxproj | 6 +- JSON/JSON_x64_vs120.vcxproj.filters | 7 +- JSON/JSON_x64_vs140.vcxproj | 6 +- JSON/JSON_x64_vs140.vcxproj.filters | 7 +- JSON/JSON_x64_vs150.vcxproj | 6 +- JSON/JSON_x64_vs150.vcxproj.filters | 16 +- JSON/JSON_x64_vs90.vcproj | 6 +- JSON/Makefile | 2 +- JSON/include/Poco/JSON/Parser.h | 4 +- JSON/include/Poco/JSON/ParserImpl.h | 4 +- JSON/src/Parser.cpp | 6 + JSON/src/ParserImpl.cpp | 4 +- JSON/src/pd_json.h | 50 --- JSON/src/pd_json_private.h | 52 --- JSON/src/{pd_json.c => pdjson.c} | 113 ++++-- JSON/src/pdjson.h | 104 ++++++ 37 files changed, 595 insertions(+), 402 deletions(-) delete mode 100644 JSON/src/pd_json.h delete mode 100644 JSON/src/pd_json_private.h rename JSON/src/{pd_json.c => pdjson.c} (89%) create mode 100644 JSON/src/pdjson.h diff --git a/JSON/CMakeLists.txt b/JSON/CMakeLists.txt index b49373cc8..8b5f5e765 100644 --- a/JSON/CMakeLists.txt +++ b/JSON/CMakeLists.txt @@ -12,8 +12,8 @@ POCO_SOURCES_AUTO( SRCS ${SRCS_G}) # Headers file(GLOB_RECURSE HDRS_G "include/*.h" ) POCO_HEADERS_AUTO( SRCS ${HDRS_G}) -POCO_SOURCES(SRCS pdjson src/pd_json.c) -SET_SOURCE_FILES_PROPERTIES(src/pd_json.c PROPERTIES LANGUAGE CXX) +POCO_SOURCES(SRCS pdjson src/pdjson.c) +SET_SOURCE_FILES_PROPERTIES(src/pdjson.c PROPERTIES LANGUAGE CXX) add_library( "${LIBNAME}" ${LIB_MODE} ${SRCS} ) add_library( "${POCO_LIBNAME}" ALIAS "${LIBNAME}") diff --git a/JSON/JSON_CE_vs90.vcproj b/JSON/JSON_CE_vs90.vcproj index 083e0e117..5379a722b 100644 --- a/JSON/JSON_CE_vs90.vcproj +++ b/JSON/JSON_CE_vs90.vcproj @@ -451,7 +451,7 @@ + RelativePath=".\src\pdjson.c"> + RelativePath=".\src\pdjson.h"/> + RelativePath=".\include\pdjson_private.h"/> - + @@ -47,8 +47,8 @@ - - + + diff --git a/JSON/JSON_WEC2013_vs110.vcxproj.filters b/JSON/JSON_WEC2013_vs110.vcxproj.filters index 83ac3fe65..656e2d777 100644 --- a/JSON/JSON_WEC2013_vs110.vcxproj.filters +++ b/JSON/JSON_WEC2013_vs110.vcxproj.filters @@ -30,7 +30,7 @@ Source Files - + Source Files @@ -74,10 +74,7 @@ Header Files - - Header Files - - + Header Files diff --git a/JSON/JSON_WEC2013_vs120.vcxproj b/JSON/JSON_WEC2013_vs120.vcxproj index f37414014..7637fe942 100644 --- a/JSON/JSON_WEC2013_vs120.vcxproj +++ b/JSON/JSON_WEC2013_vs120.vcxproj @@ -8,7 +8,7 @@ - + @@ -47,8 +47,8 @@ - - + + diff --git a/JSON/JSON_WEC2013_vs120.vcxproj.filters b/JSON/JSON_WEC2013_vs120.vcxproj.filters index c0f837783..03bcc718a 100644 --- a/JSON/JSON_WEC2013_vs120.vcxproj.filters +++ b/JSON/JSON_WEC2013_vs120.vcxproj.filters @@ -30,7 +30,7 @@ Source Files - + Source Files @@ -74,10 +74,7 @@ Header Files - - Header Files - - + Header Files diff --git a/JSON/JSON_vs100.vcxproj b/JSON/JSON_vs100.vcxproj index 1dd16ea64..17967cd30 100644 --- a/JSON/JSON_vs100.vcxproj +++ b/JSON/JSON_vs100.vcxproj @@ -282,7 +282,7 @@ - + true CompileAsCpp true @@ -311,8 +311,8 @@ - - + + diff --git a/JSON/JSON_vs100.vcxproj.filters b/JSON/JSON_vs100.vcxproj.filters index a5996bfc1..bd511ec52 100644 --- a/JSON/JSON_vs100.vcxproj.filters +++ b/JSON/JSON_vs100.vcxproj.filters @@ -30,7 +30,7 @@ Source Files - + Source Files @@ -74,10 +74,7 @@ Header Files - - Header Files - - + Header Files diff --git a/JSON/JSON_vs110.vcxproj b/JSON/JSON_vs110.vcxproj index e563f955e..9f51bbb4f 100644 --- a/JSON/JSON_vs110.vcxproj +++ b/JSON/JSON_vs110.vcxproj @@ -283,7 +283,7 @@ - + true CompileAsCpp true @@ -312,8 +312,8 @@ - - + + diff --git a/JSON/JSON_vs110.vcxproj.filters b/JSON/JSON_vs110.vcxproj.filters index 300ced88e..ab61ad51d 100644 --- a/JSON/JSON_vs110.vcxproj.filters +++ b/JSON/JSON_vs110.vcxproj.filters @@ -30,7 +30,7 @@ Source Files - + Source Files @@ -74,10 +74,7 @@ Header Files - - Header Files - - + Header Files diff --git a/JSON/JSON_vs120.vcxproj b/JSON/JSON_vs120.vcxproj index ee2e6a037..b146e9759 100644 --- a/JSON/JSON_vs120.vcxproj +++ b/JSON/JSON_vs120.vcxproj @@ -283,7 +283,7 @@ - + true CompileAsCpp true @@ -312,8 +312,8 @@ - - + + diff --git a/JSON/JSON_vs120.vcxproj.filters b/JSON/JSON_vs120.vcxproj.filters index bd7c95d51..301cea23b 100644 --- a/JSON/JSON_vs120.vcxproj.filters +++ b/JSON/JSON_vs120.vcxproj.filters @@ -30,7 +30,7 @@ Source Files - + Source Files @@ -74,10 +74,7 @@ Header Files - - Header Files - - + Header Files diff --git a/JSON/JSON_vs140.vcxproj b/JSON/JSON_vs140.vcxproj index 0cd6748d9..924e06209 100644 --- a/JSON/JSON_vs140.vcxproj +++ b/JSON/JSON_vs140.vcxproj @@ -283,7 +283,7 @@ - + true CompileAsCpp true @@ -304,8 +304,8 @@ - - + + diff --git a/JSON/JSON_vs140.vcxproj.filters b/JSON/JSON_vs140.vcxproj.filters index 7e267ab7b..c890cc9fc 100644 --- a/JSON/JSON_vs140.vcxproj.filters +++ b/JSON/JSON_vs140.vcxproj.filters @@ -30,7 +30,7 @@ Source Files - + Source Files @@ -74,10 +74,7 @@ Header Files - - Header Files - - + Header Files diff --git a/JSON/JSON_vs150.vcxproj b/JSON/JSON_vs150.vcxproj index 6d1a83217..85f342bba 100644 --- a/JSON/JSON_vs150.vcxproj +++ b/JSON/JSON_vs150.vcxproj @@ -283,7 +283,7 @@ - + true CompileAsCpp true @@ -304,8 +304,8 @@ - - + + diff --git a/JSON/JSON_vs150.vcxproj.filters b/JSON/JSON_vs150.vcxproj.filters index c68ebec3e..46a8693be 100644 --- a/JSON/JSON_vs150.vcxproj.filters +++ b/JSON/JSON_vs150.vcxproj.filters @@ -30,7 +30,7 @@ Source Files - + Source Files @@ -74,10 +74,7 @@ Header Files - - Header Files - - + Header Files diff --git a/JSON/JSON_vs90.vcproj b/JSON/JSON_vs90.vcproj index 5a124f9d8..892660971 100644 --- a/JSON/JSON_vs90.vcproj +++ b/JSON/JSON_vs90.vcproj @@ -1,35 +1,46 @@ + Keyword="Win32Proj" + TargetFrameworkVersion="0" + > + Name="Win32" + /> - + + + CharacterSet="2" + > + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + Name="VCXMLDataGeneratorTool" + /> + Name="VCWebServiceProxyGeneratorTool" + /> + Name="VCMIDLTool" + /> + /> + Name="VCManagedResourceCompilerTool" + /> + Name="VCResourceCompilerTool" + /> + Name="VCPreLinkEventTool" + /> + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCPostBuildEventTool" + /> + CharacterSet="2" + > + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + Name="VCXMLDataGeneratorTool" + /> + Name="VCWebServiceProxyGeneratorTool" + /> + Name="VCMIDLTool" + /> + /> + Name="VCManagedResourceCompilerTool" + /> + Name="VCResourceCompilerTool" + /> + Name="VCPreLinkEventTool" + /> + /> + Name="VCALinkTool" + /> + Name="VCManifestTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCAppVerifierTool" + /> + Name="VCPostBuildEventTool" + /> + CharacterSet="2" + > + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + Name="VCXMLDataGeneratorTool" + /> + Name="VCWebServiceProxyGeneratorTool" + /> + Name="VCMIDLTool" + /> + /> + Name="VCManagedResourceCompilerTool" + /> + Name="VCResourceCompilerTool" + /> + Name="VCPreLinkEventTool" + /> + OutputFile="..\lib\PocoJSONmtd.lib" + /> + Name="VCALinkTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCPostBuildEventTool" + /> + CharacterSet="2" + > + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + Name="VCXMLDataGeneratorTool" + /> + Name="VCWebServiceProxyGeneratorTool" + /> + Name="VCMIDLTool" + /> + /> + Name="VCManagedResourceCompilerTool" + /> + Name="VCResourceCompilerTool" + /> + Name="VCPreLinkEventTool" + /> + OutputFile="..\lib\PocoJSONmt.lib" + /> + Name="VCALinkTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCPostBuildEventTool" + /> + CharacterSet="2" + > + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + Name="VCXMLDataGeneratorTool" + /> + Name="VCWebServiceProxyGeneratorTool" + /> + Name="VCMIDLTool" + /> + /> + Name="VCManagedResourceCompilerTool" + /> + Name="VCResourceCompilerTool" + /> + Name="VCPreLinkEventTool" + /> + OutputFile="..\lib\PocoJSONmdd.lib" + /> + Name="VCALinkTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCPostBuildEventTool" + /> + CharacterSet="2" + > + Name="VCPreBuildEventTool" + /> + Name="VCCustomBuildTool" + /> + Name="VCXMLDataGeneratorTool" + /> + Name="VCWebServiceProxyGeneratorTool" + /> + Name="VCMIDLTool" + /> + /> + Name="VCManagedResourceCompilerTool" + /> + Name="VCResourceCompilerTool" + /> + Name="VCPreLinkEventTool" + /> + OutputFile="..\lib\PocoJSONmd.lib" + /> + Name="VCALinkTool" + /> + Name="VCXDCMakeTool" + /> + Name="VCBscMakeTool" + /> + Name="VCFxCopTool" + /> + Name="VCPostBuildEventTool" + /> - + + + Name="Source Files" + > + RelativePath=".\src\Array.cpp" + > + + RelativePath=".\src\Handler.cpp" + > + + RelativePath=".\src\JSONException.cpp" + > + + RelativePath=".\src\Object.cpp" + > + + RelativePath=".\src\ParseHandler.cpp" + > + + RelativePath=".\src\Parser.cpp" + > + + RelativePath=".\src\ParserImpl.cpp" + > + + RelativePath=".\src\pdjson.c" + > + Name="debug_shared|Win32" + > + CompileAs="2" + /> + Name="release_shared|Win32" + > + CompileAs="2" + /> + Name="debug_static_mt|Win32" + > + CompileAs="2" + /> + Name="release_static_mt|Win32" + > + CompileAs="2" + /> + Name="debug_static_md|Win32" + > + CompileAs="2" + /> + Name="release_static_md|Win32" + > + CompileAs="2" + /> + RelativePath=".\src\PrintHandler.cpp" + > + + RelativePath=".\src\Query.cpp" + > + + RelativePath=".\src\Stringifier.cpp" + > + + RelativePath=".\src\Template.cpp" + > + + RelativePath=".\src\TemplateCache.cpp" + > + + Name="Header Files" + > + RelativePath=".\include\Poco\JSON\Array.h" + > + + RelativePath=".\include\Poco\JSON\Handler.h" + > + + RelativePath=".\include\Poco\JSON\JSON.h" + > + + RelativePath=".\include\Poco\JSON\JSONException.h" + > + + RelativePath=".\include\Poco\JSON\Object.h" + > + + RelativePath=".\include\Poco\JSON\ParseHandler.h" + > + + RelativePath=".\include\Poco\JSON\Parser.h" + > + + RelativePath=".\include\Poco\JSON\ParserImpl.h" + > + + RelativePath=".\src\pdjson.h" + > + + RelativePath=".\include\pdjson_private.h" + > + + RelativePath=".\include\Poco\JSON\PrintHandler.h" + > + + RelativePath=".\include\Poco\JSON\Query.h" + > + + RelativePath=".\include\Poco\JSON\Stringifier.h" + > + + RelativePath=".\include\Poco\JSON\Template.h" + > + + RelativePath=".\include\Poco\JSON\TemplateCache.h" + > + - + + diff --git a/JSON/JSON_x64_vs100.vcxproj b/JSON/JSON_x64_vs100.vcxproj index aa6611f48..6b5b88b63 100644 --- a/JSON/JSON_x64_vs100.vcxproj +++ b/JSON/JSON_x64_vs100.vcxproj @@ -280,7 +280,7 @@ - + true CompileAsCpp true @@ -309,8 +309,8 @@ - - + + diff --git a/JSON/JSON_x64_vs100.vcxproj.filters b/JSON/JSON_x64_vs100.vcxproj.filters index a74acef1d..2ba6645d3 100644 --- a/JSON/JSON_x64_vs100.vcxproj.filters +++ b/JSON/JSON_x64_vs100.vcxproj.filters @@ -30,7 +30,7 @@ Source Files - + Source Files @@ -74,10 +74,7 @@ Header Files - - Header Files - - + Header Files diff --git a/JSON/JSON_x64_vs110.vcxproj b/JSON/JSON_x64_vs110.vcxproj index ee9bbe50d..f766c7656 100644 --- a/JSON/JSON_x64_vs110.vcxproj +++ b/JSON/JSON_x64_vs110.vcxproj @@ -282,7 +282,7 @@ - + true CompileAsCpp true @@ -311,8 +311,8 @@ - - + + diff --git a/JSON/JSON_x64_vs110.vcxproj.filters b/JSON/JSON_x64_vs110.vcxproj.filters index cda532863..2e74a618a 100644 --- a/JSON/JSON_x64_vs110.vcxproj.filters +++ b/JSON/JSON_x64_vs110.vcxproj.filters @@ -30,7 +30,7 @@ Source Files - + Source Files @@ -74,10 +74,7 @@ Header Files - - Header Files - - + Header Files diff --git a/JSON/JSON_x64_vs120.vcxproj b/JSON/JSON_x64_vs120.vcxproj index d1d493986..7f088dd8d 100644 --- a/JSON/JSON_x64_vs120.vcxproj +++ b/JSON/JSON_x64_vs120.vcxproj @@ -282,7 +282,7 @@ - + true CompileAsCpp true @@ -311,8 +311,8 @@ - - + + diff --git a/JSON/JSON_x64_vs120.vcxproj.filters b/JSON/JSON_x64_vs120.vcxproj.filters index 3c28c946d..a6f98a2f4 100644 --- a/JSON/JSON_x64_vs120.vcxproj.filters +++ b/JSON/JSON_x64_vs120.vcxproj.filters @@ -30,7 +30,7 @@ Source Files - + Source Files @@ -74,10 +74,7 @@ Header Files - - Header Files - - + Header Files diff --git a/JSON/JSON_x64_vs140.vcxproj b/JSON/JSON_x64_vs140.vcxproj index 68bbd7fba..dc08fcfc6 100644 --- a/JSON/JSON_x64_vs140.vcxproj +++ b/JSON/JSON_x64_vs140.vcxproj @@ -282,7 +282,7 @@ - + true CompileAsCpp true @@ -303,8 +303,8 @@ - - + + diff --git a/JSON/JSON_x64_vs140.vcxproj.filters b/JSON/JSON_x64_vs140.vcxproj.filters index 071ff1244..6ae813397 100644 --- a/JSON/JSON_x64_vs140.vcxproj.filters +++ b/JSON/JSON_x64_vs140.vcxproj.filters @@ -30,7 +30,7 @@ Source Files - + Source Files @@ -74,10 +74,7 @@ Header Files - - Header Files - - + Header Files diff --git a/JSON/JSON_x64_vs150.vcxproj b/JSON/JSON_x64_vs150.vcxproj index 342a8d6eb..c50df669a 100644 --- a/JSON/JSON_x64_vs150.vcxproj +++ b/JSON/JSON_x64_vs150.vcxproj @@ -282,7 +282,7 @@ - + true CompileAsCpp true @@ -303,8 +303,8 @@ - - + + diff --git a/JSON/JSON_x64_vs150.vcxproj.filters b/JSON/JSON_x64_vs150.vcxproj.filters index 51bbf68dc..40537c87a 100644 --- a/JSON/JSON_x64_vs150.vcxproj.filters +++ b/JSON/JSON_x64_vs150.vcxproj.filters @@ -30,9 +30,6 @@ Source Files - - Source Files - Source Files @@ -48,6 +45,9 @@ Source Files + + Source Files + @@ -74,12 +74,6 @@ Header Files - - Header Files - - - Header Files - Header Files @@ -95,5 +89,9 @@ Header Files + + + Header Files + \ No newline at end of file diff --git a/JSON/JSON_x64_vs90.vcproj b/JSON/JSON_x64_vs90.vcproj index f79f7e114..5afbef29f 100644 --- a/JSON/JSON_x64_vs90.vcproj +++ b/JSON/JSON_x64_vs90.vcproj @@ -410,7 +410,7 @@ + RelativePath=".\src\pdjson.c"> + RelativePath=".\src\pdjson.h"/> + RelativePath=".\include\pdjson_private.h"/> - +//#include "pdjson.h" struct json_stream; @@ -104,7 +104,7 @@ private: void stripComments(std::string& json); bool checkError(); - json_stream* _pJSON; + struct json_stream* _pJSON; Handler::Ptr _pHandler; int _depth; char _decimalPoint; diff --git a/JSON/src/Parser.cpp b/JSON/src/Parser.cpp index 480ef9a9c..368a3a5d6 100644 --- a/JSON/src/Parser.cpp +++ b/JSON/src/Parser.cpp @@ -40,4 +40,10 @@ Parser::~Parser() } +void Parser::setHandler(const Handler::Ptr& pHandler) +{ + setHandlerImpl(pHandler); +} + + } } // namespace Poco::JSON diff --git a/JSON/src/ParserImpl.cpp b/JSON/src/ParserImpl.cpp index 3812169e9..40784a742 100644 --- a/JSON/src/ParserImpl.cpp +++ b/JSON/src/ParserImpl.cpp @@ -24,9 +24,9 @@ #include #include #include -#include "pd_json.h" - +#include "pdjson.h" +typedef struct json_stream json_stream; namespace Poco { namespace JSON { diff --git a/JSON/src/pd_json.h b/JSON/src/pd_json.h deleted file mode 100644 index 7c2e58bdb..000000000 --- a/JSON/src/pd_json.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef PDJSON_H -#define PDJSON_H - -#include - -#if defined(__cplusplus) && !(defined(_WIN32_WCE) || defined(_WIN32) || defined(_WIN64)) -extern "C" { -#endif - -enum json_type { - JSON_ERROR = 1, JSON_DONE, - JSON_OBJECT, JSON_OBJECT_END, JSON_ARRAY, JSON_ARRAY_END, - JSON_STRING, JSON_NUMBER, JSON_TRUE, JSON_FALSE, JSON_NULL -}; - -struct json_allocator { - void *(*malloc)(size_t); - void *(*realloc)(void *, size_t); - void (*free)(void *); -}; - -#include "pd_json_private.h" - -typedef struct json_stream json_stream; -typedef struct json_allocator json_allocator; - -void json_open_buffer(json_stream *json, const void *buffer, size_t size); -void json_open_string(json_stream *json, const char *string); -void json_open_stream(json_stream *json, FILE *stream); -void json_close(json_stream *json); - -void json_set_allocator(json_stream *json, json_allocator *a); -void json_set_streaming(json_stream *json, bool strict); - -enum json_type json_next(json_stream *json); -enum json_type json_peek(json_stream *json); -void json_reset(json_stream *json); -const char *json_get_string(json_stream *json, size_t *length); -double json_get_number(json_stream *json); - -size_t json_get_lineno(json_stream *json); -size_t json_get_position(json_stream *json); -size_t json_get_depth(json_stream *json); -const char *json_get_error(json_stream *json); - -#if defined(__cplusplus) && !(defined(_WIN32_WCE) || defined(_WIN32) || defined(_WIN64)) -} -#endif - -#endif diff --git a/JSON/src/pd_json_private.h b/JSON/src/pd_json_private.h deleted file mode 100644 index 4efa9aa54..000000000 --- a/JSON/src/pd_json_private.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef PDJSON_PRIVATE_H -#define PDJSON_PRIVATE_H - -#if defined(__STDC_VERSION__) || (__STDC_VERSION__ >= 199901L) -#include -#endif // __STDC_VERSION__ -#include - -struct json_source { - int (*get) (struct json_source *); - int (*peek) (struct json_source *); - size_t position; - union { - struct { - FILE *stream; - } stream; - struct { - const char *buffer; - size_t length; - } buffer; - } source; -}; - -struct json_stack { - enum json_type type; - long count; -}; - -struct json_stream { - size_t lineno; - - struct json_stack *stack; - size_t stack_top; - size_t stack_size; - enum json_type next; - int error : 31; - bool streaming : 1; - - struct { - char *string; - size_t string_fill; - size_t string_size; - } data; - - size_t ntokens; - - struct json_source source; - struct json_allocator alloc; - char errmsg[128]; -}; - -#endif diff --git a/JSON/src/pd_json.c b/JSON/src/pdjson.c similarity index 89% rename from JSON/src/pd_json.c rename to JSON/src/pdjson.c index 48e4467fa..5a711cee7 100644 --- a/JSON/src/pd_json.c +++ b/JSON/src/pdjson.c @@ -1,33 +1,37 @@ +#define _POSIX_C_SOURCE 200112L #include +// patched for poco 1.8.x #if defined(__STDC_VERSION__) || (__STDC_VERSION__ >= 199901L) #include +//#elif !defined(_MSC_VER) +//typedef enum { false, true } bool; #endif // __STDC_VERSION__ #include #include #include #include -#include "pd_json.h" +#include "pdjson.h" -#if defined(_MSC_VER) -#define strerror_r(err, buf, len) strerror_s(buf, len, err) -#endif +#define JSON_FLAG_ERROR (1u << 0) +#define JSON_FLAG_STREAMING (1u << 1) +// patched for poco 1.8.x (VS 2008) #if defined(_MSC_VER) && (_MSC_VER < 1900) #define json_error(json, format, ...) \ - if (!json->error) { \ - json->error = 1; \ - _snprintf_s(json->errmsg, sizeof(json->errmsg), _TRUNCATE, \ - "error: %lu: " format, \ - (unsigned long) json->lineno, \ - __VA_ARGS__); \ - } \ + if (!(json->flags & JSON_FLAG_ERROR)) { \ + json->flags |= JSON_FLAG_ERROR; \ + _snprintf_s(json->errmsg, sizeof(json->errmsg), _TRUNCATE,\ + "error: %lu: " format, \ + (unsigned long) json->lineno, \ + __VA_ARGS__); \ + } \ #else #define json_error(json, format, ...) \ - if (!json->error) { \ - json->error = 1; \ + if (!(json->flags & JSON_FLAG_ERROR)) { \ + json->flags |= JSON_FLAG_ERROR; \ snprintf(json->errmsg, sizeof(json->errmsg), \ "error: %lu: " format, \ (unsigned long) json->lineno, \ @@ -36,6 +40,31 @@ #endif // POCO_MSVS_VERSION +#define STACK_INC 4 + +#if defined(_MSC_VER) || defined(__MINGW32__) +#define strerror_r(err, buf, len) strerror_s(buf, len, err) +#endif +/* +const char *json_typename[] = { + [JSON_ERROR] = "ERROR", + [JSON_DONE] = "DONE", + [JSON_OBJECT] = "OBJECT", + [JSON_OBJECT_END] = "OBJECT_END", + [JSON_ARRAY] = "ARRAY", + [JSON_ARRAY_END] = "ARRAY_END", + [JSON_STRING] = "STRING", + [JSON_NUMBER] = "NUMBER", + [JSON_TRUE] = "TRUE", + [JSON_FALSE] = "FALSE", + [JSON_NULL] = "NULL", +}; +*/ +struct json_stack { + enum json_type type; + long count; +}; + static void json_error_s(json_stream *json, int err) { char errbuf[1024] = {0}; @@ -43,8 +72,6 @@ static void json_error_s(json_stream *json, int err) json_error(json, "%s", errbuf); } -#define STACK_INC 4 - static enum json_type push(json_stream *json, enum json_type type) { @@ -74,18 +101,12 @@ pop(json_stream *json, int c, enum json_type expected) { if (json->stack == NULL || json->stack[json->stack_top].type != expected) { json_error(json, "unexpected byte, '%c'", c); - json->alloc.free(json->stack); return JSON_ERROR; } json->stack_top--; return expected == JSON_ARRAY ? JSON_ARRAY_END : JSON_OBJECT_END; } -static void pop_all(json_stream *json) -{ - json->alloc.free(json->stack); -} - static int buffer_peek(struct json_source *source) { if (source->position < source->source.buffer.length) @@ -117,11 +138,10 @@ static int stream_peek(struct json_source *source) static void init(json_stream *json) { json->lineno = 1; - json->error = 0; + json->flags = JSON_FLAG_STREAMING; json->errmsg[0] = '\0'; json->ntokens = 0; json->next = (enum json_type) 0; - json->streaming = true; json->stack = NULL; json->stack_top = -1; @@ -334,7 +354,7 @@ int read_escaped(json_stream *json) case '"': { const char *codes = "\\bfnrt/\""; - const char *p = strchr(codes, c); + char *p = (char*) strchr(codes, c); if (pushchar(json, "\\\b\f\n\r\t/\""[p - codes]) != 0) return -1; } @@ -492,7 +512,7 @@ read_string(json_stream *json) return JSON_ERROR; } else { if (char_needs_escaping(c)) { - json_error(json, "%s:%u", "unescaped control character in string", (unsigned)c); + json_error(json, "%s", "unescaped control character in string"); return JSON_ERROR; } @@ -661,7 +681,7 @@ enum json_type json_peek(json_stream *json) enum json_type json_next(json_stream *json) { - if (json->error) + if (json->flags & JSON_FLAG_ERROR) return JSON_ERROR; if (json->next != 0) { enum json_type next = json->next; @@ -677,13 +697,15 @@ enum json_type json_next(json_stream *json) c = json->source.get(&json->source); } } while (json_isspace(c)); - if (!json->streaming && c != EOF) { + + if (!(json->flags & JSON_FLAG_STREAMING) && c != EOF) { return JSON_ERROR; } + return JSON_DONE; } int c = next(json); - if (json->stack == NULL) + if (json->stack_top == (size_t)-1) return read_value(json, c); if (json->stack[json->stack_top].type == JSON_ARRAY) { if (json->stack[json->stack_top].count == 0) { @@ -750,9 +772,9 @@ enum json_type json_next(json_stream *json) void json_reset(json_stream *json) { - pop_all(json); + json->stack_top = -1; json->ntokens = 0; - json->error = 0; + json->flags &= ~JSON_FLAG_ERROR; json->errmsg[0] = '\0'; } @@ -774,7 +796,7 @@ double json_get_number(json_stream *json) const char *json_get_error(json_stream *json) { - return json->error ? json->errmsg : NULL; + return json->flags & JSON_FLAG_ERROR ? json->errmsg : NULL; } size_t json_get_lineno(json_stream *json) @@ -797,7 +819,7 @@ void json_open_buffer(json_stream *json, const void *buffer, size_t size) init(json); json->source.get = buffer_get; json->source.peek = buffer_peek; - json->source.source.buffer.buffer = (const char*) buffer; + json->source.source.buffer.buffer = (char*) buffer; json->source.source.buffer.length = size; } @@ -814,6 +836,26 @@ void json_open_stream(json_stream *json, FILE * stream) json->source.source.stream.stream = stream; } +static int user_get(struct json_source *json) +{ + return json->source.user.get(json->source.user.ptr); +} + +static int user_peek(struct json_source *json) +{ + return json->source.user.peek(json->source.user.ptr); +} + +void json_open_user(json_stream *json, json_user_io get, json_user_io peek, void *user) +{ + init(json); + json->source.get = user_get; + json->source.peek = user_peek; + json->source.source.user.ptr = user; + json->source.source.user.get = get; + json->source.source.user.peek = peek; +} + void json_set_allocator(json_stream *json, json_allocator *a) { json->alloc = *a; @@ -821,11 +863,14 @@ void json_set_allocator(json_stream *json, json_allocator *a) void json_set_streaming(json_stream *json, bool streaming) { - json->streaming = streaming; + if (streaming) + json->flags |= JSON_FLAG_STREAMING; + else + json->flags &= ~JSON_FLAG_STREAMING; } void json_close(json_stream *json) { - pop_all(json); + json->alloc.free(json->stack); json->alloc.free(json->data.string); } diff --git a/JSON/src/pdjson.h b/JSON/src/pdjson.h new file mode 100644 index 000000000..b720c0c49 --- /dev/null +++ b/JSON/src/pdjson.h @@ -0,0 +1,104 @@ +#ifndef PDJSON_H +#define PDJSON_H + +#if defined(__cplusplus) +extern "C" { +#endif // __cplusplus + +#include +#if !defined(_MSC_VER) // for poco 1.8.x we must compile as C++ + #if defined(__STDC_VERSION__) || (__STDC_VERSION__ >= 199901L) + #include + #else + typedef enum { false, true } bool; + #endif // __STDC_VERSION__ +#endif + +enum json_type { + JSON_ERROR = 1, JSON_DONE, + JSON_OBJECT, JSON_OBJECT_END, JSON_ARRAY, JSON_ARRAY_END, + JSON_STRING, JSON_NUMBER, JSON_TRUE, JSON_FALSE, JSON_NULL +}; + +struct json_allocator { + void *(*malloc)(size_t); + void *(*realloc)(void *, size_t); + void (*free)(void *); +}; + +typedef int (*json_user_io) (void *user); + +typedef struct json_stream json_stream; +typedef struct json_allocator json_allocator; + +//extern const char *json_typename[]; + +void json_open_buffer(json_stream *json, const void *buffer, size_t size); +void json_open_string(json_stream *json, const char *string); +void json_open_stream(json_stream *json, FILE *stream); +void json_open_user(json_stream *json, json_user_io get, json_user_io peek, void *user); +void json_close(json_stream *json); + +void json_set_allocator(json_stream *json, json_allocator *a); +void json_set_streaming(json_stream *json, bool strict); + +enum json_type json_next(json_stream *json); +enum json_type json_peek(json_stream *json); +void json_reset(json_stream *json); +const char *json_get_string(json_stream *json, size_t *length); +double json_get_number(json_stream *json); + +size_t json_get_lineno(json_stream *json); +size_t json_get_position(json_stream *json); +size_t json_get_depth(json_stream *json); +const char *json_get_error(json_stream *json); + +/* internal */ + +struct json_source { + int (*get) (struct json_source *); + int (*peek) (struct json_source *); + size_t position; + union { + struct { + FILE *stream; + } stream; + struct { + const char *buffer; + size_t length; + } buffer; + struct { + void *ptr; + json_user_io get; + json_user_io peek; + } user; + } source; +}; + +struct json_stream { + size_t lineno; + + struct json_stack *stack; + size_t stack_top; + size_t stack_size; + enum json_type next; + unsigned flags; + + struct { + char *string; + size_t string_fill; + size_t string_size; + } data; + + size_t ntokens; + + struct json_source source; + struct json_allocator alloc; + char errmsg[128]; +}; + +#if defined(__cplusplus) +} // extern "C" +#endif // __cplusplus + +#endif