File indexing completed on 2024-04-28 16:07:46
0001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 0002 /* ***** BEGIN LICENSE BLOCK ***** 0003 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 0004 * 0005 * The contents of this file are subject to the Mozilla Public License Version 0006 * 1.1 (the "License"); you may not use this file except in compliance with 0007 * the License. You may obtain a copy of the License at 0008 * http://www.mozilla.org/MPL/ 0009 * 0010 * Software distributed under the License is distributed on an "AS IS" basis, 0011 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 0012 * for the specific language governing rights and limitations under the 0013 * License. 0014 * 0015 * The Original Code is the Netscape Portable Runtime (NSPR). 0016 * 0017 * The Initial Developer of the Original Code is 0018 * Netscape Communications Corporation. 0019 * Portions created by the Initial Developer are Copyright (C) 1998-2000 0020 * the Initial Developer. All Rights Reserved. 0021 * 0022 * Contributor(s): 0023 * 0024 * Alternatively, the contents of this file may be used under the terms of 0025 * either the GNU General Public License Version 2 or later (the "GPL"), or 0026 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 0027 * in which case the provisions of the GPL or the LGPL are applicable instead 0028 * of those above. If you wish to allow use of your version of this file only 0029 * under the terms of either the GPL or the LGPL, and not to allow others to 0030 * use your version of this file under the terms of the MPL, indicate your 0031 * decision by deleting the provisions above and replace them with the notice 0032 * and other provisions required by the GPL or the LGPL. If you do not delete 0033 * the provisions above, a recipient may use your version of this file under 0034 * the terms of any one of the MPL, the GPL or the LGPL. 0035 * 0036 * ***** END LICENSE BLOCK ***** */ 0037 0038 /* 0039 ** File: prtypes.h 0040 ** Description: Definitions of NSPR's basic types 0041 ** 0042 ** Prototypes and macros used to make up for deficiencies that we have found 0043 ** in ANSI environments. 0044 ** 0045 ** Since we do not wrap <stdlib.h> and all the other standard headers, authors 0046 ** of portable code will not know in general that they need these definitions. 0047 ** Instead of requiring these authors to find the dependent uses in their code 0048 ** and take the following steps only in those C files, we take steps once here 0049 ** for all C files. 0050 **/ 0051 0052 #ifndef prtypes_h___ 0053 #define prtypes_h___ 0054 0055 #ifdef MDCPUCFG 0056 #include MDCPUCFG 0057 #else 0058 #include "prcpucfg.h" 0059 #endif 0060 0061 #include <stddef.h> 0062 0063 /*********************************************************************** 0064 ** MACROS: PR_EXTERN 0065 ** PR_IMPLEMENT 0066 ** DESCRIPTION: 0067 ** These are only for externally visible routines and globals. For 0068 ** internal routines, just use "extern" for type checking and that 0069 ** will not export internal cross-file or forward-declared symbols. 0070 ** Define a macro for declaring procedures return types. We use this to 0071 ** deal with windoze specific type hackery for DLL definitions. Use 0072 ** PR_EXTERN when the prototype for the method is declared. Use 0073 ** PR_IMPLEMENT for the implementation of the method. 0074 ** 0075 ** Example: 0076 ** in dowhim.h 0077 ** PR_EXTERN( void ) DoWhatIMean( void ); 0078 ** in dowhim.c 0079 ** PR_IMPLEMENT( void ) DoWhatIMean( void ) { return; } 0080 ** 0081 ** 0082 ***********************************************************************/ 0083 #if defined(WIN32) 0084 0085 #define PR_EXPORT(__type) extern __declspec(dllexport) __type 0086 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type 0087 #define PR_IMPORT(__type) __declspec(dllimport) __type 0088 #define PR_IMPORT_DATA(__type) __declspec(dllimport) __type 0089 0090 #define PR_EXTERN(__type) extern __declspec(dllexport) __type 0091 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type 0092 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type 0093 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type 0094 0095 #define PR_CALLBACK 0096 #define PR_CALLBACK_DECL 0097 #define PR_STATIC_CALLBACK(__x) static __x 0098 0099 #elif defined(XP_BEOS) 0100 0101 #define PR_EXPORT(__type) extern __declspec(dllexport) __type 0102 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type 0103 #define PR_IMPORT(__type) extern __declspec(dllexport) __type 0104 #define PR_IMPORT_DATA(__type) extern __declspec(dllexport) __type 0105 0106 #define PR_EXTERN(__type) extern __declspec(dllexport) __type 0107 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type 0108 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type 0109 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type 0110 0111 #define PR_CALLBACK 0112 #define PR_CALLBACK_DECL 0113 #define PR_STATIC_CALLBACK(__x) static __x 0114 0115 #elif defined(XP_OS2) && defined(__declspec) 0116 0117 #define PR_EXPORT(__type) extern __declspec(dllexport) __type 0118 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type 0119 #define PR_IMPORT(__type) extern __declspec(dllimport) __type 0120 #define PR_IMPORT_DATA(__type) extern __declspec(dllimport) __type 0121 0122 #define PR_EXTERN(__type) extern __declspec(dllexport) __type 0123 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type 0124 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type 0125 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type 0126 0127 #define PR_CALLBACK 0128 #define PR_CALLBACK_DECL 0129 #define PR_STATIC_CALLBACK(__x) static __x 0130 0131 #elif defined(SYMBIAN) 0132 0133 #define PR_EXPORT(__type) extern __declspec(dllexport) __type 0134 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type 0135 #ifdef __WINS__ 0136 #define PR_IMPORT(__type) extern __declspec(dllexport) __type 0137 #define PR_IMPORT_DATA(__type) extern __declspec(dllexport) __type 0138 #else 0139 #define PR_IMPORT(__type) extern __declspec(dllimport) __type 0140 #define PR_IMPORT_DATA(__type) extern __declspec(dllimport) __type 0141 #endif 0142 0143 #define PR_EXTERN(__type) extern __type 0144 #define PR_IMPLEMENT(__type) __type 0145 #define PR_EXTERN_DATA(__type) extern __type 0146 #define PR_IMPLEMENT_DATA(__type) __type 0147 0148 #define PR_CALLBACK 0149 #define PR_CALLBACK_DECL 0150 #define PR_STATIC_CALLBACK(__x) static __x 0151 0152 #else /* Unix */ 0153 0154 /* GCC 3.3 and later support the visibility attribute. */ 0155 #if (__GNUC__ >= 4) || \ 0156 (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) 0157 #define PR_VISIBILITY_DEFAULT __attribute__((visibility("default"))) 0158 #else 0159 #define PR_VISIBILITY_DEFAULT 0160 #endif 0161 0162 #define PR_EXPORT(__type) extern PR_VISIBILITY_DEFAULT __type 0163 #define PR_EXPORT_DATA(__type) extern PR_VISIBILITY_DEFAULT __type 0164 #define PR_IMPORT(__type) extern PR_VISIBILITY_DEFAULT __type 0165 #define PR_IMPORT_DATA(__type) extern PR_VISIBILITY_DEFAULT __type 0166 0167 #define PR_EXTERN(__type) extern PR_VISIBILITY_DEFAULT __type 0168 #define PR_IMPLEMENT(__type) PR_VISIBILITY_DEFAULT __type 0169 #define PR_EXTERN_DATA(__type) extern PR_VISIBILITY_DEFAULT __type 0170 #define PR_IMPLEMENT_DATA(__type) PR_VISIBILITY_DEFAULT __type 0171 #define PR_CALLBACK 0172 #define PR_CALLBACK_DECL 0173 #define PR_STATIC_CALLBACK(__x) static __x 0174 0175 #endif 0176 0177 #if defined(_NSPR_BUILD_) 0178 #define NSPR_API(__type) PR_EXPORT(__type) 0179 #define NSPR_DATA_API(__type) PR_EXPORT_DATA(__type) 0180 #else 0181 #define NSPR_API(__type) PR_IMPORT(__type) 0182 #define NSPR_DATA_API(__type) PR_IMPORT_DATA(__type) 0183 #endif 0184 0185 /*********************************************************************** 0186 ** MACROS: PR_BEGIN_MACRO 0187 ** PR_END_MACRO 0188 ** DESCRIPTION: 0189 ** Macro body brackets so that macros with compound statement definitions 0190 ** behave syntactically more like functions when called. 0191 ***********************************************************************/ 0192 #define PR_BEGIN_MACRO do { 0193 #define PR_END_MACRO } while (0) 0194 0195 /*********************************************************************** 0196 ** MACROS: PR_BEGIN_EXTERN_C 0197 ** PR_END_EXTERN_C 0198 ** DESCRIPTION: 0199 ** Macro shorthands for conditional C++ extern block delimiters. 0200 ***********************************************************************/ 0201 #ifdef __cplusplus 0202 #define PR_BEGIN_EXTERN_C extern "C" { 0203 #define PR_END_EXTERN_C } 0204 #else 0205 #define PR_BEGIN_EXTERN_C 0206 #define PR_END_EXTERN_C 0207 #endif 0208 0209 /*********************************************************************** 0210 ** MACROS: PR_BIT 0211 ** PR_BITMASK 0212 ** DESCRIPTION: 0213 ** Bit masking macros. XXX n must be <= 31 to be portable 0214 ***********************************************************************/ 0215 #define PR_BIT(n) ((PRUint32)1 << (n)) 0216 #define PR_BITMASK(n) (PR_BIT(n) - 1) 0217 0218 /*********************************************************************** 0219 ** MACROS: PR_ROUNDUP 0220 ** PR_MIN 0221 ** PR_MAX 0222 ** PR_ABS 0223 ** DESCRIPTION: 0224 ** Commonly used macros for operations on compatible types. 0225 ***********************************************************************/ 0226 #define PR_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y)) 0227 #define PR_MIN(x,y) ((x)<(y)?(x):(y)) 0228 #define PR_MAX(x,y) ((x)>(y)?(x):(y)) 0229 #define PR_ABS(x) ((x)<0?-(x):(x)) 0230 0231 PR_BEGIN_EXTERN_C 0232 0233 /************************************************************************ 0234 ** TYPES: PRUint8 0235 ** PRInt8 0236 ** DESCRIPTION: 0237 ** The int8 types are known to be 8 bits each. There is no type that 0238 ** is equivalent to a plain "char". 0239 ************************************************************************/ 0240 #if PR_BYTES_PER_BYTE == 1 0241 typedef unsigned char PRUint8; 0242 /* 0243 ** Some cfront-based C++ compilers do not like 'signed char' and 0244 ** issue the warning message: 0245 ** warning: "signed" not implemented (ignored) 0246 ** For these compilers, we have to define PRInt8 as plain 'char'. 0247 ** Make sure that plain 'char' is indeed signed under these compilers. 0248 */ 0249 #if (defined(HPUX) && defined(__cplusplus) \ 0250 && !defined(__GNUC__) && __cplusplus < 199707L) \ 0251 || (defined(SCO) && defined(__cplusplus) \ 0252 && !defined(__GNUC__) && __cplusplus == 1L) 0253 typedef char PRInt8; 0254 #else 0255 typedef signed char PRInt8; 0256 #endif 0257 #else 0258 #error No suitable type for PRInt8/PRUint8 0259 #endif 0260 0261 /************************************************************************ 0262 * MACROS: PR_INT8_MAX 0263 * PR_INT8_MIN 0264 * PR_UINT8_MAX 0265 * DESCRIPTION: 0266 * The maximum and minimum values of a PRInt8 or PRUint8. 0267 ************************************************************************/ 0268 0269 #define PR_INT8_MAX 127 0270 #define PR_INT8_MIN (-128) 0271 #define PR_UINT8_MAX 255U 0272 0273 /************************************************************************ 0274 ** TYPES: PRUint16 0275 ** PRInt16 0276 ** DESCRIPTION: 0277 ** The int16 types are known to be 16 bits each. 0278 ************************************************************************/ 0279 #if PR_BYTES_PER_SHORT == 2 0280 typedef unsigned short PRUint16; 0281 typedef short PRInt16; 0282 #else 0283 #error No suitable type for PRInt16/PRUint16 0284 #endif 0285 0286 /************************************************************************ 0287 * MACROS: PR_INT16_MAX 0288 * PR_INT16_MIN 0289 * PR_UINT16_MAX 0290 * DESCRIPTION: 0291 * The maximum and minimum values of a PRInt16 or PRUint16. 0292 ************************************************************************/ 0293 0294 #define PR_INT16_MAX 32767 0295 #define PR_INT16_MIN (-32768) 0296 #define PR_UINT16_MAX 65535U 0297 0298 /************************************************************************ 0299 ** TYPES: PRUint32 0300 ** PRInt32 0301 ** DESCRIPTION: 0302 ** The int32 types are known to be 32 bits each. 0303 ************************************************************************/ 0304 #if PR_BYTES_PER_INT == 4 0305 typedef unsigned int PRUint32; 0306 typedef int PRInt32; 0307 #define PR_INT32(x) x 0308 #define PR_UINT32(x) x ## U 0309 #elif PR_BYTES_PER_LONG == 4 0310 typedef unsigned long PRUint32; 0311 typedef long PRInt32; 0312 #define PR_INT32(x) x ## L 0313 #define PR_UINT32(x) x ## UL 0314 #else 0315 #error No suitable type for PRInt32/PRUint32 0316 #endif 0317 0318 /************************************************************************ 0319 * MACROS: PR_INT32_MAX 0320 * PR_INT32_MIN 0321 * PR_UINT32_MAX 0322 * DESCRIPTION: 0323 * The maximum and minimum values of a PRInt32 or PRUint32. 0324 ************************************************************************/ 0325 0326 #define PR_INT32_MAX PR_INT32(2147483647) 0327 #define PR_INT32_MIN (-PR_INT32_MAX - 1) 0328 #define PR_UINT32_MAX PR_UINT32(4294967295) 0329 0330 /************************************************************************ 0331 ** TYPES: PRUint64 0332 ** PRInt64 0333 ** DESCRIPTION: 0334 ** The int64 types are known to be 64 bits each. Care must be used when 0335 ** declaring variables of type PRUint64 or PRInt64. Different hardware 0336 ** architectures and even different compilers have varying support for 0337 ** 64 bit values. The only guaranteed portability requires the use of 0338 ** the LL_ macros (see prlong.h). 0339 ************************************************************************/ 0340 #ifdef HAVE_LONG_LONG 0341 /* Keep this in sync with prlong.h. */ 0342 /* 0343 * On 64-bit Mac OS X, uint64 needs to be defined as unsigned long long to 0344 * match uint64_t, otherwise our uint64 typedef conflicts with the uint64 0345 * typedef in cssmconfig.h, which CoreServices.h includes indirectly. 0346 */ 0347 #if PR_BYTES_PER_LONG == 8 && !defined(__APPLE__) 0348 typedef long PRInt64; 0349 typedef unsigned long PRUint64; 0350 #elif defined(WIN32) && !defined(__GNUC__) 0351 typedef __int64 PRInt64; 0352 typedef unsigned __int64 PRUint64; 0353 #else 0354 typedef long long PRInt64; 0355 typedef unsigned long long PRUint64; 0356 #endif /* PR_BYTES_PER_LONG == 8 */ 0357 #else /* !HAVE_LONG_LONG */ 0358 typedef struct { 0359 #ifdef IS_LITTLE_ENDIAN 0360 PRUint32 lo, hi; 0361 #else 0362 PRUint32 hi, lo; 0363 #endif 0364 } PRInt64; 0365 typedef PRInt64 PRUint64; 0366 #endif /* !HAVE_LONG_LONG */ 0367 0368 /************************************************************************ 0369 ** TYPES: PRUintn 0370 ** PRIntn 0371 ** DESCRIPTION: 0372 ** The PRIntn types are most appropriate for automatic variables. They are 0373 ** guaranteed to be at least 16 bits, though various architectures may 0374 ** define them to be wider (e.g., 32 or even 64 bits). These types are 0375 ** never valid for fields of a structure. 0376 ************************************************************************/ 0377 #if PR_BYTES_PER_INT >= 2 0378 typedef int PRIntn; 0379 typedef unsigned int PRUintn; 0380 #else 0381 #error 'sizeof(int)' not sufficient for platform use 0382 #endif 0383 0384 /************************************************************************ 0385 ** TYPES: PRFloat64 0386 ** DESCRIPTION: 0387 ** NSPR's floating point type is always 64 bits. 0388 ************************************************************************/ 0389 typedef double PRFloat64; 0390 0391 /************************************************************************ 0392 ** TYPES: PRSize 0393 ** DESCRIPTION: 0394 ** A type for representing the size of objects. 0395 ************************************************************************/ 0396 typedef size_t PRSize; 0397 0398 0399 /************************************************************************ 0400 ** TYPES: PROffset32, PROffset64 0401 ** DESCRIPTION: 0402 ** A type for representing byte offsets from some location. 0403 ************************************************************************/ 0404 typedef PRInt32 PROffset32; 0405 typedef PRInt64 PROffset64; 0406 0407 /************************************************************************ 0408 ** TYPES: PRPtrDiff 0409 ** DESCRIPTION: 0410 ** A type for pointer difference. Variables of this type are suitable 0411 ** for storing a pointer or pointer subtraction. 0412 ************************************************************************/ 0413 typedef ptrdiff_t PRPtrdiff; 0414 0415 /************************************************************************ 0416 ** TYPES: PRUptrdiff 0417 ** DESCRIPTION: 0418 ** A type for pointer difference. Variables of this type are suitable 0419 ** for storing a pointer or pointer sutraction. 0420 ************************************************************************/ 0421 #ifdef _WIN64 0422 typedef unsigned __int64 PRUptrdiff; 0423 #else 0424 typedef unsigned long PRUptrdiff; 0425 #endif 0426 0427 /************************************************************************ 0428 ** TYPES: PRBool 0429 ** DESCRIPTION: 0430 ** Use PRBool for variables and parameter types. Use PR_FALSE and PR_TRUE 0431 ** for clarity of target type in assignments and actual arguments. Use 0432 ** 'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans 0433 ** just as you would C int-valued conditions. 0434 ************************************************************************/ 0435 typedef PRIntn PRBool; 0436 #define PR_TRUE 1 0437 #define PR_FALSE 0 0438 0439 /************************************************************************ 0440 ** TYPES: PRPackedBool 0441 ** DESCRIPTION: 0442 ** Use PRPackedBool within structs where bitfields are not desirable 0443 ** but minimum and consistant overhead matters. 0444 ************************************************************************/ 0445 typedef PRUint8 PRPackedBool; 0446 0447 /* 0448 ** Status code used by some routines that have a single point of failure or 0449 ** special status return. 0450 */ 0451 typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus; 0452 0453 #ifndef __PRUNICHAR__ 0454 #define __PRUNICHAR__ 0455 #ifdef WIN32 0456 typedef wchar_t PRUnichar; 0457 #else 0458 typedef PRUint16 PRUnichar; 0459 #endif 0460 #endif 0461 0462 /* 0463 ** WARNING: The undocumented data types PRWord and PRUword are 0464 ** only used in the garbage collection and arena code. Do not 0465 ** use PRWord and PRUword in new code. 0466 ** 0467 ** A PRWord is an integer that is the same size as a void*. 0468 ** It implements the notion of a "word" in the Java Virtual 0469 ** Machine. (See Sec. 3.4 "Words", The Java Virtual Machine 0470 ** Specification, Addison-Wesley, September 1996. 0471 ** http://java.sun.com/docs/books/vmspec/index.html.) 0472 */ 0473 #ifdef _WIN64 0474 typedef __int64 PRWord; 0475 typedef unsigned __int64 PRUword; 0476 #else 0477 typedef long PRWord; 0478 typedef unsigned long PRUword; 0479 #endif 0480 0481 #if defined(NO_NSPR_10_SUPPORT) 0482 #else 0483 /********* ???????????????? FIX ME ??????????????????????????? *****/ 0484 /********************** Some old definitions until pr=>ds transition is done ***/ 0485 /********************** Also, we are still using NSPR 1.0. GC ******************/ 0486 /* 0487 ** Fundamental NSPR macros, used nearly everywhere. 0488 */ 0489 0490 #define PR_PUBLIC_API PR_IMPLEMENT 0491 0492 /* 0493 ** Macro body brackets so that macros with compound statement definitions 0494 ** behave syntactically more like functions when called. 0495 */ 0496 #define NSPR_BEGIN_MACRO do { 0497 #define NSPR_END_MACRO } while (0) 0498 0499 /* 0500 ** Macro shorthands for conditional C++ extern block delimiters. 0501 */ 0502 #ifdef NSPR_BEGIN_EXTERN_C 0503 #undef NSPR_BEGIN_EXTERN_C 0504 #endif 0505 #ifdef NSPR_END_EXTERN_C 0506 #undef NSPR_END_EXTERN_C 0507 #endif 0508 0509 #ifdef __cplusplus 0510 #define NSPR_BEGIN_EXTERN_C extern "C" { 0511 #define NSPR_END_EXTERN_C } 0512 #else 0513 #define NSPR_BEGIN_EXTERN_C 0514 #define NSPR_END_EXTERN_C 0515 #endif 0516 0517 #include "obsolete/protypes.h" 0518 0519 /********* ????????????? End Fix me ?????????????????????????????? *****/ 0520 #endif /* NO_NSPR_10_SUPPORT */ 0521 0522 PR_END_EXTERN_C 0523 0524 #endif /* prtypes_h___ */ 0525