diff --git a/arangod/Documentation/glossary.dox b/arangod/Documentation/glossary.dox index 1233de6caf..2fccb9b1ff 100644 --- a/arangod/Documentation/glossary.dox +++ b/arangod/Documentation/glossary.dox @@ -125,7 +125,7 @@ /// /// @GE{Edge}: Edges in ArangoDB are special documents. In addition to the /// internal attributes @LIT{_id} and @LIT{_rev}, they have two attributes -/// @LIT{_form} and @LIT{_to}, which contain document handles namely the +/// @LIT{_from} and @LIT{_to}, which contain document handles namely the /// start-point and the end-point of the edge. /// /// @page GlossaryEdgeCollection diff --git a/arangod/RestHandler/RestImportHandler.cpp b/arangod/RestHandler/RestImportHandler.cpp index 965e6a9522..c2f4cde883 100644 --- a/arangod/RestHandler/RestImportHandler.cpp +++ b/arangod/RestHandler/RestImportHandler.cpp @@ -482,7 +482,7 @@ TRI_json_t* RestImportHandler::parseJsonLine (const string& line) { if (errmsg != 0) { // must free this error message, otherwise we'll have a memleak - TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, errmsg); + TRI_FreeString(TRI_CORE_MEM_ZONE, errmsg); } return json; } diff --git a/arangod/RestServer/ArangoServer.cpp b/arangod/RestServer/ArangoServer.cpp index 5f62f2638e..0cac392fa8 100644 --- a/arangod/RestServer/ArangoServer.cpp +++ b/arangod/RestServer/ArangoServer.cpp @@ -721,7 +721,7 @@ int ArangoServer::executeConsole (OperationMode::server_operation_mode_e mode) { } // ............................................................................. - // run console + // run script // ............................................................................. case OperationMode::MODE_SCRIPT: { @@ -787,15 +787,15 @@ int ArangoServer::executeConsole (OperationMode::server_operation_mode_e mode) { case OperationMode::MODE_CONSOLE: { context->_context->Global()->Set(v8::String::New("DATABASEPATH"), v8::String::New(_databasePath.c_str()), v8::ReadOnly); context->_context->Global()->Set(v8::String::New("VALGRIND"), _runningOnValgrind ? v8::True() : v8::False(), v8::ReadOnly); - V8LineEditor* console = new V8LineEditor(context->_context, ".arango"); + V8LineEditor console(context->_context, ".arango"); - console->open(true); + console.open(true); while (true) { while(! v8::V8::IdleNotification()) { } - char* input = console->prompt("arangod> "); + char* input = console.prompt("arangod> "); if (input == 0) { printf("\n%s\n", TRI_BYE_MESSAGE); @@ -807,7 +807,7 @@ int ArangoServer::executeConsole (OperationMode::server_operation_mode_e mode) { continue; } - console->addHistory(input); + console.addHistory(input); v8::HandleScope scope; v8::TryCatch tryCatch; @@ -819,11 +819,7 @@ int ArangoServer::executeConsole (OperationMode::server_operation_mode_e mode) { cout << TRI_StringifyV8Exception(&tryCatch); } } - - console->close(); - - delete console; - + break; } @@ -962,12 +958,12 @@ int ArangoServer::executeRubyConsole () { // create a line editor printf("ArangoDB MRuby shell [DB version %s]\n", TRIAGENS_VERSION); - MRLineEditor* console = new MRLineEditor(context->_mrb, ".arango-mrb"); + MRLineEditor console(context->_mrb, ".arango-mrb"); - console->open(false); + console.open(false); while (true) { - char* input = console->prompt("arangod> "); + char* input = console.prompt("arangod> "); if (input == 0) { printf("\n" TRI_BYE_MESSAGE "\n"); @@ -979,7 +975,7 @@ int ArangoServer::executeRubyConsole () { continue; } - console->addHistory(input); + console.addHistory(input); struct mrb_parser_state* p = mrb_parse_string(context->_mrb, input, NULL); TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, input); @@ -1011,8 +1007,7 @@ int ArangoServer::executeRubyConsole () { } // close the console - console->close(); - delete console; + console.close(); // close the database closeDatabase(); diff --git a/arangod/SkipLists/skiplist.c b/arangod/SkipLists/skiplist.c index 700acbcb5e..c457fe7680 100755 --- a/arangod/SkipLists/skiplist.c +++ b/arangod/SkipLists/skiplist.c @@ -400,6 +400,7 @@ void TRI_InitSkipList (TRI_skiplist_t* skiplist, size_t elementSize, // do it here once off. // .......................................................................... skiplist->_base._random = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(uint32_t) * skiplist->_base._numRandom, false); + // TODO: memory allocation might fail // .......................................................................... // Assign the element size diff --git a/arangod/V8Server/v8-query.cpp b/arangod/V8Server/v8-query.cpp index 3a014feb13..13212149c7 100755 --- a/arangod/V8Server/v8-query.cpp +++ b/arangod/V8Server/v8-query.cpp @@ -2528,22 +2528,22 @@ void TRI_InitV8Queries (v8::Handle context) { rt = v8g->VocbaseColTempl; rt->Set(AllFuncName, v8::FunctionTemplate::New(JS_AllQuery)); - rt->Set(AllNLFuncName, v8::FunctionTemplate::New(JS_AllNLQuery)); + rt->Set(AllNLFuncName, v8::FunctionTemplate::New(JS_AllNLQuery), v8::DontEnum); rt->Set(ByConditionBitarrayFuncName, v8::FunctionTemplate::New(JS_ByConditionBitarray)); - rt->Set(ByConditionBitarrayNLFuncName, v8::FunctionTemplate::New(JS_ByConditionNLBitarray)); + rt->Set(ByConditionBitarrayNLFuncName, v8::FunctionTemplate::New(JS_ByConditionNLBitarray), v8::DontEnum); rt->Set(ByConditionSkiplistFuncName, v8::FunctionTemplate::New(JS_ByConditionSkiplist)); - rt->Set(ByConditionSkiplistNLFuncName, v8::FunctionTemplate::New(JS_ByConditionNLSkiplist)); + rt->Set(ByConditionSkiplistNLFuncName, v8::FunctionTemplate::New(JS_ByConditionNLSkiplist), v8::DontEnum); rt->Set(ByExampleBitarrayFuncName, v8::FunctionTemplate::New(JS_ByExampleBitarray)); - rt->Set(ByExampleBitarrayNLFuncName, v8::FunctionTemplate::New(JS_ByExampleNLBitarray)); + rt->Set(ByExampleBitarrayNLFuncName, v8::FunctionTemplate::New(JS_ByExampleNLBitarray), v8::DontEnum); rt->Set(ByExampleFuncName, v8::FunctionTemplate::New(JS_ByExampleQuery)); rt->Set(ByExampleHashFuncName, v8::FunctionTemplate::New(JS_ByExampleHashIndex)); - rt->Set(ByExampleHashNLFuncName, v8::FunctionTemplate::New(JS_ByExampleNLHashIndex)); + rt->Set(ByExampleHashNLFuncName, v8::FunctionTemplate::New(JS_ByExampleNLHashIndex), v8::DontEnum); rt->Set(ByExampleSkiplistFuncName, v8::FunctionTemplate::New(JS_ByExampleSkiplist)); - rt->Set(ByExampleSkiplistNLFuncName, v8::FunctionTemplate::New(JS_ByExampleNLSkiplist)); + rt->Set(ByExampleSkiplistNLFuncName, v8::FunctionTemplate::New(JS_ByExampleNLSkiplist), v8::DontEnum); rt->Set(NearFuncName, v8::FunctionTemplate::New(JS_NearQuery)); - rt->Set(NearNLFuncName, v8::FunctionTemplate::New(JS_NearNLQuery)); + rt->Set(NearNLFuncName, v8::FunctionTemplate::New(JS_NearNLQuery), v8::DontEnum); rt->Set(WithinFuncName, v8::FunctionTemplate::New(JS_WithinQuery)); - rt->Set(WithinNLFuncName, v8::FunctionTemplate::New(JS_WithinNLQuery)); + rt->Set(WithinNLFuncName, v8::FunctionTemplate::New(JS_WithinNLQuery), v8::DontEnum); rt->Set(EdgesFuncName, v8::FunctionTemplate::New(JS_EdgesQuery)); rt->Set(InEdgesFuncName, v8::FunctionTemplate::New(JS_InEdgesQuery)); rt->Set(OutEdgesFuncName, v8::FunctionTemplate::New(JS_OutEdgesQuery)); diff --git a/arangod/VocBase/document-collection.c b/arangod/VocBase/document-collection.c index 03971e41ec..481ac753d3 100755 --- a/arangod/VocBase/document-collection.c +++ b/arangod/VocBase/document-collection.c @@ -1011,8 +1011,10 @@ static TRI_doc_mptr_t CreateShapedJson (TRI_primary_collection_t* primary, marker._shape = json->_sid; return CreateDocument(collection, - &marker, sizeof(marker), - json->_data.data, json->_data.length, + &marker, + sizeof(marker), + json->_data.data, + json->_data.length, &result, data, did, @@ -1128,8 +1130,10 @@ static TRI_doc_mptr_t UpdateShapedJson (TRI_primary_collection_t* primary, return UpdateDocument(collection, header, - &marker, sizeof(marker), - json->_data.data, json->_data.length, + &marker, + sizeof(marker), + json->_data.data, + json->_data.length, rid, oldRid, policy, diff --git a/arangod/VocBase/headers.c b/arangod/VocBase/headers.c index bd7746f0a8..6526ce4410 100644 --- a/arangod/VocBase/headers.c +++ b/arangod/VocBase/headers.c @@ -91,7 +91,7 @@ static TRI_doc_mptr_t* RequestSimpleHeaders (TRI_headers_t* h) { begin = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, NUMBER_HEADERS_PER_BLOCK * headers->_headerSize, false); // out of memory - if (!begin) { + if (begin == NULL) { TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY); return NULL; } diff --git a/arangoirb/MRClient/arangoirb.cpp b/arangoirb/MRClient/arangoirb.cpp index c19786a6d5..7fe2ae89eb 100644 --- a/arangoirb/MRClient/arangoirb.cpp +++ b/arangoirb/MRClient/arangoirb.cpp @@ -244,12 +244,12 @@ static void InitMRClientConnection (mrb_state* mrb, MRubyClientConnection* conne //////////////////////////////////////////////////////////////////////////////// static void RunShell (mrb_state* mrb) { - MRLineEditor* console = new MRLineEditor(mrb, ".arango-mrb"); + MRLineEditor* console(mrb, ".arango-mrb"); - console->open(false /*! NoAutoComplete*/); + console.open(false /*! NoAutoComplete*/); while (true) { - char* input = console->prompt("arangoirb> "); + char* input = console.prompt("arangoirb> "); if (input == 0) { break; @@ -260,7 +260,7 @@ static void RunShell (mrb_state* mrb) { continue; } - console->addHistory(input); + console.addHistory(input); struct mrb_parser_state* p = mrb_parse_nstring(mrb, input, strlen(input), NULL); TRI_FreeString(TRI_CORE_MEM_ZONE, input); @@ -291,7 +291,7 @@ static void RunShell (mrb_state* mrb) { } } - console->close(); + console.close(); cout << endl; diff --git a/arangosh/V8Client/arangosh.cpp b/arangosh/V8Client/arangosh.cpp index 2ca1a3fc62..6e8e09fee3 100644 --- a/arangosh/V8Client/arangosh.cpp +++ b/arangosh/V8Client/arangosh.cpp @@ -809,15 +809,15 @@ static void RunShell (v8::Handle context) { v8::Context::Scope contextScope(context); v8::Local name(v8::String::New("(shell)")); - V8LineEditor* console = new V8LineEditor(context, ".arangosh"); + V8LineEditor console(context, ".arangosh"); - console->open(BaseClient.autoComplete()); + console.open(BaseClient.autoComplete()); while (true) { while (! v8::V8::IdleNotification()) { } - char* input = console->prompt("arangosh> "); + char* input = console.prompt("arangosh> "); if (input == 0) { break; @@ -839,7 +839,7 @@ static void RunShell (v8::Handle context) { input = TRI_DuplicateString("help()"); } - console->addHistory(input); + console.addHistory(input); v8::HandleScope scope; v8::TryCatch tryCatch; @@ -856,9 +856,7 @@ static void RunShell (v8::Handle context) { BaseClient.stopPager(); } - console->close(); - - delete console; + console.close(); cout << endl; diff --git a/lib/Scheduler/SocketTask.cpp b/lib/Scheduler/SocketTask.cpp index e7bc7ab4c0..9f149f2073 100644 --- a/lib/Scheduler/SocketTask.cpp +++ b/lib/Scheduler/SocketTask.cpp @@ -159,7 +159,7 @@ bool SocketTask::fillReadBuffer (bool& closed) { else if (nr == 0) { closed = true; - LOGGER_TRACE << "read return 0 with " << errno << " (" << strerror(errno) << ")"; + LOGGER_TRACE << "read returned 0"; return false; } diff --git a/lib/Utilities/LineEditor.cpp b/lib/Utilities/LineEditor.cpp index a3ccf8c9ec..7c97db743d 100644 --- a/lib/Utilities/LineEditor.cpp +++ b/lib/Utilities/LineEditor.cpp @@ -53,7 +53,8 @@ using namespace std; LineEditor::LineEditor (std::string const& history) : _current(), - _historyFilename(history) { + _historyFilename(history), + _state(STATE_NONE) { rl_initialize(); } @@ -62,6 +63,7 @@ LineEditor::LineEditor (std::string const& history) //////////////////////////////////////////////////////////////////////////////// LineEditor::~LineEditor () { + close(); } //////////////////////////////////////////////////////////////////////////////// @@ -85,6 +87,8 @@ bool LineEditor::open (bool) { using_history(); stifle_history(MAX_HISTORY_ENTRIES); + _state = STATE_OPENED; + return read_history(historyPath().c_str()) == 0; } @@ -93,6 +97,13 @@ bool LineEditor::open (bool) { //////////////////////////////////////////////////////////////////////////////// bool LineEditor::close () { + if (_state != STATE_OPENED) { + // avoid duplicate saving of history + return true; + } + + _state = STATE_CLOSED; + return (write_history(historyPath().c_str()) == 0); } diff --git a/lib/Utilities/LineEditor.h b/lib/Utilities/LineEditor.h index 55a9b93c48..f8d10b068a 100644 --- a/lib/Utilities/LineEditor.h +++ b/lib/Utilities/LineEditor.h @@ -166,6 +166,33 @@ class LineEditor { /// @} //////////////////////////////////////////////////////////////////////////////// +// ----------------------------------------------------------------------------- +// --SECTION-- private types +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @addtogroup LineEditor +/// @{ +//////////////////////////////////////////////////////////////////////////////// + + private: + +//////////////////////////////////////////////////////////////////////////////// +/// @brief state of the console +//////////////////////////////////////////////////////////////////////////////// + + typedef enum { + STATE_NONE = 0, + STATE_OPENED, + STATE_CLOSED, + } + console_state_e; + +//////////////////////////////////////////////////////////////////////////////// +/// @} +//////////////////////////////////////////////////////////////////////////////// + + // ----------------------------------------------------------------------------- // --SECTION-- protected variables // ----------------------------------------------------------------------------- @@ -188,6 +215,12 @@ class LineEditor { //////////////////////////////////////////////////////////////////////////////// std::string _historyFilename; + +//////////////////////////////////////////////////////////////////////////////// +/// @brief current console state +//////////////////////////////////////////////////////////////////////////////// + + console_state_e _state; }; ////////////////////////////////////////////////////////////////////////////////