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 #include <stddef.h>
00056 #include <prtypes.h>
00057 
00058 /***********************************************************************
00059 ** MACROS:      PR_EXTERN
00060 **              PR_IMPLEMENT
00061 ** DESCRIPTION:
00062 **      These are only for externally visible routines and globals.  For
00063 **      internal routines, just use "extern" for type checking and that
00064 **      will not export internal cross-file or forward-declared symbols.
00065 **      Define a macro for declaring procedures return types. We use this to
00066 **      deal with windoze specific type hackery for DLL definitions. Use
00067 **      PR_EXTERN when the prototype for the method is declared. Use
00068 **      PR_IMPLEMENT for the implementation of the method.
00069 **
00070 ** Example:
00071 **   in dowhim.h
00072 **     PR_EXTERN( void ) DoWhatIMean( void );
00073 **   in dowhim.c
00074 **     PR_IMPLEMENT( void ) DoWhatIMean( void ) { return; }
00075 **
00076 **
00077 ***********************************************************************/
00078 #if defined(WIN32)
00079 
00080 #define PR_EXPORT(__type) extern __declspec(dllexport) __type
00081 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
00082 #define PR_IMPORT(__type) __declspec(dllimport) __type
00083 #define PR_IMPORT_DATA(__type) __declspec(dllimport) __type
00084 
00085 #define PR_EXTERN(__type) extern __declspec(dllexport) __type
00086 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type
00087 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
00088 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
00089 
00090 #define PR_CALLBACK
00091 #define PR_CALLBACK_DECL
00092 #define PR_STATIC_CALLBACK(__x) static __x
00093 
00094 #elif defined(XP_BEOS)
00095 
00096 #define PR_EXPORT(__type) extern __declspec(dllexport) __type
00097 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
00098 #define PR_IMPORT(__type) extern __declspec(dllexport) __type
00099 #define PR_IMPORT_DATA(__type) extern __declspec(dllexport) __type
00100 
00101 #define PR_EXTERN(__type) extern __declspec(dllexport) __type
00102 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type
00103 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
00104 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
00105 
00106 #define PR_CALLBACK
00107 #define PR_CALLBACK_DECL
00108 #define PR_STATIC_CALLBACK(__x) static __x
00109 
00110 #elif defined(WIN16)
00111 
00112 #define PR_CALLBACK_DECL        __cdecl
00113 
00114 #if defined(_WINDLL)
00115 #define PR_EXPORT(__type) extern __type _cdecl _export _loadds
00116 #define PR_IMPORT(__type) extern __type _cdecl _export _loadds
00117 #define PR_EXPORT_DATA(__type) extern __type _export
00118 #define PR_IMPORT_DATA(__type) extern __type _export
00119 
00120 #define PR_EXTERN(__type) extern __type _cdecl _export _loadds
00121 #define PR_IMPLEMENT(__type) __type _cdecl _export _loadds
00122 #define PR_EXTERN_DATA(__type) extern __type _export
00123 #define PR_IMPLEMENT_DATA(__type) __type _export
00124 
00125 #define PR_CALLBACK             __cdecl __loadds
00126 #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
00127 
00128 #else /* this must be .EXE */
00129 #define PR_EXPORT(__type) extern __type _cdecl _export
00130 #define PR_IMPORT(__type) extern __type _cdecl _export
00131 #define PR_EXPORT_DATA(__type) extern __type _export
00132 #define PR_IMPORT_DATA(__type) extern __type _export
00133 
00134 #define PR_EXTERN(__type) extern __type _cdecl _export
00135 #define PR_IMPLEMENT(__type) __type _cdecl _export
00136 #define PR_EXTERN_DATA(__type) extern __type _export
00137 #define PR_IMPLEMENT_DATA(__type) __type _export
00138 
00139 #define PR_CALLBACK             __cdecl __loadds
00140 #define PR_STATIC_CALLBACK(__x) __x PR_CALLBACK
00141 #endif /* _WINDLL */
00142 
00143 #elif defined(XP_MAC)
00144 
00145 #define PR_EXPORT(__type) extern __declspec(export) __type
00146 #define PR_EXPORT_DATA(__type) extern __declspec(export) __type
00147 #define PR_IMPORT(__type) extern __declspec(export) __type
00148 #define PR_IMPORT_DATA(__type) extern __declspec(export) __type
00149 
00150 #define PR_EXTERN(__type) extern __declspec(export) __type
00151 #define PR_IMPLEMENT(__type) __declspec(export) __type
00152 #define PR_EXTERN_DATA(__type) extern __declspec(export) __type
00153 #define PR_IMPLEMENT_DATA(__type) __declspec(export) __type
00154 
00155 #define PR_CALLBACK
00156 #define PR_CALLBACK_DECL
00157 #define PR_STATIC_CALLBACK(__x) static __x
00158 
00159 #elif defined(XP_OS2_VACPP) 
00160 
00161 #define PR_EXPORT(__type) extern __type
00162 #define PR_EXPORT_DATA(__type) extern __type
00163 #define PR_IMPORT(__type) extern __type
00164 #define PR_IMPORT_DATA(__type) extern __type
00165 
00166 #define PR_EXTERN(__type) extern __type
00167 #define PR_IMPLEMENT(__type) __type
00168 #define PR_EXTERN_DATA(__type) extern __type
00169 #define PR_IMPLEMENT_DATA(__type) __type
00170 #define PR_CALLBACK _Optlink
00171 #define PR_CALLBACK_DECL
00172 #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
00173 
00174 #else /* Unix */
00175 
00176 /* GCC 3.3 and later support the visibility attribute. */
00177 #if (__GNUC__ >= 4) || \
00178     (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
00179 #define PR_VISIBILITY_DEFAULT __attribute__((visibility("default")))
00180 #else
00181 #define PR_VISIBILITY_DEFAULT
00182 #endif
00183 
00184 #define PR_EXPORT(__type) extern PR_VISIBILITY_DEFAULT __type
00185 #define PR_EXPORT_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
00186 #define PR_IMPORT(__type) extern PR_VISIBILITY_DEFAULT __type
00187 #define PR_IMPORT_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
00188 
00189 #define PR_EXTERN(__type) extern PR_VISIBILITY_DEFAULT __type
00190 #define PR_IMPLEMENT(__type) PR_VISIBILITY_DEFAULT __type
00191 #define PR_EXTERN_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
00192 #define PR_IMPLEMENT_DATA(__type) PR_VISIBILITY_DEFAULT __type
00193 #define PR_CALLBACK
00194 #define PR_CALLBACK_DECL
00195 #define PR_STATIC_CALLBACK(__x) static __x
00196 
00197 #endif
00198 
00199 #if defined(_NSPR_BUILD_)
00200 #define NSPR_API(__type) PR_EXPORT(__type)
00201 #define NSPR_DATA_API(__type) PR_EXPORT_DATA(__type)
00202 #else
00203 #define NSPR_API(__type) PR_IMPORT(__type)
00204 #define NSPR_DATA_API(__type) PR_IMPORT_DATA(__type)
00205 #endif
00206 
00207 /***********************************************************************
00208 ** MACROS:      PR_BEGIN_MACRO
00209 **              PR_END_MACRO
00210 ** DESCRIPTION:
00211 **      Macro body brackets so that macros with compound statement definitions
00212 **      behave syntactically more like functions when called.
00213 ***********************************************************************/
00214 #define PR_BEGIN_MACRO  do {
00215 #define PR_END_MACRO    } while (0)
00216 
00217 /***********************************************************************
00218 ** MACROS:      PR_BEGIN_EXTERN_C
00219 **              PR_END_EXTERN_C
00220 ** DESCRIPTION:
00221 **      Macro shorthands for conditional C++ extern block delimiters.
00222 ***********************************************************************/
00223 #ifdef __cplusplus
00224 #define PR_BEGIN_EXTERN_C       extern "C" {
00225 #define PR_END_EXTERN_C         }
00226 #else
00227 #define PR_BEGIN_EXTERN_C
00228 #define PR_END_EXTERN_C
00229 #endif
00230 
00231 /***********************************************************************
00232 ** MACROS:      PR_BIT
00233 **              PR_BITMASK
00234 ** DESCRIPTION:
00235 ** Bit masking macros.  XXX n must be <= 31 to be portable
00236 ***********************************************************************/
00237 #define PR_BIT(n)       ((PRUint32)1 << (n))
00238 #define PR_BITMASK(n)   (PR_BIT(n) - 1)
00239 
00240 /***********************************************************************
00241 ** MACROS:      PR_ROUNDUP
00242 **              PR_MIN
00243 **              PR_MAX
00244 **              PR_ABS
00245 ** DESCRIPTION:
00246 **      Commonly used macros for operations on compatible types.
00247 ***********************************************************************/
00248 #define PR_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y))
00249 #define PR_MIN(x,y)     ((x)<(y)?(x):(y))
00250 #define PR_MAX(x,y)     ((x)>(y)?(x):(y))
00251 #define PR_ABS(x)       ((x)<0?-(x):(x))
00252 
00253 PR_BEGIN_EXTERN_C
00254 
00255 /************************************************************************
00256 ** TYPES:       PRUint8
00257 **              PRInt8
00258 ** DESCRIPTION:
00259 **  The int8 types are known to be 8 bits each. There is no type that
00260 **      is equivalent to a plain "char". 
00261 ************************************************************************/
00262 typedef unsigned char PRUint8;
00263 typedef char PRInt8;
00264 
00265 /************************************************************************
00266  * MACROS:      PR_INT8_MAX
00267  *              PR_INT8_MIN
00268  *              PR_UINT8_MAX
00269  * DESCRIPTION:
00270  *  The maximum and minimum values of a PRInt8 or PRUint8.
00271 ************************************************************************/
00272 
00273 #define PR_INT8_MAX 127
00274 #define PR_INT8_MIN (-128)
00275 #define PR_UINT8_MAX 255U
00276 
00277 /************************************************************************
00278 ** TYPES:       PRUint16
00279 **              PRInt16
00280 ** DESCRIPTION:
00281 **  The int16 types are known to be 16 bits each. 
00282 ************************************************************************/
00283 typedef unsigned short PRUint16;
00284 typedef short PRInt16;
00285 
00286 /************************************************************************
00287  * MACROS:      PR_INT16_MAX
00288  *              PR_INT16_MIN
00289  *              PR_UINT16_MAX
00290  * DESCRIPTION:
00291  *  The maximum and minimum values of a PRInt16 or PRUint16.
00292 ************************************************************************/
00293 
00294 #define PR_INT16_MAX 32767
00295 #define PR_INT16_MIN (-32768)
00296 #define PR_UINT16_MAX 65535U
00297 
00298 /************************************************************************
00299 ** TYPES:       PRUint32
00300 **              PRInt32
00301 ** DESCRIPTION:
00302 **  The int32 types are known to be 32 bits each. 
00303 ************************************************************************/
00304 typedef unsigned int PRUint32;
00305 typedef int PRInt32;
00306 #define PR_INT32(x)  x
00307 #define PR_UINT32(x) x ## U
00308 
00309 /************************************************************************
00310  * MACROS:      PR_INT32_MAX
00311  *              PR_INT32_MIN
00312  *              PR_UINT32_MAX
00313  * DESCRIPTION:
00314  *  The maximum and minimum values of a PRInt32 or PRUint32.
00315 ************************************************************************/
00316 
00317 #define PR_INT32_MAX PR_INT32(2147483647)
00318 #define PR_INT32_MIN (-PR_INT32_MAX - 1)
00319 #define PR_UINT32_MAX PR_UINT32(4294967295)
00320 
00321 /************************************************************************
00322 ** TYPES:       PRUint64
00323 **              PRInt64
00324 ** DESCRIPTION:
00325 **  The int64 types are known to be 64 bits each. Care must be used when
00326 **      declaring variables of type PRUint64 or PRInt64. Different hardware
00327 **      architectures and even different compilers have varying support for
00328 **      64 bit values. The only guaranteed portability requires the use of
00329 **      the LL_ macros (see prlong.h).
00330 ************************************************************************/
00331 #ifdef HAVE_LONG_LONG
00332 #if PR_BYTES_PER_LONG == 8
00333 typedef long PRInt64;
00334 typedef unsigned long PRUint64;
00335 #elif defined(WIN16)
00336 typedef __int64 PRInt64;
00337 typedef unsigned __int64 PRUint64;
00338 #elif defined(WIN32) && !defined(__GNUC__)
00339 typedef __int64  PRInt64;
00340 typedef unsigned __int64 PRUint64;
00341 #else
00342 typedef long long PRInt64;
00343 typedef unsigned long long PRUint64;
00344 #endif /* PR_BYTES_PER_LONG == 8 */
00345 #else  /* !HAVE_LONG_LONG */
00346 typedef struct {
00347 #ifdef IS_LITTLE_ENDIAN
00348     PRUint32 lo, hi;
00349 #else
00350     PRUint32 hi, lo;
00351 #endif
00352 } PRInt64;
00353 typedef PRInt64 PRUint64;
00354 #endif /* !HAVE_LONG_LONG */
00355 
00356 /************************************************************************
00357 ** TYPES:       PRUintn
00358 **              PRIntn
00359 ** DESCRIPTION:
00360 **  The PRIntn types are most appropriate for automatic variables. They are
00361 **      guaranteed to be at least 16 bits, though various architectures may
00362 **      define them to be wider (e.g., 32 or even 64 bits). These types are
00363 **      never valid for fields of a structure. 
00364 ************************************************************************/
00365 typedef int PRIntn;
00366 typedef unsigned int PRUintn;
00367 
00368 /************************************************************************
00369 ** TYPES:       PRFloat64
00370 ** DESCRIPTION:
00371 **  NSPR's floating point type is always 64 bits. 
00372 ************************************************************************/
00373 typedef double          PRFloat64;
00374 
00375 /************************************************************************
00376 ** TYPES:       PRSize
00377 ** DESCRIPTION:
00378 **  A type for representing the size of objects. 
00379 ************************************************************************/
00380 typedef size_t PRSize;
00381 
00382 
00383 /************************************************************************
00384 ** TYPES:       PROffset32, PROffset64
00385 ** DESCRIPTION:
00386 **  A type for representing byte offsets from some location. 
00387 ************************************************************************/
00388 typedef PRInt32 PROffset32;
00389 typedef PRInt64 PROffset64;
00390 
00391 /************************************************************************
00392 ** TYPES:       PRPtrDiff
00393 ** DESCRIPTION:
00394 **  A type for pointer difference. Variables of this type are suitable
00395 **      for storing a pointer or pointer subtraction. 
00396 ************************************************************************/
00397 typedef ptrdiff_t PRPtrdiff;
00398 
00399 /************************************************************************
00400 ** TYPES:       PRUptrdiff
00401 ** DESCRIPTION:
00402 **  A type for pointer difference. Variables of this type are suitable
00403 **      for storing a pointer or pointer sutraction. 
00404 ************************************************************************/
00405 typedef unsigned long PRUptrdiff;
00406 
00407 /************************************************************************
00408 ** TYPES:       PRBool
00409 ** DESCRIPTION:
00410 **  Use PRBool for variables and parameter types. Use PR_FALSE and PR_TRUE
00411 **      for clarity of target type in assignments and actual arguments. Use
00412 **      'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
00413 **      just as you would C int-valued conditions. 
00414 ************************************************************************/
00415 typedef PRIntn PRBool;
00416 #define PR_TRUE 1
00417 #define PR_FALSE 0
00418 
00419 /************************************************************************
00420 ** TYPES:       PRPackedBool
00421 ** DESCRIPTION:
00422 **  Use PRPackedBool within structs where bitfields are not desirable
00423 **      but minimum and consistant overhead matters.
00424 ************************************************************************/
00425 typedef PRUint8 PRPackedBool;
00426 
00427 /*
00428 ** Status code used by some routines that have a single point of failure or 
00429 ** special status return.
00430 */
00431 typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
00432 
00433 #ifndef __PRUNICHAR__
00434 #define __PRUNICHAR__
00435 #if defined(WIN32) || defined(XP_MAC)
00436 typedef wchar_t PRUnichar;
00437 #else
00438 typedef PRUint16 PRUnichar;
00439 #endif
00440 #endif
00441 
00442 /*
00443 ** WARNING: The undocumented data types PRWord and PRUword are
00444 ** only used in the garbage collection and arena code.  Do not
00445 ** use PRWord and PRUword in new code.
00446 **
00447 ** A PRWord is an integer that is the same size as a void*.
00448 ** It implements the notion of a "word" in the Java Virtual
00449 ** Machine.  (See Sec. 3.4 "Words", The Java Virtual Machine
00450 ** Specification, Addison-Wesley, September 1996.
00451 ** http://java.sun.com/docs/books/vmspec/index.html.)
00452 */
00453 typedef long PRWord;
00454 typedef unsigned long PRUword;
00455 
00456 #if defined(NO_NSPR_10_SUPPORT)
00457 #else
00458 /********* ???????????????? FIX ME       ??????????????????????????? *****/
00459 /********************** Some old definitions until pr=>ds transition is done ***/
00460 /********************** Also, we are still using NSPR 1.0. GC ******************/
00461 /*
00462 ** Fundamental NSPR macros, used nearly everywhere.
00463 */
00464 
00465 #define PR_PUBLIC_API      PR_IMPLEMENT
00466 
00467 /*
00468 ** Macro body brackets so that macros with compound statement definitions
00469 ** behave syntactically more like functions when called.
00470 */
00471 #define NSPR_BEGIN_MACRO        do {
00472 #define NSPR_END_MACRO          } while (0)
00473 
00474 /*
00475 ** Macro shorthands for conditional C++ extern block delimiters.
00476 */
00477 #ifdef NSPR_BEGIN_EXTERN_C
00478 #undef NSPR_BEGIN_EXTERN_C
00479 #endif
00480 #ifdef NSPR_END_EXTERN_C
00481 #undef NSPR_END_EXTERN_C
00482 #endif
00483 
00484 #ifdef __cplusplus
00485 #define NSPR_BEGIN_EXTERN_C     extern "C" {
00486 #define NSPR_END_EXTERN_C       }
00487 #else
00488 #define NSPR_BEGIN_EXTERN_C
00489 #define NSPR_END_EXTERN_C
00490 #endif
00491 
00492 /********* ????????????? End Fix me ?????????????????????????????? *****/
00493 #endif /* NO_NSPR_10_SUPPORT */
00494 
00495 PR_END_EXTERN_C
00496 
00497 #endif /* prtypes_h___ */
00498 
Generated by  doxygen 1.6.2-20100208