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