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