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
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/
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
15 * The Original Code is the Netscape Portable Runtime (NSPR).
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.
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.
36 * ***** END LICENSE BLOCK ***** */
40 ** Description: Definitions of NSPR's basic types
42 ** Prototypes and macros used to make up for deficiencies that we have found
43 ** in ANSI environments.
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
63 /***********************************************************************
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.
77 ** PR_EXTERN( void ) DoWhatIMean( void );
79 ** PR_IMPLEMENT( void ) DoWhatIMean( void ) { return; }
82 ***********************************************************************/
85 #define PR_EXPORT(__type) extern __declspec(dllexport) __type
86 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
87 #define PR_IMPORT(__type) __declspec(dllimport) __type
88 #define PR_IMPORT_DATA(__type) __declspec(dllimport) __type
90 #define PR_EXTERN(__type) extern __declspec(dllexport) __type
91 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type
92 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
93 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
96 #define PR_CALLBACK_DECL
97 #define PR_STATIC_CALLBACK(__x) static __x
99 #elif defined(XP_BEOS)
101 #define PR_EXPORT(__type) extern __declspec(dllexport) __type
102 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
103 #define PR_IMPORT(__type) extern __declspec(dllexport) __type
104 #define PR_IMPORT_DATA(__type) extern __declspec(dllexport) __type
106 #define PR_EXTERN(__type) extern __declspec(dllexport) __type
107 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type
108 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
109 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
112 #define PR_CALLBACK_DECL
113 #define PR_STATIC_CALLBACK(__x) static __x
117 #define PR_CALLBACK_DECL __cdecl
120 #define PR_EXPORT(__type) extern __type _cdecl _export _loadds
121 #define PR_IMPORT(__type) extern __type _cdecl _export _loadds
122 #define PR_EXPORT_DATA(__type) extern __type _export
123 #define PR_IMPORT_DATA(__type) extern __type _export
125 #define PR_EXTERN(__type) extern __type _cdecl _export _loadds
126 #define PR_IMPLEMENT(__type) __type _cdecl _export _loadds
127 #define PR_EXTERN_DATA(__type) extern __type _export
128 #define PR_IMPLEMENT_DATA(__type) __type _export
130 #define PR_CALLBACK __cdecl __loadds
131 #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
133 #else /* this must be .EXE */
134 #define PR_EXPORT(__type) extern __type _cdecl _export
135 #define PR_IMPORT(__type) extern __type _cdecl _export
136 #define PR_EXPORT_DATA(__type) extern __type _export
137 #define PR_IMPORT_DATA(__type) extern __type _export
139 #define PR_EXTERN(__type) extern __type _cdecl _export
140 #define PR_IMPLEMENT(__type) __type _cdecl _export
141 #define PR_EXTERN_DATA(__type) extern __type _export
142 #define PR_IMPLEMENT_DATA(__type) __type _export
144 #define PR_CALLBACK __cdecl __loadds
145 #define PR_STATIC_CALLBACK(__x) __x PR_CALLBACK
148 #elif defined(XP_MAC)
150 #define PR_EXPORT(__type) extern __declspec(export) __type
151 #define PR_EXPORT_DATA(__type) extern __declspec(export) __type
152 #define PR_IMPORT(__type) extern __declspec(export) __type
153 #define PR_IMPORT_DATA(__type) extern __declspec(export) __type
155 #define PR_EXTERN(__type) extern __declspec(export) __type
156 #define PR_IMPLEMENT(__type) __declspec(export) __type
157 #define PR_EXTERN_DATA(__type) extern __declspec(export) __type
158 #define PR_IMPLEMENT_DATA(__type) __declspec(export) __type
161 #define PR_CALLBACK_DECL
162 #define PR_STATIC_CALLBACK(__x) static __x
164 #elif defined(XP_OS2) && defined(__declspec)
166 #define PR_EXPORT(__type) extern __declspec(dllexport) __type
167 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
168 #define PR_IMPORT(__type) extern __declspec(dllimport) __type
169 #define PR_IMPORT_DATA(__type) extern __declspec(dllimport) __type
171 #define PR_EXTERN(__type) extern __declspec(dllexport) __type
172 #define PR_IMPLEMENT(__type) __declspec(dllexport) __type
173 #define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
174 #define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
177 #define PR_CALLBACK_DECL
178 #define PR_STATIC_CALLBACK(__x) static __x
180 #elif defined(SYMBIAN)
182 #define PR_EXPORT(__type) extern __declspec(dllexport) __type
183 #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
185 #define PR_IMPORT(__type) extern __declspec(dllexport) __type
186 #define PR_IMPORT_DATA(__type) extern __declspec(dllexport) __type
188 #define PR_IMPORT(__type) extern __declspec(dllimport) __type
189 #define PR_IMPORT_DATA(__type) extern __declspec(dllimport) __type
192 #define PR_EXTERN(__type) extern __type
193 #define PR_IMPLEMENT(__type) __type
194 #define PR_EXTERN_DATA(__type) extern __type
195 #define PR_IMPLEMENT_DATA(__type) __type
198 #define PR_CALLBACK_DECL
199 #define PR_STATIC_CALLBACK(__x) static __x
203 /* GCC 3.3 and later support the visibility attribute. */
204 #if (__GNUC__ >= 4) || \
205 (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
206 #define PR_VISIBILITY_DEFAULT __attribute__((visibility("default")))
208 #define PR_VISIBILITY_DEFAULT
211 #define PR_EXPORT(__type) extern PR_VISIBILITY_DEFAULT __type
212 #define PR_EXPORT_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
213 #define PR_IMPORT(__type) extern PR_VISIBILITY_DEFAULT __type
214 #define PR_IMPORT_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
216 #define PR_EXTERN(__type) extern PR_VISIBILITY_DEFAULT __type
217 #define PR_IMPLEMENT(__type) PR_VISIBILITY_DEFAULT __type
218 #define PR_EXTERN_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
219 #define PR_IMPLEMENT_DATA(__type) PR_VISIBILITY_DEFAULT __type
221 #define PR_CALLBACK_DECL
222 #define PR_STATIC_CALLBACK(__x) static __x
226 #if defined(_NSPR_BUILD_)
227 #define NSPR_API(__type) PR_EXPORT(__type)
228 #define NSPR_DATA_API(__type) PR_EXPORT_DATA(__type)
230 #define NSPR_API(__type) PR_IMPORT(__type)
231 #define NSPR_DATA_API(__type) PR_IMPORT_DATA(__type)
234 /***********************************************************************
235 ** MACROS: PR_BEGIN_MACRO
238 ** Macro body brackets so that macros with compound statement definitions
239 ** behave syntactically more like functions when called.
240 ***********************************************************************/
241 #define PR_BEGIN_MACRO do {
242 #define PR_END_MACRO } while (0)
244 /***********************************************************************
245 ** MACROS: PR_BEGIN_EXTERN_C
248 ** Macro shorthands for conditional C++ extern block delimiters.
249 ***********************************************************************/
251 #define PR_BEGIN_EXTERN_C extern "C" {
252 #define PR_END_EXTERN_C }
254 #define PR_BEGIN_EXTERN_C
255 #define PR_END_EXTERN_C
258 /***********************************************************************
262 ** Bit masking macros. XXX n must be <= 31 to be portable
263 ***********************************************************************/
264 #define PR_BIT(n) ((PRUint32)1 << (n))
265 #define PR_BITMASK(n) (PR_BIT(n) - 1)
267 /***********************************************************************
268 ** MACROS: PR_ROUNDUP
273 ** Commonly used macros for operations on compatible types.
274 ***********************************************************************/
275 #define PR_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y))
276 #define PR_MIN(x,y) ((x)<(y)?(x):(y))
277 #define PR_MAX(x,y) ((x)>(y)?(x):(y))
278 #define PR_ABS(x) ((x)<0?-(x):(x))
282 /************************************************************************
286 ** The int8 types are known to be 8 bits each. There is no type that
287 ** is equivalent to a plain "char".
288 ************************************************************************/
289 #if PR_BYTES_PER_BYTE == 1
290 typedef unsigned char PRUint8
;
292 ** Some cfront-based C++ compilers do not like 'signed char' and
293 ** issue the warning message:
294 ** warning: "signed" not implemented (ignored)
295 ** For these compilers, we have to define PRInt8 as plain 'char'.
296 ** Make sure that plain 'char' is indeed signed under these compilers.
298 #if (defined(HPUX) && defined(__cplusplus) \
299 && !defined(__GNUC__) && __cplusplus < 199707L) \
300 || (defined(SCO) && defined(__cplusplus) \
301 && !defined(__GNUC__) && __cplusplus == 1L)
304 typedef signed char PRInt8
;
307 #error No suitable type for PRInt8/PRUint8
310 /************************************************************************
311 * MACROS: PR_INT8_MAX
315 * The maximum and minimum values of a PRInt8 or PRUint8.
316 ************************************************************************/
318 #define PR_INT8_MAX 127
319 #define PR_INT8_MIN (-128)
320 #define PR_UINT8_MAX 255U
322 /************************************************************************
326 ** The int16 types are known to be 16 bits each.
327 ************************************************************************/
328 #if PR_BYTES_PER_SHORT == 2
329 typedef unsigned short PRUint16
;
330 typedef short PRInt16
;
332 #error No suitable type for PRInt16/PRUint16
335 /************************************************************************
336 * MACROS: PR_INT16_MAX
340 * The maximum and minimum values of a PRInt16 or PRUint16.
341 ************************************************************************/
343 #define PR_INT16_MAX 32767
344 #define PR_INT16_MIN (-32768)
345 #define PR_UINT16_MAX 65535U
347 /************************************************************************
351 ** The int32 types are known to be 32 bits each.
352 ************************************************************************/
353 #if PR_BYTES_PER_INT == 4
354 typedef unsigned int PRUint32
;
356 #define PR_INT32(x) x
357 #define PR_UINT32(x) x ## U
358 #elif PR_BYTES_PER_LONG == 4
359 typedef unsigned long PRUint32
;
360 typedef long PRInt32
;
361 #define PR_INT32(x) x ## L
362 #define PR_UINT32(x) x ## UL
364 #error No suitable type for PRInt32/PRUint32
367 /************************************************************************
368 * MACROS: PR_INT32_MAX
372 * The maximum and minimum values of a PRInt32 or PRUint32.
373 ************************************************************************/
375 #define PR_INT32_MAX PR_INT32(2147483647)
376 #define PR_INT32_MIN (-PR_INT32_MAX - 1)
377 #define PR_UINT32_MAX PR_UINT32(4294967295)
379 /************************************************************************
383 ** The int64 types are known to be 64 bits each. Care must be used when
384 ** declaring variables of type PRUint64 or PRInt64. Different hardware
385 ** architectures and even different compilers have varying support for
386 ** 64 bit values. The only guaranteed portability requires the use of
387 ** the LL_ macros (see prlong.h).
388 ************************************************************************/
389 #ifdef HAVE_LONG_LONG
390 #if PR_BYTES_PER_LONG == 8
391 typedef long PRInt64
;
392 typedef unsigned long PRUint64
;
394 typedef __int64 PRInt64
;
395 typedef unsigned __int64 PRUint64
;
396 #elif defined(WIN32) && !defined(__GNUC__)
397 typedef __int64 PRInt64
;
398 typedef unsigned __int64 PRUint64
;
400 typedef long long PRInt64
;
401 typedef unsigned long long PRUint64
;
402 #endif /* PR_BYTES_PER_LONG == 8 */
403 #else /* !HAVE_LONG_LONG */
405 #ifdef IS_LITTLE_ENDIAN
411 typedef PRInt64 PRUint64
;
412 #endif /* !HAVE_LONG_LONG */
414 /************************************************************************
418 ** The PRIntn types are most appropriate for automatic variables. They are
419 ** guaranteed to be at least 16 bits, though various architectures may
420 ** define them to be wider (e.g., 32 or even 64 bits). These types are
421 ** never valid for fields of a structure.
422 ************************************************************************/
423 #if PR_BYTES_PER_INT >= 2
425 typedef unsigned int PRUintn
;
427 #error 'sizeof(int)' not sufficient for platform use
430 /************************************************************************
433 ** NSPR's floating point type is always 64 bits.
434 ************************************************************************/
435 typedef double PRFloat64
;
437 /************************************************************************
440 ** A type for representing the size of objects.
441 ************************************************************************/
442 typedef size_t PRSize
;
445 /************************************************************************
446 ** TYPES: PROffset32, PROffset64
448 ** A type for representing byte offsets from some location.
449 ************************************************************************/
450 typedef PRInt32 PROffset32
;
451 typedef PRInt64 PROffset64
;
453 /************************************************************************
456 ** A type for pointer difference. Variables of this type are suitable
457 ** for storing a pointer or pointer subtraction.
458 ************************************************************************/
459 typedef ptrdiff_t PRPtrdiff
;
461 /************************************************************************
464 ** A type for pointer difference. Variables of this type are suitable
465 ** for storing a pointer or pointer sutraction.
466 ************************************************************************/
468 typedef unsigned __int64 PRUptrdiff
;
470 typedef unsigned long PRUptrdiff
;
473 /************************************************************************
476 ** Use PRBool for variables and parameter types. Use PR_FALSE and PR_TRUE
477 ** for clarity of target type in assignments and actual arguments. Use
478 ** 'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
479 ** just as you would C int-valued conditions.
480 ************************************************************************/
481 typedef PRIntn PRBool
;
485 /************************************************************************
486 ** TYPES: PRPackedBool
488 ** Use PRPackedBool within structs where bitfields are not desirable
489 ** but minimum and consistant overhead matters.
490 ************************************************************************/
491 typedef PRUint8 PRPackedBool
;
494 ** Status code used by some routines that have a single point of failure or
495 ** special status return.
497 typedef enum { PR_FAILURE
= -1, PR_SUCCESS
= 0 } PRStatus
;
499 #ifndef __PRUNICHAR__
500 #define __PRUNICHAR__
501 #if defined(WIN32) || defined(XP_MAC)
502 typedef wchar_t PRUnichar
;
504 typedef PRUint16 PRUnichar
;
509 ** WARNING: The undocumented data types PRWord and PRUword are
510 ** only used in the garbage collection and arena code. Do not
511 ** use PRWord and PRUword in new code.
513 ** A PRWord is an integer that is the same size as a void*.
514 ** It implements the notion of a "word" in the Java Virtual
515 ** Machine. (See Sec. 3.4 "Words", The Java Virtual Machine
516 ** Specification, Addison-Wesley, September 1996.
517 ** http://java.sun.com/docs/books/vmspec/index.html.)
520 typedef __int64 PRWord
;
521 typedef unsigned __int64 PRUword
;
524 typedef unsigned long PRUword
;
527 #if defined(NO_NSPR_10_SUPPORT)
529 /********* ???????????????? FIX ME ??????????????????????????? *****/
530 /********************** Some old definitions until pr=>ds transition is done ***/
531 /********************** Also, we are still using NSPR 1.0. GC ******************/
533 ** Fundamental NSPR macros, used nearly everywhere.
536 #define PR_PUBLIC_API PR_IMPLEMENT
539 ** Macro body brackets so that macros with compound statement definitions
540 ** behave syntactically more like functions when called.
542 #define NSPR_BEGIN_MACRO do {
543 #define NSPR_END_MACRO } while (0)
546 ** Macro shorthands for conditional C++ extern block delimiters.
548 #ifdef NSPR_BEGIN_EXTERN_C
549 #undef NSPR_BEGIN_EXTERN_C
551 #ifdef NSPR_END_EXTERN_C
552 #undef NSPR_END_EXTERN_C
556 #define NSPR_BEGIN_EXTERN_C extern "C" {
557 #define NSPR_END_EXTERN_C }
559 #define NSPR_BEGIN_EXTERN_C
560 #define NSPR_END_EXTERN_C
564 #include "protypes.h"
566 #include "obsolete/protypes.h"
569 /********* ????????????? End Fix me ?????????????????????????????? *****/
570 #endif /* NO_NSPR_10_SUPPORT */
574 #endif /* prtypes_h___ */