Debian Codegraph @

nsdejavu/npsdk/prtypes.h

raw
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 "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 defined(WIN32)
84
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
89
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
94
95 #define PR_CALLBACK
96 #define PR_CALLBACK_DECL
97 #define PR_STATIC_CALLBACK(__x) static __x
98
99 #elif defined(XP_BEOS)
100
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
105
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
110
111 #define PR_CALLBACK
112 #define PR_CALLBACK_DECL
113 #define PR_STATIC_CALLBACK(__x) static __x
114
115 #elif defined(WIN16)
116
117 #define PR_CALLBACK_DECL __cdecl
118
119 #if defined(_WINDLL)
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
124
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
129
130 #define PR_CALLBACK __cdecl __loadds
131 #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
132
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
138
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
143
144 #define PR_CALLBACK __cdecl __loadds
145 #define PR_STATIC_CALLBACK(__x) __x PR_CALLBACK
146 #endif /* _WINDLL */
147
148 #elif defined(XP_MAC)
149
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
154
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
159
160 #define PR_CALLBACK
161 #define PR_CALLBACK_DECL
162 #define PR_STATIC_CALLBACK(__x) static __x
163
164 #elif defined(XP_OS2) && defined(__declspec)
165
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
170
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
175
176 #define PR_CALLBACK
177 #define PR_CALLBACK_DECL
178 #define PR_STATIC_CALLBACK(__x) static __x
179
180 #elif defined(XP_OS2_VACPP)
181
182 #define PR_EXPORT(__type) extern __type
183 #define PR_EXPORT_DATA(__type) extern __type
184 #define PR_IMPORT(__type) extern __type
185 #define PR_IMPORT_DATA(__type) extern __type
186
187 #define PR_EXTERN(__type) extern __type
188 #define PR_IMPLEMENT(__type) __type
189 #define PR_EXTERN_DATA(__type) extern __type
190 #define PR_IMPLEMENT_DATA(__type) __type
191 #define PR_CALLBACK _Optlink
192 #define PR_CALLBACK_DECL
193 #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
194
195 #else /* Unix */
196
197 /* GCC 3.3 and later support the visibility attribute. */
198 #if (__GNUC__ >= 4) || \
199 (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
200 #define PR_VISIBILITY_DEFAULT __attribute__((visibility("default")))
201 #else
202 #define PR_VISIBILITY_DEFAULT
203 #endif
204
205 #define PR_EXPORT(__type) extern PR_VISIBILITY_DEFAULT __type
206 #define PR_EXPORT_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
207 #define PR_IMPORT(__type) extern PR_VISIBILITY_DEFAULT __type
208 #define PR_IMPORT_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
209
210 #define PR_EXTERN(__type) extern PR_VISIBILITY_DEFAULT __type
211 #define PR_IMPLEMENT(__type) PR_VISIBILITY_DEFAULT __type
212 #define PR_EXTERN_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
213 #define PR_IMPLEMENT_DATA(__type) PR_VISIBILITY_DEFAULT __type
214 #define PR_CALLBACK
215 #define PR_CALLBACK_DECL
216 #define PR_STATIC_CALLBACK(__x) static __x
217
218 #endif
219
220 #if defined(_NSPR_BUILD_)
221 #define NSPR_API(__type) PR_EXPORT(__type)
222 #define NSPR_DATA_API(__type) PR_EXPORT_DATA(__type)
223 #else
224 #define NSPR_API(__type) PR_IMPORT(__type)
225 #define NSPR_DATA_API(__type) PR_IMPORT_DATA(__type)
226 #endif
227
228 /***********************************************************************
229 ** MACROS: PR_BEGIN_MACRO
230 ** PR_END_MACRO
231 ** DESCRIPTION:
232 ** Macro body brackets so that macros with compound statement definitions
233 ** behave syntactically more like functions when called.
234 ***********************************************************************/
235 #define PR_BEGIN_MACRO do {
236 #define PR_END_MACRO } while (0)
237
238 /***********************************************************************
239 ** MACROS: PR_BEGIN_EXTERN_C
240 ** PR_END_EXTERN_C
241 ** DESCRIPTION:
242 ** Macro shorthands for conditional C++ extern block delimiters.
243 ***********************************************************************/
244 #ifdef __cplusplus
245 #define PR_BEGIN_EXTERN_C extern "C" {
246 #define PR_END_EXTERN_C }
247 #else
248 #define PR_BEGIN_EXTERN_C
249 #define PR_END_EXTERN_C
250 #endif
251
252 /***********************************************************************
253 ** MACROS: PR_BIT
254 ** PR_BITMASK
255 ** DESCRIPTION:
256 ** Bit masking macros. XXX n must be <= 31 to be portable
257 ***********************************************************************/
258 #define PR_BIT(n) ((PRUint32)1 << (n))
259 #define PR_BITMASK(n) (PR_BIT(n) - 1)
260
261 /***********************************************************************
262 ** MACROS: PR_ROUNDUP
263 ** PR_MIN
264 ** PR_MAX
265 ** PR_ABS
266 ** DESCRIPTION:
267 ** Commonly used macros for operations on compatible types.
268 ***********************************************************************/
269 #define PR_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y))
270 #define PR_MIN(x,y) ((x)<(y)?(x):(y))
271 #define PR_MAX(x,y) ((x)>(y)?(x):(y))
272 #define PR_ABS(x) ((x)<0?-(x):(x))
273
274 PR_BEGIN_EXTERN_C
275
276 /************************************************************************
277 ** TYPES: PRUint8
278 ** PRInt8
279 ** DESCRIPTION:
280 ** The int8 types are known to be 8 bits each. There is no type that
281 ** is equivalent to a plain "char".
282 ************************************************************************/
283 #if PR_BYTES_PER_BYTE == 1
284 typedef unsigned char PRUint8;
285 /*
286 ** Some cfront-based C++ compilers do not like 'signed char' and
287 ** issue the warning message:
288 ** warning: "signed" not implemented (ignored)
289 ** For these compilers, we have to define PRInt8 as plain 'char'.
290 ** Make sure that plain 'char' is indeed signed under these compilers.
291 */
292 #if (defined(HPUX) && defined(__cplusplus) \
293 && !defined(__GNUC__) && __cplusplus < 199707L) \
294 || (defined(SCO) && defined(__cplusplus) \
295 && !defined(__GNUC__) && __cplusplus == 1L)
296 typedef char PRInt8;
297 #else
298 typedef signed char PRInt8;
299 #endif
300 #else
301 #error No suitable type for PRInt8/PRUint8
302 #endif
303
304 /************************************************************************
305 * MACROS: PR_INT8_MAX
306 * PR_INT8_MIN
307 * PR_UINT8_MAX
308 * DESCRIPTION:
309 * The maximum and minimum values of a PRInt8 or PRUint8.
310 ************************************************************************/
311
312 #define PR_INT8_MAX 127
313 #define PR_INT8_MIN (-128)
314 #define PR_UINT8_MAX 255U
315
316 /************************************************************************
317 ** TYPES: PRUint16
318 ** PRInt16
319 ** DESCRIPTION:
320 ** The int16 types are known to be 16 bits each.
321 ************************************************************************/
322 #if PR_BYTES_PER_SHORT == 2
323 typedef unsigned short PRUint16;
324 typedef short PRInt16;
325 #else
326 #error No suitable type for PRInt16/PRUint16
327 #endif
328
329 /************************************************************************
330 * MACROS: PR_INT16_MAX
331 * PR_INT16_MIN
332 * PR_UINT16_MAX
333 * DESCRIPTION:
334 * The maximum and minimum values of a PRInt16 or PRUint16.
335 ************************************************************************/
336
337 #define PR_INT16_MAX 32767
338 #define PR_INT16_MIN (-32768)
339 #define PR_UINT16_MAX 65535U
340
341 /************************************************************************
342 ** TYPES: PRUint32
343 ** PRInt32
344 ** DESCRIPTION:
345 ** The int32 types are known to be 32 bits each.
346 ************************************************************************/
347 #if PR_BYTES_PER_INT == 4
348 typedef unsigned int PRUint32;
349 typedef int PRInt32;
350 #define PR_INT32(x) x
351 #define PR_UINT32(x) x ## U
352 #elif PR_BYTES_PER_LONG == 4
353 typedef unsigned long PRUint32;
354 typedef long PRInt32;
355 #define PR_INT32(x) x ## L
356 #define PR_UINT32(x) x ## UL
357 #else
358 #error No suitable type for PRInt32/PRUint32
359 #endif
360
361 /************************************************************************
362 * MACROS: PR_INT32_MAX
363 * PR_INT32_MIN
364 * PR_UINT32_MAX
365 * DESCRIPTION:
366 * The maximum and minimum values of a PRInt32 or PRUint32.
367 ************************************************************************/
368
369 #define PR_INT32_MAX PR_INT32(2147483647)
370 #define PR_INT32_MIN (-PR_INT32_MAX - 1)
371 #define PR_UINT32_MAX PR_UINT32(4294967295)
372
373 /************************************************************************
374 ** TYPES: PRUint64
375 ** PRInt64
376 ** DESCRIPTION:
377 ** The int64 types are known to be 64 bits each. Care must be used when
378 ** declaring variables of type PRUint64 or PRInt64. Different hardware
379 ** architectures and even different compilers have varying support for
380 ** 64 bit values. The only guaranteed portability requires the use of
381 ** the LL_ macros (see prlong.h).
382 ************************************************************************/
383 #ifdef HAVE_LONG_LONG
384 #if PR_BYTES_PER_LONG == 8
385 typedef long PRInt64;
386 typedef unsigned long PRUint64;
387 #elif defined(WIN16)
388 typedef __int64 PRInt64;
389 typedef unsigned __int64 PRUint64;
390 #elif defined(WIN32) && !defined(__GNUC__)
391 typedef __int64 PRInt64;
392 typedef unsigned __int64 PRUint64;
393 #else
394 typedef long long PRInt64;
395 typedef unsigned long long PRUint64;
396 #endif /* PR_BYTES_PER_LONG == 8 */
397 #else /* !HAVE_LONG_LONG */
398 typedef struct {
399 #ifdef IS_LITTLE_ENDIAN
400 PRUint32 lo, hi;
401 #else
402 PRUint32 hi, lo;
403 #endif
404 } PRInt64;
405 typedef PRInt64 PRUint64;
406 #endif /* !HAVE_LONG_LONG */
407
408 /************************************************************************
409 ** TYPES: PRUintn
410 ** PRIntn
411 ** DESCRIPTION:
412 ** The PRIntn types are most appropriate for automatic variables. They are
413 ** guaranteed to be at least 16 bits, though various architectures may
414 ** define them to be wider (e.g., 32 or even 64 bits). These types are
415 ** never valid for fields of a structure.
416 ************************************************************************/
417 #if PR_BYTES_PER_INT >= 2
418 typedef int PRIntn;
419 typedef unsigned int PRUintn;
420 #else
421 #error 'sizeof(int)' not sufficient for platform use
422 #endif
423
424 /************************************************************************
425 ** TYPES: PRFloat64
426 ** DESCRIPTION:
427 ** NSPR's floating point type is always 64 bits.
428 ************************************************************************/
429 typedef double PRFloat64;
430
431 /************************************************************************
432 ** TYPES: PRSize
433 ** DESCRIPTION:
434 ** A type for representing the size of objects.
435 ************************************************************************/
436 typedef size_t PRSize;
437
438
439 /************************************************************************
440 ** TYPES: PROffset32, PROffset64
441 ** DESCRIPTION:
442 ** A type for representing byte offsets from some location.
443 ************************************************************************/
444 typedef PRInt32 PROffset32;
445 typedef PRInt64 PROffset64;
446
447 /************************************************************************
448 ** TYPES: PRPtrDiff
449 ** DESCRIPTION:
450 ** A type for pointer difference. Variables of this type are suitable
451 ** for storing a pointer or pointer subtraction.
452 ************************************************************************/
453 typedef ptrdiff_t PRPtrdiff;
454
455 /************************************************************************
456 ** TYPES: PRUptrdiff
457 ** DESCRIPTION:
458 ** A type for pointer difference. Variables of this type are suitable
459 ** for storing a pointer or pointer sutraction.
460 ************************************************************************/
461 #ifdef _WIN64
462 typedef unsigned __int64 PRUptrdiff;
463 #else
464 typedef unsigned long PRUptrdiff;
465 #endif
466
467 /************************************************************************
468 ** TYPES: PRBool
469 ** DESCRIPTION:
470 ** Use PRBool for variables and parameter types. Use PR_FALSE and PR_TRUE
471 ** for clarity of target type in assignments and actual arguments. Use
472 ** 'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
473 ** just as you would C int-valued conditions.
474 ************************************************************************/
475 typedef PRIntn PRBool;
476 #define PR_TRUE 1
477 #define PR_FALSE 0
478
479 /************************************************************************
480 ** TYPES: PRPackedBool
481 ** DESCRIPTION:
482 ** Use PRPackedBool within structs where bitfields are not desirable
483 ** but minimum and consistant overhead matters.
484 ************************************************************************/
485 typedef PRUint8 PRPackedBool;
486
487 /*
488 ** Status code used by some routines that have a single point of failure or
489 ** special status return.
490 */
491 typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
492
493 #ifndef __PRUNICHAR__
494 #define __PRUNICHAR__
495 #if defined(WIN32) || defined(XP_MAC)
496 typedef wchar_t PRUnichar;
497 #else
498 typedef PRUint16 PRUnichar;
499 #endif
500 #endif
501
502 /*
503 ** WARNING: The undocumented data types PRWord and PRUword are
504 ** only used in the garbage collection and arena code. Do not
505 ** use PRWord and PRUword in new code.
506 **
507 ** A PRWord is an integer that is the same size as a void*.
508 ** It implements the notion of a "word" in the Java Virtual
509 ** Machine. (See Sec. 3.4 "Words", The Java Virtual Machine
510 ** Specification, Addison-Wesley, September 1996.
511 ** http://java.sun.com/docs/books/vmspec/index.html.)
512 */
513 #ifdef _WIN64
514 typedef __int64 PRWord;
515 typedef unsigned __int64 PRUword;
516 #else
517 typedef long PRWord;
518 typedef unsigned long PRUword;
519 #endif
520
521 #if defined(NO_NSPR_10_SUPPORT)
522 #else
523 /********* ???????????????? FIX ME ??????????????????????????? *****/
524 /********************** Some old definitions until pr=>ds transition is done ***/
525 /********************** Also, we are still using NSPR 1.0. GC ******************/
526 /*
527 ** Fundamental NSPR macros, used nearly everywhere.
528 */
529
530 #define PR_PUBLIC_API PR_IMPLEMENT
531
532 /*
533 ** Macro body brackets so that macros with compound statement definitions
534 ** behave syntactically more like functions when called.
535 */
536 #define NSPR_BEGIN_MACRO do {
537 #define NSPR_END_MACRO } while (0)
538
539 /*
540 ** Macro shorthands for conditional C++ extern block delimiters.
541 */
542 #ifdef NSPR_BEGIN_EXTERN_C
543 #undef NSPR_BEGIN_EXTERN_C
544 #endif
545 #ifdef NSPR_END_EXTERN_C
546 #undef NSPR_END_EXTERN_C
547 #endif
548
549 #ifdef __cplusplus
550 #define NSPR_BEGIN_EXTERN_C extern "C" {
551 #define NSPR_END_EXTERN_C }
552 #else
553 #define NSPR_BEGIN_EXTERN_C
554 #define NSPR_END_EXTERN_C
555 #endif
556
557 #ifdef XP_MAC
558 #include "protypes.h"
559 #else
560 #include "obsolete/protypes.h"
561 #endif
562
563 /********* ????????????? End Fix me ?????????????????????????????? *****/
564 #endif /* NO_NSPR_10_SUPPORT */
565
566 PR_END_EXTERN_C
567
568 #endif /* prtypes_h___ */
569