/gecko_api/include/prtypes.h

http://firefox-mac-pdf.googlecode.com/ · C++ Header · 569 lines · 262 code · 74 blank · 233 comment · 25 complexity · e9f7b4c2bb8b206f605147dd0a8381c2 MD5 · raw file

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