mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-16 05:45:33 +00:00
Bug 711672 - Break mfbt's dependency on jstypes.h by moving various API macros out of JS and into mfbt. r=luke, r=cjones
--HG-- extra : rebase_source : f18993e1eec1a5e5bcdb9cd97fa7d7c6ad261e2c
This commit is contained in:
parent
9dc2c72bd7
commit
bcd5afef4c
@ -41,8 +41,7 @@
|
||||
#ifndef js_template_lib_h__
|
||||
#define js_template_lib_h__
|
||||
|
||||
#include "mozilla/Types.h"
|
||||
#include "jsstdint.h"
|
||||
#include "jstypes.h"
|
||||
|
||||
/*
|
||||
* Library of reusable template meta-functions (that is, functions on types and
|
||||
|
@ -43,7 +43,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mozilla/Util.h"
|
||||
#include "jstypes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
|
@ -54,9 +54,8 @@
|
||||
#ifndef jstypes_h___
|
||||
#define jstypes_h___
|
||||
|
||||
#include "mozilla/StdInt.h"
|
||||
#include "mozilla/Util.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include "js-config.h"
|
||||
|
||||
/***********************************************************************
|
||||
@ -80,50 +79,11 @@
|
||||
**
|
||||
***********************************************************************/
|
||||
|
||||
#if defined(WIN32) || defined(XP_OS2)
|
||||
|
||||
/* These also work for __MWERKS__ */
|
||||
# define JS_EXTERN_API(__type) extern __declspec(dllexport) __type
|
||||
# define JS_EXPORT_API(__type) __declspec(dllexport) __type
|
||||
# define JS_EXTERN_DATA(__type) extern __declspec(dllexport) __type
|
||||
# define JS_EXPORT_DATA(__type) __declspec(dllexport) __type
|
||||
|
||||
#else /* Unix */
|
||||
|
||||
# ifdef HAVE_VISIBILITY_ATTRIBUTE
|
||||
# define JS_EXTERNAL_VIS __attribute__((visibility ("default")))
|
||||
# elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
|
||||
# define JS_EXTERNAL_VIS __global
|
||||
# else
|
||||
# define JS_EXTERNAL_VIS
|
||||
# endif
|
||||
|
||||
# define JS_EXTERN_API(__type) extern JS_EXTERNAL_VIS __type
|
||||
# define JS_EXPORT_API(__type) JS_EXTERNAL_VIS __type
|
||||
# define JS_EXTERN_DATA(__type) extern JS_EXTERNAL_VIS __type
|
||||
# define JS_EXPORT_DATA(__type) JS_EXTERNAL_VIS __type
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# if defined(__MWERKS__) || defined(__GNUC__)
|
||||
# define JS_IMPORT_API(__x) __x
|
||||
# else
|
||||
# define JS_IMPORT_API(__x) __declspec(dllimport) __x
|
||||
# endif
|
||||
#elif defined(XP_OS2)
|
||||
# define JS_IMPORT_API(__x) __declspec(dllimport) __x
|
||||
#else
|
||||
# define JS_IMPORT_API(__x) JS_EXPORT_API (__x)
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && !defined(__MWERKS__)
|
||||
# define JS_IMPORT_DATA(__x) __declspec(dllimport) __x
|
||||
#elif defined(XP_OS2)
|
||||
# define JS_IMPORT_DATA(__x) __declspec(dllimport) __x
|
||||
#else
|
||||
# define JS_IMPORT_DATA(__x) JS_EXPORT_DATA (__x)
|
||||
#endif
|
||||
#define JS_EXTERN_API(type) extern MOZ_EXPORT_API(type)
|
||||
#define JS_EXPORT_API(type) MOZ_EXPORT_API(type)
|
||||
#define JS_EXPORT_DATA(type) MOZ_EXPORT_DATA(type)
|
||||
#define JS_IMPORT_API(type) MOZ_IMPORT_API(type)
|
||||
#define JS_IMPORT_DATA(type) MOZ_IMPORT_DATA(type)
|
||||
|
||||
/*
|
||||
* The linkage of JS API functions differs depending on whether the file is
|
||||
@ -132,20 +92,14 @@
|
||||
* should not. STATIC_JS_API is used to build JS as a static library.
|
||||
*/
|
||||
#if defined(STATIC_JS_API)
|
||||
|
||||
# define JS_PUBLIC_API(t) t
|
||||
# define JS_PUBLIC_DATA(t) t
|
||||
|
||||
# define JS_PUBLIC_API(t) t
|
||||
# define JS_PUBLIC_DATA(t) t
|
||||
#elif defined(EXPORT_JS_API) || defined(STATIC_EXPORTABLE_JS_API)
|
||||
|
||||
# define JS_PUBLIC_API(t) JS_EXPORT_API(t)
|
||||
# define JS_PUBLIC_DATA(t) JS_EXPORT_DATA(t)
|
||||
|
||||
# define JS_PUBLIC_API(t) MOZ_EXPORT_API(t)
|
||||
# define JS_PUBLIC_DATA(t) MOZ_EXPORT_DATA(t)
|
||||
#else
|
||||
|
||||
# define JS_PUBLIC_API(t) JS_IMPORT_API(t)
|
||||
# define JS_PUBLIC_DATA(t) JS_IMPORT_DATA(t)
|
||||
|
||||
# define JS_PUBLIC_API(t) MOZ_IMPORT_API(t)
|
||||
# define JS_PUBLIC_DATA(t) MOZ_IMPORT_DATA(t)
|
||||
#endif
|
||||
|
||||
#define JS_FRIEND_API(t) JS_PUBLIC_API(t)
|
||||
@ -245,17 +199,8 @@
|
||||
** DESCRIPTION:
|
||||
** Macro shorthands for conditional C++ extern block delimiters.
|
||||
***********************************************************************/
|
||||
#ifdef __cplusplus
|
||||
|
||||
# define JS_BEGIN_EXTERN_C extern "C" {
|
||||
# define JS_END_EXTERN_C }
|
||||
|
||||
#else
|
||||
|
||||
# define JS_BEGIN_EXTERN_C
|
||||
# define JS_END_EXTERN_C
|
||||
|
||||
#endif
|
||||
#define JS_BEGIN_EXTERN_C MOZ_BEGIN_EXTERN_C
|
||||
#define JS_END_EXTERN_C MOZ_END_EXTERN_C
|
||||
|
||||
/***********************************************************************
|
||||
** MACROS: JS_BIT
|
||||
|
@ -53,6 +53,8 @@
|
||||
# include <signal.h>
|
||||
#endif
|
||||
|
||||
#include "js/TemplateLib.h"
|
||||
|
||||
using namespace js;
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -96,7 +98,16 @@ CrashInJS()
|
||||
#endif
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void) JS_Assert(const char *s, const char *file, JSIntn ln)
|
||||
/*
|
||||
* |JS_Assert| historically took |JSIntn ln| as its last argument. We've
|
||||
* boiled |JSIntn ln| down to simply |int ln| so that mfbt may declare the
|
||||
* function without depending on the |JSIntn| typedef, so we must manually
|
||||
* verify that the |JSIntn| typedef is consistent.
|
||||
*/
|
||||
JS_STATIC_ASSERT((tl::IsSameType<JSIntn, int>::result));
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_Assert(const char *s, const char *file, int ln)
|
||||
{
|
||||
fprintf(stderr, "Assertion failure: %s, at %s:%d\n", s, file, ln);
|
||||
fflush(stderr);
|
||||
|
@ -231,8 +231,8 @@ my_GetErrorMessage(void *userRef, const char *locale, const uintN errorNumber);
|
||||
|
||||
#ifdef EDITLINE
|
||||
JS_BEGIN_EXTERN_C
|
||||
JS_EXTERN_API(char) *readline(const char *prompt);
|
||||
JS_EXTERN_API(void) add_history(char *line);
|
||||
extern JS_EXPORT_API(char *) readline(const char *prompt);
|
||||
extern JS_EXPORT_API(void) add_history(char *line);
|
||||
JS_END_EXTERN_C
|
||||
#endif
|
||||
|
||||
|
@ -246,7 +246,7 @@ GetLocationProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
|
||||
#ifdef EDITLINE
|
||||
extern "C" {
|
||||
extern JS_EXPORT_API(char) *readline(const char *prompt);
|
||||
extern JS_EXPORT_API(char *) readline(const char *prompt);
|
||||
extern JS_EXPORT_API(void) add_history(char *line);
|
||||
}
|
||||
#endif
|
||||
|
136
mfbt/Types.h
136
mfbt/Types.h
@ -37,51 +37,125 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/*
|
||||
* NB: This header must be both valid C and C++. It must be
|
||||
* include-able by code embedding SpiderMonkey *and* Gecko.
|
||||
*/
|
||||
/* mfbt foundational types and macros. */
|
||||
|
||||
#ifndef mozilla_Types_h_
|
||||
#define mozilla_Types_h_
|
||||
|
||||
/*
|
||||
* Expose the standard integer types from <stdint.h> (and the integer type
|
||||
* limit and constant macros, if the right __STDC_*_MACRO has been defined for
|
||||
* each). These are all usable throughout mfbt code, and throughout Mozilla
|
||||
* code more generally.
|
||||
* This header must be valid C and C++, includable by code embedding either
|
||||
* SpiderMonkey or Gecko.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Expose all the integer types defined in C99's <stdint.h> (and the integer
|
||||
* limit and constant macros, if compiling C code or if compiling C++ code and
|
||||
* the right __STDC_*_MACRO has been defined for each). These are all usable
|
||||
* throughout mfbt code, and throughout Mozilla code more generally.
|
||||
*/
|
||||
#include "mozilla/StdInt.h"
|
||||
|
||||
/*
|
||||
* mfbt is logically "lower level" than js/src, but needs basic
|
||||
* definitions of numerical types and macros for compiler/linker
|
||||
* directives. js/src already goes through some pain to provide them
|
||||
* on numerous platforms, so instead of moving all that goop here,
|
||||
* this header makes use of the fact that for the foreseeable future
|
||||
* mfbt code will be part and parcel with libmozjs, static or not.
|
||||
*
|
||||
* For now, the policy is to use jstypes definitions but add a layer
|
||||
* of indirection on top of them in case a Great Refactoring ever
|
||||
* happens.
|
||||
*/
|
||||
#include "jstypes.h"
|
||||
/* Also expose size_t. */
|
||||
#include <stddef.h>
|
||||
|
||||
#define MOZ_EXPORT_API(type_) JS_EXPORT_API(type_)
|
||||
#define MOZ_IMPORT_API(type_) JS_IMPORT_API(type_)
|
||||
/* Implement compiler and linker macros needed for APIs. */
|
||||
|
||||
/*
|
||||
* mfbt definitions need to see export declarations when built, but
|
||||
* other code needs to see import declarations when using mfbt.
|
||||
* MOZ_EXPORT_API is used to declare and define a method which is externally
|
||||
* visible to users of the current library. It encapsulates various decorations
|
||||
* needed to properly export the method's symbol. MOZ_EXPORT_DATA serves the
|
||||
* same purpose for data.
|
||||
*
|
||||
* api.h:
|
||||
* extern MOZ_EXPORT_API(int) MeaningOfLife(void);
|
||||
* extern MOZ_EXPORT_DATA(int) LuggageCombination;
|
||||
*
|
||||
* api.c:
|
||||
* MOZ_EXPORT_API(int) MeaningOfLife(void) { return 42; }
|
||||
* MOZ_EXPORT_DATA(int) LuggageCombination = 12345;
|
||||
*
|
||||
* If you are merely sharing a method across files, just use plain |extern|.
|
||||
* These macros are designed for use by library interfaces -- not for normal
|
||||
* methods or data used cross-file.
|
||||
*/
|
||||
#if defined(IMPL_MFBT)
|
||||
# define MFBT_API(type_) MOZ_EXPORT_API(type_)
|
||||
#else
|
||||
# define MFBT_API(type_) MOZ_IMPORT_API(type_)
|
||||
#if defined(WIN32) || defined(XP_OS2)
|
||||
# define MOZ_EXPORT_API(type) __declspec(dllexport) type
|
||||
# define MOZ_EXPORT_DATA(type) __declspec(dllexport) type
|
||||
#else /* Unix */
|
||||
# ifdef HAVE_VISIBILITY_ATTRIBUTE
|
||||
# define MOZ_EXTERNAL_VIS __attribute__((visibility("default")))
|
||||
# elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
|
||||
# define MOZ_EXTERNAL_VIS __global
|
||||
# else
|
||||
# define MOZ_EXTERNAL_VIS
|
||||
# endif
|
||||
# define MOZ_EXPORT_API(type) MOZ_EXTERNAL_VIS type
|
||||
# define MOZ_EXPORT_DATA(type) MOZ_EXTERNAL_VIS type
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Whereas implementers use MOZ_EXPORT_API and MOZ_EXPORT_DATA to declare and
|
||||
* define library symbols, users use MOZ_IMPORT_API and MOZ_IMPORT_DATA to
|
||||
* access them. Most often the implementer of the library will expose an API
|
||||
* macro which expands to either the export or import version of the macro,
|
||||
* depending upon the compilation mode.
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
# if defined(__MWERKS__) || defined(__GNUC__)
|
||||
# define MOZ_IMPORT_API(x) x
|
||||
# else
|
||||
# define MOZ_IMPORT_API(x) __declspec(dllimport) x
|
||||
# endif
|
||||
#elif defined(XP_OS2)
|
||||
# define MOZ_IMPORT_API(x) __declspec(dllimport) x
|
||||
#else
|
||||
# define MOZ_IMPORT_API(x) MOZ_EXPORT_API(x)
|
||||
#endif
|
||||
|
||||
#define MOZ_BEGIN_EXTERN_C JS_BEGIN_EXTERN_C
|
||||
#define MOZ_END_EXTERN_C JS_END_EXTERN_C
|
||||
#if defined(_WIN32) && !defined(__MWERKS__)
|
||||
# define MOZ_IMPORT_DATA(x) __declspec(dllimport) x
|
||||
#elif defined(XP_OS2)
|
||||
# define MOZ_IMPORT_DATA(x) __declspec(dllimport) x
|
||||
#else
|
||||
# define MOZ_IMPORT_DATA(x) MOZ_EXPORT_DATA(x)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Consistent with the above comment, the MFBT_API and MFBT_DATA macros expose
|
||||
* export mfbt declarations when building mfbt, and they expose import mfbt
|
||||
* declarations when using mfbt.
|
||||
*/
|
||||
#if defined(IMPL_MFBT)
|
||||
# define MFBT_API(type) MOZ_EXPORT_API(type)
|
||||
# define MFBT_DATA(type) MOZ_EXPORT_DATA(type)
|
||||
#else
|
||||
# define MFBT_API(type) MOZ_IMPORT_API(type)
|
||||
# define MFBT_DATA(type) MOZ_IMPORT_DATA(type)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* C symbols in C++ code must be declared immediately within |extern "C"|
|
||||
* blocks. However, in C code, they need not be declared specially. This
|
||||
* difference is abstracted behind the MOZ_BEGIN_EXTERN_C and MOZ_END_EXTERN_C
|
||||
* macros, so that the user need not know whether he is being used in C or C++
|
||||
* code.
|
||||
*
|
||||
* MOZ_BEGIN_EXTERN_C
|
||||
*
|
||||
* extern MOZ_EXPORT_API(int) MostRandomNumber(void);
|
||||
* ...other declarations...
|
||||
*
|
||||
* MOZ_END_EXTERN_C
|
||||
*
|
||||
* This said, it is preferable to just use |extern "C"| in C++ header files for
|
||||
* its greater clarity.
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
# define MOZ_BEGIN_EXTERN_C extern "C" {
|
||||
# define MOZ_END_EXTERN_C }
|
||||
#else
|
||||
# define MOZ_BEGIN_EXTERN_C
|
||||
# define MOZ_END_EXTERN_C
|
||||
#endif
|
||||
|
||||
#endif /* mozilla_Types_h_ */
|
||||
|
@ -59,7 +59,7 @@
|
||||
MOZ_BEGIN_EXTERN_C
|
||||
|
||||
extern MFBT_API(void)
|
||||
JS_Assert(const char *s, const char *file, JSIntn ln);
|
||||
JS_Assert(const char *s, const char *file, int ln);
|
||||
|
||||
MOZ_END_EXTERN_C
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user