Back to index

lightning-sunbird  0.9+nobinonly
prtypes.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039 ** File:                prtypes.h
00040 ** Description: Definitions of NSPR's basic types
00041 **
00042 ** Prototypes and macros used to make up for deficiencies that we have found
00043 ** in ANSI environments.
00044 **
00045 ** Since we do not wrap <stdlib.h> and all the other standard headers, authors
00046 ** of portable code will not know in general that they need these definitions.
00047 ** Instead of requiring these authors to find the dependent uses in their code
00048 ** and take the following steps only in those C files, we take steps once here
00049 ** for all C files.
00050 **/
00051 
00052 #ifndef prtypes_h___
00053 #define prtypes_h___
00054 
00055 #ifdef MDCPUCFG
00056 #include MDCPUCFG
00057 #else
00058 #include "prcpucfg.h"
00059 #endif
00060 
00061 #include <stddef.h>
00062 
00063 /***********************************************************************
00064 ** MACROS:      PR_EXTERN
00065 **              PR_IMPLEMENT
00066 ** DESCRIPTION:
00067 **      These are only for externally visible routines and globals.  For
00068 **      internal routines, just use "extern" for type checking and that
00069 **      will not export internal cross-file or forward-declared symbols.
00070 **      Define a macro for declaring procedures return types. We use this to
00071 **      deal with windoze specific type hackery for DLL definitions. Use
00072 **      PR_EXTERN when the prototype for the method is declared. Use
00073 **      PR_IMPLEMENT for the implementation of the method.
00074 **
00075 ** Example:
00076 **   in dowhim.h
00077 **     PR_EXTERN( void ) DoWhatIMean( void );
00078 **   in dowhim.c
00079 **     PR_IMPLEMENT( void ) DoWhatIMean( void ) { return; }
00080 **
00081 **
00082 ***********************************************************************/
00083 #if defined(WIN32)
00084 
00085 #define PR_EXPORT(__type) extern __declspec(dllexport) __type
00086 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
00087 #define PR_IMPORT(__type) __declspec(dllimport) __type
00088 #define PR_IMPORT_DATA(__type) __declspec(dllimport) __type
00089 
00090 #define PR_EXTERN(__type) extern __declspec(dllexport) __type
00091 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type
00092 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
00093 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
00094 
00095 #define PR_CALLBACK
00096 #define PR_CALLBACK_DECL
00097 #define PR_STATIC_CALLBACK(__x) static __x
00098 
00099 #elif defined(XP_BEOS)
00100 
00101 #define PR_EXPORT(__type) extern __declspec(dllexport) __type
00102 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
00103 #define PR_IMPORT(__type) extern __declspec(dllexport) __type
00104 #define PR_IMPORT_DATA(__type) extern __declspec(dllexport) __type
00105 
00106 #define PR_EXTERN(__type) extern __declspec(dllexport) __type
00107 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type
00108 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
00109 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
00110 
00111 #define PR_CALLBACK
00112 #define PR_CALLBACK_DECL
00113 #define PR_STATIC_CALLBACK(__x) static __x
00114 
00115 #elif defined(WIN16)
00116 
00117 #define PR_CALLBACK_DECL        __cdecl
00118 
00119 #if defined(_WINDLL)
00120 #define PR_EXPORT(__type) extern __type _cdecl _export _loadds
00121 #define PR_IMPORT(__type) extern __type _cdecl _export _loadds
00122 #define PR_EXPORT_DATA(__type) extern __type _export
00123 #define PR_IMPORT_DATA(__type) extern __type _export
00124 
00125 #define PR_EXTERN(__type) extern __type _cdecl _export _loadds
00126 #define PR_IMPLEMENT(__type) __type _cdecl _export _loadds
00127 #define PR_EXTERN_DATA(__type) extern __type _export
00128 #define PR_IMPLEMENT_DATA(__type) __type _export
00129 
00130 #define PR_CALLBACK             __cdecl __loadds
00131 #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
00132 
00133 #else /* this must be .EXE */
00134 #define PR_EXPORT(__type) extern __type _cdecl _export
00135 #define PR_IMPORT(__type) extern __type _cdecl _export
00136 #define PR_EXPORT_DATA(__type) extern __type _export
00137 #define PR_IMPORT_DATA(__type) extern __type _export
00138 
00139 #define PR_EXTERN(__type) extern __type _cdecl _export
00140 #define PR_IMPLEMENT(__type) __type _cdecl _export
00141 #define PR_EXTERN_DATA(__type) extern __type _export
00142 #define PR_IMPLEMENT_DATA(__type) __type _export
00143 
00144 #define PR_CALLBACK             __cdecl __loadds
00145 #define PR_STATIC_CALLBACK(__x) __x PR_CALLBACK
00146 #endif /* _WINDLL */
00147 
00148 #elif defined(XP_MAC)
00149 
00150 #define PR_EXPORT(__type) extern __declspec(export) __type
00151 #define PR_EXPORT_DATA(__type) extern __declspec(export) __type
00152 #define PR_IMPORT(__type) extern __declspec(export) __type
00153 #define PR_IMPORT_DATA(__type) extern __declspec(export) __type
00154 
00155 #define PR_EXTERN(__type) extern __declspec(export) __type
00156 #define PR_IMPLEMENT(__type) __declspec(export) __type
00157 #define PR_EXTERN_DATA(__type) extern __declspec(export) __type
00158 #define PR_IMPLEMENT_DATA(__type) __declspec(export) __type
00159 
00160 #define PR_CALLBACK
00161 #define PR_CALLBACK_DECL
00162 #define PR_STATIC_CALLBACK(__x) static __x
00163 
00164 #elif defined(XP_OS2_VACPP) 
00165 
00166 #define PR_EXPORT(__type) extern __type
00167 #define PR_EXPORT_DATA(__type) extern __type
00168 #define PR_IMPORT(__type) extern __type
00169 #define PR_IMPORT_DATA(__type) extern __type
00170 
00171 #define PR_EXTERN(__type) extern __type
00172 #define PR_IMPLEMENT(__type) __type
00173 #define PR_EXTERN_DATA(__type) extern __type
00174 #define PR_IMPLEMENT_DATA(__type) __type
00175 #define PR_CALLBACK _Optlink
00176 #define PR_CALLBACK_DECL
00177 #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
00178 
00179 #else /* Unix */
00180 
00181 /* GCC 3.3 and later support the visibility attribute. */
00182 #if (__GNUC__ >= 4) || \
00183     (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
00184 #define PR_VISIBILITY_DEFAULT __attribute__((visibility("default")))
00185 #else
00186 #define PR_VISIBILITY_DEFAULT
00187 #endif
00188 
00189 #define PR_EXPORT(__type) extern PR_VISIBILITY_DEFAULT __type
00190 #define PR_EXPORT_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
00191 #define PR_IMPORT(__type) extern PR_VISIBILITY_DEFAULT __type
00192 #define PR_IMPORT_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
00193 
00194 #define PR_EXTERN(__type) extern PR_VISIBILITY_DEFAULT __type
00195 #define PR_IMPLEMENT(__type) PR_VISIBILITY_DEFAULT __type
00196 #define PR_EXTERN_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
00197 #define PR_IMPLEMENT_DATA(__type) PR_VISIBILITY_DEFAULT __type
00198 #define PR_CALLBACK
00199 #define PR_CALLBACK_DECL
00200 #define PR_STATIC_CALLBACK(__x) static __x
00201 
00202 #endif
00203 
00204 #if defined(_NSPR_BUILD_)
00205 #define NSPR_API(__type) PR_EXPORT(__type)
00206 #define NSPR_DATA_API(__type) PR_EXPORT_DATA(__type)
00207 #else
00208 #define NSPR_API(__type) PR_IMPORT(__type)
00209 #define NSPR_DATA_API(__type) PR_IMPORT_DATA(__type)
00210 #endif
00211 
00212 /***********************************************************************
00213 ** MACROS:      PR_BEGIN_MACRO
00214 **              PR_END_MACRO
00215 ** DESCRIPTION:
00216 **      Macro body brackets so that macros with compound statement definitions
00217 **      behave syntactically more like functions when called.
00218 ***********************************************************************/
00219 #define PR_BEGIN_MACRO  do {
00220 #define PR_END_MACRO    } while (0)
00221 
00222 /***********************************************************************
00223 ** MACROS:      PR_BEGIN_EXTERN_C
00224 **              PR_END_EXTERN_C
00225 ** DESCRIPTION:
00226 **      Macro shorthands for conditional C++ extern block delimiters.
00227 ***********************************************************************/
00228 #ifdef __cplusplus
00229 #define PR_BEGIN_EXTERN_C       extern "C" {
00230 #define PR_END_EXTERN_C         }
00231 #else
00232 #define PR_BEGIN_EXTERN_C
00233 #define PR_END_EXTERN_C
00234 #endif
00235 
00236 /***********************************************************************
00237 ** MACROS:      PR_BIT
00238 **              PR_BITMASK
00239 ** DESCRIPTION:
00240 ** Bit masking macros.  XXX n must be <= 31 to be portable
00241 ***********************************************************************/
00242 #define PR_BIT(n)       ((PRUint32)1 << (n))
00243 #define PR_BITMASK(n)   (PR_BIT(n) - 1)
00244 
00245 /***********************************************************************
00246 ** MACROS:      PR_ROUNDUP
00247 **              PR_MIN
00248 **              PR_MAX
00249 **              PR_ABS
00250 ** DESCRIPTION:
00251 **      Commonly used macros for operations on compatible types.
00252 ***********************************************************************/
00253 #define PR_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y))
00254 #define PR_MIN(x,y)     ((x)<(y)?(x):(y))
00255 #define PR_MAX(x,y)     ((x)>(y)?(x):(y))
00256 #define PR_ABS(x)       ((x)<0?-(x):(x))
00257 
00258 PR_BEGIN_EXTERN_C
00259 
00260 /************************************************************************
00261 ** TYPES:       PRUint8
00262 **              PRInt8
00263 ** DESCRIPTION:
00264 **  The int8 types are known to be 8 bits each. There is no type that
00265 **      is equivalent to a plain "char". 
00266 ************************************************************************/
00267 #if PR_BYTES_PER_BYTE == 1
00268 typedef unsigned char PRUint8;
00269 /*
00270 ** Some cfront-based C++ compilers do not like 'signed char' and
00271 ** issue the warning message:
00272 **     warning: "signed" not implemented (ignored)
00273 ** For these compilers, we have to define PRInt8 as plain 'char'.
00274 ** Make sure that plain 'char' is indeed signed under these compilers.
00275 */
00276 #if (defined(HPUX) && defined(__cplusplus) \
00277         && !defined(__GNUC__) && __cplusplus < 199707L) \
00278     || (defined(SCO) && defined(__cplusplus) \
00279         && !defined(__GNUC__) && __cplusplus == 1L)
00280 typedef char PRInt8;
00281 #else
00282 typedef signed char PRInt8;
00283 #endif
00284 #else
00285 #error No suitable type for PRInt8/PRUint8
00286 #endif
00287 
00288 /************************************************************************
00289  * MACROS:      PR_INT8_MAX
00290  *              PR_INT8_MIN
00291  *              PR_UINT8_MAX
00292  * DESCRIPTION:
00293  *  The maximum and minimum values of a PRInt8 or PRUint8.
00294 ************************************************************************/
00295 
00296 #define PR_INT8_MAX 127
00297 #define PR_INT8_MIN (-128)
00298 #define PR_UINT8_MAX 255U
00299 
00300 /************************************************************************
00301 ** TYPES:       PRUint16
00302 **              PRInt16
00303 ** DESCRIPTION:
00304 **  The int16 types are known to be 16 bits each. 
00305 ************************************************************************/
00306 #if PR_BYTES_PER_SHORT == 2
00307 typedef unsigned short PRUint16;
00308 typedef short PRInt16;
00309 #else
00310 #error No suitable type for PRInt16/PRUint16
00311 #endif
00312 
00313 /************************************************************************
00314  * MACROS:      PR_INT16_MAX
00315  *              PR_INT16_MIN
00316  *              PR_UINT16_MAX
00317  * DESCRIPTION:
00318  *  The maximum and minimum values of a PRInt16 or PRUint16.
00319 ************************************************************************/
00320 
00321 #define PR_INT16_MAX 32767
00322 #define PR_INT16_MIN (-32768)
00323 #define PR_UINT16_MAX 65535U
00324 
00325 /************************************************************************
00326 ** TYPES:       PRUint32
00327 **              PRInt32
00328 ** DESCRIPTION:
00329 **  The int32 types are known to be 32 bits each. 
00330 ************************************************************************/
00331 #if PR_BYTES_PER_INT == 4
00332 typedef unsigned int PRUint32;
00333 typedef int PRInt32;
00334 #define PR_INT32(x)  x
00335 #define PR_UINT32(x) x ## U
00336 #elif PR_BYTES_PER_LONG == 4
00337 typedef unsigned long PRUint32;
00338 typedef long PRInt32;
00339 #define PR_INT32(x)  x ## L
00340 #define PR_UINT32(x) x ## UL
00341 #else
00342 #error No suitable type for PRInt32/PRUint32
00343 #endif
00344 
00345 /************************************************************************
00346  * MACROS:      PR_INT32_MAX
00347  *              PR_INT32_MIN
00348  *              PR_UINT32_MAX
00349  * DESCRIPTION:
00350  *  The maximum and minimum values of a PRInt32 or PRUint32.
00351 ************************************************************************/
00352 
00353 #define PR_INT32_MAX PR_INT32(2147483647)
00354 #define PR_INT32_MIN (-PR_INT32_MAX - 1)
00355 #define PR_UINT32_MAX PR_UINT32(4294967295)
00356 
00357 /************************************************************************
00358 ** TYPES:       PRUint64
00359 **              PRInt64
00360 ** DESCRIPTION:
00361 **  The int64 types are known to be 64 bits each. Care must be used when
00362 **      declaring variables of type PRUint64 or PRInt64. Different hardware
00363 **      architectures and even different compilers have varying support for
00364 **      64 bit values. The only guaranteed portability requires the use of
00365 **      the LL_ macros (see prlong.h).
00366 ************************************************************************/
00367 #ifdef HAVE_LONG_LONG
00368 #if PR_BYTES_PER_LONG == 8
00369 typedef long PRInt64;
00370 typedef unsigned long PRUint64;
00371 #elif defined(WIN16)
00372 typedef __int64 PRInt64;
00373 typedef unsigned __int64 PRUint64;
00374 #elif defined(WIN32) && !defined(__GNUC__)
00375 typedef __int64  PRInt64;
00376 typedef unsigned __int64 PRUint64;
00377 #else
00378 typedef long long PRInt64;
00379 typedef unsigned long long PRUint64;
00380 #endif /* PR_BYTES_PER_LONG == 8 */
00381 #else  /* !HAVE_LONG_LONG */
00382 typedef struct {
00383 #ifdef IS_LITTLE_ENDIAN
00384     PRUint32 lo, hi;
00385 #else
00386     PRUint32 hi, lo;
00387 #endif
00388 } PRInt64;
00389 typedef PRInt64 PRUint64;
00390 #endif /* !HAVE_LONG_LONG */
00391 
00392 /************************************************************************
00393 ** TYPES:       PRUintn
00394 **              PRIntn
00395 ** DESCRIPTION:
00396 **  The PRIntn types are most appropriate for automatic variables. They are
00397 **      guaranteed to be at least 16 bits, though various architectures may
00398 **      define them to be wider (e.g., 32 or even 64 bits). These types are
00399 **      never valid for fields of a structure. 
00400 ************************************************************************/
00401 #if PR_BYTES_PER_INT >= 2
00402 typedef int PRIntn;
00403 typedef unsigned int PRUintn;
00404 #else
00405 #error 'sizeof(int)' not sufficient for platform use
00406 #endif
00407 
00408 /************************************************************************
00409 ** TYPES:       PRFloat64
00410 ** DESCRIPTION:
00411 **  NSPR's floating point type is always 64 bits. 
00412 ************************************************************************/
00413 typedef double          PRFloat64;
00414 
00415 /************************************************************************
00416 ** TYPES:       PRSize
00417 ** DESCRIPTION:
00418 **  A type for representing the size of objects. 
00419 ************************************************************************/
00420 typedef size_t PRSize;
00421 
00422 
00423 /************************************************************************
00424 ** TYPES:       PROffset32, PROffset64
00425 ** DESCRIPTION:
00426 **  A type for representing byte offsets from some location. 
00427 ************************************************************************/
00428 typedef PRInt32 PROffset32;
00429 typedef PRInt64 PROffset64;
00430 
00431 /************************************************************************
00432 ** TYPES:       PRPtrDiff
00433 ** DESCRIPTION:
00434 **  A type for pointer difference. Variables of this type are suitable
00435 **      for storing a pointer or pointer subtraction. 
00436 ************************************************************************/
00437 typedef ptrdiff_t PRPtrdiff;
00438 
00439 /************************************************************************
00440 ** TYPES:       PRUptrdiff
00441 ** DESCRIPTION:
00442 **  A type for pointer difference. Variables of this type are suitable
00443 **      for storing a pointer or pointer sutraction. 
00444 ************************************************************************/
00445 typedef unsigned long PRUptrdiff;
00446 
00447 /************************************************************************
00448 ** TYPES:       PRBool
00449 ** DESCRIPTION:
00450 **  Use PRBool for variables and parameter types. Use PR_FALSE and PR_TRUE
00451 **      for clarity of target type in assignments and actual arguments. Use
00452 **      'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
00453 **      just as you would C int-valued conditions. 
00454 ************************************************************************/
00455 typedef PRIntn PRBool;
00456 #define PR_TRUE 1
00457 #define PR_FALSE 0
00458 
00459 /************************************************************************
00460 ** TYPES:       PRPackedBool
00461 ** DESCRIPTION:
00462 **  Use PRPackedBool within structs where bitfields are not desirable
00463 **      but minimum and consistant overhead matters.
00464 ************************************************************************/
00465 typedef PRUint8 PRPackedBool;
00466 
00467 /*
00468 ** Status code used by some routines that have a single point of failure or 
00469 ** special status return.
00470 */
00471 typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
00472 
00473 #ifndef __PRUNICHAR__
00474 #define __PRUNICHAR__
00475 #if defined(WIN32) || defined(XP_MAC)
00476 typedef wchar_t PRUnichar;
00477 #else
00478 typedef PRUint16 PRUnichar;
00479 #endif
00480 #endif
00481 
00482 /*
00483 ** WARNING: The undocumented data types PRWord and PRUword are
00484 ** only used in the garbage collection and arena code.  Do not
00485 ** use PRWord and PRUword in new code.
00486 **
00487 ** A PRWord is an integer that is the same size as a void*.
00488 ** It implements the notion of a "word" in the Java Virtual
00489 ** Machine.  (See Sec. 3.4 "Words", The Java Virtual Machine
00490 ** Specification, Addison-Wesley, September 1996.
00491 ** http://java.sun.com/docs/books/vmspec/index.html.)
00492 */
00493 typedef long PRWord;
00494 typedef unsigned long PRUword;
00495 
00496 #if defined(NO_NSPR_10_SUPPORT)
00497 #else
00498 /********* ???????????????? FIX ME       ??????????????????????????? *****/
00499 /********************** Some old definitions until pr=>ds transition is done ***/
00500 /********************** Also, we are still using NSPR 1.0. GC ******************/
00501 /*
00502 ** Fundamental NSPR macros, used nearly everywhere.
00503 */
00504 
00505 #define PR_PUBLIC_API              PR_IMPLEMENT
00506 
00507 /*
00508 ** Macro body brackets so that macros with compound statement definitions
00509 ** behave syntactically more like functions when called.
00510 */
00511 #define NSPR_BEGIN_MACRO        do {
00512 #define NSPR_END_MACRO          } while (0)
00513 
00514 /*
00515 ** Macro shorthands for conditional C++ extern block delimiters.
00516 */
00517 #ifdef NSPR_BEGIN_EXTERN_C
00518 #undef NSPR_BEGIN_EXTERN_C
00519 #endif
00520 #ifdef NSPR_END_EXTERN_C
00521 #undef NSPR_END_EXTERN_C
00522 #endif
00523 
00524 #ifdef __cplusplus
00525 #define NSPR_BEGIN_EXTERN_C     extern "C" {
00526 #define NSPR_END_EXTERN_C       }
00527 #else
00528 #define NSPR_BEGIN_EXTERN_C
00529 #define NSPR_END_EXTERN_C
00530 #endif
00531 
00532 #ifdef XP_MAC
00533 #include "protypes.h"
00534 #else
00535 #include "obsolete/protypes.h"
00536 #endif
00537 
00538 /********* ????????????? End Fix me ?????????????????????????????? *****/
00539 #endif /* NO_NSPR_10_SUPPORT */
00540 
00541 PR_END_EXTERN_C
00542 
00543 #endif /* prtypes_h___ */
00544