Home | History | Annotate | Download | only in nspr
      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* ***** BEGIN LICENSE BLOCK *****
      3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
      4  *
      5  * The contents of this file are subject to the Mozilla Public License Version
      6  * 1.1 (the "License"); you may not use this file except in compliance with
      7  * the License. You may obtain a copy of the License at
      8  * http://www.mozilla.org/MPL/
      9  *
     10  * Software distributed under the License is distributed on an "AS IS" basis,
     11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
     12  * for the specific language governing rights and limitations under the
     13  * License.
     14  *
     15  * The Original Code is the Netscape Portable Runtime (NSPR).
     16  *
     17  * The Initial Developer of the Original Code is
     18  * Netscape Communications Corporation.
     19  * Portions created by the Initial Developer are Copyright (C) 1998-2000
     20  * the Initial Developer. All Rights Reserved.
     21  *
     22  * Contributor(s):
     23  *
     24  * Alternatively, the contents of this file may be used under the terms of
     25  * either the GNU General Public License Version 2 or later (the "GPL"), or
     26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
     27  * in which case the provisions of the GPL or the LGPL are applicable instead
     28  * of those above. If you wish to allow use of your version of this file only
     29  * under the terms of either the GPL or the LGPL, and not to allow others to
     30  * use your version of this file under the terms of the MPL, indicate your
     31  * decision by deleting the provisions above and replace them with the notice
     32  * and other provisions required by the GPL or the LGPL. If you do not delete
     33  * the provisions above, a recipient may use your version of this file under
     34  * the terms of any one of the MPL, the GPL or the LGPL.
     35  *
     36  * ***** END LICENSE BLOCK ***** */
     37 
     38 /*
     39 ** File:                prtypes.h
     40 ** Description: Definitions of NSPR's basic types
     41 **
     42 ** Prototypes and macros used to make up for deficiencies that we have found
     43 ** in ANSI environments.
     44 **
     45 ** Since we do not wrap <stdlib.h> and all the other standard headers, authors
     46 ** of portable code will not know in general that they need these definitions.
     47 ** Instead of requiring these authors to find the dependent uses in their code
     48 ** and take the following steps only in those C files, we take steps once here
     49 ** for all C files.
     50 **/
     51 
     52 #ifndef prtypes_h___
     53 #define prtypes_h___
     54 
     55 #ifdef MDCPUCFG
     56 #include MDCPUCFG
     57 #else
     58 #include "base/third_party/nspr/prcpucfg.h"
     59 #endif
     60 
     61 #include <stddef.h>
     62 
     63 /***********************************************************************
     64 ** MACROS:      PR_EXTERN
     65 **              PR_IMPLEMENT
     66 ** DESCRIPTION:
     67 **      These are only for externally visible routines and globals.  For
     68 **      internal routines, just use "extern" for type checking and that
     69 **      will not export internal cross-file or forward-declared symbols.
     70 **      Define a macro for declaring procedures return types. We use this to
     71 **      deal with windoze specific type hackery for DLL definitions. Use
     72 **      PR_EXTERN when the prototype for the method is declared. Use
     73 **      PR_IMPLEMENT for the implementation of the method.
     74 **
     75 ** Example:
     76 **   in dowhim.h
     77 **     PR_EXTERN( void ) DoWhatIMean( void );
     78 **   in dowhim.c
     79 **     PR_IMPLEMENT( void ) DoWhatIMean( void ) { return; }
     80 **
     81 **
     82 ***********************************************************************/
     83 #if 1
     84 
     85 /*
     86 ** Local change: the portions of NSPR used by the base module are
     87 ** implementation details.  NSPR symbols do not need to be exported beyond
     88 ** the base module.  For all platforms, avoid decorating functions with
     89 ** specific visibility and access keywords.
     90 */
     91 
     92 #define PR_EXPORT(__type) extern __type
     93 #define PR_EXPORT_DATA(__type) extern __type
     94 #define PR_IMPORT(__type) extern __type
     95 #define PR_IMPORT_DATA(__type) extern __type
     96 
     97 #define PR_EXTERN(__type) extern __type
     98 #define PR_IMPLEMENT(__type) __type
     99 #define PR_EXTERN_DATA(__type) extern __type
    100 #define PR_IMPLEMENT_DATA(__type) __type
    101 
    102 #define PR_CALLBACK
    103 #define PR_CALLBACK_DECL
    104 #define PR_STATIC_CALLBACK(__x) static __x
    105 
    106 #elif defined(WIN32)
    107 
    108 #define PR_EXPORT(__type) extern __declspec(dllexport) __type
    109 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
    110 #define PR_IMPORT(__type) __declspec(dllimport) __type
    111 #define PR_IMPORT_DATA(__type) __declspec(dllimport) __type
    112 
    113 #define PR_EXTERN(__type) extern __declspec(dllexport) __type
    114 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type
    115 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
    116 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
    117 
    118 #define PR_CALLBACK
    119 #define PR_CALLBACK_DECL
    120 #define PR_STATIC_CALLBACK(__x) static __x
    121 
    122 #elif defined(XP_BEOS)
    123 
    124 #define PR_EXPORT(__type) extern __declspec(dllexport) __type
    125 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
    126 #define PR_IMPORT(__type) extern __declspec(dllexport) __type
    127 #define PR_IMPORT_DATA(__type) extern __declspec(dllexport) __type
    128 
    129 #define PR_EXTERN(__type) extern __declspec(dllexport) __type
    130 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type
    131 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
    132 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
    133 
    134 #define PR_CALLBACK
    135 #define PR_CALLBACK_DECL
    136 #define PR_STATIC_CALLBACK(__x) static __x
    137 
    138 #elif defined(XP_OS2) && defined(__declspec)
    139 
    140 #define PR_EXPORT(__type) extern __declspec(dllexport) __type
    141 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
    142 #define PR_IMPORT(__type) extern  __declspec(dllimport) __type
    143 #define PR_IMPORT_DATA(__type) extern __declspec(dllimport) __type
    144 
    145 #define PR_EXTERN(__type) extern __declspec(dllexport) __type
    146 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type
    147 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
    148 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
    149 
    150 #define PR_CALLBACK
    151 #define PR_CALLBACK_DECL
    152 #define PR_STATIC_CALLBACK(__x) static __x
    153 
    154 #elif defined(SYMBIAN)
    155 
    156 #define PR_EXPORT(__type) extern __declspec(dllexport) __type
    157 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
    158 #ifdef __WINS__
    159 #define PR_IMPORT(__type) extern __declspec(dllexport) __type
    160 #define PR_IMPORT_DATA(__type) extern __declspec(dllexport) __type
    161 #else
    162 #define PR_IMPORT(__type) extern __declspec(dllimport) __type
    163 #define PR_IMPORT_DATA(__type) extern __declspec(dllimport) __type
    164 #endif
    165 
    166 #define PR_EXTERN(__type) extern __type
    167 #define PR_IMPLEMENT(__type) __type
    168 #define PR_EXTERN_DATA(__type) extern __type
    169 #define PR_IMPLEMENT_DATA(__type) __type
    170 
    171 #define PR_CALLBACK
    172 #define PR_CALLBACK_DECL
    173 #define PR_STATIC_CALLBACK(__x) static __x
    174 
    175 #else /* Unix */
    176 
    177 /* GCC 3.3 and later support the visibility attribute. */
    178 #if (__GNUC__ >= 4) || \
    179     (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
    180 #define PR_VISIBILITY_DEFAULT __attribute__((visibility("default")))
    181 #else
    182 #define PR_VISIBILITY_DEFAULT
    183 #endif
    184 
    185 #define PR_EXPORT(__type) extern PR_VISIBILITY_DEFAULT __type
    186 #define PR_EXPORT_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
    187 #define PR_IMPORT(__type) extern PR_VISIBILITY_DEFAULT __type
    188 #define PR_IMPORT_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
    189 
    190 #define PR_EXTERN(__type) extern PR_VISIBILITY_DEFAULT __type
    191 #define PR_IMPLEMENT(__type) PR_VISIBILITY_DEFAULT __type
    192 #define PR_EXTERN_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
    193 #define PR_IMPLEMENT_DATA(__type) PR_VISIBILITY_DEFAULT __type
    194 #define PR_CALLBACK
    195 #define PR_CALLBACK_DECL
    196 #define PR_STATIC_CALLBACK(__x) static __x
    197 
    198 #endif
    199 
    200 #if defined(_NSPR_BUILD_)
    201 #define NSPR_API(__type) PR_EXPORT(__type)
    202 #define NSPR_DATA_API(__type) PR_EXPORT_DATA(__type)
    203 #else
    204 #define NSPR_API(__type) PR_IMPORT(__type)
    205 #define NSPR_DATA_API(__type) PR_IMPORT_DATA(__type)
    206 #endif
    207 
    208 /***********************************************************************
    209 ** MACROS:      PR_BEGIN_MACRO
    210 **              PR_END_MACRO
    211 ** DESCRIPTION:
    212 **      Macro body brackets so that macros with compound statement definitions
    213 **      behave syntactically more like functions when called.
    214 ***********************************************************************/
    215 #define PR_BEGIN_MACRO  do {
    216 #define PR_END_MACRO    } while (0)
    217 
    218 /***********************************************************************
    219 ** MACROS:      PR_BEGIN_EXTERN_C
    220 **              PR_END_EXTERN_C
    221 ** DESCRIPTION:
    222 **      Macro shorthands for conditional C++ extern block delimiters.
    223 ***********************************************************************/
    224 #ifdef __cplusplus
    225 #define PR_BEGIN_EXTERN_C       extern "C" {
    226 #define PR_END_EXTERN_C         }
    227 #else
    228 #define PR_BEGIN_EXTERN_C
    229 #define PR_END_EXTERN_C
    230 #endif
    231 
    232 /***********************************************************************
    233 ** MACROS:      PR_BIT
    234 **              PR_BITMASK
    235 ** DESCRIPTION:
    236 ** Bit masking macros.  XXX n must be <= 31 to be portable
    237 ***********************************************************************/
    238 #define PR_BIT(n)       ((PRUint32)1 << (n))
    239 #define PR_BITMASK(n)   (PR_BIT(n) - 1)
    240 
    241 /***********************************************************************
    242 ** MACROS:      PR_ROUNDUP
    243 **              PR_MIN
    244 **              PR_MAX
    245 **              PR_ABS
    246 ** DESCRIPTION:
    247 **      Commonly used macros for operations on compatible types.
    248 ***********************************************************************/
    249 #define PR_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y))
    250 #define PR_MIN(x,y)     ((x)<(y)?(x):(y))
    251 #define PR_MAX(x,y)     ((x)>(y)?(x):(y))
    252 #define PR_ABS(x)       ((x)<0?-(x):(x))
    253 
    254 PR_BEGIN_EXTERN_C
    255 
    256 /************************************************************************
    257 ** TYPES:       PRUint8
    258 **              PRInt8
    259 ** DESCRIPTION:
    260 **  The int8 types are known to be 8 bits each. There is no type that
    261 **      is equivalent to a plain "char".
    262 ************************************************************************/
    263 #if PR_BYTES_PER_BYTE == 1
    264 typedef unsigned char PRUint8;
    265 /*
    266 ** Some cfront-based C++ compilers do not like 'signed char' and
    267 ** issue the warning message:
    268 **     warning: "signed" not implemented (ignored)
    269 ** For these compilers, we have to define PRInt8 as plain 'char'.
    270 ** Make sure that plain 'char' is indeed signed under these compilers.
    271 */
    272 #if (defined(HPUX) && defined(__cplusplus) \
    273         && !defined(__GNUC__) && __cplusplus < 199707L) \
    274     || (defined(SCO) && defined(__cplusplus) \
    275         && !defined(__GNUC__) && __cplusplus == 1L)
    276 typedef char PRInt8;
    277 #else
    278 typedef signed char PRInt8;
    279 #endif
    280 #else
    281 #error No suitable type for PRInt8/PRUint8
    282 #endif
    283 
    284 /************************************************************************
    285  * MACROS:      PR_INT8_MAX
    286  *              PR_INT8_MIN
    287  *              PR_UINT8_MAX
    288  * DESCRIPTION:
    289  *  The maximum and minimum values of a PRInt8 or PRUint8.
    290 ************************************************************************/
    291 
    292 #define PR_INT8_MAX 127
    293 #define PR_INT8_MIN (-128)
    294 #define PR_UINT8_MAX 255U
    295 
    296 /************************************************************************
    297 ** TYPES:       PRUint16
    298 **              PRInt16
    299 ** DESCRIPTION:
    300 **  The int16 types are known to be 16 bits each.
    301 ************************************************************************/
    302 #if PR_BYTES_PER_SHORT == 2
    303 typedef unsigned short PRUint16;
    304 typedef short PRInt16;
    305 #else
    306 #error No suitable type for PRInt16/PRUint16
    307 #endif
    308 
    309 /************************************************************************
    310  * MACROS:      PR_INT16_MAX
    311  *              PR_INT16_MIN
    312  *              PR_UINT16_MAX
    313  * DESCRIPTION:
    314  *  The maximum and minimum values of a PRInt16 or PRUint16.
    315 ************************************************************************/
    316 
    317 #define PR_INT16_MAX 32767
    318 #define PR_INT16_MIN (-32768)
    319 #define PR_UINT16_MAX 65535U
    320 
    321 /************************************************************************
    322 ** TYPES:       PRUint32
    323 **              PRInt32
    324 ** DESCRIPTION:
    325 **  The int32 types are known to be 32 bits each.
    326 ************************************************************************/
    327 #if PR_BYTES_PER_INT == 4
    328 typedef unsigned int PRUint32;
    329 typedef int PRInt32;
    330 #define PR_INT32(x)  x
    331 #define PR_UINT32(x) x ## U
    332 #elif PR_BYTES_PER_LONG == 4
    333 typedef unsigned long PRUint32;
    334 typedef long PRInt32;
    335 #define PR_INT32(x)  x ## L
    336 #define PR_UINT32(x) x ## UL
    337 #else
    338 #error No suitable type for PRInt32/PRUint32
    339 #endif
    340 
    341 /************************************************************************
    342  * MACROS:      PR_INT32_MAX
    343  *              PR_INT32_MIN
    344  *              PR_UINT32_MAX
    345  * DESCRIPTION:
    346  *  The maximum and minimum values of a PRInt32 or PRUint32.
    347 ************************************************************************/
    348 
    349 #define PR_INT32_MAX PR_INT32(2147483647)
    350 #define PR_INT32_MIN (-PR_INT32_MAX - 1)
    351 #define PR_UINT32_MAX PR_UINT32(4294967295)
    352 
    353 /************************************************************************
    354 ** TYPES:       PRUint64
    355 **              PRInt64
    356 ** DESCRIPTION:
    357 **  The int64 types are known to be 64 bits each. Care must be used when
    358 **      declaring variables of type PRUint64 or PRInt64. Different hardware
    359 **      architectures and even different compilers have varying support for
    360 **      64 bit values. The only guaranteed portability requires the use of
    361 **      the LL_ macros (see prlong.h).
    362 ************************************************************************/
    363 #ifdef HAVE_LONG_LONG
    364 /* Keep this in sync with prlong.h. */
    365 /*
    366  * On 64-bit Mac OS X, uint64 needs to be defined as unsigned long long to
    367  * match uint64_t, otherwise our uint64 typedef conflicts with the uint64
    368  * typedef in cssmconfig.h, which CoreServices.h includes indirectly.
    369  */
    370 #if PR_BYTES_PER_LONG == 8 && !defined(__APPLE__)
    371 typedef long PRInt64;
    372 typedef unsigned long PRUint64;
    373 #elif defined(WIN32) && !defined(__GNUC__)
    374 typedef __int64  PRInt64;
    375 typedef unsigned __int64 PRUint64;
    376 #else
    377 typedef long long PRInt64;
    378 typedef unsigned long long PRUint64;
    379 #endif /* PR_BYTES_PER_LONG == 8 */
    380 #else  /* !HAVE_LONG_LONG */
    381 typedef struct {
    382 #ifdef IS_LITTLE_ENDIAN
    383     PRUint32 lo, hi;
    384 #else
    385     PRUint32 hi, lo;
    386 #endif
    387 } PRInt64;
    388 typedef PRInt64 PRUint64;
    389 #endif /* !HAVE_LONG_LONG */
    390 
    391 /************************************************************************
    392 ** TYPES:       PRUintn
    393 **              PRIntn
    394 ** DESCRIPTION:
    395 **  The PRIntn types are most appropriate for automatic variables. They are
    396 **      guaranteed to be at least 16 bits, though various architectures may
    397 **      define them to be wider (e.g., 32 or even 64 bits). These types are
    398 **      never valid for fields of a structure.
    399 ************************************************************************/
    400 #if PR_BYTES_PER_INT >= 2
    401 typedef int PRIntn;
    402 typedef unsigned int PRUintn;
    403 #else
    404 #error 'sizeof(int)' not sufficient for platform use
    405 #endif
    406 
    407 /************************************************************************
    408 ** TYPES:       PRFloat64
    409 ** DESCRIPTION:
    410 **  NSPR's floating point type is always 64 bits.
    411 ************************************************************************/
    412 typedef double          PRFloat64;
    413 
    414 /************************************************************************
    415 ** TYPES:       PRSize
    416 ** DESCRIPTION:
    417 **  A type for representing the size of objects.
    418 ************************************************************************/
    419 typedef size_t PRSize;
    420 
    421 
    422 /************************************************************************
    423 ** TYPES:       PROffset32, PROffset64
    424 ** DESCRIPTION:
    425 **  A type for representing byte offsets from some location.
    426 ************************************************************************/
    427 typedef PRInt32 PROffset32;
    428 typedef PRInt64 PROffset64;
    429 
    430 /************************************************************************
    431 ** TYPES:       PRPtrDiff
    432 ** DESCRIPTION:
    433 **  A type for pointer difference. Variables of this type are suitable
    434 **      for storing a pointer or pointer subtraction.
    435 ************************************************************************/
    436 typedef ptrdiff_t PRPtrdiff;
    437 
    438 /************************************************************************
    439 ** TYPES:       PRUptrdiff
    440 ** DESCRIPTION:
    441 **  A type for pointer difference. Variables of this type are suitable
    442 **      for storing a pointer or pointer sutraction.
    443 ************************************************************************/
    444 #ifdef _WIN64
    445 typedef PRUint64 PRUptrdiff;
    446 #else
    447 typedef unsigned long PRUptrdiff;
    448 #endif
    449 
    450 /************************************************************************
    451 ** TYPES:       PRBool
    452 ** DESCRIPTION:
    453 **  Use PRBool for variables and parameter types. Use PR_FALSE and PR_TRUE
    454 **      for clarity of target type in assignments and actual arguments. Use
    455 **      'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
    456 **      just as you would C int-valued conditions.
    457 ************************************************************************/
    458 typedef PRIntn PRBool;
    459 #define PR_TRUE 1
    460 #define PR_FALSE 0
    461 
    462 /************************************************************************
    463 ** TYPES:       PRPackedBool
    464 ** DESCRIPTION:
    465 **  Use PRPackedBool within structs where bitfields are not desirable
    466 **      but minimum and consistant overhead matters.
    467 ************************************************************************/
    468 typedef PRUint8 PRPackedBool;
    469 
    470 /*
    471 ** Status code used by some routines that have a single point of failure or
    472 ** special status return.
    473 */
    474 typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
    475 
    476 #ifndef __PRUNICHAR__
    477 #define __PRUNICHAR__
    478 #ifdef WIN32
    479 typedef wchar_t PRUnichar;
    480 #else
    481 typedef PRUint16 PRUnichar;
    482 #endif
    483 #endif
    484 
    485 /*
    486 ** WARNING: The undocumented data types PRWord and PRUword are
    487 ** only used in the garbage collection and arena code.  Do not
    488 ** use PRWord and PRUword in new code.
    489 **
    490 ** A PRWord is an integer that is the same size as a void*.
    491 ** It implements the notion of a "word" in the Java Virtual
    492 ** Machine.  (See Sec. 3.4 "Words", The Java Virtual Machine
    493 ** Specification, Addison-Wesley, September 1996.
    494 ** http://java.sun.com/docs/books/vmspec/index.html.)
    495 */
    496 #ifdef _WIN64
    497 typedef PRInt64 PRWord;
    498 typedef PRUint64 PRUword;
    499 #else
    500 typedef long PRWord;
    501 typedef unsigned long PRUword;
    502 #endif
    503 
    504 #if defined(NO_NSPR_10_SUPPORT)
    505 #else
    506 /********* ???????????????? FIX ME       ??????????????????????????? *****/
    507 /********************** Some old definitions until pr=>ds transition is done ***/
    508 /********************** Also, we are still using NSPR 1.0. GC ******************/
    509 /*
    510 ** Fundamental NSPR macros, used nearly everywhere.
    511 */
    512 
    513 #define PR_PUBLIC_API		PR_IMPLEMENT
    514 
    515 /*
    516 ** Macro body brackets so that macros with compound statement definitions
    517 ** behave syntactically more like functions when called.
    518 */
    519 #define NSPR_BEGIN_MACRO        do {
    520 #define NSPR_END_MACRO          } while (0)
    521 
    522 /*
    523 ** Macro shorthands for conditional C++ extern block delimiters.
    524 */
    525 #ifdef NSPR_BEGIN_EXTERN_C
    526 #undef NSPR_BEGIN_EXTERN_C
    527 #endif
    528 #ifdef NSPR_END_EXTERN_C
    529 #undef NSPR_END_EXTERN_C
    530 #endif
    531 
    532 #ifdef __cplusplus
    533 #define NSPR_BEGIN_EXTERN_C     extern "C" {
    534 #define NSPR_END_EXTERN_C       }
    535 #else
    536 #define NSPR_BEGIN_EXTERN_C
    537 #define NSPR_END_EXTERN_C
    538 #endif
    539 
    540 /********* ????????????? End Fix me ?????????????????????????????? *****/
    541 #endif /* NO_NSPR_10_SUPPORT */
    542 
    543 /*
    544 ** Compile-time assert. "condition" must be a constant expression.
    545 ** The macro can be used only in places where an "extern" declaration is
    546 ** allowed.
    547 */
    548 #define PR_STATIC_ASSERT(condition) \
    549     extern void pr_static_assert(int arg[(condition) ? 1 : -1])
    550 
    551 PR_END_EXTERN_C
    552 
    553 #if !defined(NO_NSPR_10_SUPPORT)
    554 #include "base/basictypes.h"
    555 #endif
    556 
    557 #endif /* prtypes_h___ */
    558 
    559