Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / xpcom / base / nsError.h
blob040cd4612c2d73e30daa23f14fe41b2a9f92055a
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsError_h__
8 #define nsError_h__
10 #ifndef __cplusplus
11 # error nsError.h no longer supports C sources
12 #endif
14 #include "mozilla/Attributes.h"
15 #include "mozilla/Likely.h"
17 #include <stdint.h>
19 #define NS_ERROR_SEVERITY_SUCCESS 0
20 #define NS_ERROR_SEVERITY_ERROR 1
22 #include "ErrorList.h" // IWYU pragma: export
24 /**
25 * @name Standard Error Handling Macros
26 * @return 0 or 1 (false/true with bool type for C++)
29 inline uint32_t NS_FAILED_impl(nsresult aErr) {
30 return static_cast<uint32_t>(aErr) & 0x80000000;
32 #define NS_FAILED(_nsresult) ((bool)MOZ_UNLIKELY(NS_FAILED_impl(_nsresult)))
33 #define NS_SUCCEEDED(_nsresult) ((bool)MOZ_LIKELY(!NS_FAILED_impl(_nsresult)))
35 /* Check that our enum type is actually uint32_t as expected */
36 static_assert(((nsresult)0) < ((nsresult)-1),
37 "nsresult must be an unsigned type");
38 static_assert(sizeof(nsresult) == sizeof(uint32_t), "nsresult must be 32 bits");
40 #define MOZ_ALWAYS_SUCCEEDS(expr) MOZ_ALWAYS_TRUE(NS_SUCCEEDED(expr))
42 /**
43 * @name Standard Error Generating Macros
46 #define NS_ERROR_GENERATE(sev, module, code) \
47 (nsresult)(((uint32_t)(sev) << 31) | \
48 ((uint32_t)(module + NS_ERROR_MODULE_BASE_OFFSET) << 16) | \
49 ((uint32_t)(code)))
51 #define NS_ERROR_GENERATE_SUCCESS(module, code) \
52 NS_ERROR_GENERATE(NS_ERROR_SEVERITY_SUCCESS, module, code)
54 #define NS_ERROR_GENERATE_FAILURE(module, code) \
55 NS_ERROR_GENERATE(NS_ERROR_SEVERITY_ERROR, module, code)
58 * This will return the nsresult corresponding to the most recent NSPR failure
59 * returned by PR_GetError.
61 ***********************************************************************
62 * Do not depend on this function. It will be going away!
63 ***********************************************************************
65 extern nsresult NS_ErrorAccordingToNSPR();
67 /**
68 * @name Standard Macros for retrieving error bits
71 inline constexpr uint16_t NS_ERROR_GET_CODE(nsresult aErr) {
72 return uint32_t(aErr) & 0xffff;
74 inline constexpr uint16_t NS_ERROR_GET_MODULE(nsresult aErr) {
75 return ((uint32_t(aErr) >> 16) - NS_ERROR_MODULE_BASE_OFFSET) & 0x1fff;
77 inline bool NS_ERROR_GET_SEVERITY(nsresult aErr) {
78 return uint32_t(aErr) >> 31;
81 #ifdef _MSC_VER
82 # pragma warning(disable : 4251) /* 'nsCOMPtr<class nsIInputStream>' needs to \
83 have dll-interface to be used by clients \
84 of class 'nsInputStream' */
85 # pragma warning( \
86 disable : 4275) /* non dll-interface class 'nsISupports' used as base \
87 for dll-interface class 'nsIRDFNode' */
88 #endif
90 #endif