From 42cf0e62a83fcbd92eee1f7ade22725135b045c5 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Thu, 20 Dec 2012 15:39:35 -0500 Subject: [PATCH] bug fixes / windows port --- include/fc/filesystem.hpp | 3 ++- include/fc/log.hpp | 4 +--- include/fc/value.hpp | 10 ++++------ include/fc/value_cast.hpp | 2 +- src/error_report.cpp | 6 +++++- src/filesystem.cpp | 16 ++++++++++++++-- src/iostream.cpp | 1 - src/json_rpc_connection.cpp | 2 ++ src/json_rpc_stream_connection.cpp | 2 -- src/log.cpp | 3 +++ src/process.cpp | 8 ++++---- src/thread.cpp | 3 --- src/value.cpp | 12 ++++++++---- 13 files changed, 44 insertions(+), 28 deletions(-) diff --git a/include/fc/filesystem.hpp b/include/fc/filesystem.hpp index 7ab1404..c04a242 100644 --- a/include/fc/filesystem.hpp +++ b/include/fc/filesystem.hpp @@ -78,9 +78,10 @@ namespace fc { bool is_directory( const path& p ); bool is_regular_file( const path& p ); void create_directories( const path& p ); + void remove_all( const path& p ); path absolute( const path& p ); path canonical( const path& p ); - size_t file_size( const path& p ); + uint64_t file_size( const path& p ); bool remove( const path& p ); void copy( const path& from, const path& to ); void create_hard_link( const path& from, const path& to ); diff --git a/include/fc/log.hpp b/include/fc/log.hpp index ab3f6c6..4ad5dd9 100644 --- a/include/fc/log.hpp +++ b/include/fc/log.hpp @@ -1,5 +1,4 @@ -#ifndef _FC_LOG_HPP_ -#define _FC_LOG_HPP_ +#pragma once #include namespace boost { class mutex; } @@ -30,4 +29,3 @@ namespace fc { #define elog(...) do { fc::log( CONSOLE_RED, __FILE__, __LINE__, __func__, __VA_ARGS__ ); }while(false) -#endif // _FC_LOG_HPP_ diff --git a/include/fc/value.hpp b/include/fc/value.hpp index f6ed0df..0f15134 100644 --- a/include/fc/value.hpp +++ b/include/fc/value.hpp @@ -6,9 +6,6 @@ #include #include -#include -#include - namespace fc { template struct tuple; @@ -30,14 +27,14 @@ namespace fc { class key_val; class object { public: - typedef std::vector::const_iterator const_iterator; + typedef fc::vector::const_iterator const_iterator; //fc::string type; - std::vector fields; + fc::vector fields; }; class array { public: array( size_t s = 0 ):fields(s){} - std::vector fields; + fc::vector fields; }; struct const_visitor { @@ -141,6 +138,7 @@ namespace fc { /** gets the stored type **/ const char* type()const; bool is_null()const; + bool is_string()const; void visit( const_visitor&& v )const; diff --git a/include/fc/value_cast.hpp b/include/fc/value_cast.hpp index 0ac751e..d40f34d 100644 --- a/include/fc/value_cast.hpp +++ b/include/fc/value_cast.hpp @@ -75,7 +75,7 @@ namespace fc { virtual void operator()( const float& v ){ m_out = fc::lexical_cast(v); } virtual void operator()( const double& v ){ m_out = fc::lexical_cast(v); } virtual void operator()( const bool& v ){ m_out = v != 0 ? "true" : "false"; } - virtual void operator()( const fc::string& v ){ m_out = v; } + virtual void operator()( const fc::string& v ) { m_out = v; } virtual void operator()( const value::object& ) { FC_THROW_MSG("bad cast"); } virtual void operator()( const value::array& ) { FC_THROW_MSG("bad cast"); } virtual void operator()( ) { FC_THROW_MSG("bad cast"); } diff --git a/src/error_report.cpp b/src/error_report.cpp index 4535e37..9095752 100644 --- a/src/error_report.cpp +++ b/src/error_report.cpp @@ -107,7 +107,11 @@ fc::string error_frame::to_string()const { if( meta ) { auto itr = meta->find( key.c_str() ); if( itr != meta->end() ) { - ss << fc::json::to_string( itr->val ); + if( itr->val.is_string() ) { + ss<val.cast(); + } else { + ss << fc::json::to_string( itr->val ); + } } else { ss << "???"; } diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 676c874..23835fd 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace fc { void pack( fc::value& v, const fc::path& s ) { @@ -121,8 +122,19 @@ namespace fc { void create_directories( const path& p ) { boost::filesystem::create_directories(p); } bool is_directory( const path& p ) { return boost::filesystem::is_directory(p); } bool is_regular_file( const path& p ) { return boost::filesystem::is_regular_file(p); } - size_t file_size( const path& p ) { return boost::filesystem::file_size(p); } - void copy( const path& f, const path& t ) { boost::filesystem::copy( boost::filesystem::path(f), boost::filesystem::path(t) ); } + uint64_t file_size( const path& p ) { return boost::filesystem::file_size(p); } + void remove_all( const path& p ) { boost::filesystem::remove_all(p); } + void copy( const path& f, const path& t ) { + try { + boost::filesystem::copy( boost::filesystem::path(f), boost::filesystem::path(t) ); + } catch ( boost::system::system_error& e ) { + FC_THROW_REPORT( "Copy from ${srcfile} to ${dstfile} failed because ${reason}", + fc::value().set("srcfile",f).set("dstfile",t).set("reason",e.what() ) ); + } catch ( ... ) { + FC_THROW_REPORT( "Copy from ${srcfile} to ${dstfile} failed", + fc::value().set("srcfile",f).set("dstfile",t).set("inner", fc::except_str() ) ); + } + } void create_hard_link( const path& f, const path& t ) { boost::filesystem::create_hard_link( f, t ); } bool remove( const path& f ) { return boost::filesystem::remove( f ); } fc::path canonical( const fc::path& p ) { return boost::filesystem::canonical(p); } diff --git a/src/iostream.cpp b/src/iostream.cpp index 9644523..bdd2ed1 100644 --- a/src/iostream.cpp +++ b/src/iostream.cpp @@ -118,7 +118,6 @@ namespace fc { } cin_t::~cin_t() { - wlog( "~cin_t" ); /* cin_buffer& b = get_cin_buffer(); if( b.read_ready ) { diff --git a/src/json_rpc_connection.cpp b/src/json_rpc_connection.cpp index f790e8f..21e4b83 100644 --- a/src/json_rpc_connection.cpp +++ b/src/json_rpc_connection.cpp @@ -80,8 +80,10 @@ namespace fc { namespace json { send_error( id, error_object( "error report", fc::value(eo) ) ); } } catch ( const fc::json::error_object& eo ) { + wlog( "%s", eo.message.c_str() ); send_error( id, eo ); } catch ( ... ) { + wlog( "%s", fc::except_str().c_str() ); send_error( id, error_object( fc::except_str(), fc::value() ) ); } } else { // ignore exception + result diff --git a/src/json_rpc_stream_connection.cpp b/src/json_rpc_stream_connection.cpp index 90da8a9..505047f 100644 --- a/src/json_rpc_stream_connection.cpp +++ b/src/json_rpc_stream_connection.cpp @@ -55,12 +55,10 @@ namespace fc { namespace json { rpc_stream_connection::rpc_stream_connection( fc::istream& i, fc::ostream& o ) :my( new impl(i,o,*this) ){ - slog( "%p", this ); } rpc_stream_connection::rpc_stream_connection(){ slog( "%p...",this); } rpc_stream_connection::rpc_stream_connection(const rpc_stream_connection& c):my(c.my){ slog( "%p",this); } rpc_stream_connection::~rpc_stream_connection(){ - slog( "my %p", my.get() ); } // the life of the streams must exceed the life of all copies diff --git a/src/log.cpp b/src/log.cpp index b5f8d7f..fa10025 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -26,6 +26,9 @@ namespace fc { } return file_name; } + boost::mutex& log_mutex() { + static boost::mutex* m = new boost::mutex(); return *m; + } #ifdef WIN32 #define isatty _isatty diff --git a/src/process.cpp b/src/process.cpp index 5521ad2..1b5db40 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -43,12 +43,13 @@ namespace fc { try { return static_cast(fc::asio::read_some( *m_pi, boost::asio::buffer( s, static_cast(n) ) )); } catch ( const boost::system::system_error& e ) { - wlog( "%s", fc::except_str().c_str() ); + // wlog( "%s", fc::except_str().c_str() ); if( e.code() == boost::asio::error::eof ) return -1; + wlog( "%s", fc::except_str().c_str() ); throw; } catch ( ... ) { - wlog( "%s", fc::except_str().c_str() ); + //wlog( "%s", fc::except_str().c_str() ); return -1; } } @@ -74,8 +75,7 @@ FC_START_SHARED_IMPL( fc::process ) inp->close(); } if( _exited.valid() && !_exited.ready()) { - slog( "terminate..."); - child->terminate(); + //child->terminate(); _exited.wait(); } }catch(...) { diff --git a/src/thread.cpp b/src/thread.cpp index 26b2b3b..fa73079 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -9,9 +9,6 @@ namespace fc { void* thread_ptr() { return &thread::current(); } - boost::mutex& log_mutex() { - static boost::mutex m; return m; - } thread*& current_thread() { #ifdef _MSC_VER diff --git a/src/value.cpp b/src/value.cpp index 2c4ccd8..a69a042 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace fc { @@ -290,6 +291,9 @@ value& value::operator=( const value& v ){ bool value::is_null()const { return strcmp(gh(holder)->type(), "void") == 0; } +bool value::is_string()const { + return strcmp(gh(holder)->type(), "string") == 0; +} value::object::const_iterator value::find( const char* key )const { @@ -302,7 +306,7 @@ value::object::const_iterator value::find( const char* key )const { } return o->val.fields.end(); } - FC_THROW_MSG( "Bad cast of %s to object", gh(holder)->type() ); + //FC_THROW_MSG( "Bad cast of %s to object", gh(holder)->type() ); return value::object::const_iterator(); } value::object::const_iterator value::begin()const { @@ -310,7 +314,7 @@ value::object::const_iterator value::begin()const { const detail::value_holder_impl* o = static_cast*>(gh(holder)); return o->val.fields.begin(); } - FC_THROW_MSG( "Bad cast of %s to object", gh(holder)->type() ); + //// FC_THROW_MSG( "Bad cast of %s to object", gh(holder)->type() ); return value::object::const_iterator(); //return nullptr; } @@ -319,7 +323,7 @@ value::object::const_iterator value::end()const { const detail::value_holder_impl* o = static_cast*>(gh(holder)); return o->val.fields.end(); } - FC_THROW_MSG( "Bad cast of %s to object", gh(holder)->type() ); + ////FC_THROW_MSG( "Bad cast of %s to object", gh(holder)->type() ); return value::object::const_iterator(); //return nullptr; } @@ -338,7 +342,7 @@ value& value::operator[]( const char* key ) { new (gh(holder)) detail::value_holder_impl(value::object()); return (*this)[key]; } - FC_THROW_MSG( "Bad cast of %s to object", gh(holder)->type() ); + FC_THROW_REPORT( "Bad cast of ${type} to object", fc::value().set("type",gh(holder)->type()) ); return *((value*)0); } value& value::operator[]( const fc::string& key ) { return (*this)[key.c_str()]; }