michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nscore_h___ michael@0: #define nscore_h___ michael@0: michael@0: /** michael@0: * Make sure that we have the proper platform specific michael@0: * c++ definitions needed by nscore.h michael@0: */ michael@0: #ifndef _XPCOM_CONFIG_H_ michael@0: #include "xpcom-config.h" michael@0: #endif michael@0: michael@0: /* Definitions of functions and operators that allocate memory. */ michael@0: #if !defined(XPCOM_GLUE) && !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC) michael@0: # include "mozilla/mozalloc.h" michael@0: #endif michael@0: michael@0: /** michael@0: * Incorporate the integer data types which XPCOM uses. michael@0: */ michael@0: #include michael@0: #include michael@0: michael@0: #ifdef __cplusplus michael@0: # include "mozilla/NullPtr.h" michael@0: #endif michael@0: michael@0: #include "mozilla/RefCountType.h" michael@0: michael@0: /* Core XPCOM declarations. */ michael@0: michael@0: /*----------------------------------------------------------------------*/ michael@0: /* Import/export defines */ michael@0: michael@0: /** michael@0: * Using the visibility("hidden") attribute allows the compiler to use michael@0: * PC-relative addressing to call this function. If a function does not michael@0: * access any global data, and does not call any methods which are not either michael@0: * file-local or hidden, then on ELF systems we avoid loading the address of michael@0: * the PLT into a register at the start of the function, which reduces code michael@0: * size and frees up a register for general use. michael@0: * michael@0: * As a general rule, this should be used for any non-exported symbol michael@0: * (including virtual method implementations). NS_IMETHOD uses this by michael@0: * default; if you need to have your NS_IMETHOD functions exported, you can michael@0: * wrap your class as follows: michael@0: * michael@0: * #undef IMETHOD_VISIBILITY michael@0: * #define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT michael@0: * michael@0: * class Foo { michael@0: * ... michael@0: * }; michael@0: * michael@0: * #undef IMETHOD_VISIBILITY michael@0: * #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN michael@0: * michael@0: * Don't forget to change the visibility back to hidden before the end michael@0: * of a header! michael@0: * michael@0: * Other examples: michael@0: * michael@0: * NS_HIDDEN_(int) someMethod(); michael@0: * SomeCtor() NS_HIDDEN; michael@0: */ michael@0: michael@0: #ifdef HAVE_VISIBILITY_HIDDEN_ATTRIBUTE michael@0: #define NS_VISIBILITY_HIDDEN __attribute__ ((visibility ("hidden"))) michael@0: #else michael@0: #define NS_VISIBILITY_HIDDEN michael@0: #endif michael@0: michael@0: #if defined(HAVE_VISIBILITY_ATTRIBUTE) michael@0: #define NS_VISIBILITY_DEFAULT __attribute__ ((visibility ("default"))) michael@0: #elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) michael@0: #define NS_VISIBILITY_DEFAULT __global michael@0: #else michael@0: #define NS_VISIBILITY_DEFAULT michael@0: #endif michael@0: michael@0: #define NS_HIDDEN_(type) NS_VISIBILITY_HIDDEN type michael@0: #define NS_EXTERNAL_VIS_(type) NS_VISIBILITY_DEFAULT type michael@0: michael@0: #define NS_HIDDEN NS_VISIBILITY_HIDDEN michael@0: #define NS_EXTERNAL_VIS NS_VISIBILITY_DEFAULT michael@0: michael@0: #undef IMETHOD_VISIBILITY michael@0: #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN michael@0: michael@0: /** michael@0: * Mark a function as using a potentially non-standard function calling michael@0: * convention. This can be used on functions that are called very michael@0: * frequently, to reduce the overhead of the function call. It is still worth michael@0: * using the macro for C++ functions which take no parameters since it allows michael@0: * passing |this| in a register. michael@0: * michael@0: * - Do not use this on any scriptable interface method since xptcall won't be michael@0: * aware of the different calling convention. michael@0: * - This must appear on the declaration, not the definition. michael@0: * - Adding this to a public function _will_ break binary compatibility. michael@0: * - This may be used on virtual functions but you must ensure it is applied michael@0: * to all implementations - the compiler will _not_ warn but it will crash. michael@0: * - This has no effect for functions which take a variable number of michael@0: * arguments. michael@0: * - __fastcall on windows should not be applied to class michael@0: * constructors/destructors - use the NS_CONSTRUCTOR_FASTCALL macro for michael@0: * constructors/destructors. michael@0: * michael@0: * Examples: int NS_FASTCALL func1(char *foo); michael@0: * NS_HIDDEN_(int) NS_FASTCALL func2(char *foo); michael@0: */ michael@0: michael@0: #if defined(__i386__) && defined(__GNUC__) michael@0: #define NS_FASTCALL __attribute__ ((regparm (3), stdcall)) michael@0: #define NS_CONSTRUCTOR_FASTCALL __attribute__ ((regparm (3), stdcall)) michael@0: #elif defined(XP_WIN) && !defined(_WIN64) michael@0: #define NS_FASTCALL __fastcall michael@0: #define NS_CONSTRUCTOR_FASTCALL michael@0: #else michael@0: #define NS_FASTCALL michael@0: #define NS_CONSTRUCTOR_FASTCALL michael@0: #endif michael@0: michael@0: #ifdef XP_WIN michael@0: michael@0: #define NS_IMPORT __declspec(dllimport) michael@0: #define NS_IMPORT_(type) __declspec(dllimport) type __stdcall michael@0: #define NS_EXPORT __declspec(dllexport) michael@0: #define NS_EXPORT_(type) __declspec(dllexport) type __stdcall michael@0: #define NS_IMETHOD_(type) virtual type __stdcall michael@0: #define NS_IMETHODIMP_(type) type __stdcall michael@0: #define NS_METHOD_(type) type __stdcall michael@0: #define NS_CALLBACK_(_type, _name) _type (__stdcall * _name) michael@0: #ifndef _WIN64 michael@0: // Win64 has only one calling convention. __stdcall will be ignored by the compiler. michael@0: #define NS_STDCALL __stdcall michael@0: #define NS_HAVE_STDCALL michael@0: #else michael@0: #define NS_STDCALL michael@0: #endif michael@0: #define NS_FROZENCALL __cdecl michael@0: michael@0: /* michael@0: These are needed to mark static members in exported classes, due to michael@0: gcc bug XXX insert bug# here. michael@0: */ michael@0: michael@0: #define NS_EXPORT_STATIC_MEMBER_(type) type michael@0: #define NS_IMPORT_STATIC_MEMBER_(type) type michael@0: michael@0: #else michael@0: michael@0: #define NS_IMPORT NS_EXTERNAL_VIS michael@0: #define NS_IMPORT_(type) NS_EXTERNAL_VIS_(type) michael@0: #define NS_EXPORT NS_EXTERNAL_VIS michael@0: #define NS_EXPORT_(type) NS_EXTERNAL_VIS_(type) michael@0: #define NS_IMETHOD_(type) virtual IMETHOD_VISIBILITY type michael@0: #define NS_IMETHODIMP_(type) type michael@0: #define NS_METHOD_(type) type michael@0: #define NS_CALLBACK_(_type, _name) _type (* _name) michael@0: #define NS_STDCALL michael@0: #define NS_FROZENCALL michael@0: #define NS_EXPORT_STATIC_MEMBER_(type) NS_EXTERNAL_VIS_(type) michael@0: #define NS_IMPORT_STATIC_MEMBER_(type) NS_EXTERNAL_VIS_(type) michael@0: michael@0: #endif michael@0: michael@0: /** michael@0: * Macro for creating typedefs for pointer-to-member types which are michael@0: * declared with stdcall. It is important to use this for any type which is michael@0: * declared as stdcall (i.e. NS_IMETHOD). For example, instead of writing: michael@0: * michael@0: * typedef nsresult (nsIFoo::*someType)(nsISupports* arg); michael@0: * michael@0: * you should write: michael@0: * michael@0: * typedef michael@0: * NS_STDCALL_FUNCPROTO(nsresult, someType, nsIFoo, typeFunc, (nsISupports*)); michael@0: * michael@0: * where nsIFoo::typeFunc is any method declared as michael@0: * NS_IMETHOD typeFunc(nsISupports*); michael@0: * michael@0: * XXX this can be simplified to always use the non-typeof implementation michael@0: * when http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11893 is fixed. michael@0: */ michael@0: michael@0: #ifdef __GNUC__ michael@0: #define NS_STDCALL_FUNCPROTO(ret, name, class, func, args) \ michael@0: typeof(&class::func) name michael@0: #else michael@0: #define NS_STDCALL_FUNCPROTO(ret, name, class, func, args) \ michael@0: ret (NS_STDCALL class::*name) args michael@0: #endif michael@0: michael@0: /** michael@0: * Deprecated declarations. michael@0: */ michael@0: #ifdef __GNUC__ michael@0: # define MOZ_DEPRECATED __attribute__((deprecated)) michael@0: #elif defined(_MSC_VER) michael@0: # define MOZ_DEPRECATED __declspec(deprecated) michael@0: #else michael@0: # define MOZ_DEPRECATED michael@0: #endif michael@0: michael@0: /** michael@0: * Generic API modifiers which return the standard XPCOM nsresult type michael@0: */ michael@0: #define NS_IMETHOD NS_IMETHOD_(nsresult) michael@0: #define NS_IMETHODIMP NS_IMETHODIMP_(nsresult) michael@0: #define NS_METHOD NS_METHOD_(nsresult) michael@0: #define NS_CALLBACK(_name) NS_CALLBACK_(nsresult, _name) michael@0: michael@0: /** michael@0: * Import/Export macros for XPCOM APIs michael@0: */ michael@0: michael@0: #ifdef __cplusplus michael@0: #define NS_EXTERN_C extern "C" michael@0: #else michael@0: #define NS_EXTERN_C michael@0: #endif michael@0: michael@0: #define EXPORT_XPCOM_API(type) NS_EXTERN_C NS_EXPORT type NS_FROZENCALL michael@0: #define IMPORT_XPCOM_API(type) NS_EXTERN_C NS_IMPORT type NS_FROZENCALL michael@0: #define GLUE_XPCOM_API(type) NS_EXTERN_C NS_HIDDEN_(type) NS_FROZENCALL michael@0: michael@0: #ifdef IMPL_LIBXUL michael@0: #define XPCOM_API(type) EXPORT_XPCOM_API(type) michael@0: #elif defined(XPCOM_GLUE) michael@0: #define XPCOM_API(type) GLUE_XPCOM_API(type) michael@0: #else michael@0: #define XPCOM_API(type) IMPORT_XPCOM_API(type) michael@0: #endif michael@0: michael@0: #ifdef MOZILLA_INTERNAL_API michael@0: # define NS_COM_GLUE michael@0: /* michael@0: The frozen string API has different definitions of nsAC?String michael@0: classes than the internal API. On systems that explicitly declare michael@0: dllexport symbols this is not a problem, but on ELF systems michael@0: internal symbols can accidentally "shine through"; we rename the michael@0: internal classes to avoid symbol conflicts. michael@0: */ michael@0: # define nsAString nsAString_internal michael@0: # define nsACString nsACString_internal michael@0: #else michael@0: # ifdef HAVE_VISIBILITY_ATTRIBUTE michael@0: # define NS_COM_GLUE NS_VISIBILITY_HIDDEN michael@0: # else michael@0: # define NS_COM_GLUE michael@0: # endif michael@0: #endif michael@0: michael@0: #if (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING)) michael@0: /* Make refcnt logging part of the build. This doesn't mean that michael@0: * actual logging will occur (that requires a separate enable; see michael@0: * nsTraceRefcnt and nsISupportsImpl.h for more information). */ michael@0: #define NS_BUILD_REFCNT_LOGGING michael@0: #endif michael@0: michael@0: /* If NO_BUILD_REFCNT_LOGGING is defined then disable refcnt logging michael@0: * in the build. This overrides FORCE_BUILD_REFCNT_LOGGING. */ michael@0: #if defined(NO_BUILD_REFCNT_LOGGING) michael@0: #undef NS_BUILD_REFCNT_LOGGING michael@0: #endif michael@0: michael@0: /* If a program allocates memory for the lifetime of the app, it doesn't make michael@0: * sense to touch memory pages and free that memory at shutdown, michael@0: * unless we are running leak stats. michael@0: */ michael@0: #if defined(NS_TRACE_MALLOC) || defined(NS_BUILD_REFCNT_LOGGING) || defined(MOZ_VALGRIND) michael@0: #define NS_FREE_PERMANENT_DATA michael@0: #endif michael@0: michael@0: /** michael@0: * NS_NO_VTABLE is emitted by xpidl in interface declarations whenever michael@0: * xpidl can determine that the interface can't contain a constructor. michael@0: * This results in some space savings and possible runtime savings - michael@0: * see bug 49416. We undefine it first, as xpidl-generated headers michael@0: * define it for IDL uses that don't include this file. michael@0: */ michael@0: #ifdef NS_NO_VTABLE michael@0: #undef NS_NO_VTABLE michael@0: #endif michael@0: #if defined(_MSC_VER) michael@0: #define NS_NO_VTABLE __declspec(novtable) michael@0: #else michael@0: #define NS_NO_VTABLE michael@0: #endif michael@0: michael@0: michael@0: /** michael@0: * Generic XPCOM result data type michael@0: */ michael@0: #include "nsError.h" michael@0: michael@0: typedef MozRefCountType nsrefcnt; michael@0: michael@0: /* michael@0: * Use these macros to do 64bit safe pointer conversions. michael@0: */ michael@0: michael@0: #define NS_PTR_TO_INT32(x) ((int32_t) (intptr_t) (x)) michael@0: #define NS_PTR_TO_UINT32(x) ((uint32_t) (intptr_t) (x)) michael@0: #define NS_INT32_TO_PTR(x) ((void *) (intptr_t) (x)) michael@0: michael@0: /* michael@0: * Use NS_STRINGIFY to form a string literal from the value of a macro. michael@0: */ michael@0: #define NS_STRINGIFY_HELPER(x_) #x_ michael@0: #define NS_STRINGIFY(x_) NS_STRINGIFY_HELPER(x_) michael@0: michael@0: /* michael@0: * If we're being linked as standalone glue, we don't want a dynamic michael@0: * dependency on NSPR libs, so we skip the debug thread-safety michael@0: * checks, and we cannot use the THREADSAFE_ISUPPORTS macros. michael@0: */ michael@0: #if defined(XPCOM_GLUE) && !defined(XPCOM_GLUE_USE_NSPR) michael@0: #define XPCOM_GLUE_AVOID_NSPR michael@0: #endif michael@0: michael@0: #if defined(HAVE_THREAD_TLS_KEYWORD) michael@0: #define NS_TLS __thread michael@0: #endif michael@0: michael@0: /* michael@0: * SEH exception macros. michael@0: */ michael@0: #ifdef HAVE_SEH_EXCEPTIONS michael@0: #define MOZ_SEH_TRY __try michael@0: #define MOZ_SEH_EXCEPT(expr) __except(expr) michael@0: #else michael@0: #define MOZ_SEH_TRY if(true) michael@0: #define MOZ_SEH_EXCEPT(expr) else michael@0: #endif michael@0: michael@0: #endif /* nscore_h___ */