2014-06-30 19:39:45 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-10-19 21:48:55 +04:00
|
|
|
|
|
|
|
#ifndef nsDebug_h___
|
|
|
|
#define nsDebug_h___
|
|
|
|
|
2001-09-27 07:43:00 +04:00
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsError.h"
|
1998-10-19 21:48:55 +04:00
|
|
|
|
2006-02-10 18:00:36 +03:00
|
|
|
#include "nsXPCOM.h"
|
2012-09-22 23:45:44 +04:00
|
|
|
#include "mozilla/Assertions.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2013-11-30 16:48:34 +04:00
|
|
|
#include <stdarg.h>
|
2006-02-10 18:00:36 +03:00
|
|
|
|
1998-10-19 21:48:55 +04:00
|
|
|
#ifdef DEBUG
|
2016-12-09 23:50:37 +03:00
|
|
|
#include "mozilla/IntegerPrintfMacros.h"
|
|
|
|
#include "mozilla/Printf.h"
|
1998-10-19 21:48:55 +04:00
|
|
|
#endif
|
|
|
|
|
2013-11-20 01:27:36 +04:00
|
|
|
/**
|
|
|
|
* Warn if the given condition is true. The condition is evaluated in both
|
|
|
|
* release and debug builds, and the result is an expression which can be
|
|
|
|
* used in subsequent expressions, such as:
|
|
|
|
*
|
2016-09-02 10:12:24 +03:00
|
|
|
* if (NS_WARN_IF(NS_FAILED(rv)) {
|
2013-11-20 01:27:36 +04:00
|
|
|
* return rv;
|
2016-09-02 10:12:24 +03:00
|
|
|
* }
|
2013-11-20 01:27:36 +04:00
|
|
|
*
|
|
|
|
* This explicit warning and return is preferred to the NS_ENSURE_* macros
|
|
|
|
* which hide the warning and the return control flow.
|
|
|
|
*
|
2016-09-02 10:12:24 +03:00
|
|
|
* This macro can also be used outside of conditions just to issue a warning,
|
|
|
|
* like so:
|
|
|
|
*
|
|
|
|
* Unused << NS_WARN_IF(NS_FAILED(FnWithSideEffects());
|
|
|
|
*
|
|
|
|
* (The |Unused <<| is necessary because of the MOZ_MUST_USE annotation.)
|
|
|
|
*
|
|
|
|
* However, note that the argument to this macro is evaluated in all builds. If
|
|
|
|
* you just want a warning assertion, it is better to use NS_WARNING_ASSERTION
|
|
|
|
* (which evaluates the condition only in debug builds) like so:
|
|
|
|
*
|
|
|
|
* NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "operation failed");
|
|
|
|
*
|
2013-11-20 01:27:36 +04:00
|
|
|
* @note This is C++-only
|
|
|
|
*/
|
|
|
|
#ifdef __cplusplus
|
1999-10-01 01:39:31 +04:00
|
|
|
#ifdef DEBUG
|
2016-09-02 10:12:24 +03:00
|
|
|
inline MOZ_MUST_USE bool NS_warn_if_impl(bool aCondition, const char* aExpr,
|
|
|
|
const char* aFile, int32_t aLine)
|
2013-11-20 01:27:36 +04:00
|
|
|
{
|
2014-06-27 05:35:39 +04:00
|
|
|
if (MOZ_UNLIKELY(aCondition)) {
|
|
|
|
NS_DebugBreak(NS_DEBUG_WARNING, nullptr, aExpr, aFile, aLine);
|
2013-11-20 01:27:36 +04:00
|
|
|
}
|
2014-06-27 05:35:39 +04:00
|
|
|
return aCondition;
|
2013-11-20 01:27:36 +04:00
|
|
|
}
|
|
|
|
#define NS_WARN_IF(condition) \
|
|
|
|
NS_warn_if_impl(condition, #condition, __FILE__, __LINE__)
|
|
|
|
#else
|
|
|
|
#define NS_WARN_IF(condition) (bool)(condition)
|
|
|
|
#endif
|
|
|
|
#endif
|
1999-10-01 01:39:31 +04:00
|
|
|
|
|
|
|
/**
|
2016-09-01 08:01:16 +03:00
|
|
|
* Test an assertion for truth. If the expression is not true then
|
|
|
|
* emit a warning.
|
1999-10-01 01:39:31 +04:00
|
|
|
*
|
|
|
|
* Program execution continues past the usage of this macro.
|
|
|
|
*
|
|
|
|
* Note also that the non-debug version of this macro does <b>not</b>
|
|
|
|
* evaluate the message argument.
|
|
|
|
*/
|
2013-11-20 01:27:36 +04:00
|
|
|
#ifdef DEBUG
|
2016-09-01 08:01:16 +03:00
|
|
|
#define NS_WARNING_ASSERTION(_expr, _msg) \
|
2012-09-07 01:54:59 +04:00
|
|
|
do { \
|
2002-01-24 12:20:51 +03:00
|
|
|
if (!(_expr)) { \
|
2006-03-01 01:19:55 +03:00
|
|
|
NS_DebugBreak(NS_DEBUG_WARNING, _msg, #_expr, __FILE__, __LINE__); \
|
2002-01-24 12:20:51 +03:00
|
|
|
} \
|
2012-09-07 01:54:59 +04:00
|
|
|
} while(0)
|
2013-11-20 01:27:36 +04:00
|
|
|
#else
|
2016-09-01 08:01:16 +03:00
|
|
|
#define NS_WARNING_ASSERTION(_expr, _msg) do { /* nothing */ } while(0)
|
2013-11-20 01:27:36 +04:00
|
|
|
#endif
|
1999-10-01 01:39:31 +04:00
|
|
|
|
1998-10-19 21:48:55 +04:00
|
|
|
/**
|
|
|
|
* Test an assertion for truth. If the expression is not true then
|
|
|
|
* trigger a program failure.
|
2013-11-20 01:27:36 +04:00
|
|
|
*
|
|
|
|
* Note that the non-debug version of this macro does <b>not</b>
|
|
|
|
* evaluate the message argument.
|
1998-10-19 21:48:55 +04:00
|
|
|
*/
|
2013-11-20 01:27:36 +04:00
|
|
|
#ifdef DEBUG
|
2015-04-19 04:23:50 +03:00
|
|
|
inline void MOZ_PretendNoReturn()
|
|
|
|
MOZ_PRETEND_NORETURN_FOR_STATIC_ANALYSIS {}
|
2002-01-24 12:20:51 +03:00
|
|
|
#define NS_ASSERTION(expr, str) \
|
2012-09-07 01:54:59 +04:00
|
|
|
do { \
|
2002-01-24 12:20:51 +03:00
|
|
|
if (!(expr)) { \
|
2006-02-10 18:00:36 +03:00
|
|
|
NS_DebugBreak(NS_DEBUG_ASSERTION, str, #expr, __FILE__, __LINE__); \
|
2015-04-19 04:23:50 +03:00
|
|
|
MOZ_PretendNoReturn(); \
|
2002-01-24 12:20:51 +03:00
|
|
|
} \
|
2012-09-07 01:54:59 +04:00
|
|
|
} while(0)
|
2013-11-20 01:27:36 +04:00
|
|
|
#else
|
|
|
|
#define NS_ASSERTION(expr, str) do { /* nothing */ } while(0)
|
|
|
|
#endif
|
1998-10-19 21:48:55 +04:00
|
|
|
|
|
|
|
/**
|
2013-11-20 01:27:36 +04:00
|
|
|
* NS_PRECONDITION/POSTCONDITION are synonyms for NS_ASSERTION.
|
1998-10-19 21:48:55 +04:00
|
|
|
*/
|
2013-11-20 01:27:36 +04:00
|
|
|
#define NS_PRECONDITION(expr, str) NS_ASSERTION(expr, str)
|
|
|
|
#define NS_POSTCONDITION(expr, str) NS_ASSERTION(expr, str)
|
1998-10-19 21:48:55 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This macros triggers a program failure if executed. It indicates that
|
2005-06-03 14:26:28 +04:00
|
|
|
* an attempt was made to execute some unimplemented functionality.
|
1998-10-19 21:48:55 +04:00
|
|
|
*/
|
2013-11-20 01:27:36 +04:00
|
|
|
#ifdef DEBUG
|
2002-01-24 12:20:51 +03:00
|
|
|
#define NS_NOTYETIMPLEMENTED(str) \
|
2015-04-19 04:23:50 +03:00
|
|
|
do { \
|
|
|
|
NS_DebugBreak(NS_DEBUG_ASSERTION, str, "NotYetImplemented", __FILE__, __LINE__); \
|
|
|
|
MOZ_PretendNoReturn(); \
|
|
|
|
} while(0)
|
2013-11-20 01:27:36 +04:00
|
|
|
#else
|
|
|
|
#define NS_NOTYETIMPLEMENTED(str) do { /* nothing */ } while(0)
|
|
|
|
#endif
|
1998-10-19 21:48:55 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This macros triggers a program failure if executed. It indicates that
|
2013-11-20 01:27:36 +04:00
|
|
|
* an attempt was made to execute a codepath which should not be reachable.
|
1998-10-19 21:48:55 +04:00
|
|
|
*/
|
2013-11-20 01:27:36 +04:00
|
|
|
#ifdef DEBUG
|
2002-01-24 12:20:51 +03:00
|
|
|
#define NS_NOTREACHED(str) \
|
2015-04-19 04:23:50 +03:00
|
|
|
do { \
|
|
|
|
NS_DebugBreak(NS_DEBUG_ASSERTION, str, "Not Reached", __FILE__, __LINE__); \
|
|
|
|
MOZ_PretendNoReturn(); \
|
|
|
|
} while(0)
|
2013-11-20 01:27:36 +04:00
|
|
|
#else
|
|
|
|
#define NS_NOTREACHED(str) do { /* nothing */ } while(0)
|
|
|
|
#endif
|
1998-10-19 21:48:55 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Log an error message.
|
|
|
|
*/
|
2013-11-20 01:27:36 +04:00
|
|
|
#ifdef DEBUG
|
2002-01-24 12:20:51 +03:00
|
|
|
#define NS_ERROR(str) \
|
2015-04-19 04:23:50 +03:00
|
|
|
do { \
|
|
|
|
NS_DebugBreak(NS_DEBUG_ASSERTION, str, "Error", __FILE__, __LINE__); \
|
|
|
|
MOZ_PretendNoReturn(); \
|
|
|
|
} while(0)
|
2013-11-20 01:27:36 +04:00
|
|
|
#else
|
|
|
|
#define NS_ERROR(str) do { /* nothing */ } while(0)
|
|
|
|
#endif
|
1998-10-19 21:48:55 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Log a warning message.
|
|
|
|
*/
|
2013-11-20 01:27:36 +04:00
|
|
|
#ifdef DEBUG
|
2002-01-24 12:20:51 +03:00
|
|
|
#define NS_WARNING(str) \
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_DebugBreak(NS_DEBUG_WARNING, str, nullptr, __FILE__, __LINE__)
|
2013-11-20 01:27:36 +04:00
|
|
|
#else
|
|
|
|
#define NS_WARNING(str) do { /* nothing */ } while(0)
|
|
|
|
#endif
|
1998-10-19 21:48:55 +04:00
|
|
|
|
|
|
|
/**
|
2013-11-20 01:27:36 +04:00
|
|
|
* Trigger an debug-only abort.
|
|
|
|
*
|
|
|
|
* @see NS_RUNTIMEABORT for release-mode asserts.
|
1998-10-19 21:48:55 +04:00
|
|
|
*/
|
2013-11-20 01:27:36 +04:00
|
|
|
#ifdef DEBUG
|
2002-01-24 12:20:51 +03:00
|
|
|
#define NS_ABORT() \
|
2015-04-19 04:23:50 +03:00
|
|
|
do { \
|
|
|
|
NS_DebugBreak(NS_DEBUG_ABORT, nullptr, nullptr, __FILE__, __LINE__); \
|
|
|
|
MOZ_PretendNoReturn(); \
|
|
|
|
} while(0)
|
2013-11-20 01:27:36 +04:00
|
|
|
#else
|
|
|
|
#define NS_ABORT() do { /* nothing */ } while(0)
|
|
|
|
#endif
|
1998-10-19 21:48:55 +04:00
|
|
|
|
|
|
|
/**
|
2013-11-20 01:27:36 +04:00
|
|
|
* Trigger a debugger breakpoint, only in debug builds.
|
1998-10-19 21:48:55 +04:00
|
|
|
*/
|
2013-11-20 01:27:36 +04:00
|
|
|
#ifdef DEBUG
|
2002-01-24 12:20:51 +03:00
|
|
|
#define NS_BREAK() \
|
2015-04-19 04:23:50 +03:00
|
|
|
do { \
|
|
|
|
NS_DebugBreak(NS_DEBUG_BREAK, nullptr, nullptr, __FILE__, __LINE__); \
|
|
|
|
MOZ_PretendNoReturn(); \
|
|
|
|
} while(0)
|
2013-11-20 01:27:36 +04:00
|
|
|
#else
|
2012-09-07 01:54:59 +04:00
|
|
|
#define NS_BREAK() do { /* nothing */ } while(0)
|
2013-11-20 01:27:36 +04:00
|
|
|
#endif
|
2001-09-27 07:43:00 +04:00
|
|
|
|
2010-04-22 22:13:05 +04:00
|
|
|
/******************************************************************************
|
|
|
|
** Macros for static assertions. These are used by the sixgill tool.
|
|
|
|
** When the tool is not running these macros are no-ops.
|
|
|
|
******************************************************************************/
|
|
|
|
|
2010-10-02 08:00:55 +04:00
|
|
|
/* Avoid name collision if included with other headers defining annotations. */
|
|
|
|
#ifndef HAVE_STATIC_ANNOTATIONS
|
|
|
|
#define HAVE_STATIC_ANNOTATIONS
|
|
|
|
|
2010-04-22 22:13:05 +04:00
|
|
|
#ifdef XGILL_PLUGIN
|
|
|
|
|
|
|
|
#define STATIC_PRECONDITION(COND) __attribute__((precondition(#COND)))
|
|
|
|
#define STATIC_PRECONDITION_ASSUME(COND) __attribute__((precondition_assume(#COND)))
|
|
|
|
#define STATIC_POSTCONDITION(COND) __attribute__((postcondition(#COND)))
|
|
|
|
#define STATIC_POSTCONDITION_ASSUME(COND) __attribute__((postcondition_assume(#COND)))
|
|
|
|
#define STATIC_INVARIANT(COND) __attribute__((invariant(#COND)))
|
|
|
|
#define STATIC_INVARIANT_ASSUME(COND) __attribute__((invariant_assume(#COND)))
|
|
|
|
|
|
|
|
/* Used to make identifiers for assert/assume annotations in a function. */
|
|
|
|
#define STATIC_PASTE2(X,Y) X ## Y
|
|
|
|
#define STATIC_PASTE1(X,Y) STATIC_PASTE2(X,Y)
|
|
|
|
|
|
|
|
#define STATIC_ASSUME(COND) \
|
2012-09-07 01:54:59 +04:00
|
|
|
do { \
|
2010-10-02 08:00:55 +04:00
|
|
|
__attribute__((assume_static(#COND), unused)) \
|
|
|
|
int STATIC_PASTE1(assume_static_, __COUNTER__); \
|
2012-09-07 01:54:59 +04:00
|
|
|
} while(0)
|
2010-04-22 22:13:05 +04:00
|
|
|
|
|
|
|
#define STATIC_ASSERT_RUNTIME(COND) \
|
2012-09-07 01:54:59 +04:00
|
|
|
do { \
|
2010-10-02 08:00:55 +04:00
|
|
|
__attribute__((assert_static_runtime(#COND), unused)) \
|
|
|
|
int STATIC_PASTE1(assert_static_runtime_, __COUNTER__); \
|
2012-09-07 01:54:59 +04:00
|
|
|
} while(0)
|
2010-04-22 22:13:05 +04:00
|
|
|
|
|
|
|
#else /* XGILL_PLUGIN */
|
|
|
|
|
|
|
|
#define STATIC_PRECONDITION(COND) /* nothing */
|
|
|
|
#define STATIC_PRECONDITION_ASSUME(COND) /* nothing */
|
|
|
|
#define STATIC_POSTCONDITION(COND) /* nothing */
|
|
|
|
#define STATIC_POSTCONDITION_ASSUME(COND) /* nothing */
|
|
|
|
#define STATIC_INVARIANT(COND) /* nothing */
|
|
|
|
#define STATIC_INVARIANT_ASSUME(COND) /* nothing */
|
|
|
|
|
2012-09-07 01:54:59 +04:00
|
|
|
#define STATIC_ASSUME(COND) do { /* nothing */ } while(0)
|
|
|
|
#define STATIC_ASSERT_RUNTIME(COND) do { /* nothing */ } while(0)
|
2010-04-22 22:13:05 +04:00
|
|
|
|
|
|
|
#endif /* XGILL_PLUGIN */
|
2010-04-15 22:44:23 +04:00
|
|
|
|
2010-10-02 08:00:55 +04:00
|
|
|
#define STATIC_SKIP_INFERENCE STATIC_INVARIANT(skip_inference())
|
|
|
|
|
|
|
|
#endif /* HAVE_STATIC_ANNOTATIONS */
|
|
|
|
|
2009-04-19 05:54:23 +04:00
|
|
|
/******************************************************************************
|
|
|
|
** Macros for terminating execution when an unrecoverable condition is
|
2013-11-20 01:27:36 +04:00
|
|
|
** reached. These need to be compiled regardless of the DEBUG flag.
|
2009-04-19 05:54:23 +04:00
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Terminate execution <i>immediately</i>, and if possible on the current
|
|
|
|
* platform, in such a way that execution can't be continued by other
|
|
|
|
* code (e.g., by intercepting a signal).
|
|
|
|
*/
|
|
|
|
#define NS_RUNTIMEABORT(msg) \
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_DebugBreak(NS_DEBUG_ABORT, msg, nullptr, __FILE__, __LINE__)
|
2009-04-19 05:54:23 +04:00
|
|
|
|
|
|
|
|
2013-11-20 01:27:36 +04:00
|
|
|
/* Macros for checking the trueness of an expression passed in within an
|
|
|
|
* interface implementation. These need to be compiled regardless of the
|
|
|
|
* DEBUG flag. New code should use NS_WARN_IF(condition) instead!
|
|
|
|
* @status deprecated
|
|
|
|
*/
|
2001-09-27 07:43:00 +04:00
|
|
|
|
2002-01-24 12:20:51 +03:00
|
|
|
#define NS_ENSURE_TRUE(x, ret) \
|
2012-09-07 01:54:59 +04:00
|
|
|
do { \
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(!(x))) { \
|
2002-01-24 12:20:51 +03:00
|
|
|
NS_WARNING("NS_ENSURE_TRUE(" #x ") failed"); \
|
|
|
|
return ret; \
|
|
|
|
} \
|
2012-09-07 01:54:59 +04:00
|
|
|
} while(0)
|
2001-09-27 07:43:00 +04:00
|
|
|
|
2002-01-24 12:20:51 +03:00
|
|
|
#define NS_ENSURE_FALSE(x, ret) \
|
2001-09-27 07:43:00 +04:00
|
|
|
NS_ENSURE_TRUE(!(x), ret)
|
|
|
|
|
2012-09-14 14:00:31 +04:00
|
|
|
#define NS_ENSURE_TRUE_VOID(x) \
|
|
|
|
do { \
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(!(x))) { \
|
2012-09-14 14:00:31 +04:00
|
|
|
NS_WARNING("NS_ENSURE_TRUE(" #x ") failed"); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define NS_ENSURE_FALSE_VOID(x) \
|
|
|
|
NS_ENSURE_TRUE_VOID(!(x))
|
|
|
|
|
2005-09-08 17:59:09 +04:00
|
|
|
/******************************************************************************
|
|
|
|
** Macros for checking results
|
|
|
|
******************************************************************************/
|
2001-09-27 07:43:00 +04:00
|
|
|
|
2007-09-28 22:59:07 +04:00
|
|
|
#if defined(DEBUG) && !defined(XPCOM_GLUE_AVOID_NSPR)
|
|
|
|
|
|
|
|
#define NS_ENSURE_SUCCESS_BODY(res, ret) \
|
2016-12-09 23:50:37 +03:00
|
|
|
char *msg = mozilla::Smprintf("NS_ENSURE_SUCCESS(%s, %s) failed with " \
|
|
|
|
"result 0x%" PRIX32, #res, #ret, \
|
|
|
|
static_cast<uint32_t>(__rv)); \
|
2007-09-28 22:59:07 +04:00
|
|
|
NS_WARNING(msg); \
|
2016-12-09 23:50:37 +03:00
|
|
|
mozilla::SmprintfFree(msg);
|
2007-09-28 22:59:07 +04:00
|
|
|
|
2012-09-14 14:00:31 +04:00
|
|
|
#define NS_ENSURE_SUCCESS_BODY_VOID(res) \
|
2016-12-09 23:50:37 +03:00
|
|
|
char *msg = mozilla::Smprintf("NS_ENSURE_SUCCESS_VOID(%s) failed with " \
|
|
|
|
"result 0x%" PRIX32, #res, \
|
|
|
|
static_cast<uint32_t>(__rv)); \
|
2012-09-14 14:00:31 +04:00
|
|
|
NS_WARNING(msg); \
|
2016-12-09 23:50:37 +03:00
|
|
|
mozilla::SmprintfFree(msg);
|
2012-09-14 14:00:31 +04:00
|
|
|
|
2007-09-28 22:59:07 +04:00
|
|
|
#else
|
|
|
|
|
|
|
|
#define NS_ENSURE_SUCCESS_BODY(res, ret) \
|
|
|
|
NS_WARNING("NS_ENSURE_SUCCESS(" #res ", " #ret ") failed");
|
|
|
|
|
2012-09-14 14:00:31 +04:00
|
|
|
#define NS_ENSURE_SUCCESS_BODY_VOID(res) \
|
|
|
|
NS_WARNING("NS_ENSURE_SUCCESS_VOID(" #res ") failed");
|
|
|
|
|
2007-09-28 22:59:07 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NS_ENSURE_SUCCESS(res, ret) \
|
2012-09-07 01:54:59 +04:00
|
|
|
do { \
|
2007-09-28 22:59:07 +04:00
|
|
|
nsresult __rv = res; /* Don't evaluate |res| more than once */ \
|
|
|
|
if (NS_FAILED(__rv)) { \
|
|
|
|
NS_ENSURE_SUCCESS_BODY(res, ret) \
|
|
|
|
return ret; \
|
|
|
|
} \
|
2012-09-07 01:54:59 +04:00
|
|
|
} while(0)
|
2001-09-27 07:43:00 +04:00
|
|
|
|
2012-09-14 14:00:31 +04:00
|
|
|
#define NS_ENSURE_SUCCESS_VOID(res) \
|
|
|
|
do { \
|
|
|
|
nsresult __rv = res; \
|
|
|
|
if (NS_FAILED(__rv)) { \
|
|
|
|
NS_ENSURE_SUCCESS_BODY_VOID(res) \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
2005-09-08 17:59:09 +04:00
|
|
|
/******************************************************************************
|
|
|
|
** Macros for checking state and arguments upon entering interface boundaries
|
|
|
|
******************************************************************************/
|
2001-09-27 07:43:00 +04:00
|
|
|
|
2002-01-24 12:20:51 +03:00
|
|
|
#define NS_ENSURE_ARG(arg) \
|
2001-09-27 07:43:00 +04:00
|
|
|
NS_ENSURE_TRUE(arg, NS_ERROR_INVALID_ARG)
|
|
|
|
|
2002-01-24 12:20:51 +03:00
|
|
|
#define NS_ENSURE_ARG_POINTER(arg) \
|
2001-09-27 07:43:00 +04:00
|
|
|
NS_ENSURE_TRUE(arg, NS_ERROR_INVALID_POINTER)
|
|
|
|
|
2002-01-24 12:20:51 +03:00
|
|
|
#define NS_ENSURE_ARG_MIN(arg, min) \
|
2001-09-27 07:43:00 +04:00
|
|
|
NS_ENSURE_TRUE((arg) >= min, NS_ERROR_INVALID_ARG)
|
|
|
|
|
2002-01-24 12:20:51 +03:00
|
|
|
#define NS_ENSURE_ARG_MAX(arg, max) \
|
2001-09-27 07:43:00 +04:00
|
|
|
NS_ENSURE_TRUE((arg) <= max, NS_ERROR_INVALID_ARG)
|
|
|
|
|
2002-01-24 12:20:51 +03:00
|
|
|
#define NS_ENSURE_ARG_RANGE(arg, min, max) \
|
2001-09-27 07:43:00 +04:00
|
|
|
NS_ENSURE_TRUE(((arg) >= min) && ((arg) <= max), NS_ERROR_INVALID_ARG)
|
|
|
|
|
2002-01-24 12:20:51 +03:00
|
|
|
#define NS_ENSURE_STATE(state) \
|
2001-09-27 07:43:00 +04:00
|
|
|
NS_ENSURE_TRUE(state, NS_ERROR_UNEXPECTED)
|
|
|
|
|
2002-01-24 12:20:51 +03:00
|
|
|
#define NS_ENSURE_NO_AGGREGATION(outer) \
|
2001-09-27 07:43:00 +04:00
|
|
|
NS_ENSURE_FALSE(outer, NS_ERROR_NO_AGGREGATION)
|
|
|
|
|
2005-09-08 17:59:09 +04:00
|
|
|
/*****************************************************************************/
|
2001-09-27 07:43:00 +04:00
|
|
|
|
2016-08-01 14:16:16 +03:00
|
|
|
#if (defined(DEBUG) || (defined(NIGHTLY_BUILD) && !defined(MOZ_PROFILING))) && !defined(XPCOM_GLUE_AVOID_NSPR)
|
|
|
|
#define MOZ_THREAD_SAFETY_OWNERSHIP_CHECKS_SUPPORTED 1
|
|
|
|
#endif
|
|
|
|
|
2005-07-01 16:24:07 +04:00
|
|
|
#ifdef XPCOM_GLUE
|
2012-07-05 18:32:10 +04:00
|
|
|
#define NS_CheckThreadSafe(owningThread, msg)
|
2005-07-01 16:24:07 +04:00
|
|
|
#else
|
2012-07-05 18:32:10 +04:00
|
|
|
#define NS_CheckThreadSafe(owningThread, msg) \
|
2013-08-30 21:06:37 +04:00
|
|
|
if (MOZ_UNLIKELY(owningThread != PR_GetCurrentThread())) { \
|
|
|
|
MOZ_CRASH(msg); \
|
|
|
|
}
|
2005-07-01 16:24:07 +04:00
|
|
|
#endif
|
2003-07-08 02:11:36 +04:00
|
|
|
|
2013-11-26 00:06:17 +04:00
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2014-06-27 05:35:39 +04:00
|
|
|
void NS_ABORT_OOM(size_t aSize);
|
2013-11-26 00:06:17 +04:00
|
|
|
#else
|
|
|
|
inline void NS_ABORT_OOM(size_t)
|
|
|
|
{
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-09-12 22:22:40 +04:00
|
|
|
/* When compiling the XPCOM Glue on Windows, we pretend that it's going to
|
|
|
|
* be linked with a static CRT (-MT) even when it's not. This means that we
|
|
|
|
* cannot link to data exports from the CRT, only function exports. So,
|
|
|
|
* instead of referencing "stderr" directly, use fdopen.
|
|
|
|
*/
|
2012-09-07 01:54:59 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2006-09-12 22:22:40 +04:00
|
|
|
|
2014-11-27 09:29:44 +03:00
|
|
|
/**
|
|
|
|
* printf_stderr(...) is much like fprintf(stderr, ...), except that:
|
|
|
|
* - on Android and Firefox OS, *instead* of printing to stderr, it
|
|
|
|
* prints to logcat. (Newlines in the string lead to multiple lines
|
|
|
|
* of logcat, but each function call implicitly completes a line even
|
|
|
|
* if the string does not end with a newline.)
|
|
|
|
* - on Windows, if a debugger is present, it calls OutputDebugString
|
|
|
|
* in *addition* to writing to stderr
|
|
|
|
*/
|
2014-08-27 01:14:51 +04:00
|
|
|
void printf_stderr(const char* aFmt, ...) MOZ_FORMAT_PRINTF(1, 2);
|
2006-09-12 22:22:40 +04:00
|
|
|
|
2014-11-27 09:29:44 +03:00
|
|
|
/**
|
|
|
|
* Same as printf_stderr, but taking va_list instead of varargs
|
|
|
|
*/
|
2014-08-28 02:47:27 +04:00
|
|
|
void vprintf_stderr(const char* aFmt, va_list aArgs);
|
2013-11-24 02:44:18 +04:00
|
|
|
|
2014-11-27 09:29:44 +03:00
|
|
|
/**
|
|
|
|
* fprintf_stderr is like fprintf, except that if its file argument
|
|
|
|
* is stderr, it invokes printf_stderr instead.
|
|
|
|
*
|
|
|
|
* This is useful for general debugging code that logs information to a
|
|
|
|
* file, but that you would like to be useful on Android and Firefox OS.
|
|
|
|
* If you use fprintf_stderr instead of fprintf in such debugging code,
|
|
|
|
* then callers can pass stderr to get logging that works on Android and
|
|
|
|
* Firefox OS (and also the other side-effects of using printf_stderr).
|
|
|
|
*
|
|
|
|
* Code that is structured this way needs to be careful not to split a
|
|
|
|
* line of output across multiple calls to fprintf_stderr, since doing
|
|
|
|
* so will cause it to appear in multiple lines in logcat output.
|
|
|
|
* (Producing multiple lines at once is fine.)
|
|
|
|
*/
|
2014-08-27 01:14:51 +04:00
|
|
|
void fprintf_stderr(FILE* aFile, const char* aFmt, ...) MOZ_FORMAT_PRINTF(2, 3);
|
2013-11-24 02:44:18 +04:00
|
|
|
|
2012-09-07 01:54:59 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2006-09-12 22:22:40 +04:00
|
|
|
|
1998-10-19 21:48:55 +04:00
|
|
|
#endif /* nsDebug_h___ */
|