1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 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/
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.
13 * The Original Code is the Netscape Portable Runtime (NSPR).
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
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
37 ** Description: Definitions of NSPR's basic types
39 ** Prototypes and macros used to make up for deficiencies in ANSI environments
40 ** that we have found.
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
60 /***********************************************************************
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.
74 ** PR_EXTERN( void ) DoWhatIMean( void );
76 ** PR_IMPLEMENT( void ) DoWhatIMean( void ) { return; }
79 ***********************************************************************/
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
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
93 #define PR_CALLBACK_DECL
94 #define PR_STATIC_CALLBACK(__x) static __x
96 #elif defined(XP_BEOS)
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
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
109 #define PR_CALLBACK_DECL
110 #define PR_STATIC_CALLBACK(__x) static __x
114 #define PR_CALLBACK_DECL __cdecl
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
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
127 #define PR_CALLBACK __cdecl __loadds
128 #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
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
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
141 #define PR_CALLBACK __cdecl __loadds
142 #define PR_STATIC_CALLBACK(__x) __x PR_CALLBACK
145 #elif defined(XP_MAC)
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
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
158 #define PR_CALLBACK_DECL
159 #define PR_STATIC_CALLBACK(__x) static __x
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
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
173 #define PR_CALLBACK_DECL
174 #define PR_STATIC_CALLBACK(__x) static __x
178 #if defined(_NSPR_BUILD_)
179 #define NSPR_API(__type) PR_EXPORT(__type)
180 #define NSPR_DATA_API(__type) PR_EXPORT_DATA(__type)
182 #define NSPR_API(__type) PR_IMPORT(__type)
183 #define NSPR_DATA_API(__type) PR_IMPORT_DATA(__type)
186 /***********************************************************************
187 ** MACROS: PR_BEGIN_MACRO
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)
196 /***********************************************************************
197 ** MACROS: PR_BEGIN_EXTERN_C
200 ** Macro shorthands for conditional C++ extern block delimiters.
201 ***********************************************************************/
203 #define PR_BEGIN_EXTERN_C extern "C" {
204 #define PR_END_EXTERN_C }
206 #define PR_BEGIN_EXTERN_C
207 #define PR_END_EXTERN_C
210 /***********************************************************************
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)
219 /***********************************************************************
220 ** MACROS: PR_ROUNDUP
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))
234 /************************************************************************
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;
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.
250 #if (defined(HPUX) && defined(__cplusplus) \
251 && !defined(__GNUC__) && __cplusplus < 199707L) \
252 || (defined(SCO) && defined(__cplusplus) \
253 && !defined(__GNUC__) && __cplusplus == 1L)
256 typedef signed char PRInt8;
259 #error No suitable type for PRInt8/PRUint8
262 /************************************************************************
263 * MACROS: PR_INT8_MAX
267 * The maximum and minimum values of a PRInt8 or PRUint8.
268 ************************************************************************/
270 #define PR_INT8_MAX 127
271 #define PR_INT8_MIN (-128)
272 #define PR_UINT8_MAX 255U
274 /************************************************************************
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;
284 #error No suitable type for PRInt16/PRUint16
287 /************************************************************************
288 * MACROS: PR_INT16_MAX
292 * The maximum and minimum values of a PRInt16 or PRUint16.
293 ************************************************************************/
295 #define PR_INT16_MAX 32767
296 #define PR_INT16_MIN (-32768)
297 #define PR_UINT16_MAX 65535U
299 /************************************************************************
303 ** The int32 types are known to be 32 bits each.
304 ************************************************************************/
305 #if PR_BYTES_PER_INT == 4
306 typedef unsigned int PRUint32;
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
316 #error No suitable type for PRInt32/PRUint32
319 /************************************************************************
320 * MACROS: PR_INT32_MAX
324 * The maximum and minimum values of a PRInt32 or PRUint32.
325 ************************************************************************/
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)
331 /************************************************************************
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;
346 typedef __int64 PRInt64;
347 typedef unsigned __int64 PRUint64;
348 #elif defined(WIN32) && !defined(__GNUC__)
349 typedef __int64 PRInt64;
350 typedef unsigned __int64 PRUint64;
352 typedef long long PRInt64;
353 typedef unsigned long long PRUint64;
354 #endif /* PR_BYTES_PER_LONG == 8 */
355 #else /* !HAVE_LONG_LONG */
357 #ifdef IS_LITTLE_ENDIAN
363 typedef PRInt64 PRUint64;
364 #endif /* !HAVE_LONG_LONG */
366 /************************************************************************
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
377 typedef unsigned int PRUintn;
379 #error 'sizeof(int)' not sufficient for platform use
382 /************************************************************************
385 ** NSPR's floating point type is always 64 bits.
386 ************************************************************************/
387 typedef double PRFloat64;
389 /************************************************************************
392 ** A type for representing the size of objects.
393 ************************************************************************/
394 typedef size_t PRSize;
397 /************************************************************************
398 ** TYPES: PROffset32, PROffset64
400 ** A type for representing byte offsets from some location.
401 ************************************************************************/
402 typedef PRInt32 PROffset32;
403 typedef PRInt64 PROffset64;
405 /************************************************************************
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;
413 /************************************************************************
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;
421 /************************************************************************
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;
433 /************************************************************************
434 ** TYPES: PRPackedBool
436 ** Use PRPackedBOol within structs where bitfields are not desireable
437 ** but minimum and consistant overhead matters.
438 ************************************************************************/
439 typedef PRUint8 PRPackedBool;
442 ** Status code used by some routines that have a single point of failure or
443 ** special status return.
445 typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
449 * EXPERIMENTAL: This type may be removed in a future release.
451 #ifndef __PRUNICHAR__
452 #define __PRUNICHAR__
453 #if defined(WIN32) || defined(XP_MAC)
454 typedef wchar_t PRUnichar;
456 typedef PRUint16 PRUnichar;
459 #endif /* MOZ_UNICODE */
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.
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.)
473 typedef unsigned long PRUword;
475 #if defined(NO_NSPR_10_SUPPORT)
477 /********* ???????????????? FIX ME ??????????????????????????? *****/
478 /********************** Some old definitions until pr=>ds transition is done ***/
479 /********************** Also, we are still using NSPR 1.0. GC ******************/
481 ** Fundamental NSPR macros, used nearly everywhere.
484 #define PR_PUBLIC_API PR_IMPLEMENT
487 ** Macro body brackets so that macros with compound statement definitions
488 ** behave syntactically more like functions when called.
490 #define NSPR_BEGIN_MACRO do {
491 #define NSPR_END_MACRO } while (0)
494 ** Macro shorthands for conditional C++ extern block delimiters.
496 #ifdef NSPR_BEGIN_EXTERN_C
497 #undef NSPR_BEGIN_EXTERN_C
499 #ifdef NSPR_END_EXTERN_C
500 #undef NSPR_END_EXTERN_C
504 #define NSPR_BEGIN_EXTERN_C extern "C" {
505 #define NSPR_END_EXTERN_C }
507 #define NSPR_BEGIN_EXTERN_C
508 #define NSPR_END_EXTERN_C
512 #include "protypes.h"
514 #include "obsolete/protypes.h"
517 /********* ????????????? End Fix me ?????????????????????????????? *****/
518 #endif /* NO_NSPR_10_SUPPORT */
522 #endif /* prtypes_h___ */