[totem] browser-plugin: Fix compile-time warnings
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem] browser-plugin: Fix compile-time warnings
- Date: Wed, 27 Mar 2013 13:12:49 +0000 (UTC)
commit 34ddbd798b40b0f799853448843c92d06d697556
Author: Bastien Nocera <hadess hadess net>
Date: Fri Mar 22 10:52:48 2013 +0100
browser-plugin: Fix compile-time warnings
By updating our copies of npruntime.h and nptypes.h from
gnome-shell's browser-plugin.
browser-plugin/Makefile.am | 1 +
browser-plugin/npruntime.h | 306 +++++++++++++++++++++++++-------------------
browser-plugin/nptypes.h | 121 +++++++++++++++++
3 files changed, 296 insertions(+), 132 deletions(-)
---
diff --git a/browser-plugin/Makefile.am b/browser-plugin/Makefile.am
index 60798d6..3b730c2 100644
--- a/browser-plugin/Makefile.am
+++ b/browser-plugin/Makefile.am
@@ -20,6 +20,7 @@ plugin_sources = \
npapi.h \
npruntime.h \
npupp.h \
+ nptypes.h \
totemNPNGlue.cpp \
totemNPClass.cpp \
totemNPClass.h \
diff --git a/browser-plugin/npruntime.h b/browser-plugin/npruntime.h
index 5725b72..6e89165 100644
--- a/browser-plugin/npruntime.h
+++ b/browser-plugin/npruntime.h
@@ -1,11 +1,12 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
- * Copyright (C) 2004, Apple Computer, Inc. and The Mozilla Foundation.
+ * Copyright (c) 2004, Apple Computer, Inc. and The Mozilla Foundation.
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
@@ -15,7 +16,7 @@
* Foundation ("Mozilla") nor the names of their contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY APPLE, MOZILLA AND THEIR CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
@@ -28,42 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * Revision 1 (March 4, 2004):
- * Initial proposal.
- *
- * Revision 2 (March 10, 2004):
- * All calls into script were made asynchronous. Results are
- * provided via the NPScriptResultFunctionPtr callback.
- *
- * Revision 3 (March 10, 2004):
- * Corrected comments to not refer to class retain/release FunctionPtrs.
- *
- * Revision 4 (March 11, 2004):
- * Added additional convenience NPN_SetExceptionWithUTF8().
- * Changed NPHasPropertyFunctionPtr and NPHasMethodFunctionPtr to take NPClass
- * pointers instead of NPObject pointers.
- * Added NPIsValidIdentifier().
- *
- * Revision 5 (March 17, 2004):
- * Added context parameter to result callbacks from ScriptObject functions.
- *
- * Revision 6 (March 29, 2004):
- * Renamed functions implemented by user agent to NPN_*. Removed _ from
- * type names.
- * Renamed "JavaScript" types to "Script".
- *
- * Revision 7 (April 21, 2004):
- * NPIdentifier becomes a void*, was int32_t
- * Remove NP_IsValidIdentifier, renamed NP_IdentifierFromUTF8 to NP_GetIdentifier
- * Added NPVariant and modified functions to use this new type.
- *
- * Revision 8 (July 9, 2004):
- * Updated to joint Apple-Mozilla license.
- *
- * Revision 9 (August 12, 2004):
- * Changed NPVariantType enum values to form PVariantType_XXX
- * Added NPP arguments to NPObject functions.
- * Replaced NPVariant functions with macros.
*/
#ifndef _NP_RUNTIME_H_
#define _NP_RUNTIME_H_
@@ -72,15 +37,14 @@
extern "C" {
#endif
-#include <stdint.h>
-#include "npapi.h"
+#include "nptypes.h"
/*
This API is used to facilitate binding code written in C to script
objects. The API in this header does not assume the presence of a
user agent. That is, it can be used to bind C code to scripting
environments outside of the context of a user agent.
-
+
However, the normal use of the this API is in the context of a
scripting environment running in a browser or other user agent.
In particular it is used to support the extended Netscape
@@ -106,6 +70,8 @@ extern "C" {
language used by the scripting environment have been minimized.
*/
+#define NP_BEGIN_MACRO do {
+#define NP_END_MACRO } while (0)
/*
Objects (non-primitive data) passed between 'C' and script is
@@ -120,7 +86,7 @@ typedef struct _NPString {
const NPUTF8 *UTF8Characters;
uint32_t UTF8Length;
} NPString;
-
+
typedef enum {
NPVariantType_Void,
NPVariantType_Null,
@@ -143,16 +109,16 @@ typedef struct _NPVariant {
} NPVariant;
/*
- NPN_ReleaseVariantValue is called on all 'out' parameters references.
- Specifically it is called on variants that are resultant out parameters
- in NPGetPropertyFunctionPtr and NPInvokeFunctionPtr. Resultant variants
- from these two functions should be initialized using the
- NPN_InitializeVariantXXX() functions.
-
- After calling NPReleaseVariantValue, the type of the variant will
- be set to NPVariantUndefinedType.
+ NPN_ReleaseVariantValue is called on all 'out' parameters
+ references. Specifically it is to be called on variants that own
+ their value, as is the case with all non-const NPVariant*
+ arguments after a successful call to any methods (except this one)
+ in this API.
+
+ After calling NPN_ReleaseVariantValue, the type of the variant
+ will be NPVariantType_Void.
*/
-void NPN_ReleaseVariantValue (NPVariant *variant);
+void NPN_ReleaseVariantValue(NPVariant *variant);
#define NPVARIANT_IS_VOID(_v) ((_v).type == NPVariantType_Void)
#define NPVARIANT_IS_NULL(_v) ((_v).type == NPVariantType_Null)
@@ -168,38 +134,77 @@ void NPN_ReleaseVariantValue (NPVariant *variant);
#define NPVARIANT_TO_STRING(_v) ((_v).value.stringValue)
#define NPVARIANT_TO_OBJECT(_v) ((_v).value.objectValue)
-#define NP_BEGIN_MACRO do {
-#define NP_END_MACRO } while (0)
+#define VOID_TO_NPVARIANT(_v) \
+NP_BEGIN_MACRO \
+ (_v).type = NPVariantType_Void; \
+ (_v).value.objectValue = NULL; \
+NP_END_MACRO
+
+#define NULL_TO_NPVARIANT(_v) \
+NP_BEGIN_MACRO \
+ (_v).type = NPVariantType_Null; \
+ (_v).value.objectValue = NULL; \
+NP_END_MACRO
+
+#define BOOLEAN_TO_NPVARIANT(_val, _v) \
+NP_BEGIN_MACRO \
+ (_v).type = NPVariantType_Bool; \
+ (_v).value.boolValue = !!(_val); \
+NP_END_MACRO
+
+#define INT32_TO_NPVARIANT(_val, _v) \
+NP_BEGIN_MACRO \
+ (_v).type = NPVariantType_Int32; \
+ (_v).value.intValue = _val; \
+NP_END_MACRO
+
+#define DOUBLE_TO_NPVARIANT(_val, _v) \
+NP_BEGIN_MACRO \
+ (_v).type = NPVariantType_Double; \
+ (_v).value.doubleValue = _val; \
+NP_END_MACRO
+
+#define STRINGZ_TO_NPVARIANT(_val, _v) \
+NP_BEGIN_MACRO \
+ (_v).type = NPVariantType_String; \
+ NPString str = { _val, (uint32_t)(strlen(_val)) }; \
+ (_v).value.stringValue = str; \
+NP_END_MACRO
+
+#define STRINGN_TO_NPVARIANT(_val, _len, _v) \
+NP_BEGIN_MACRO \
+ (_v).type = NPVariantType_String; \
+ NPString str = { _val, (uint32_t)(_len) }; \
+ (_v).value.stringValue = str; \
+NP_END_MACRO
+
+#define OBJECT_TO_NPVARIANT(_val, _v) \
+NP_BEGIN_MACRO \
+ (_v).type = NPVariantType_Object; \
+ (_v).value.objectValue = _val; \
+NP_END_MACRO
-#define VOID_TO_NPVARIANT(_v) NP_BEGIN_MACRO (_v).type = NPVariantType_Void;
(_v).value.objectValue = NULL; NP_END_MACRO
-#define NULL_TO_NPVARIANT(_v) NP_BEGIN_MACRO (_v).type = NPVariantType_Null;
(_v).value.objectValue = NULL; NP_END_MACRO
-#define BOOLEAN_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_Bool;
(_v).value.boolValue = !!(_val); NP_END_MACRO
-#define INT32_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_Int32;
(_v).value.intValue = _val; NP_END_MACRO
-#define DOUBLE_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_Double;
(_v).value.doubleValue = _val; NP_END_MACRO
-#define STRINGZ_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_String; NPString str =
{ _val, strlen(_val) }; (_v).value.stringValue = str; NP_END_MACRO
-#define STRINGN_TO_NPVARIANT(_val, _len, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_String; NPString str =
{ _val, _len }; (_v).value.stringValue = str; NP_END_MACRO
-#define OBJECT_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_Object;
(_v).value.objectValue = _val; NP_END_MACRO
/*
- Type mappings (JavaScript types have been used for illustration
+ Type mappings (JavaScript types have been used for illustration
purposes):
- JavaScript to C (NPVariant with type:)
- undefined NPVariantType_Void
- null NPVariantType_Null
- Boolean NPVariantType_Bool
- Number NPVariantType_Double or NPVariantType_Int32
- String NPVariantType_String
- Object NPVariantType_Object
-
- C (NPVariant with type:) to JavaScript
- NPVariantType_Void undefined
- NPVariantType_Null null
- NPVariantType_Bool Boolean
- NPVariantType_Int32 Number
- NPVariantType_Double Number
- NPVariantType_String String
- NPVariantType_Object Object
+ JavaScript to C (NPVariant with type:)
+ undefined NPVariantType_Void
+ null NPVariantType_Null
+ Boolean NPVariantType_Bool
+ Number NPVariantType_Double or NPVariantType_Int32
+ String NPVariantType_String
+ Object NPVariantType_Object
+
+ C (NPVariant with type:) to JavaScript
+ NPVariantType_Void undefined
+ NPVariantType_Null null
+ NPVariantType_Bool Boolean
+ NPVariantType_Int32 Number
+ NPVariantType_Double Number
+ NPVariantType_String String
+ NPVariantType_Object Object
*/
typedef void *NPIdentifier;
@@ -211,10 +216,13 @@ typedef void *NPIdentifier;
methods and properties can be identified by either strings or
integers (i.e. foo["bar"] vs foo[1]). NPIdentifiers can be
compared using ==. In case of any errors, the requested
- NPIdentifier(s) will be NULL.
+ NPIdentifier(s) will be NULL. NPIdentifier lifetime is controlled
+ by the browser. Plugins do not need to worry about memory management
+ with regards to NPIdentifiers.
*/
NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name);
-void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers);
+void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount,
+ NPIdentifier *identifiers);
NPIdentifier NPN_GetIntIdentifier(int32_t intid);
bool NPN_IdentifierIsString(NPIdentifier identifier);
@@ -237,37 +245,52 @@ int32_t NPN_IntFromIdentifier(NPIdentifier identifier);
applicable) should be released using NPN_ReleaseVariantValue().
*/
typedef NPObject *(*NPAllocateFunctionPtr)(NPP npp, NPClass *aClass);
-typedef void (*NPDeallocateFunctionPtr)(NPObject *obj);
-typedef void (*NPInvalidateFunctionPtr)(NPObject *obj);
-typedef bool (*NPHasMethodFunctionPtr)(NPObject *obj, NPIdentifier name);
-typedef bool (*NPInvokeFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t
argCount, NPVariant *result);
-typedef bool (*NPInvokeDefaultFunctionPtr)(NPObject *npobj, const NPVariant *args, uint32_t argCount,
NPVariant *result);
-typedef bool (*NPHasPropertyFunctionPtr)(NPObject *obj, NPIdentifier name);
-typedef bool (*NPGetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, NPVariant *result);
-typedef bool (*NPSetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *value);
-typedef bool (*NPRemovePropertyFunctionPtr)(NPObject *npobj, NPIdentifier name);
-typedef bool (*NPEnumerationFunctionPtr)(NPObject *npobj, NPIdentifier **value, uint32_t *count);
+typedef void (*NPDeallocateFunctionPtr)(NPObject *npobj);
+typedef void (*NPInvalidateFunctionPtr)(NPObject *npobj);
+typedef bool (*NPHasMethodFunctionPtr)(NPObject *npobj, NPIdentifier name);
+typedef bool (*NPInvokeFunctionPtr)(NPObject *npobj, NPIdentifier name,
+ const NPVariant *args, uint32_t argCount,
+ NPVariant *result);
+typedef bool (*NPInvokeDefaultFunctionPtr)(NPObject *npobj,
+ const NPVariant *args,
+ uint32_t argCount,
+ NPVariant *result);
+typedef bool (*NPHasPropertyFunctionPtr)(NPObject *npobj, NPIdentifier name);
+typedef bool (*NPGetPropertyFunctionPtr)(NPObject *npobj, NPIdentifier name,
+ NPVariant *result);
+typedef bool (*NPSetPropertyFunctionPtr)(NPObject *npobj, NPIdentifier name,
+ const NPVariant *value);
+typedef bool (*NPRemovePropertyFunctionPtr)(NPObject *npobj,
+ NPIdentifier name);
+typedef bool (*NPEnumerationFunctionPtr)(NPObject *npobj, NPIdentifier **value,
+ uint32_t *count);
+typedef bool (*NPConstructFunctionPtr)(NPObject *npobj,
+ const NPVariant *args,
+ uint32_t argCount,
+ NPVariant *result);
/*
- NPObjects returned by create have a reference count of one. It is the caller's responsibility
- to release the returned object.
-
- NPInvokeFunctionPtr function may return false to indicate a the method could not be invoked.
-
- NPGetPropertyFunctionPtr and NPSetPropertyFunctionPtr may return false to indicate a property doesn't
- exist.
-
- NPInvalidateFunctionPtr is called by the scripting environment when the native code is
- shutdown. Any attempt to message a NPObject instance after the invalidate
- callback has been called will result in undefined behavior, even if the
- native code is still retaining those NPObject instances.
- (The runtime will typically return immediately, with 0 or NULL, from an attempt to
- dispatch to a NPObject, but this behavior should not be depended upon.)
-
- The NPEnumerationFunctionPtr function may pass an array of
- NPIdentifiers back to the caller. The callee allocs the memory of
- the array using NPN_MemAlloc(), and it's the caller's responsibility
- to release it using NPN_MemFree().
+ NPObjects returned by create, retain, invoke, and getProperty pass
+ a reference count to the caller. That is, the callee adds a
+ reference count which passes to the caller. It is the caller's
+ responsibility to release the returned object.
+
+ NPInvokeFunctionPtr function may return 0 to indicate a void
+ result.
+
+ NPInvalidateFunctionPtr is called by the scripting environment
+ when the native code is shutdown. Any attempt to message a
+ NPObject instance after the invalidate callback has been
+ called will result in undefined behavior, even if the native code
+ is still retaining those NPObject instances. (The runtime
+ will typically return immediately, with 0 or NULL, from an attempt
+ to dispatch to a NPObject, but this behavior should not be
+ depended upon.)
+
+ The NPEnumerationFunctionPtr function may pass an array of
+ NPIdentifiers back to the caller. The callee allocs the memory of
+ the array using NPN_MemAlloc(), and it's the caller's responsibility
+ to release it using NPN_MemFree().
*/
struct NPClass
{
@@ -283,38 +306,47 @@ struct NPClass
NPSetPropertyFunctionPtr setProperty;
NPRemovePropertyFunctionPtr removeProperty;
NPEnumerationFunctionPtr enumerate;
+ NPConstructFunctionPtr construct;
};
-#define NP_CLASS_STRUCT_VERSION 2
-#define NP_CLASS_STRUCT_VERSION_ENUM 2
+#define NP_CLASS_STRUCT_VERSION 3
+
+#define NP_CLASS_STRUCT_VERSION_ENUM 2
+#define NP_CLASS_STRUCT_VERSION_CTOR 3
+
#define NP_CLASS_STRUCT_VERSION_HAS_ENUM(npclass) \
- ((npclass)->structVersion >= NP_CLASS_STRUCT_VERSION_ENUM)
+ ((npclass)->structVersion >= NP_CLASS_STRUCT_VERSION_ENUM)
+
+#define NP_CLASS_STRUCT_VERSION_HAS_CTOR(npclass) \
+ ((npclass)->structVersion >= NP_CLASS_STRUCT_VERSION_CTOR)
struct NPObject {
NPClass *_class;
uint32_t referenceCount;
- // Additional space may be allocated here by types of NPObjects
+ /*
+ * Additional space may be allocated here by types of NPObjects
+ */
};
/*
- If the class has an allocate function, NPN_CreateObject invokes that function,
- otherwise a NPObject is allocated and returned. If a class has an allocate
- function it is the responsibility of that implementation to set the initial retain
- count to 1.
+ If the class has an allocate function, NPN_CreateObject invokes
+ that function, otherwise a NPObject is allocated and
+ returned. This method will initialize the referenceCount member of
+ the NPObject to 1.
*/
NPObject *NPN_CreateObject(NPP npp, NPClass *aClass);
/*
Increment the NPObject's reference count.
*/
-NPObject *NPN_RetainObject (NPObject *obj);
+NPObject *NPN_RetainObject(NPObject *npobj);
/*
Decremented the NPObject's reference count. If the reference
count goes to zero, the class's destroy function is invoke if
specified, otherwise the object is freed directly.
*/
-void NPN_ReleaseObject (NPObject *obj);
+void NPN_ReleaseObject(NPObject *npobj);
/*
Functions to access script objects represented by NPObject.
@@ -323,26 +355,36 @@ void NPN_ReleaseObject (NPObject *obj);
value, it will be supplied via the result NPVariant
argument. Successful calls will return true, false will be
returned in case of an error.
-
+
Calls made from plugin code to script must be made from the thread
on which the plugin was initialized.
*/
-bool NPN_Invoke(NPP npp, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount,
NPVariant *result);
-bool NPN_InvokeDefault(NPP npp, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant
*result);
-bool NPN_Evaluate(NPP npp, NPObject *npobj, NPString *script, NPVariant *result);
-bool NPN_GetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, NPVariant *result);
-bool NPN_SetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value);
+
+bool NPN_Invoke(NPP npp, NPObject *npobj, NPIdentifier methodName,
+ const NPVariant *args, uint32_t argCount, NPVariant *result);
+bool NPN_InvokeDefault(NPP npp, NPObject *npobj, const NPVariant *args,
+ uint32_t argCount, NPVariant *result);
+bool NPN_Evaluate(NPP npp, NPObject *npobj, NPString *script,
+ NPVariant *result);
+bool NPN_GetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName,
+ NPVariant *result);
+bool NPN_SetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName,
+ const NPVariant *value);
bool NPN_RemoveProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName);
bool NPN_HasProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName);
bool NPN_HasMethod(NPP npp, NPObject *npobj, NPIdentifier methodName);
-bool NPN_Enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier, uint32_t *count);
-bool NPN_Construct(NPP npp, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result);
+bool NPN_Enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier,
+ uint32_t *count);
+bool NPN_Construct(NPP npp, NPObject *npobj, const NPVariant *args,
+ uint32_t argCount, NPVariant *result);
/*
- NPN_SetException may be called to trigger a script exception upon return
- from entry points into NPObjects.
+ NPN_SetException may be called to trigger a script exception upon
+ return from entry points into NPObjects. Typical usage:
+
+ NPN_SetException (npobj, message);
*/
-void NPN_SetException (NPObject *obj, const NPUTF8 *message);
+void NPN_SetException(NPObject *npobj, const NPUTF8 *message);
#ifdef __cplusplus
}
diff --git a/browser-plugin/nptypes.h b/browser-plugin/nptypes.h
new file mode 100644
index 0000000..abcc96b
--- /dev/null
+++ b/browser-plugin/nptypes.h
@@ -0,0 +1,121 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * mozilla.org.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Johnny Stenback <jst mozilla org> (Original author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef nptypes_h_
+#define nptypes_h_
+
+/*
+ * Header file for ensuring that C99 types ([u]int32_t, [u]int64_t and bool) and
+ * true/false macros are available.
+ */
+
+#if defined(WIN32) || defined(OS2)
+ /*
+ * Win32 and OS/2 don't know C99, so define [u]int_16/32/64 here. The bool
+ * is predefined tho, both in C and C++.
+ */
+ typedef short int16_t;
+ typedef unsigned short uint16_t;
+ typedef int int32_t;
+ typedef unsigned int uint32_t;
+ typedef long long int64_t;
+ typedef unsigned long long uint64_t;
+#elif defined(_AIX) || defined(__sun) || defined(__osf__) || defined(IRIX) || defined(HPUX)
+ /*
+ * AIX and SunOS ship a inttypes.h header that defines [u]int32_t,
+ * but not bool for C.
+ */
+ #include <inttypes.h>
+
+ #ifndef __cplusplus
+ typedef int bool;
+ #define true 1
+ #define false 0
+ #endif
+#elif defined(bsdi) || defined(FREEBSD) || defined(OPENBSD)
+ /*
+ * BSD/OS, FreeBSD, and OpenBSD ship sys/types.h that define int32_t and
+ * u_int32_t.
+ */
+ #include <sys/types.h>
+
+ /*
+ * BSD/OS ships no header that defines uint32_t, nor bool (for C)
+ */
+ #if defined(bsdi)
+ typedef u_int32_t uint32_t;
+ typedef u_int64_t uint64_t;
+
+ #if !defined(__cplusplus)
+ typedef int bool;
+ #define true 1
+ #define false 0
+ #endif
+ #else
+ /*
+ * FreeBSD and OpenBSD define uint32_t and bool.
+ */
+ #include <inttypes.h>
+ #include <stdbool.h>
+ #endif
+#elif defined(BEOS)
+ #include <inttypes.h>
+#else
+ /*
+ * For those that ship a standard C99 stdint.h header file, include
+ * it. Can't do the same for stdbool.h tho, since some systems ship
+ * with a stdbool.h file that doesn't compile!
+ */
+ #include <stdint.h>
+
+ #ifndef __cplusplus
+ #if !defined(__GNUC__) || (__GNUC__ > 2 || __GNUC_MINOR__ > 95)
+ #include <stdbool.h>
+ #else
+ /*
+ * GCC 2.91 can't deal with a typedef for bool, but a #define
+ * works.
+ */
+ #define bool int
+ #define true 1
+ #define false 0
+ #endif
+ #endif
+#endif
+
+#endif /* nptypes_h_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]