From b9772d48fed63a4863869751c4bc0cb3842c40b5 Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Thu, 24 Jan 2002 09:20:51 +0000 Subject: [PATCH] Fixing bug 120899. Changing the NS_WARN_IF_FALSE() macro so that it can't be mis-used in optimized builds. This change makes the macro not usable in expressions that are supposed to be evaluated in release code since the macro now expands to nothing in non-debug builds. Also eliminate NS_VALIDATE which is equally mis-usable. r=dbaron@fas.harvard.edu, sr=brendan@mozilla.org git-svn-id: svn://10.0.0.236/trunk@112678 18797224-902f-48f8-a5cc-f745e15eee43 --- .../src/base/nsAccessibilityService.cpp | 8 +- mozilla/docshell/base/nsDocShell.cpp | 30 ++-- mozilla/js/jsd/jsd_xpc.cpp | 32 ++-- mozilla/layout/generic/nsContainerFrame.cpp | 7 +- mozilla/layout/generic/nsLineBox.h | 3 +- mozilla/layout/generic/nsTextFrame.cpp | 3 +- mozilla/layout/generic/nsTextTransformer.cpp | 14 +- .../layout/html/base/src/nsContainerFrame.cpp | 7 +- mozilla/layout/html/base/src/nsLineBox.h | 3 +- mozilla/layout/html/base/src/nsTextFrame.cpp | 3 +- .../html/base/src/nsTextTransformer.cpp | 14 +- .../mailnews/compose/src/nsMsgCompFields.cpp | 7 +- mozilla/xpcom/base/nsDebug.cpp | 5 +- mozilla/xpcom/base/nsDebug.h | 148 ++++++++---------- mozilla/xpcom/base/nsTraceRefcnt.cpp | 9 +- mozilla/xpcom/base/nsTraceRefcntImpl.cpp | 9 +- mozilla/xpcom/glue/nsDebug.cpp | 5 +- mozilla/xpcom/glue/nsDebug.h | 148 ++++++++---------- mozilla/xpcom/proxy/src/nsProxyEventClass.cpp | 2 +- .../search/src/nsLocalSearchService.cpp | 8 +- mozilla/xpinstall/src/ScheduledTasks.cpp | 2 +- 21 files changed, 240 insertions(+), 227 deletions(-) diff --git a/mozilla/accessible/src/base/nsAccessibilityService.cpp b/mozilla/accessible/src/base/nsAccessibilityService.cpp index c7e0496b75e..ce6f05a94fc 100644 --- a/mozilla/accessible/src/base/nsAccessibilityService.cpp +++ b/mozilla/accessible/src/base/nsAccessibilityService.cpp @@ -244,15 +244,15 @@ nsAccessibilityService::CreateIFrameAccessible(nsIDOMNode* aDOMNode, nsIAccessib GetShellFromNode(aDOMNode, getter_AddRefs(outerWeakShell)); nsCOMPtr outerPresShell(do_QueryReferent(outerWeakShell)); - if (NS_WARN_IF_FALSE(outerPresShell, - "No outer pres shell in CreateHTMLIFrameAccessible!")) { + if (!outerPresShell) { + NS_WARNING("No outer pres shell in CreateHTMLIFrameAccessible!"); return NS_ERROR_FAILURE; } nsCOMPtr outerPresContext; outerPresShell->GetPresContext(getter_AddRefs(outerPresContext)); - if (NS_WARN_IF_FALSE(outerPresContext, - "No outer pres context in CreateHTMLIFrameAccessible!")) { + if (!outerPresContext) { + NS_WARNING("No outer pres context in CreateHTMLIFrameAccessible!"); return NS_ERROR_FAILURE; } diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index dbda5604044..7cf382f30c6 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -221,19 +221,23 @@ nsDocShell::~nsDocShell() NS_IMETHODIMP nsDocShell::DestroyChildren() { - PRInt32 i, n = mChildren.Count(); - nsCOMPtr shell; - for (i = 0; i < n; i++) { - shell = dont_AddRef((nsIDocShellTreeItem *) mChildren.ElementAt(i)); - if (!NS_WARN_IF_FALSE(shell, "docshell has null child")) - shell->SetParent(nsnull); - shell->SetTreeOwner(nsnull); - // just clear out the array. When the nsFrameFrame that holds the subshell is - // destroyed, then the Destroy() method of that subshell will actually get - // called. - } - mChildren.Clear(); - return NS_OK; + PRInt32 i, n = mChildren.Count(); + nsCOMPtr shell; + for (i = 0; i < n; i++) { + shell = dont_AddRef((nsIDocShellTreeItem *) mChildren.ElementAt(i)); + NS_WARN_IF_FALSE(shell, "docshell has null child"); + + if (shell) { + shell->SetParent(nsnull); + shell->SetTreeOwner(nsnull); + // just clear out the array. When the nsFrameFrame that holds + // the subshell is destroyed, then the Destroy() method of + // that subshell will actually get called. + } + } + + mChildren.Clear(); + return NS_OK; } //***************************************************************************** diff --git a/mozilla/js/jsd/jsd_xpc.cpp b/mozilla/js/jsd/jsd_xpc.cpp index c3e2d6548c0..fb8f837fda4 100644 --- a/mozilla/js/jsd/jsd_xpc.cpp +++ b/mozilla/js/jsd/jsd_xpc.cpp @@ -340,25 +340,37 @@ jsds_FilterHook (JSDContext *jsdc, JSDThreadState *state) JSContext *cx = JSD_GetJSContext (jsdc, state); void *glob = NS_STATIC_CAST(void *, JS_GetGlobalObject (cx)); - if (NS_WARN_IF_FALSE(glob, "No global in threadstate")) + + if (!glob) { + NS_WARNING("No global in threadstate"); return PR_TRUE; + } JSDStackFrameInfo *frame = JSD_GetStackFrame (jsdc, state); - if (NS_WARN_IF_FALSE(frame, "No frame in threadstate")) + + if (!frame) { + NS_WARNING("No frame in threadstate"); return PR_TRUE; - + } + JSDScript *script = JSD_GetScriptForStackFrame (jsdc, state, frame); - if (NS_WARN_IF_FALSE(script, "No script in threadstate")) + if (!script) { + NS_WARNING("No script in threadstate"); return PR_TRUE; + } jsuint pc = JSD_GetPCForStackFrame (jsdc, state, frame); - if (NS_WARN_IF_FALSE(pc, "No pc in threadstate")) + if (!pc) { + NS_WARNING("No pc in threadstate"); return PR_TRUE; - + } + PRUint32 currentLine = JSD_GetClosestLine (jsdc, script, pc); - if (NS_WARN_IF_FALSE(currentLine, "Can't convert pc to line")) + if (!currentLine) { + NS_WARNING("Can't convert pc to line"); return PR_TRUE; - + } + const char *url = nsnull; PRUint32 len = 0; FilterRecord *currentFilter = gFilters; @@ -1075,8 +1087,10 @@ jsdScript::GetFunctionSource(nsAString & aFunctionSource) { ASSERT_VALID_SCRIPT; JSContext *cx = JSD_GetDefaultJSContext (mCx); - if (NS_WARN_IF_FALSE(cx, "No default context !?")) + if (!cx) { + NS_WARNING("No default context !?"); return NS_ERROR_FAILURE; + } JSFunction *fun = JSD_GetJSFunction (mCx, mScript); JSString *jsstr; if (fun) diff --git a/mozilla/layout/generic/nsContainerFrame.cpp b/mozilla/layout/generic/nsContainerFrame.cpp index cedf60d58aa..09fdbe1b530 100644 --- a/mozilla/layout/generic/nsContainerFrame.cpp +++ b/mozilla/layout/generic/nsContainerFrame.cpp @@ -431,7 +431,12 @@ nsContainerFrame::PositionFrameView(nsIPresContext* aPresContext, // We have the origin in the coordinate space of the containing view, // but we need it in the coordinate space of the parent view so do a // view translation - NS_VERIFY(TranslatePointTo(origin, containingView, parentView), "translation failed"); +#ifdef DEBUG + PRBool ok = +#endif + TranslatePointTo(origin, containingView, parentView); + + NS_ASSERTION(ok, "translation failed"); } } diff --git a/mozilla/layout/generic/nsLineBox.h b/mozilla/layout/generic/nsLineBox.h index be8ef9c17f4..83bd73c2f46 100644 --- a/mozilla/layout/generic/nsLineBox.h +++ b/mozilla/layout/generic/nsLineBox.h @@ -300,7 +300,8 @@ public: return (PRInt32) mFlags.mChildCount; } void SetChildCount(PRInt32 aNewCount) { - if (NS_WARN_IF_FALSE(aNewCount >= 0, "negative child count")) { + if (aNewCount < 0) { + NS_WARNING("negative child count"); aNewCount = 0; } if (aNewCount > LINE_MAX_CHILD_COUNT) { diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 0baa9652bc5..bd167db5132 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -5159,7 +5159,8 @@ nsTextFrame::Reflow(nsIPresContext* aPresContext, // Setup text transformer to transform this frames text content nsCOMPtr doc; mContent->GetDocument(*getter_AddRefs(doc)); - if (NS_WARN_IF_FALSE(doc, "Content has no document.")) { + if (!doc) { + NS_WARNING("Content has no document."); return NS_ERROR_FAILURE; } nsCOMPtr lb; diff --git a/mozilla/layout/generic/nsTextTransformer.cpp b/mozilla/layout/generic/nsTextTransformer.cpp index b46fa369a51..75a215cae30 100644 --- a/mozilla/layout/generic/nsTextTransformer.cpp +++ b/mozilla/layout/generic/nsTextTransformer.cpp @@ -207,11 +207,12 @@ nsTextTransformer::Init(nsIFrame* aFrame, tc->GetText(&mFrag); // Sanitize aStartingOffset - if (NS_WARN_IF_FALSE(aStartingOffset >= 0, "bad starting offset")) { + if (aStartingOffset < 0) { + NS_WARNING("bad starting offset"); aStartingOffset = 0; } - else if (NS_WARN_IF_FALSE(aStartingOffset <= mFrag->GetLength(), - "bad starting offset")) { + else if (aStartingOffset > mFrag->GetLength()) { + NS_WARNING("bad starting offset"); aStartingOffset = mFrag->GetLength(); } mOffset = aStartingOffset; @@ -1606,11 +1607,12 @@ nsTextTransformer::Init2(const nsTextFragment* aFrag, mFrag = aFrag; // Sanitize aStartingOffset - if (NS_WARN_IF_FALSE(aStartingOffset >= 0, "bad starting offset")) { + if (aStartingOffset < 0) { + NS_WARNING("bad starting offset"); aStartingOffset = 0; } - else if (NS_WARN_IF_FALSE(aStartingOffset <= mFrag->GetLength(), - "bad starting offset")) { + else if (aStartingOffset > mFrag->GetLength()) { + NS_WARNING("bad starting offset"); aStartingOffset = mFrag->GetLength(); } mOffset = aStartingOffset; diff --git a/mozilla/layout/html/base/src/nsContainerFrame.cpp b/mozilla/layout/html/base/src/nsContainerFrame.cpp index cedf60d58aa..09fdbe1b530 100644 --- a/mozilla/layout/html/base/src/nsContainerFrame.cpp +++ b/mozilla/layout/html/base/src/nsContainerFrame.cpp @@ -431,7 +431,12 @@ nsContainerFrame::PositionFrameView(nsIPresContext* aPresContext, // We have the origin in the coordinate space of the containing view, // but we need it in the coordinate space of the parent view so do a // view translation - NS_VERIFY(TranslatePointTo(origin, containingView, parentView), "translation failed"); +#ifdef DEBUG + PRBool ok = +#endif + TranslatePointTo(origin, containingView, parentView); + + NS_ASSERTION(ok, "translation failed"); } } diff --git a/mozilla/layout/html/base/src/nsLineBox.h b/mozilla/layout/html/base/src/nsLineBox.h index be8ef9c17f4..83bd73c2f46 100644 --- a/mozilla/layout/html/base/src/nsLineBox.h +++ b/mozilla/layout/html/base/src/nsLineBox.h @@ -300,7 +300,8 @@ public: return (PRInt32) mFlags.mChildCount; } void SetChildCount(PRInt32 aNewCount) { - if (NS_WARN_IF_FALSE(aNewCount >= 0, "negative child count")) { + if (aNewCount < 0) { + NS_WARNING("negative child count"); aNewCount = 0; } if (aNewCount > LINE_MAX_CHILD_COUNT) { diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index 0baa9652bc5..bd167db5132 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -5159,7 +5159,8 @@ nsTextFrame::Reflow(nsIPresContext* aPresContext, // Setup text transformer to transform this frames text content nsCOMPtr doc; mContent->GetDocument(*getter_AddRefs(doc)); - if (NS_WARN_IF_FALSE(doc, "Content has no document.")) { + if (!doc) { + NS_WARNING("Content has no document."); return NS_ERROR_FAILURE; } nsCOMPtr lb; diff --git a/mozilla/layout/html/base/src/nsTextTransformer.cpp b/mozilla/layout/html/base/src/nsTextTransformer.cpp index b46fa369a51..75a215cae30 100644 --- a/mozilla/layout/html/base/src/nsTextTransformer.cpp +++ b/mozilla/layout/html/base/src/nsTextTransformer.cpp @@ -207,11 +207,12 @@ nsTextTransformer::Init(nsIFrame* aFrame, tc->GetText(&mFrag); // Sanitize aStartingOffset - if (NS_WARN_IF_FALSE(aStartingOffset >= 0, "bad starting offset")) { + if (aStartingOffset < 0) { + NS_WARNING("bad starting offset"); aStartingOffset = 0; } - else if (NS_WARN_IF_FALSE(aStartingOffset <= mFrag->GetLength(), - "bad starting offset")) { + else if (aStartingOffset > mFrag->GetLength()) { + NS_WARNING("bad starting offset"); aStartingOffset = mFrag->GetLength(); } mOffset = aStartingOffset; @@ -1606,11 +1607,12 @@ nsTextTransformer::Init2(const nsTextFragment* aFrag, mFrag = aFrag; // Sanitize aStartingOffset - if (NS_WARN_IF_FALSE(aStartingOffset >= 0, "bad starting offset")) { + if (aStartingOffset < 0) { + NS_WARNING("bad starting offset"); aStartingOffset = 0; } - else if (NS_WARN_IF_FALSE(aStartingOffset <= mFrag->GetLength(), - "bad starting offset")) { + else if (aStartingOffset > mFrag->GetLength()) { + NS_WARNING("bad starting offset"); aStartingOffset = mFrag->GetLength(); } mOffset = aStartingOffset; diff --git a/mozilla/mailnews/compose/src/nsMsgCompFields.cpp b/mozilla/mailnews/compose/src/nsMsgCompFields.cpp index 608a8ff43d7..55a5a670f91 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompFields.cpp +++ b/mozilla/mailnews/compose/src/nsMsgCompFields.cpp @@ -99,7 +99,8 @@ nsMsgCompFields::~nsMsgCompFields() nsresult nsMsgCompFields::SetAsciiHeader(MsgHeaderID header, const char *value) { - NS_VERIFY (header >= 0 && header < MSG_MAX_HEADERS, "Invalid message header index!"); + NS_ASSERTION(header >= 0 && header < MSG_MAX_HEADERS, + "Invalid message header index!"); int rv = NS_OK; char* old = m_headers[header]; /* Done with careful paranoia, in case the @@ -126,7 +127,9 @@ nsresult nsMsgCompFields::SetAsciiHeader(MsgHeaderID header, const char *value) const char* nsMsgCompFields::GetAsciiHeader(MsgHeaderID header) { - NS_VERIFY (header >= 0 && header < MSG_MAX_HEADERS, "Invalid message header index!"); + NS_ASSERTION(header >= 0 && header < MSG_MAX_HEADERS, + "Invalid message header index!"); + return m_headers[header] ? m_headers[header] : ""; } diff --git a/mozilla/xpcom/base/nsDebug.cpp b/mozilla/xpcom/base/nsDebug.cpp index 80da09e5c80..c022df2cc61 100644 --- a/mozilla/xpcom/base/nsDebug.cpp +++ b/mozilla/xpcom/base/nsDebug.cpp @@ -390,11 +390,10 @@ NS_COM void nsDebug::AbortIfFalse(const char* aStr, const char* aExpr, Assertion(aStr, aExpr, aFile, aLine); } -NS_COM PRBool nsDebug::WarnIfFalse(const char* aStr, const char* aExpr, - const char* aFile, PRIntn aLine) +NS_COM void nsDebug::WarnIfFalse(const char* aStr, const char* aExpr, + const char* aFile, PRIntn aLine) { Assertion(aStr, aExpr, aFile, aLine); - return PR_TRUE; } NS_COM void nsDebug::Abort(const char* aFile, PRIntn aLine) diff --git a/mozilla/xpcom/base/nsDebug.h b/mozilla/xpcom/base/nsDebug.h index 14f1699dfb9..d391756b69b 100644 --- a/mozilla/xpcom/base/nsDebug.h +++ b/mozilla/xpcom/base/nsDebug.h @@ -77,8 +77,8 @@ public: * The default behavior of this method is print a message to stderr * and to log an event in the NSPR log file. */ - static NS_COM PRBool WarnIfFalse(const char* aStr, const char* aExpr, - const char* aFile, PRIntn aLine); + static NS_COM void WarnIfFalse(const char* aStr, const char* aExpr, + const char* aFile, PRIntn aLine); /** * Enable flying a warning message box (if the platform supports @@ -181,35 +181,27 @@ public: * Note also that the non-debug version of this macro does not * evaluate the message argument. */ -#define NS_ABORT_IF_FALSE(_expr,_msg) \ -PR_BEGIN_MACRO \ - if (!(_expr)) { \ - nsDebug::AbortIfFalse(_msg, #_expr, __FILE__, __LINE__); \ - } \ -PR_END_MACRO +#define NS_ABORT_IF_FALSE(_expr, _msg) \ + PR_BEGIN_MACRO \ + if (!(_expr)) { \ + nsDebug::AbortIfFalse(_msg, #_expr, __FILE__, __LINE__);\ + } \ + PR_END_MACRO /** * Warn if a given condition is false. * * Program execution continues past the usage of this macro. * - * The macro returns a status value that can be used in an "if" - * statement. For example: - * - * if (NS_WARN_IF_FALSE(aPtr, "null pointer")) { - * return NS_ERROR_NULL_POINTER; - * } - * - * Note that the non-debug version of this macro does evaluate - * the expression as this macro continues to return a boolean - * value. Therefore side effect expressions will work - * correctly. However, they are still "poor form" so don't do it! - * * Note also that the non-debug version of this macro does not * evaluate the message argument. */ -#define NS_WARN_IF_FALSE(_e,_msg) \ - (!(_e) ? nsDebug::WarnIfFalse(_msg, #_e, __FILE__, __LINE__) : PR_FALSE) +#define NS_WARN_IF_FALSE(_expr,_msg) \ + PR_BEGIN_MACRO \ + if (!(_expr)) { \ + nsDebug::WarnIfFalse(_msg, #_expr, __FILE__, __LINE__); \ + } \ + PR_END_MACRO // Note: Macros below this line are the old ones; please start using // the new ones. The old ones will be removed eventually! @@ -220,102 +212,90 @@ PR_END_MACRO * Test a precondition for truth. If the expression is not true then * trigger a program failure. */ -#define NS_PRECONDITION(expr,str) \ -if (!(expr)) \ - nsDebug::PreCondition(str, #expr, __FILE__, __LINE__) +#define NS_PRECONDITION(expr, str) \ + PR_BEGIN_MACRO \ + if (!(expr)) { \ + nsDebug::PreCondition(str, #expr, __FILE__, __LINE__); \ + } \ + PR_END_MACRO /** * Test an assertion for truth. If the expression is not true then * trigger a program failure. */ -#define NS_ASSERTION(expr,str) \ -if (!(expr)) \ - nsDebug::Assertion(str, #expr, __FILE__, __LINE__) - -/** - * Test an assertion for truth. If the expression is not true then - * trigger a program failure. The expression will still be - * executed in release mode. - */ -#define NS_VERIFY(expr,str) \ -if (!(expr)) \ - nsDebug::Assertion(str, #expr, __FILE__, __LINE__) +#define NS_ASSERTION(expr, str) \ + PR_BEGIN_MACRO \ + if (!(expr)) { \ + nsDebug::Assertion(str, #expr, __FILE__, __LINE__); \ + } \ + PR_END_MACRO /** * Test a post-condition for truth. If the expression is not true then * trigger a program failure. */ -#define NS_POSTCONDITION(expr,str) \ -if (!(expr)) \ - nsDebug::PostCondition(str, #expr, __FILE__, __LINE__) +#define NS_POSTCONDITION(expr, str) \ + PR_BEGIN_MACRO \ + if (!(expr)) { \ + nsDebug::PostCondition(str, #expr, __FILE__, __LINE__); \ + } \ + PR_END_MACRO /** * This macros triggers a program failure if executed. It indicates that * an attempt was made to execute some unimplimented functionality. */ -#define NS_NOTYETIMPLEMENTED(str) \ +#define NS_NOTYETIMPLEMENTED(str) \ nsDebug::NotYetImplemented(str, __FILE__, __LINE__) /** * This macros triggers a program failure if executed. It indicates that * an attempt was made to execute some unimplimented functionality. */ -#define NS_NOTREACHED(str) \ +#define NS_NOTREACHED(str) \ nsDebug::NotReached(str, __FILE__, __LINE__) /** * Log an error message. */ -#define NS_ERROR(str) \ +#define NS_ERROR(str) \ nsDebug::Error(str, __FILE__, __LINE__) /** * Log a warning message. */ -#define NS_WARNING(str) \ +#define NS_WARNING(str) \ nsDebug::Warning(str, __FILE__, __LINE__) /** * Trigger an abort */ -#define NS_ABORT() \ +#define NS_ABORT() \ nsDebug::Abort(__FILE__, __LINE__) /** * Cause a break */ -#define NS_BREAK() \ +#define NS_BREAK() \ nsDebug::Break(__FILE__, __LINE__) #else /* NS_DEBUG */ /** - * The non-debug version of this macro does not evaluate the + * The non-debug version of these macros do not evaluate the * expression or the message arguments to the macro. */ -#define NS_ABORT_IF_FALSE(_expr,_msg) {} - -/** - * Note that the non-debug version of this macro does evaluate - * the expression as this macro continues to return a boolean - * value. - * - * The non-debug version of this macro does not evaluate the - * message argument. - */ -#define NS_WARN_IF_FALSE(_e,_msg) \ - (!(_e) ? PR_TRUE : PR_FALSE) - -#define NS_PRECONDITION(expr,str) {} -#define NS_ASSERTION(expr,str) {} -#define NS_VERIFY(expr,str) expr -#define NS_POSTCONDITION(expr,str) {} -#define NS_NOTYETIMPLEMENTED(str) {} -#define NS_NOTREACHED(str) {} -#define NS_ERROR(str) {} -#define NS_WARNING(str) {} -#define NS_ABORT() {} -#define NS_BREAK() {} +#define NS_ABORT_IF_FALSE(_expr, _msg) /* nothing */ +#define NS_WARN_IF_FALSE(_expr, _msg) /* nothing */ +#define NS_PRECONDITION(expr, str) /* nothing */ +#define NS_ASSERTION(expr, str) /* nothing */ +#define NS_POSTCONDITION(expr, str) /* nothing */ +#define NS_NOTYETIMPLEMENTED(str) /* nothing */ +#define NS_NOTREACHED(str) /* nothing */ +#define NS_ERROR(str) /* nothing */ +#define NS_WARNING(str) /* nothing */ +#define NS_ABORT() /* nothing */ +#define NS_BREAK() /* nothing */ #endif /* ! NS_DEBUG */ #endif /* __cplusplus */ @@ -325,13 +305,15 @@ if (!(expr)) \ // NS_DEBUG flag /////////////////////////////////////////////////////////////////////////////// -#define NS_ENSURE_TRUE(x, ret) \ - PR_BEGIN_MACRO \ - if(NS_WARN_IF_FALSE(x, "NS_ENSURE_TRUE(" #x ") failed")) \ - return ret; \ +#define NS_ENSURE_TRUE(x, ret) \ + PR_BEGIN_MACRO \ + if (!(x)) { \ + NS_WARNING("NS_ENSURE_TRUE(" #x ") failed"); \ + return ret; \ + } \ PR_END_MACRO -#define NS_ENSURE_FALSE(x, ret) \ +#define NS_ENSURE_FALSE(x, ret) \ NS_ENSURE_TRUE(!(x), ret) /////////////////////////////////////////////////////////////////////////////// @@ -345,28 +327,28 @@ if (!(expr)) \ // Macros for checking state and arguments upon entering interface boundaries /////////////////////////////////////////////////////////////////////////////// -#define NS_ENSURE_ARG(arg) \ +#define NS_ENSURE_ARG(arg) \ NS_ENSURE_TRUE(arg, NS_ERROR_INVALID_ARG) -#define NS_ENSURE_ARG_POINTER(arg) \ +#define NS_ENSURE_ARG_POINTER(arg) \ NS_ENSURE_TRUE(arg, NS_ERROR_INVALID_POINTER) -#define NS_ENSURE_ARG_MIN(arg, min) \ +#define NS_ENSURE_ARG_MIN(arg, min) \ NS_ENSURE_TRUE((arg) >= min, NS_ERROR_INVALID_ARG) -#define NS_ENSURE_ARG_MAX(arg, max) \ +#define NS_ENSURE_ARG_MAX(arg, max) \ NS_ENSURE_TRUE((arg) <= max, NS_ERROR_INVALID_ARG) -#define NS_ENSURE_ARG_RANGE(arg, min, max) \ +#define NS_ENSURE_ARG_RANGE(arg, min, max) \ NS_ENSURE_TRUE(((arg) >= min) && ((arg) <= max), NS_ERROR_INVALID_ARG) -#define NS_ENSURE_STATE(state) \ +#define NS_ENSURE_STATE(state) \ NS_ENSURE_TRUE(state, NS_ERROR_UNEXPECTED) -#define NS_ENSURE_NO_AGGREGATION(outer) \ +#define NS_ENSURE_NO_AGGREGATION(outer) \ NS_ENSURE_FALSE(outer, NS_ERROR_NO_AGGREGATION) -#define NS_ENSURE_PROPER_AGGREGATION(outer, iid) \ +#define NS_ENSURE_PROPER_AGGREGATION(outer, iid) \ NS_ENSURE_FALSE(outer && !iid.Equals(NS_GET_IID(nsISupports)), NS_ERROR_INVALID_ARG) /////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/xpcom/base/nsTraceRefcnt.cpp b/mozilla/xpcom/base/nsTraceRefcnt.cpp index d5211cb0239..68f88ed4d93 100644 --- a/mozilla/xpcom/base/nsTraceRefcnt.cpp +++ b/mozilla/xpcom/base/nsTraceRefcnt.cpp @@ -702,7 +702,8 @@ static void InitTraceLog(void) gLogLeaksOnly = InitLog("XPCOM_MEM_LEAK_LOG", "leaks", &gBloatLog); if (defined || gLogLeaksOnly) { RecreateBloatView(); - if (NS_WARN_IF_FALSE(gBloatView, "out of memory")) { + if (!gBloatView) { + NS_WARNING("out of memory"); gBloatLog = nsnull; gLogLeaksOnly = PR_FALSE; } @@ -757,7 +758,8 @@ static void InitTraceLog(void) PL_CompareStrings, PL_CompareValues, NULL, NULL); - if (NS_WARN_IF_FALSE(gTypesToLog, "out of memory")) { + if (!gTypesToLog) { + NS_WARNING("out of memory"); fprintf(stdout, "### XPCOM_MEM_LOG_CLASSES defined -- unable to log specific classes\n"); } else { @@ -794,7 +796,8 @@ static void InitTraceLog(void) PL_CompareValues, NULL, NULL); - if (NS_WARN_IF_FALSE(gObjectsToLog, "out of memory")) { + if (!gObjectsToLog) { + NS_WARNING("out of memory"); fprintf(stdout, "### XPCOM_MEM_LOG_OBJECTS defined -- unable to log specific objects\n"); } else if (! (gRefcntsLog || gAllocLog || gCOMPtrLog)) { diff --git a/mozilla/xpcom/base/nsTraceRefcntImpl.cpp b/mozilla/xpcom/base/nsTraceRefcntImpl.cpp index d5211cb0239..68f88ed4d93 100644 --- a/mozilla/xpcom/base/nsTraceRefcntImpl.cpp +++ b/mozilla/xpcom/base/nsTraceRefcntImpl.cpp @@ -702,7 +702,8 @@ static void InitTraceLog(void) gLogLeaksOnly = InitLog("XPCOM_MEM_LEAK_LOG", "leaks", &gBloatLog); if (defined || gLogLeaksOnly) { RecreateBloatView(); - if (NS_WARN_IF_FALSE(gBloatView, "out of memory")) { + if (!gBloatView) { + NS_WARNING("out of memory"); gBloatLog = nsnull; gLogLeaksOnly = PR_FALSE; } @@ -757,7 +758,8 @@ static void InitTraceLog(void) PL_CompareStrings, PL_CompareValues, NULL, NULL); - if (NS_WARN_IF_FALSE(gTypesToLog, "out of memory")) { + if (!gTypesToLog) { + NS_WARNING("out of memory"); fprintf(stdout, "### XPCOM_MEM_LOG_CLASSES defined -- unable to log specific classes\n"); } else { @@ -794,7 +796,8 @@ static void InitTraceLog(void) PL_CompareValues, NULL, NULL); - if (NS_WARN_IF_FALSE(gObjectsToLog, "out of memory")) { + if (!gObjectsToLog) { + NS_WARNING("out of memory"); fprintf(stdout, "### XPCOM_MEM_LOG_OBJECTS defined -- unable to log specific objects\n"); } else if (! (gRefcntsLog || gAllocLog || gCOMPtrLog)) { diff --git a/mozilla/xpcom/glue/nsDebug.cpp b/mozilla/xpcom/glue/nsDebug.cpp index 80da09e5c80..c022df2cc61 100644 --- a/mozilla/xpcom/glue/nsDebug.cpp +++ b/mozilla/xpcom/glue/nsDebug.cpp @@ -390,11 +390,10 @@ NS_COM void nsDebug::AbortIfFalse(const char* aStr, const char* aExpr, Assertion(aStr, aExpr, aFile, aLine); } -NS_COM PRBool nsDebug::WarnIfFalse(const char* aStr, const char* aExpr, - const char* aFile, PRIntn aLine) +NS_COM void nsDebug::WarnIfFalse(const char* aStr, const char* aExpr, + const char* aFile, PRIntn aLine) { Assertion(aStr, aExpr, aFile, aLine); - return PR_TRUE; } NS_COM void nsDebug::Abort(const char* aFile, PRIntn aLine) diff --git a/mozilla/xpcom/glue/nsDebug.h b/mozilla/xpcom/glue/nsDebug.h index 14f1699dfb9..d391756b69b 100644 --- a/mozilla/xpcom/glue/nsDebug.h +++ b/mozilla/xpcom/glue/nsDebug.h @@ -77,8 +77,8 @@ public: * The default behavior of this method is print a message to stderr * and to log an event in the NSPR log file. */ - static NS_COM PRBool WarnIfFalse(const char* aStr, const char* aExpr, - const char* aFile, PRIntn aLine); + static NS_COM void WarnIfFalse(const char* aStr, const char* aExpr, + const char* aFile, PRIntn aLine); /** * Enable flying a warning message box (if the platform supports @@ -181,35 +181,27 @@ public: * Note also that the non-debug version of this macro does not * evaluate the message argument. */ -#define NS_ABORT_IF_FALSE(_expr,_msg) \ -PR_BEGIN_MACRO \ - if (!(_expr)) { \ - nsDebug::AbortIfFalse(_msg, #_expr, __FILE__, __LINE__); \ - } \ -PR_END_MACRO +#define NS_ABORT_IF_FALSE(_expr, _msg) \ + PR_BEGIN_MACRO \ + if (!(_expr)) { \ + nsDebug::AbortIfFalse(_msg, #_expr, __FILE__, __LINE__);\ + } \ + PR_END_MACRO /** * Warn if a given condition is false. * * Program execution continues past the usage of this macro. * - * The macro returns a status value that can be used in an "if" - * statement. For example: - * - * if (NS_WARN_IF_FALSE(aPtr, "null pointer")) { - * return NS_ERROR_NULL_POINTER; - * } - * - * Note that the non-debug version of this macro does evaluate - * the expression as this macro continues to return a boolean - * value. Therefore side effect expressions will work - * correctly. However, they are still "poor form" so don't do it! - * * Note also that the non-debug version of this macro does not * evaluate the message argument. */ -#define NS_WARN_IF_FALSE(_e,_msg) \ - (!(_e) ? nsDebug::WarnIfFalse(_msg, #_e, __FILE__, __LINE__) : PR_FALSE) +#define NS_WARN_IF_FALSE(_expr,_msg) \ + PR_BEGIN_MACRO \ + if (!(_expr)) { \ + nsDebug::WarnIfFalse(_msg, #_expr, __FILE__, __LINE__); \ + } \ + PR_END_MACRO // Note: Macros below this line are the old ones; please start using // the new ones. The old ones will be removed eventually! @@ -220,102 +212,90 @@ PR_END_MACRO * Test a precondition for truth. If the expression is not true then * trigger a program failure. */ -#define NS_PRECONDITION(expr,str) \ -if (!(expr)) \ - nsDebug::PreCondition(str, #expr, __FILE__, __LINE__) +#define NS_PRECONDITION(expr, str) \ + PR_BEGIN_MACRO \ + if (!(expr)) { \ + nsDebug::PreCondition(str, #expr, __FILE__, __LINE__); \ + } \ + PR_END_MACRO /** * Test an assertion for truth. If the expression is not true then * trigger a program failure. */ -#define NS_ASSERTION(expr,str) \ -if (!(expr)) \ - nsDebug::Assertion(str, #expr, __FILE__, __LINE__) - -/** - * Test an assertion for truth. If the expression is not true then - * trigger a program failure. The expression will still be - * executed in release mode. - */ -#define NS_VERIFY(expr,str) \ -if (!(expr)) \ - nsDebug::Assertion(str, #expr, __FILE__, __LINE__) +#define NS_ASSERTION(expr, str) \ + PR_BEGIN_MACRO \ + if (!(expr)) { \ + nsDebug::Assertion(str, #expr, __FILE__, __LINE__); \ + } \ + PR_END_MACRO /** * Test a post-condition for truth. If the expression is not true then * trigger a program failure. */ -#define NS_POSTCONDITION(expr,str) \ -if (!(expr)) \ - nsDebug::PostCondition(str, #expr, __FILE__, __LINE__) +#define NS_POSTCONDITION(expr, str) \ + PR_BEGIN_MACRO \ + if (!(expr)) { \ + nsDebug::PostCondition(str, #expr, __FILE__, __LINE__); \ + } \ + PR_END_MACRO /** * This macros triggers a program failure if executed. It indicates that * an attempt was made to execute some unimplimented functionality. */ -#define NS_NOTYETIMPLEMENTED(str) \ +#define NS_NOTYETIMPLEMENTED(str) \ nsDebug::NotYetImplemented(str, __FILE__, __LINE__) /** * This macros triggers a program failure if executed. It indicates that * an attempt was made to execute some unimplimented functionality. */ -#define NS_NOTREACHED(str) \ +#define NS_NOTREACHED(str) \ nsDebug::NotReached(str, __FILE__, __LINE__) /** * Log an error message. */ -#define NS_ERROR(str) \ +#define NS_ERROR(str) \ nsDebug::Error(str, __FILE__, __LINE__) /** * Log a warning message. */ -#define NS_WARNING(str) \ +#define NS_WARNING(str) \ nsDebug::Warning(str, __FILE__, __LINE__) /** * Trigger an abort */ -#define NS_ABORT() \ +#define NS_ABORT() \ nsDebug::Abort(__FILE__, __LINE__) /** * Cause a break */ -#define NS_BREAK() \ +#define NS_BREAK() \ nsDebug::Break(__FILE__, __LINE__) #else /* NS_DEBUG */ /** - * The non-debug version of this macro does not evaluate the + * The non-debug version of these macros do not evaluate the * expression or the message arguments to the macro. */ -#define NS_ABORT_IF_FALSE(_expr,_msg) {} - -/** - * Note that the non-debug version of this macro does evaluate - * the expression as this macro continues to return a boolean - * value. - * - * The non-debug version of this macro does not evaluate the - * message argument. - */ -#define NS_WARN_IF_FALSE(_e,_msg) \ - (!(_e) ? PR_TRUE : PR_FALSE) - -#define NS_PRECONDITION(expr,str) {} -#define NS_ASSERTION(expr,str) {} -#define NS_VERIFY(expr,str) expr -#define NS_POSTCONDITION(expr,str) {} -#define NS_NOTYETIMPLEMENTED(str) {} -#define NS_NOTREACHED(str) {} -#define NS_ERROR(str) {} -#define NS_WARNING(str) {} -#define NS_ABORT() {} -#define NS_BREAK() {} +#define NS_ABORT_IF_FALSE(_expr, _msg) /* nothing */ +#define NS_WARN_IF_FALSE(_expr, _msg) /* nothing */ +#define NS_PRECONDITION(expr, str) /* nothing */ +#define NS_ASSERTION(expr, str) /* nothing */ +#define NS_POSTCONDITION(expr, str) /* nothing */ +#define NS_NOTYETIMPLEMENTED(str) /* nothing */ +#define NS_NOTREACHED(str) /* nothing */ +#define NS_ERROR(str) /* nothing */ +#define NS_WARNING(str) /* nothing */ +#define NS_ABORT() /* nothing */ +#define NS_BREAK() /* nothing */ #endif /* ! NS_DEBUG */ #endif /* __cplusplus */ @@ -325,13 +305,15 @@ if (!(expr)) \ // NS_DEBUG flag /////////////////////////////////////////////////////////////////////////////// -#define NS_ENSURE_TRUE(x, ret) \ - PR_BEGIN_MACRO \ - if(NS_WARN_IF_FALSE(x, "NS_ENSURE_TRUE(" #x ") failed")) \ - return ret; \ +#define NS_ENSURE_TRUE(x, ret) \ + PR_BEGIN_MACRO \ + if (!(x)) { \ + NS_WARNING("NS_ENSURE_TRUE(" #x ") failed"); \ + return ret; \ + } \ PR_END_MACRO -#define NS_ENSURE_FALSE(x, ret) \ +#define NS_ENSURE_FALSE(x, ret) \ NS_ENSURE_TRUE(!(x), ret) /////////////////////////////////////////////////////////////////////////////// @@ -345,28 +327,28 @@ if (!(expr)) \ // Macros for checking state and arguments upon entering interface boundaries /////////////////////////////////////////////////////////////////////////////// -#define NS_ENSURE_ARG(arg) \ +#define NS_ENSURE_ARG(arg) \ NS_ENSURE_TRUE(arg, NS_ERROR_INVALID_ARG) -#define NS_ENSURE_ARG_POINTER(arg) \ +#define NS_ENSURE_ARG_POINTER(arg) \ NS_ENSURE_TRUE(arg, NS_ERROR_INVALID_POINTER) -#define NS_ENSURE_ARG_MIN(arg, min) \ +#define NS_ENSURE_ARG_MIN(arg, min) \ NS_ENSURE_TRUE((arg) >= min, NS_ERROR_INVALID_ARG) -#define NS_ENSURE_ARG_MAX(arg, max) \ +#define NS_ENSURE_ARG_MAX(arg, max) \ NS_ENSURE_TRUE((arg) <= max, NS_ERROR_INVALID_ARG) -#define NS_ENSURE_ARG_RANGE(arg, min, max) \ +#define NS_ENSURE_ARG_RANGE(arg, min, max) \ NS_ENSURE_TRUE(((arg) >= min) && ((arg) <= max), NS_ERROR_INVALID_ARG) -#define NS_ENSURE_STATE(state) \ +#define NS_ENSURE_STATE(state) \ NS_ENSURE_TRUE(state, NS_ERROR_UNEXPECTED) -#define NS_ENSURE_NO_AGGREGATION(outer) \ +#define NS_ENSURE_NO_AGGREGATION(outer) \ NS_ENSURE_FALSE(outer, NS_ERROR_NO_AGGREGATION) -#define NS_ENSURE_PROPER_AGGREGATION(outer, iid) \ +#define NS_ENSURE_PROPER_AGGREGATION(outer, iid) \ NS_ENSURE_FALSE(outer && !iid.Equals(NS_GET_IID(nsISupports)), NS_ERROR_INVALID_ARG) /////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/xpcom/proxy/src/nsProxyEventClass.cpp b/mozilla/xpcom/proxy/src/nsProxyEventClass.cpp index 9f7fa372c71..4dfc63fa4f9 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEventClass.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyEventClass.cpp @@ -136,7 +136,7 @@ nsProxyEventClass::GetNewOrUsedClass(REFNSIID aIID) nsMemory::Free(iid); } - NS_VERIFY(isISupportsDescendent,"!isISupportsDescendent"); + NS_ASSERTION(isISupportsDescendent, "!isISupportsDescendent"); if (isISupportsDescendent) { diff --git a/mozilla/xpfe/components/search/src/nsLocalSearchService.cpp b/mozilla/xpfe/components/search/src/nsLocalSearchService.cpp index 4c26cdc6770..78edddd811f 100755 --- a/mozilla/xpfe/components/search/src/nsLocalSearchService.cpp +++ b/mozilla/xpfe/components/search/src/nsLocalSearchService.cpp @@ -925,7 +925,13 @@ LocalSearchDataSource::RemoveObserver(nsIRDFObserver *n) if (! mObservers) return(NS_OK); - NS_VERIFY(mObservers->RemoveElement(n), "observer not present"); +#ifdef DEBUG + PRBool ok = +#endif + mObservers->RemoveElement(n); + + NS_ASSERTION(ok, "observer not present"); + return(NS_OK); } diff --git a/mozilla/xpinstall/src/ScheduledTasks.cpp b/mozilla/xpinstall/src/ScheduledTasks.cpp index a2e1a881cab..d6fa3786272 100644 --- a/mozilla/xpinstall/src/ScheduledTasks.cpp +++ b/mozilla/xpinstall/src/ScheduledTasks.cpp @@ -318,7 +318,7 @@ PRInt32 ReplaceFileNow(nsIFile* replacementFile, nsIFile* doomedFile ) parentofReplacementFile->Equals(parentofFinalFile, &flagIsEqual); if(!flagIsEqual) { - NS_WARN_IF_FALSE( 0, "File unpacked into a non-dest dir" ); + NS_WARNING("File unpacked into a non-dest dir" ); replacementFile->GetLeafName(getter_Copies(leafname)); rv = replacementFile->MoveTo(parentofFinalFile, leafname); }