diff options
| author | Naram Qashat <cyberbotx@cyberbotx.com> | 2010-07-28 00:28:59 -0400 |
|---|---|---|
| committer | Naram Qashat <cyberbotx@cyberbotx.com> | 2010-07-28 00:28:59 -0400 |
| commit | aa9610a56ff18edd0703a3f391c90e1f8a761476 (patch) | |
| tree | 5fceef5b811ffcb28bcea093b59604b94a2a89c1 | |
| parent | 4700c9626861b193798b3cf3d53fb89a913c5819 (diff) | |
| parent | a2573a2c3067343ebf46292691671ba4bad855a8 (diff) | |
Merge branch '1.9' of ssh://anope.git.sf.net/gitroot/anope/anope into 1.9
51 files changed, 149 insertions, 88 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 795d04b09..81be03bd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -309,6 +309,11 @@ if(NOT DEFUMASK) endif(RUNGROUP) endif(NOT DEFUMASK) +# Set the DEBUG_BUILD for sysconf.h +if(CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") + set(DEBUG_BUILD TRUE) +endif(CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") + # Check for the existance of the following include files check_include_file(sys/types.h HAVE_SYS_TYPES_H) check_include_file(strings.h HAVE_STRINGS_H) diff --git a/docs/C++CASTING b/docs/C++CASTING index 5a121a5d1..bae24a24c 100644 --- a/docs/C++CASTING +++ b/docs/C++CASTING @@ -78,6 +78,11 @@ This is safer than C-style casting in that an invalid pointer conversion will return a NULL pointer, and an invalid reference conversion will throw a Bad_cast exception. +Note that in Anope we prefer if Anope::debug_cast is used. +This uses dynamic_cast (and checks for a NULL pointer return) on debug builds +and static_cast on release builds, to speed up the program beacuse of dynamic_cast's +reliance on RTTI. + reinterpret_cast ---------------- diff --git a/include/extensible.h b/include/extensible.h index 523a25b6d..5ab32c6eb 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -153,7 +153,7 @@ class CoreExport Extensible if (it != this->Extension_Items.end()) { - p = dynamic_cast<ExtensibleItemRegular<T> *>(it->second)->GetItem(); + p = debug_cast<ExtensibleItemRegular<T> *>(it->second)->GetItem(); return true; } @@ -172,7 +172,7 @@ class CoreExport Extensible if (it != this->Extension_Items.end()) { - p = dynamic_cast<ExtensibleItemPointer<T> *>(it->second)->GetItem(); + p = debug_cast<ExtensibleItemPointer<T> *>(it->second)->GetItem(); return true; } @@ -192,7 +192,7 @@ class CoreExport Extensible if (it != this->Extension_Items.end()) { - p = dynamic_cast<ExtensibleItemPointerArray<T> *>(it->second)->GetItem(); + p = debug_cast<ExtensibleItemPointerArray<T> *>(it->second)->GetItem(); return true; } diff --git a/include/services.h b/include/services.h index 16f365a09..fdbaccbfc 100644 --- a/include/services.h +++ b/include/services.h @@ -39,8 +39,8 @@ #include <sys/stat.h> /* for umask() on some systems */ #include <sys/types.h> -#include <assert.h> #include <fcntl.h> +#include <typeinfo> #ifndef _WIN32 # include <unistd.h> @@ -268,6 +268,22 @@ class DatabaseException : public CoreException virtual ~DatabaseException() throw() { } }; +/** Debug cast to be used instead of dynamic_cast, this uses dynamic_cast + * for debug builds and static_cast on releass builds to speed up the program + * because dynamic_cast relies on RTTI. + */ +template<typename T, typename O> inline T debug_cast(O ptr) +{ +#ifdef DEBUG_BUILD + T ret = dynamic_cast<T>(ptr); + if (ret == NULL) + throw CoreException(Anope::string("debug_cast<") + typeid(T).name() + ">(" + typeid(O).name() + ") fail"); + return ret; +#else + return static_cast<T>(ptr); +#endif +} + /*************************************************************************/ /** Class with the ability to keep flags on items, they should extend from this diff --git a/include/sysconf.h.cmake b/include/sysconf.h.cmake index 5884a3284..0184c5359 100644 --- a/include/sysconf.h.cmake +++ b/include/sysconf.h.cmake @@ -1,6 +1,8 @@ #ifndef _SYSCONF_H_ #define _SYSCONF_H_ +#cmakedefine DEBUG_BUILD + #cmakedefine DEFUMASK @DEFUMASK@ #cmakedefine HAVE_SYS_TYPES_H 1 #cmakedefine HAVE_STDINT_H 1 diff --git a/modules/core/cs_saset_noexpire.cpp b/modules/core/cs_saset_noexpire.cpp index dd485bb40..a89f30c36 100644 --- a/modules/core/cs_saset_noexpire.cpp +++ b/modules/core/cs_saset_noexpire.cpp @@ -23,7 +23,8 @@ class CommandCSSASetNoexpire : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSASetNoexpire"); if (params[1].equals_ci("ON")) { diff --git a/modules/core/cs_set_bantype.cpp b/modules/core/cs_set_bantype.cpp index 3c7e1c11a..90041c7e6 100644 --- a/modules/core/cs_set_bantype.cpp +++ b/modules/core/cs_set_bantype.cpp @@ -23,7 +23,8 @@ class CommandCSSetBanType : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetBanType"); Anope::string end; diff --git a/modules/core/cs_set_description.cpp b/modules/core/cs_set_description.cpp index 82260df63..9186b55ab 100644 --- a/modules/core/cs_set_description.cpp +++ b/modules/core/cs_set_description.cpp @@ -23,7 +23,8 @@ class CommandCSSetDescription : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetDescription"); ci->desc = params[1]; diff --git a/modules/core/cs_set_entrymsg.cpp b/modules/core/cs_set_entrymsg.cpp index 9784773e4..362a5eea3 100644 --- a/modules/core/cs_set_entrymsg.cpp +++ b/modules/core/cs_set_entrymsg.cpp @@ -23,7 +23,8 @@ class CommandCSSetEntryMsg : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetEntryMsg"); if (params.size() > 1) { diff --git a/modules/core/cs_set_founder.cpp b/modules/core/cs_set_founder.cpp index 3982764cc..4fb83a9ec 100644 --- a/modules/core/cs_set_founder.cpp +++ b/modules/core/cs_set_founder.cpp @@ -23,7 +23,8 @@ class CommandCSSetFounder : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetFounder"); if (this->permission.empty() && (ci->HasFlag(CI_SECUREFOUNDER) ? !IsFounder(u, ci) : !check_access(u, ci, CA_FOUNDER))) { diff --git a/modules/core/cs_set_keeptopic.cpp b/modules/core/cs_set_keeptopic.cpp index 5eb907dbd..28a6cd550 100644 --- a/modules/core/cs_set_keeptopic.cpp +++ b/modules/core/cs_set_keeptopic.cpp @@ -23,7 +23,8 @@ class CommandCSSetKeepTopic : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetKeepTopic"); if (params[1].equals_ci("ON")) { diff --git a/modules/core/cs_set_mlock.cpp b/modules/core/cs_set_mlock.cpp index 2dc1ef2a7..ec41913b9 100644 --- a/modules/core/cs_set_mlock.cpp +++ b/modules/core/cs_set_mlock.cpp @@ -23,7 +23,8 @@ class CommandCSSetMLock : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetMLock"); int add = -1; /* 1 if adding, 0 if deleting, -1 if neither */ ChannelMode *cm; @@ -66,7 +67,7 @@ class CommandCSSetMLock : public Command Anope::string param = params[paramcount]; - ChannelModeParam *cmp = dynamic_cast<ChannelModeParam *>(cm); + ChannelModeParam *cmp = debug_cast<ChannelModeParam *>(cm); if (!cmp || !cmp->IsValid(param)) continue; diff --git a/modules/core/cs_set_opnotice.cpp b/modules/core/cs_set_opnotice.cpp index a0d0a2ec8..2b835451c 100644 --- a/modules/core/cs_set_opnotice.cpp +++ b/modules/core/cs_set_opnotice.cpp @@ -23,7 +23,8 @@ class CommandCSSetOpNotice : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetOpNotice"); if (params[1].equals_ci("ON")) { diff --git a/modules/core/cs_set_peace.cpp b/modules/core/cs_set_peace.cpp index b00bf26d5..aa058b416 100644 --- a/modules/core/cs_set_peace.cpp +++ b/modules/core/cs_set_peace.cpp @@ -23,7 +23,8 @@ class CommandCSSetPeace : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetPeace"); if (params[1].equals_ci("ON")) { diff --git a/modules/core/cs_set_persist.cpp b/modules/core/cs_set_persist.cpp index b2876d476..2ab310f2a 100644 --- a/modules/core/cs_set_persist.cpp +++ b/modules/core/cs_set_persist.cpp @@ -23,7 +23,8 @@ class CommandCSSetPersist : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetPersist"); ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_PERM); diff --git a/modules/core/cs_set_private.cpp b/modules/core/cs_set_private.cpp index 8ade236c8..7d1cd0d82 100644 --- a/modules/core/cs_set_private.cpp +++ b/modules/core/cs_set_private.cpp @@ -23,7 +23,8 @@ class CommandCSSetPrivate : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetPrivate"); if (params[1].equals_ci("ON")) { diff --git a/modules/core/cs_set_restricted.cpp b/modules/core/cs_set_restricted.cpp index 82520bbcc..e51024baa 100644 --- a/modules/core/cs_set_restricted.cpp +++ b/modules/core/cs_set_restricted.cpp @@ -22,7 +22,8 @@ class CommandCSSetRestricted : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetRestricted"); if (params[1].equals_ci("ON")) { diff --git a/modules/core/cs_set_secure.cpp b/modules/core/cs_set_secure.cpp index 817608987..98babf1d7 100644 --- a/modules/core/cs_set_secure.cpp +++ b/modules/core/cs_set_secure.cpp @@ -23,7 +23,8 @@ class CommandCSSetSecure : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetSecure"); if (params[1].equals_ci("ON")) { diff --git a/modules/core/cs_set_securefounder.cpp b/modules/core/cs_set_securefounder.cpp index 7c2e310d9..d6ef6aef8 100644 --- a/modules/core/cs_set_securefounder.cpp +++ b/modules/core/cs_set_securefounder.cpp @@ -23,7 +23,8 @@ class CommandCSSetSecureFounder : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetSecureFounder"); if (this->permission.empty() && ci->HasFlag(CI_SECUREFOUNDER) ? !IsFounder(u, ci) : !check_access(u, ci, CA_FOUNDER)) { diff --git a/modules/core/cs_set_secureops.cpp b/modules/core/cs_set_secureops.cpp index 6d705dd6a..c9367dae7 100644 --- a/modules/core/cs_set_secureops.cpp +++ b/modules/core/cs_set_secureops.cpp @@ -23,7 +23,8 @@ class CommandCSSetSecureOps : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetSecureIos"); if (params[1].equals_ci("ON")) { diff --git a/modules/core/cs_set_signkick.cpp b/modules/core/cs_set_signkick.cpp index 93e5c287a..d62a5eec4 100644 --- a/modules/core/cs_set_signkick.cpp +++ b/modules/core/cs_set_signkick.cpp @@ -23,7 +23,8 @@ class CommandCSSetSignKick : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetSignKick"); if (params[1].equals_ci("ON")) { diff --git a/modules/core/cs_set_successor.cpp b/modules/core/cs_set_successor.cpp index 4ba445300..c0c913487 100644 --- a/modules/core/cs_set_successor.cpp +++ b/modules/core/cs_set_successor.cpp @@ -23,7 +23,8 @@ class CommandCSSetSuccessor : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetSuccessor"); if (this->permission.empty() && ci->HasFlag(CI_SECUREFOUNDER) ? !IsFounder(u, ci) : !check_access(u, ci, CA_FOUNDER)) { diff --git a/modules/core/cs_set_topiclock.cpp b/modules/core/cs_set_topiclock.cpp index 26f053b69..b60a687b4 100644 --- a/modules/core/cs_set_topiclock.cpp +++ b/modules/core/cs_set_topiclock.cpp @@ -23,7 +23,8 @@ class CommandCSSetTopicLock : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetTopicLock"); if (params[1].equals_ci("ON")) { diff --git a/modules/core/cs_set_xop.cpp b/modules/core/cs_set_xop.cpp index 37247f394..c7d4017b0 100644 --- a/modules/core/cs_set_xop.cpp +++ b/modules/core/cs_set_xop.cpp @@ -30,7 +30,8 @@ class CommandCSSetXOP : public Command } ChannelInfo *ci = cs_findchan(params[0]); - assert(ci); + if (!ci) + throw CoreException("NULL ci in CommandCSSetXOP"); if (params[1].equals_ci("ON")) { diff --git a/modules/core/db_plain.cpp b/modules/core/db_plain.cpp index 331901f86..a9d87fab7 100644 --- a/modules/core/db_plain.cpp +++ b/modules/core/db_plain.cpp @@ -1014,7 +1014,7 @@ class DBPlain : public Module { if ((*it)->Class == MC_CHANNEL) { - ChannelMode *cm = dynamic_cast<ChannelMode *>(*it); + ChannelMode *cm = debug_cast<ChannelMode *>(*it); if (ci->HasMLock(cm->Name, true)) db << " " << cm->NameAsString; @@ -1029,7 +1029,7 @@ class DBPlain : public Module { if ((*it)->Class == MC_CHANNEL) { - ChannelMode *cm = dynamic_cast<ChannelMode *>(*it); + ChannelMode *cm = debug_cast<ChannelMode *>(*it); if (ci->HasMLock(cm->Name, false)) db << " " << cm->NameAsString; @@ -1042,7 +1042,7 @@ class DBPlain : public Module { if ((*it)->Class == MC_CHANNEL) { - ChannelMode *cm = dynamic_cast<ChannelMode *>(*it); + ChannelMode *cm = debug_cast<ChannelMode *>(*it); if (ci->GetParam(cm->Name, Param)) db << "MD MLP " << cm->NameAsString << " " << Param << endl; diff --git a/modules/core/ns_saset.cpp b/modules/core/ns_saset.cpp index 4beccbcad..081e1d466 100644 --- a/modules/core/ns_saset.cpp +++ b/modules/core/ns_saset.cpp @@ -128,7 +128,8 @@ class CommandNSSASetDisplay : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); - assert(nc); + if (!nc) + throw CoreException("NULL nc in CommandNSSASetDisplay"); NickAlias *na = findnick(params[1]); if (!na || na->nc != nc) @@ -170,7 +171,8 @@ class CommandNSSASetPassword : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); - assert(nc); + if (!nc) + throw CoreException("NULL nc in CommandNSSASetPassword"); size_t len = params[1].length(); diff --git a/modules/core/ns_saset_noexpire.cpp b/modules/core/ns_saset_noexpire.cpp index 2c8f93243..62b93d7e9 100644 --- a/modules/core/ns_saset_noexpire.cpp +++ b/modules/core/ns_saset_noexpire.cpp @@ -23,7 +23,8 @@ class CommandNSSASetNoexpire : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickAlias *na = findnick(params[0]); - assert(na); + if (!na) + throw CoreException("NULL na in CommandNSSASsetNoexpire"); Anope::string param = params.size() > 1 ? params[1] : ""; diff --git a/modules/core/ns_set_autoop.cpp b/modules/core/ns_set_autoop.cpp index 2c8c8b1c4..da8b8ccb9 100644 --- a/modules/core/ns_set_autoop.cpp +++ b/modules/core/ns_set_autoop.cpp @@ -65,7 +65,8 @@ class CommandNSSASetAutoOp : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); - assert(nc); + if (!nc) + throw CoreException("NULL nc in CommandNSSASetAutoOp"); Anope::string param = params[1]; diff --git a/modules/core/ns_set_email.cpp b/modules/core/ns_set_email.cpp index bf3162611..070e93026 100644 --- a/modules/core/ns_set_email.cpp +++ b/modules/core/ns_set_email.cpp @@ -71,7 +71,8 @@ class CommandNSSASetEmail : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); - assert(nc); + if (!nc) + throw CoreException("NULL nc in CommandNSSASetEmail"); Anope::string param = params.size() > 1 ? params[1] : ""; diff --git a/modules/core/ns_set_greet.cpp b/modules/core/ns_set_greet.cpp index 128257924..4704bf1ca 100644 --- a/modules/core/ns_set_greet.cpp +++ b/modules/core/ns_set_greet.cpp @@ -58,7 +58,8 @@ class CommandNSSASetGreet : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); - assert(nc); + if (!nc) + throw CoreException("NULL nc in CommandNSSASetGreet"); Anope::string param = params.size() > 1 ? params[1] : ""; diff --git a/modules/core/ns_set_hide.cpp b/modules/core/ns_set_hide.cpp index 5eaa1f39c..8432794ff 100644 --- a/modules/core/ns_set_hide.cpp +++ b/modules/core/ns_set_hide.cpp @@ -98,7 +98,8 @@ class CommandNSSASetHide : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); - assert(nc); + if (!nc) + throw CoreException("NULL nc in CommandNSSASetHide"); Anope::string param = params[1]; diff --git a/modules/core/ns_set_kill.cpp b/modules/core/ns_set_kill.cpp index f7312710f..cad473543 100644 --- a/modules/core/ns_set_kill.cpp +++ b/modules/core/ns_set_kill.cpp @@ -88,7 +88,8 @@ class CommandNSSASetKill : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); - assert(nc); + if (!nc) + throw CoreException("NULL nc in CommandNSSASetKill"); Anope::string param = params[1]; diff --git a/modules/core/ns_set_language.cpp b/modules/core/ns_set_language.cpp index 06f29ae48..c76bf0fef 100644 --- a/modules/core/ns_set_language.cpp +++ b/modules/core/ns_set_language.cpp @@ -70,7 +70,8 @@ class CommandNSSASetLanguage : public Command CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) { NickCore *nc = findcore(params[0]); - assert(nc); + if (!nc) + throw CoreException("NULL nc in CommandNSSASetLanguage"); Anope::string param = params[1]; diff --git a/modules/core/ns_set_message.cpp b/modules/core/ns_set_message.cpp i |
