From ccf7e4f131e7fc89e82510f7dd87a09fea31f27f Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Mon, 27 Oct 2014 22:47:36 +0100 Subject: [PATCH] mini cleanup --- arangod/RestServer/ConsoleThread.cpp | 6 +++--- lib/Basics/Thread.cpp | 21 ++++++++++++------ lib/Utilities/LineEditor.cpp | 3 +-- lib/Utilities/ReadlineShell.cpp | 32 +++++++++++++--------------- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/arangod/RestServer/ConsoleThread.cpp b/arangod/RestServer/ConsoleThread.cpp index 371706cd5f..726be5f43d 100644 --- a/arangod/RestServer/ConsoleThread.cpp +++ b/arangod/RestServer/ConsoleThread.cpp @@ -61,7 +61,7 @@ ConsoleThread::ConsoleThread (ApplicationServer* applicationServer, : Thread("console"), _applicationServer(applicationServer), _applicationV8(applicationV8), - _context(0), + _context(nullptr), _vocbase(vocbase), _done(0), _userAborted(false) { @@ -151,13 +151,13 @@ void ConsoleThread::inner () { char* input = console.prompt("arangod> "); if (_userAborted) { - if (input != 0) { + if (input != nullptr) { TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, input); } throw "user aborted"; } - if (input == 0) { + if (input == nullptr) { _userAborted = true; // this will be caught by "run" diff --git a/lib/Basics/Thread.cpp b/lib/Basics/Thread.cpp index 3d50b78cb9..cbcd7f2c1a 100644 --- a/lib/Basics/Thread.cpp +++ b/lib/Basics/Thread.cpp @@ -111,25 +111,29 @@ Thread::Thread (std::string const& name) //////////////////////////////////////////////////////////////////////////////// Thread::~Thread () { - int res; - if (_running != 0) { if (! isSilent()) { LOG_WARNING("forcefully shutting down thread '%s'", _name.c_str()); } - res = TRI_StopThread(&_thread); + int res = TRI_StopThread(&_thread); if (res != TRI_ERROR_NO_ERROR) { - LOG_WARNING("unable to stop thread '%s': %s", _name.c_str(), TRI_errno_string(res)); + errno = res; + TRI_set_errno(TRI_ERROR_SYS_ERROR); + + LOG_WARNING("unable to stop thread '%s': %s", _name.c_str(), TRI_last_error()); } } if (! _joined) { - res = TRI_DetachThread(&_thread); + int res = TRI_DetachThread(&_thread); if (res != TRI_ERROR_NO_ERROR) { - LOG_WARNING("unable to detach thread '%s': %s", _name.c_str(), TRI_errno_string(res)); + errno = res; + TRI_set_errno(TRI_ERROR_SYS_ERROR); + + LOG_WARNING("unable to detach thread '%s': %s", _name.c_str(), TRI_last_error()); } } } @@ -236,9 +240,12 @@ int Thread::shutdown () { int res = TRI_StopThread(&_thread); if (res != TRI_ERROR_NO_ERROR) { + errno = res; + TRI_set_errno(TRI_ERROR_SYS_ERROR); + LOG_WARNING("unable to stop thread '%s': %s", _name.c_str(), - TRI_errno_string(res)); + TRI_last_error()); } } diff --git a/lib/Utilities/LineEditor.cpp b/lib/Utilities/LineEditor.cpp index 493fa6088b..bf47656247 100644 --- a/lib/Utilities/LineEditor.cpp +++ b/lib/Utilities/LineEditor.cpp @@ -140,9 +140,8 @@ void LineEditor::sortAlternatives (vector& completions) { void LineEditor::prepareShell () { - if (!_shellImpl) { + if (! _shellImpl) { initializeShell(); - // assert _shellImpl != 0; } } // ----------------------------------------------------------------------------- diff --git a/lib/Utilities/ReadlineShell.cpp b/lib/Utilities/ReadlineShell.cpp index 5a70413262..db715243a9 100644 --- a/lib/Utilities/ReadlineShell.cpp +++ b/lib/Utilities/ReadlineShell.cpp @@ -46,8 +46,7 @@ using namespace std; using namespace triagens; namespace { - - Completer * COMPLETER; + Completer* COMPLETER; static char WordBreakCharacters[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@', @@ -59,7 +58,7 @@ namespace { static size_t currentIndex; static vector result; // compute the possible completion - if(state == 0) { + if (state == 0) { COMPLETER->getAlternatives(text, result); LineEditor::sortAlternatives(result); } @@ -74,7 +73,6 @@ namespace { } } - static char** AttemptedCompletion (char const* text, int start, int end) { char** result; @@ -110,15 +108,16 @@ namespace { /// @brief constructs a new editor //////////////////////////////////////////////////////////////////////////////// -ReadlineShell::ReadlineShell(std::string const& history, Completer *completer) +ReadlineShell::ReadlineShell (std::string const& history, + Completer* completer) : ShellImplementation(history, completer) { - COMPLETER = completer; + COMPLETER = completer; - rl_initialize(); + rl_initialize(); - rl_attempted_completion_function = AttemptedCompletion; - rl_completer_word_break_characters = WordBreakCharacters; + rl_attempted_completion_function = AttemptedCompletion; + rl_completer_word_break_characters = WordBreakCharacters; #ifndef __APPLE__ rl_catch_signals = 0; @@ -134,9 +133,8 @@ ReadlineShell::ReadlineShell(std::string const& history, Completer *completer) /// @brief line editor open //////////////////////////////////////////////////////////////////////////////// -bool ReadlineShell::open(bool autoComplete) { +bool ReadlineShell::open (bool autoComplete) { if (autoComplete) { - // issue #289: do not append a space after completion rl_completion_append_character = '\0'; @@ -168,7 +166,6 @@ bool ReadlineShell::open(bool autoComplete) { stifle_history(1000); _state = STATE_OPENED; - return read_history(historyPath().c_str()) == 0; } @@ -176,7 +173,7 @@ bool ReadlineShell::open(bool autoComplete) { /// @brief line editor shutdown //////////////////////////////////////////////////////////////////////////////// -bool ReadlineShell::close() { +bool ReadlineShell::close () { if (_state != STATE_OPENED) { // avoid duplicate saving of history return true; @@ -206,7 +203,7 @@ bool ReadlineShell::close() { /// @brief get the history file path //////////////////////////////////////////////////////////////////////////////// -string ReadlineShell::historyPath() { +string ReadlineShell::historyPath () { string path; if (getenv("HOME")) { @@ -223,7 +220,7 @@ string ReadlineShell::historyPath() { /// @brief add to history //////////////////////////////////////////////////////////////////////////////// -void ReadlineShell::addHistory(char const* str) { +void ReadlineShell::addHistory (char const* str) { if (*str == '\0') { return; } @@ -254,13 +251,14 @@ void ReadlineShell::addHistory(char const* str) { /// @brief save history //////////////////////////////////////////////////////////////////////////////// -bool ReadlineShell::writeHistory() { +bool ReadlineShell::writeHistory () { return (write_history(historyPath().c_str()) == 0); } -char * ReadlineShell::getLine(char const * input) { +char * ReadlineShell::getLine (char const * input) { return readline(input); } + // ----------------------------------------------------------------------------- // --SECTION-- END-OF-FILE // -----------------------------------------------------------------------------