From 6dc60370a750334cb701386cfa4ef9719db9078a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 30 Mar 2010 12:38:38 +0200 Subject: replace every call to toupper with one to our own tolower_ascii This sounds like a premature optimization and since Mr. Knuth we all know that they are the root of all evil - but, and here it starts to be interesting: As the tolower_ascii method is by far the most called method we have (~60 Mio. times) and as we compare only strings containing ascii characters (package names, configuration options) using our own method reduces execution time of APT by 4% plus it avoids that the locale settings can influence us. --- apt-pkg/contrib/error.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'apt-pkg/contrib/error.h') diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h index 90747ff7e..8d5ec05ea 100644 --- a/apt-pkg/contrib/error.h +++ b/apt-pkg/contrib/error.h @@ -60,13 +60,13 @@ class GlobalError public: // Call to generate an error from a library call. - bool Errno(const char *Function,const char *Description,...) __like_printf_2 __cold; - bool WarningE(const char *Function,const char *Description,...) __like_printf_2 __cold; + bool Errno(const char *Function,const char *Description,...) __like_printf(3) __cold; + bool WarningE(const char *Function,const char *Description,...) __like_printf(3) __cold; /* A warning should be considered less severe than an error, and may be ignored by the client. */ - bool Error(const char *Description,...) __like_printf_1 __cold; - bool Warning(const char *Description,...) __like_printf_1 __cold; + bool Error(const char *Description,...) __like_printf(2) __cold; + bool Warning(const char *Description,...) __like_printf(2) __cold; // Simple accessors inline bool PendingError() {return PendingFlag;}; -- cgit v1.2.3 From 98ee7cd35cf205c52b3698ee91cec76d704a3937 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 25 Jun 2010 08:01:48 +0200 Subject: * apt-pkg/contrib/error.{cc,h}: - complete rewrite but use the same API - add NOTICE and DEBUG as new types of a message --- apt-pkg/contrib/error.h | 230 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 201 insertions(+), 29 deletions(-) (limited to 'apt-pkg/contrib/error.h') diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h index 8d5ec05ea..fc7b38f1b 100644 --- a/apt-pkg/contrib/error.h +++ b/apt-pkg/contrib/error.h @@ -42,43 +42,215 @@ #include +#include +#include #include -class GlobalError +#include + +class GlobalError /*{{{*/ { - struct Item - { - std::string Text; - bool Error; - Item *Next; - }; - - Item *List; - bool PendingFlag; - void Insert(Item *I); - - public: +public: /*{{{*/ + /** \brief a message can have one of following severity */ + enum MsgType { + /** \brief Message will be printed instantly as it is likely that + this error will lead to a complete crash */ + FATAL = 40, + /** \brief An error does hinder the correct execution and should be corrected */ + ERROR = 30, + /** \brief indicates problem that can lead to errors later on */ + WARNING = 20, + /** \brief deprecation warnings, old fallback behavior, … */ + NOTICE = 10, + /** \brief for developers only in areas it is hard to print something directly */ + DEBUG = 0 + }; - // Call to generate an error from a library call. - bool Errno(const char *Function,const char *Description,...) __like_printf(3) __cold; - bool WarningE(const char *Function,const char *Description,...) __like_printf(3) __cold; + /** \brief add a fatal error message with errno to the list + * + * \param Function name of the function generating the error + * \param Description format string for the error message + * + * \return \b false + */ + bool FatalE(const char *Function,const char *Description,...) __like_printf(3) __cold; - /* A warning should be considered less severe than an error, and may be - ignored by the client. */ - bool Error(const char *Description,...) __like_printf(2) __cold; - bool Warning(const char *Description,...) __like_printf(2) __cold; + /** \brief add an Error message with errno to the list + * + * \param Function name of the function generating the error + * \param Description format string for the error message + * + * \return \b false + */ + bool Errno(const char *Function,const char *Description,...) __like_printf(3) __cold; - // Simple accessors - inline bool PendingError() {return PendingFlag;}; - inline bool empty() {return List == 0;}; - bool PopMessage(std::string &Text); - void Discard(); + /** \brief add a warning message with errno to the list + * + * A warning should be considered less severe than an error and + * may be ignored by the client. + * + * \param Function Name of the function generates the warning. + * \param Description Format string for the warning message. + * + * \return \b false + */ + bool WarningE(const char *Function,const char *Description,...) __like_printf(3) __cold; - // Usefull routine to dump to cerr - void DumpErrors(); - - GlobalError(); + /** \brief add a notice message with errno to the list + * + * \param Function name of the function generating the error + * \param Description format string for the error message + * + * \return \b false + */ + bool NoticeE(const char *Function,const char *Description,...) __like_printf(3) __cold; + + /** \brief add a debug message with errno to the list + * + * \param Function name of the function generating the error + * \param Description format string for the error message + * + * \return \b false + */ + bool DebugE(const char *Function,const char *Description,...) __like_printf(3) __cold; + + /** \brief add an fatal error message to the list + * + * Most of the stuff we consider as "error" is also "fatal" for + * the user as the application will not have the expected result, + * but a fatal message here means that it gets printed directly + * to stderr in addiction to adding it to the list as the error + * leads sometimes to crashes and a maybe duplicated message + * is better than "Segfault" as the only displayed text + * + * \param Description Format string for the fatal error message. + * + * \return \b false + */ + bool Fatal(const char *Description,...) __like_printf(2) __cold; + + /** \brief add an Error message to the list + * + * \param Description Format string for the error message. + * + * \return \b false + */ + bool Error(const char *Description,...) __like_printf(2) __cold; + + /** \brief add a warning message to the list + * + * A warning should be considered less severe than an error and + * may be ignored by the client. + * + * \param Description Format string for the message + * + * \return \b false + */ + bool Warning(const char *Description,...) __like_printf(2) __cold; + + /** \brief add a notice message to the list + * + * A notice should be considered less severe than an error or a + * warning and can be ignored by the client without further problems + * for some times, but he should consider fixing the problem. + * This error type can be used for e.g. deprecation warnings of options. + * + * \param Description Format string for the message + * + * \return \b false + */ + bool Notice(const char *Description,...) __like_printf(2) __cold; + + /** \brief add a debug message to the list + * + * \param Description Format string for the message + * + * \return \b false + */ + bool Debug(const char *Description,...) __like_printf(2) __cold; + + /** \brief is an error in the list? + * + * \return \b true if an error is included in the list, \b false otherwise + */ + inline bool PendingError() const {return PendingFlag;}; + + /** \brief is the list empty? + * + * The default checks if the list is empty or contains only notices, + * if you want to check if also no notices happend set the parameter + * flag to \b false. + * + * \param WithoutNotice does notices count, default is \b true, so no + * + * \return \b true if an the list is empty, \b false otherwise + */ + bool empty(MsgType const &trashhold = WARNING) const; + + /** \brief returns and removes the first (or last) message in the list + * + * \param[out] Text message of the first/last item + * + * \return \b true if the message was an error, \b false otherwise + */ + bool PopMessage(std::string &Text); + + /** \brief clears the list of messages */ + void Discard(); + + /** \brief outputs the list of messages to the given stream + * + * Note that all messages are discarded, also the notices + * displayed or not. + * + * \param[out] out output stream to write the messages in + * \param WithoutNotice output notices or not + */ + void DumpErrors(std::ostream &out, MsgType const &trashhold = WARNING); + + /** \brief dumps the list of messages to std::cerr + * + * Note that all messages are discarded, also the notices + * displayed or not. + * + * \param WithoutNotice print notices or not + */ + void inline DumpErrors(MsgType const &trashhold = WARNING) { + DumpErrors(std::cerr, trashhold); + } + + GlobalError(); + /*}}}*/ +private: /*{{{*/ + struct Item { + std::string Text; + MsgType Type; + + Item(char const *Text, MsgType const &Type) : + Text(Text), Type(Type) {}; + + friend std::ostream& operator<< (std::ostream &out, Item i) { + switch(i.Type) { + case FATAL: + case ERROR: out << "E"; break; + case WARNING: out << "W"; break; + case NOTICE: out << "N"; break; + case DEBUG: out << "D"; break; + } + return out << ": " << i.Text; + } + }; + + std::list Messages; + bool PendingFlag; + + bool InsertErrno(MsgType type, const char* Function, + const char* Description, va_list const &args); + bool Insert(MsgType type, const char* Description, + va_list const &args); + /*}}}*/ }; + /*}}}*/ // The 'extra-ansi' syntax is used to help with collisions. GlobalError *_GetErrorObj(); -- cgit v1.2.3 From c4ba7c44ff03d67ff982bbab26dc48d796041e02 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 25 Jun 2010 19:16:12 +0200 Subject: add a simple stack handling to be able to delay error handling --- apt-pkg/contrib/error.h | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'apt-pkg/contrib/error.h') diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h index fc7b38f1b..73735162d 100644 --- a/apt-pkg/contrib/error.h +++ b/apt-pkg/contrib/error.h @@ -206,7 +206,8 @@ public: /*{{{*/ * \param[out] out output stream to write the messages in * \param WithoutNotice output notices or not */ - void DumpErrors(std::ostream &out, MsgType const &trashhold = WARNING); + void DumpErrors(std::ostream &out, MsgType const &trashhold = WARNING, + bool const &mergeStack = true); /** \brief dumps the list of messages to std::cerr * @@ -219,6 +220,28 @@ public: /*{{{*/ DumpErrors(std::cerr, trashhold); } + /** \brief put the current Messages into the stack + * + * All "old" messages will be pushed into a stack to + * them later back, but for now the Message query will be + * empty and performs as no messages were present before. + * + * The stack can be as deep as you want - all stack operations + * will only operate on the last element in the stack. + */ + void PushToStack(); + + /** \brief throw away all current messages */ + void RevertToStack(); + + /** \brief merge current and stack together */ + void MergeWithStack(); + + /** \brief return the deep of the stack */ + size_t StackCount() const { + return Stacks.size(); + } + GlobalError(); /*}}}*/ private: /*{{{*/ @@ -244,6 +267,16 @@ private: /*{{{*/ std::list Messages; bool PendingFlag; + struct MsgStack { + std::list const Messages; + bool const PendingFlag; + + MsgStack(std::list const &Messages, bool const &Pending) : + Messages(Messages), PendingFlag(Pending) {}; + }; + + std::list Stacks; + bool InsertErrno(MsgType type, const char* Function, const char* Description, va_list const &args); bool Insert(MsgType type, const char* Description, -- cgit v1.2.3 From 3c0929ecbeab50de9d38edc2eaebe92aeee65baf Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 10 Jul 2010 13:51:47 +0200 Subject: * apt-pkg/contrib/error.{cc,h}: - remove constness of va_list parameter to fix build on amd64 and co Thanks Eric Valette! (Closes: #588610) --- apt-pkg/contrib/error.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apt-pkg/contrib/error.h') diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h index 73735162d..e5517c2da 100644 --- a/apt-pkg/contrib/error.h +++ b/apt-pkg/contrib/error.h @@ -278,9 +278,9 @@ private: /*{{{*/ std::list Stacks; bool InsertErrno(MsgType type, const char* Function, - const char* Description, va_list const &args); + const char* Description, va_list &args); bool Insert(MsgType type, const char* Description, - va_list const &args); + va_list &args); /*}}}*/ }; /*}}}*/ -- cgit v1.2.3 From 12be8a62d1abb9253a4695badbf70e7210f9b0d2 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 29 Jul 2010 14:37:36 +0200 Subject: * apt-pkg/contrib/error.{cc,h} - docstring cleanup --- apt-pkg/contrib/error.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'apt-pkg/contrib/error.h') diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h index e5517c2da..d39500427 100644 --- a/apt-pkg/contrib/error.h +++ b/apt-pkg/contrib/error.h @@ -204,9 +204,10 @@ public: /*{{{*/ * displayed or not. * * \param[out] out output stream to write the messages in - * \param WithoutNotice output notices or not + * \param threshold minimim level considered + * \param mergeStack */ - void DumpErrors(std::ostream &out, MsgType const &trashhold = WARNING, + void DumpErrors(std::ostream &out, MsgType const &threshold = WARNING, bool const &mergeStack = true); /** \brief dumps the list of messages to std::cerr @@ -214,10 +215,10 @@ public: /*{{{*/ * Note that all messages are discarded, also the notices * displayed or not. * - * \param WithoutNotice print notices or not + * \param threshold minimum level printed */ - void inline DumpErrors(MsgType const &trashhold = WARNING) { - DumpErrors(std::cerr, trashhold); + void inline DumpErrors(MsgType const &threshold = WARNING) { + DumpErrors(std::cerr, threshold); } /** \brief put the current Messages into the stack -- cgit v1.2.3 From ca0d389c8969ddb679358ca16e4bcddfcdaf9b03 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 29 Jul 2010 14:51:05 +0200 Subject: add inline DumpError() to avoid subtle API break --- apt-pkg/contrib/error.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'apt-pkg/contrib/error.h') diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h index d39500427..4af0302c0 100644 --- a/apt-pkg/contrib/error.h +++ b/apt-pkg/contrib/error.h @@ -217,10 +217,22 @@ public: /*{{{*/ * * \param threshold minimum level printed */ - void inline DumpErrors(MsgType const &threshold = WARNING) { + void inline DumpErrors(MsgType const &threshold) { DumpErrors(std::cerr, threshold); } + // mvo: we do this instead of using a default parameter in the + // previous declaration to avoid a (subtle) API break for + // e.g. sigc++ and mem_fun0 + /** \brief dumps the messages of type WARNING or higher to std::cerr + * + * Note that all messages are discarded, displayed or not. + * + */ + void inline DumpErrors() { + DumpErrors(WARNING); + } + /** \brief put the current Messages into the stack * * All "old" messages will be pushed into a stack to -- cgit v1.2.3 From cd7bbc479f8e2f277092a9557bb486ab664deba6 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 30 Jul 2010 09:51:42 +0200 Subject: - [ABI BREAK] add an ErrorType option to CacheSetHelper * cmdline/apt-cache.cc: - use Notice instead of Error in the CacheSetHelper messages for compat reasons. Otherwise tools like sbuild blow up --- apt-pkg/contrib/error.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'apt-pkg/contrib/error.h') diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h index 4af0302c0..ae756dbc4 100644 --- a/apt-pkg/contrib/error.h +++ b/apt-pkg/contrib/error.h @@ -114,6 +114,15 @@ public: /*{{{*/ */ bool DebugE(const char *Function,const char *Description,...) __like_printf(3) __cold; + /** \brief adds an errno message with the given type + * + * \param type of the error message + * \param Function which failed + * \param Description of the error + */ + bool InsertErrno(MsgType const &type, const char* Function, + const char* Description,...) __like_printf(4) __cold; + /** \brief add an fatal error message to the list * * Most of the stuff we consider as "error" is also "fatal" for @@ -169,6 +178,13 @@ public: /*{{{*/ */ bool Debug(const char *Description,...) __like_printf(2) __cold; + /** \brief adds an error message with the given type + * + * \param type of the error message + * \param Description of the error + */ + bool Insert(MsgType const &type, const char* Description,...) __like_printf(3) __cold; + /** \brief is an error in the list? * * \return \b true if an error is included in the list, \b false otherwise -- cgit v1.2.3