2014-05-05 21:30:39 +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/. */
|
2011-08-18 17:46:39 +04:00
|
|
|
|
1999-05-19 01:43:13 +04:00
|
|
|
#ifndef nscore_h___
|
|
|
|
#define nscore_h___
|
|
|
|
|
2010-03-04 08:02:58 +03:00
|
|
|
/* Definitions of functions and operators that allocate memory. */
|
2017-12-06 03:56:02 +03:00
|
|
|
#if !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC)
|
2010-03-04 08:02:58 +03:00
|
|
|
# include "mozilla/mozalloc.h"
|
|
|
|
#endif
|
|
|
|
|
2001-09-27 07:43:00 +04:00
|
|
|
/**
|
2012-09-07 01:54:59 +04:00
|
|
|
* Incorporate the integer data types which XPCOM uses.
|
2001-09-27 07:43:00 +04:00
|
|
|
*/
|
2020-11-23 19:12:02 +03:00
|
|
|
#include <stddef.h> // IWYU pragma: export
|
|
|
|
#include <stdint.h> // IWYU pragma: export
|
2001-09-27 07:43:00 +04:00
|
|
|
|
2020-11-23 19:12:02 +03:00
|
|
|
#include "mozilla/HelperMacros.h" // IWYU pragma: export
|
2014-02-21 23:45:50 +04:00
|
|
|
#include "mozilla/RefCountType.h"
|
|
|
|
|
2001-09-27 07:43:00 +04:00
|
|
|
/* Core XPCOM declarations. */
|
|
|
|
|
1999-05-19 01:43:13 +04:00
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
/* Import/export defines */
|
|
|
|
|
2004-12-15 08:52:44 +03:00
|
|
|
#ifdef HAVE_VISIBILITY_HIDDEN_ATTRIBUTE
|
2004-02-04 07:55:57 +03:00
|
|
|
# define NS_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
|
2004-02-03 11:32:33 +03:00
|
|
|
#else
|
2004-02-04 07:55:57 +03:00
|
|
|
# define NS_VISIBILITY_HIDDEN
|
2004-12-15 08:52:44 +03:00
|
|
|
#endif
|
2004-02-04 07:55:57 +03:00
|
|
|
|
2005-11-02 17:14:18 +03:00
|
|
|
#if defined(HAVE_VISIBILITY_ATTRIBUTE)
|
2004-12-15 08:52:44 +03:00
|
|
|
# define NS_VISIBILITY_DEFAULT __attribute__((visibility("default")))
|
2008-09-08 10:21:07 +04:00
|
|
|
#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
|
|
|
|
# define NS_VISIBILITY_DEFAULT __global
|
2004-12-15 08:52:44 +03:00
|
|
|
#else
|
|
|
|
# define NS_VISIBILITY_DEFAULT
|
2004-02-03 11:32:33 +03:00
|
|
|
#endif
|
|
|
|
|
2004-12-15 08:52:44 +03:00
|
|
|
#define NS_HIDDEN_(type) NS_VISIBILITY_HIDDEN type
|
|
|
|
#define NS_EXTERNAL_VIS_(type) NS_VISIBILITY_DEFAULT type
|
|
|
|
|
2004-02-04 07:55:57 +03:00
|
|
|
#define NS_HIDDEN NS_VISIBILITY_HIDDEN
|
2004-12-15 08:52:44 +03:00
|
|
|
#define NS_EXTERNAL_VIS NS_VISIBILITY_DEFAULT
|
2004-02-03 11:32:33 +03:00
|
|
|
|
2004-07-15 02:14:34 +04:00
|
|
|
/**
|
|
|
|
* Mark a function as using a potentially non-standard function calling
|
|
|
|
* convention. This can be used on functions that are called very
|
|
|
|
* frequently, to reduce the overhead of the function call. It is still worth
|
|
|
|
* using the macro for C++ functions which take no parameters since it allows
|
|
|
|
* passing |this| in a register.
|
|
|
|
*
|
|
|
|
* - Do not use this on any scriptable interface method since xptcall won't be
|
|
|
|
* aware of the different calling convention.
|
|
|
|
* - This must appear on the declaration, not the definition.
|
|
|
|
* - Adding this to a public function _will_ break binary compatibility.
|
|
|
|
* - This may be used on virtual functions but you must ensure it is applied
|
|
|
|
* to all implementations - the compiler will _not_ warn but it will crash.
|
2012-07-06 01:38:30 +04:00
|
|
|
* - This has no effect for functions which take a variable number of
|
|
|
|
* arguments.
|
2005-11-10 17:43:22 +03:00
|
|
|
* - __fastcall on windows should not be applied to class
|
|
|
|
* constructors/destructors - use the NS_CONSTRUCTOR_FASTCALL macro for
|
|
|
|
* constructors/destructors.
|
2004-07-15 02:14:34 +04:00
|
|
|
*
|
|
|
|
* Examples: int NS_FASTCALL func1(char *foo);
|
|
|
|
* NS_HIDDEN_(int) NS_FASTCALL func2(char *foo);
|
|
|
|
*/
|
|
|
|
|
2014-02-11 02:57:01 +04:00
|
|
|
#if defined(__i386__) && defined(__GNUC__)
|
2004-07-15 02:14:34 +04:00
|
|
|
# define NS_FASTCALL __attribute__((regparm(3), stdcall))
|
2005-11-10 17:43:22 +03:00
|
|
|
# define NS_CONSTRUCTOR_FASTCALL __attribute__((regparm(3), stdcall))
|
2010-06-14 14:12:48 +04:00
|
|
|
#elif defined(XP_WIN) && !defined(_WIN64)
|
2005-11-10 17:43:22 +03:00
|
|
|
# define NS_FASTCALL __fastcall
|
|
|
|
# define NS_CONSTRUCTOR_FASTCALL
|
2004-07-15 02:14:34 +04:00
|
|
|
#else
|
|
|
|
# define NS_FASTCALL
|
2005-11-10 17:43:22 +03:00
|
|
|
# define NS_CONSTRUCTOR_FASTCALL
|
2004-07-15 02:14:34 +04:00
|
|
|
#endif
|
|
|
|
|
2017-01-10 06:08:43 +03:00
|
|
|
/**
|
|
|
|
* Various API modifiers.
|
|
|
|
*
|
|
|
|
* - NS_IMETHOD/NS_IMETHOD_: use for in-class declarations and definitions.
|
|
|
|
* - NS_IMETHODIMP/NS_IMETHODIMP_: use for out-of-class definitions.
|
|
|
|
* - NS_METHOD_: usually used in conjunction with NS_CALLBACK_. Best avoided.
|
|
|
|
* - NS_CALLBACK_: used in some legacy situations. Best avoided.
|
|
|
|
*/
|
|
|
|
|
2011-12-21 09:09:17 +04:00
|
|
|
#ifdef XP_WIN
|
2001-09-27 07:43:00 +04:00
|
|
|
|
2003-06-25 02:12:37 +04:00
|
|
|
# define NS_IMPORT __declspec(dllimport)
|
2005-11-08 21:17:49 +03:00
|
|
|
# define NS_IMPORT_(type) __declspec(dllimport) type __stdcall
|
2003-06-25 02:12:37 +04:00
|
|
|
# define NS_EXPORT __declspec(dllexport)
|
2005-11-08 21:17:49 +03:00
|
|
|
# define NS_EXPORT_(type) __declspec(dllexport) type __stdcall
|
2001-09-27 07:43:00 +04:00
|
|
|
# define NS_IMETHOD_(type) virtual type __stdcall
|
|
|
|
# define NS_IMETHODIMP_(type) type __stdcall
|
|
|
|
# define NS_METHOD_(type) type __stdcall
|
|
|
|
# define NS_CALLBACK_(_type, _name) _type(__stdcall* _name)
|
2013-07-18 18:17:13 +04:00
|
|
|
# ifndef _WIN64
|
|
|
|
// Win64 has only one calling convention. __stdcall will be ignored by the
|
|
|
|
// compiler.
|
2013-07-21 08:59:05 +04:00
|
|
|
# define NS_STDCALL __stdcall
|
2013-07-17 06:01:50 +04:00
|
|
|
# define NS_HAVE_STDCALL
|
2013-07-21 08:59:05 +04:00
|
|
|
# else
|
|
|
|
# define NS_STDCALL
|
2013-07-18 18:17:13 +04:00
|
|
|
# endif
|
2005-11-08 21:17:49 +03:00
|
|
|
# define NS_FROZENCALL __cdecl
|
2001-09-27 07:43:00 +04:00
|
|
|
|
1999-05-19 01:43:13 +04:00
|
|
|
#else
|
|
|
|
|
2004-12-15 08:52:44 +03:00
|
|
|
# define NS_IMPORT NS_EXTERNAL_VIS
|
|
|
|
# define NS_IMPORT_(type) NS_EXTERNAL_VIS_(type)
|
|
|
|
# define NS_EXPORT NS_EXTERNAL_VIS
|
|
|
|
# define NS_EXPORT_(type) NS_EXTERNAL_VIS_(type)
|
2014-08-28 02:47:27 +04:00
|
|
|
# define NS_IMETHOD_(type) virtual type
|
2001-09-27 07:43:00 +04:00
|
|
|
# define NS_IMETHODIMP_(type) type
|
|
|
|
# define NS_METHOD_(type) type
|
|
|
|
# define NS_CALLBACK_(_type, _name) _type(*_name)
|
2003-03-07 09:07:56 +03:00
|
|
|
# define NS_STDCALL
|
2005-11-08 21:17:49 +03:00
|
|
|
# define NS_FROZENCALL
|
2004-12-15 08:52:44 +03:00
|
|
|
|
2003-03-07 09:07:56 +03:00
|
|
|
#endif
|
|
|
|
|
2017-01-10 06:08:43 +03:00
|
|
|
#define NS_IMETHOD NS_IMETHOD_(nsresult)
|
|
|
|
#define NS_IMETHODIMP NS_IMETHODIMP_(nsresult)
|
|
|
|
|
2001-09-27 07:43:00 +04:00
|
|
|
/**
|
|
|
|
* Import/Export macros for XPCOM APIs
|
|
|
|
*/
|
1999-05-19 01:43:13 +04:00
|
|
|
|
2016-12-02 20:55:34 +03:00
|
|
|
#define EXPORT_XPCOM_API(type) type
|
|
|
|
#define IMPORT_XPCOM_API(type) type
|
|
|
|
#define GLUE_XPCOM_API(type) type
|
|
|
|
|
2017-01-18 04:55:24 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
# define NS_EXTERN_C extern "C"
|
|
|
|
#else
|
|
|
|
# define NS_EXTERN_C
|
|
|
|
#endif
|
|
|
|
|
2016-12-02 20:55:34 +03:00
|
|
|
#define XPCOM_API(type) NS_EXTERN_C type
|
2005-11-08 21:17:49 +03:00
|
|
|
|
2010-08-08 19:06:35 +04:00
|
|
|
/* If a program allocates memory for the lifetime of the app, it doesn't make
|
|
|
|
* sense to touch memory pages and free that memory at shutdown,
|
|
|
|
* unless we are running leak stats.
|
2019-05-31 17:17:47 +03:00
|
|
|
*
|
|
|
|
* Note that we're also setting this for code coverage and pgo profile
|
|
|
|
* generation, because both of those require atexit hooks, which won't fire
|
|
|
|
* if we're using _exit. Bug 1555974 covers improving this.
|
|
|
|
*
|
2010-08-08 19:06:35 +04:00
|
|
|
*/
|
2019-06-28 19:38:14 +03:00
|
|
|
#ifndef NS_FREE_PERMANENT_DATA
|
2021-01-08 23:07:04 +03:00
|
|
|
# if defined(NS_BUILD_REFCNT_LOGGING) || defined(MOZ_VALGRIND) || \
|
|
|
|
defined(MOZ_ASAN) || defined(MOZ_TSAN) || defined(MOZ_CODE_COVERAGE) || \
|
2021-01-28 02:40:35 +03:00
|
|
|
defined(MOZ_PROFILE_GENERATE) || defined(JS_STRUCTURED_SPEW)
|
2010-07-14 21:09:42 +04:00
|
|
|
# define NS_FREE_PERMANENT_DATA
|
|
|
|
# endif
|
2019-06-28 19:38:14 +03:00
|
|
|
#endif
|
2004-07-15 02:14:34 +04:00
|
|
|
|
2001-09-27 07:43:00 +04:00
|
|
|
/**
|
|
|
|
* NS_NO_VTABLE is emitted by xpidl in interface declarations whenever
|
|
|
|
* xpidl can determine that the interface can't contain a constructor.
|
|
|
|
* This results in some space savings and possible runtime savings -
|
|
|
|
* see bug 49416. We undefine it first, as xpidl-generated headers
|
|
|
|
* define it for IDL uses that don't include this file.
|
|
|
|
*/
|
|
|
|
#ifdef NS_NO_VTABLE
|
|
|
|
# undef NS_NO_VTABLE
|
1999-05-19 01:43:13 +04:00
|
|
|
#endif
|
2016-02-06 05:38:04 +03:00
|
|
|
#if defined(_MSC_VER)
|
2001-09-27 07:43:00 +04:00
|
|
|
# define NS_NO_VTABLE __declspec(novtable)
|
1999-05-19 01:43:13 +04:00
|
|
|
#else
|
2001-09-27 07:43:00 +04:00
|
|
|
# define NS_NO_VTABLE
|
1999-05-19 01:43:13 +04:00
|
|
|
#endif
|
|
|
|
|
2001-09-27 07:43:00 +04:00
|
|
|
/**
|
|
|
|
* Generic XPCOM result data type
|
|
|
|
*/
|
2020-11-23 19:12:02 +03:00
|
|
|
#include "nsError.h" // IWYU pragma: export
|
2001-09-27 07:43:00 +04:00
|
|
|
|
2014-02-21 23:45:50 +04:00
|
|
|
typedef MozRefCountType nsrefcnt;
|
2006-02-10 18:00:36 +03:00
|
|
|
|
2017-09-01 02:01:43 +03:00
|
|
|
namespace mozilla {
|
|
|
|
// Extensions to the mozilla::Result type for handling of nsresult values.
|
|
|
|
//
|
|
|
|
// Note that these specializations need to be defined before Result.h is
|
|
|
|
// included, or we run into explicit specialization after instantiation errors,
|
|
|
|
// especially if Result.h is used in multiple sources in a unified compile.
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
// When used as an error value, nsresult should never be NS_OK.
|
|
|
|
// This specialization allows us to pack Result<Ok, nsresult> into a
|
|
|
|
// nsresult-sized value.
|
|
|
|
template <typename T>
|
|
|
|
struct UnusedZero;
|
|
|
|
template <>
|
|
|
|
struct UnusedZero<nsresult> {
|
2020-09-03 17:14:41 +03:00
|
|
|
using StorageType = nsresult;
|
|
|
|
|
|
|
|
static constexpr bool value = true;
|
|
|
|
static constexpr StorageType nullValue = NS_OK;
|
2020-09-16 16:58:49 +03:00
|
|
|
|
2020-09-03 17:14:41 +03:00
|
|
|
static constexpr void AssertValid(StorageType aValue) {}
|
|
|
|
static constexpr const nsresult& Inspect(const StorageType& aValue) {
|
|
|
|
return aValue;
|
|
|
|
}
|
|
|
|
static constexpr nsresult Unwrap(StorageType aValue) { return aValue; }
|
|
|
|
static constexpr StorageType Store(nsresult aValue) { return aValue; }
|
2017-09-01 02:01:43 +03:00
|
|
|
};
|
|
|
|
} // namespace detail
|
2017-08-30 07:28:22 +03:00
|
|
|
|
|
|
|
template <typename T>
|
2021-09-15 08:10:51 +03:00
|
|
|
class GenericErrorResult;
|
2017-08-30 07:28:22 +03:00
|
|
|
template <>
|
2021-09-15 08:10:51 +03:00
|
|
|
class GenericErrorResult<nsresult>;
|
2017-08-30 07:28:31 +03:00
|
|
|
|
|
|
|
struct Ok;
|
|
|
|
template <typename V, typename E>
|
|
|
|
class Result;
|
|
|
|
|
|
|
|
// Allow MOZ_TRY to handle `nsresult` values.
|
2021-10-11 11:34:01 +03:00
|
|
|
template <typename E = nsresult>
|
|
|
|
inline Result<Ok, E> ToResult(nsresult aValue);
|
2017-09-01 02:01:43 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
/*
|
2001-08-14 08:14:47 +04:00
|
|
|
* Use these macros to do 64bit safe pointer conversions.
|
|
|
|
*/
|
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
#define NS_PTR_TO_INT32(x) ((int32_t)(intptr_t)(x))
|
|
|
|
#define NS_PTR_TO_UINT32(x) ((uint32_t)(intptr_t)(x))
|
|
|
|
#define NS_INT32_TO_PTR(x) ((void*)(intptr_t)(x))
|
2001-08-14 08:14:47 +04:00
|
|
|
|
2014-05-05 21:30:39 +04:00
|
|
|
/*
|
|
|
|
* If we're being linked as standalone glue, we don't want a dynamic
|
|
|
|
* dependency on NSPR libs, so we skip the debug thread-safety
|
|
|
|
* checks, and we cannot use the THREADSAFE_ISUPPORTS macros.
|
|
|
|
*/
|
2007-09-29 00:33:32 +04:00
|
|
|
#if defined(XPCOM_GLUE) && !defined(XPCOM_GLUE_USE_NSPR)
|
|
|
|
# define XPCOM_GLUE_AVOID_NSPR
|
2004-03-08 02:32:08 +03:00
|
|
|
#endif
|
|
|
|
|
2011-01-11 13:16:59 +03:00
|
|
|
/*
|
|
|
|
* SEH exception macros.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_SEH_EXCEPTIONS
|
|
|
|
# define MOZ_SEH_TRY __try
|
|
|
|
# define MOZ_SEH_EXCEPT(expr) __except (expr)
|
|
|
|
#else
|
2011-10-17 18:59:28 +04:00
|
|
|
# define MOZ_SEH_TRY if (true)
|
2011-01-11 13:16:59 +03:00
|
|
|
# define MOZ_SEH_EXCEPT(expr) else
|
|
|
|
#endif
|
|
|
|
|
1999-05-19 01:43:13 +04:00
|
|
|
#endif /* nscore_h___ */
|