From 637f475e4429d225d05ca49b7d21f1ab64e859bf Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Wed, 27 May 2015 11:26:04 -0400 Subject: [PATCH] parse doubles as strings --- CMakeLists.txt | 3 ++- include/fc/exception/exception.hpp | 10 +++++++++- include/fc/io/json_relaxed.hpp | 16 ++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c377e9..eb4eae6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ SET(BOOST_COMPONENTS) LIST(APPEND BOOST_COMPONENTS thread date_time system filesystem program_options signals serialization chrono unit_test_framework context locale iostreams) SET( Boost_USE_STATIC_LIBS ON CACHE STRING "ON or OFF" ) + IF( ECC_IMPL STREQUAL openssl ) SET( ECC_REST src/crypto/elliptic_impl_pub.cpp ) ELSE( ECC_IMPL STREQUAL openssl ) @@ -270,7 +271,7 @@ target_include_directories(fc ) #target_link_libraries( fc PUBLIC easylzma_static scrypt udt ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${ECC_LIB} ) -target_link_libraries( fc PUBLIC easylzma_static udt ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${readline_libraries} ${ECC_LIB} ) +target_link_libraries( fc PUBLIC -L/usr/local/lib easylzma_static udt ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${readline_libraries} ${ECC_LIB} ) if(MSVC) set_source_files_properties( src/network/http/websocket.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) diff --git a/include/fc/exception/exception.hpp b/include/fc/exception/exception.hpp index baffcdf..5de13f9 100644 --- a/include/fc/exception/exception.hpp +++ b/include/fc/exception/exception.hpp @@ -294,6 +294,14 @@ namespace fc } // namespace fc +#if __APPLE__ + #define LIKELY(x) __builtin_expect((long)!!(x), 1L) + #define UNLIKELY(x) __builtin_expect((long)!!(x), 0L) +#else + #define LIKELY(x) (x) + #define UNLIKELY(x) (x) +#endif + /** *@brief: Workaround for varying preprocessing behavior between MSVC and gcc */ @@ -304,7 +312,7 @@ namespace fc #define FC_ASSERT( TEST, ... ) \ FC_EXPAND_MACRO( \ FC_MULTILINE_MACRO_BEGIN \ - if( !(TEST) ) \ + if( UNLIKELY(!(TEST)) ) \ FC_THROW_EXCEPTION( fc::assert_exception, #TEST ": " __VA_ARGS__ ); \ FC_MULTILINE_MACRO_END \ ) diff --git a/include/fc/io/json_relaxed.hpp b/include/fc/io/json_relaxed.hpp index aa50948..202fc54 100644 --- a/include/fc/io/json_relaxed.hpp +++ b/include/fc/io/json_relaxed.hpp @@ -343,8 +343,8 @@ namespace fc { namespace json_relaxed template fc::variant parseNumberOrStr( const fc::string& token ) - { - + { try { + //ilog( (token) ); size_t i = 0, n = token.length(); if( n == 0 ) FC_THROW_EXCEPTION( parse_error_exception, "expected: non-empty token, got: empty token" ); @@ -426,12 +426,14 @@ namespace fc { namespace json_relaxed if( i >= n ) return parseInt<10>( token, start ); char c = token[i++]; + //idump((c)(std::string()+c)); switch( c ) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': break; case '.': + return fc::variant(token); if( dot_ok ) { dot_ok = false; @@ -442,7 +444,9 @@ namespace fc { namespace json_relaxed return fc::variant( fc::to_double(token.c_str()) ); } + //idump((i)); c = token[i+1]; + //idump((c)); switch( c ) { case '0': case '1': case '2': case '3': case '4': @@ -466,7 +470,7 @@ namespace fc { namespace json_relaxed FC_THROW_EXCEPTION( parse_error_exception, "expected digit after '.'" ); return fc::variant( token ); default: - FC_THROW_EXCEPTION( parse_error_exception, "illegal character '{c}' in token", ( "c", c ) ); + FC_THROW_EXCEPTION( parse_error_exception, "illegal character '{c}' in token", ( "c", c )("i",int(c)) ); } } else @@ -554,7 +558,7 @@ namespace fc { namespace json_relaxed FC_THROW_EXCEPTION( parse_error_exception, "illegal character '{c}' in number", ( "c", c ) ); } } - } + } FC_CAPTURE_AND_RETHROW( (token) ) } template variant_object objectFromStream( T& in ) @@ -641,13 +645,13 @@ namespace fc { namespace json_relaxed template variant numberFromStream( T& in ) - { + { try { fc::string token = tokenFromStream(in); variant result = parseNumberOrStr( token ); if( strict && !(result.is_int64() || result.is_uint64() || result.is_double()) ) FC_THROW_EXCEPTION( parse_error_exception, "expected: number" ); return result; - } + } FC_CAPTURE_AND_RETHROW() } template variant wordFromStream( T& in )