Index: trunk/include/VBox/com/defs.h
===================================================================
--- trunk/include/VBox/com/defs.h	(revision 44970)
+++ trunk/include/VBox/com/defs.h	(revision 45058)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2006-2012 Oracle Corporation
+ * Copyright (C) 2006-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -60,5 +60,5 @@
 # endif
 
-#endif /* defined (RT_OS_OS2) */
+#endif /* defined(RT_OS_OS2) */
 
 /* Include iprt/types.h (which also includes iprt/types.h) now to make sure iprt
@@ -67,7 +67,7 @@
 #include <iprt/types.h>
 
-#if !defined (VBOX_WITH_XPCOM)
-
-#if defined (RT_OS_WINDOWS)
+#if !defined(VBOX_WITH_XPCOM)
+
+#if defined(RT_OS_WINDOWS)
 
 // Windows COM
@@ -89,5 +89,5 @@
 
 /** Returns @c true if @a rc represents a warning result code */
-#define SUCCEEDED_WARNING(rc)   (SUCCEEDED (rc) && (rc) != S_OK)
+#define SUCCEEDED_WARNING(rc)   (SUCCEEDED(rc) && (rc) != S_OK)
 
 /** Tests is a COM result code indicates that the process implementing the
@@ -148,5 +148,5 @@
  * Wraps the given parameter name to generate an expression that is suitable for
  * passing the parameter to functions that take input safearray parameters
- * declared using the ComSafeArrayIn marco.
+ * declared using the ComSafeArrayIn macro.
  *
  * @param aArg  Parameter name to wrap. The given parameter must be declared
@@ -200,5 +200,5 @@
  * @param aArg Parameter name to wrap.
  */
-#define ComSafeGUIDArrayInIsNull(aArg)  ComSafeArrayInIsNull (aArg)
+#define ComSafeGUIDArrayInIsNull(aArg)  ComSafeArrayInIsNull(aArg)
 
 /**
@@ -206,5 +206,5 @@
  * @param aArg Parameter name to wrap.
  */
-#define ComSafeGUIDArrayInArg(aArg)     ComSafeArrayInArg (aArg)
+#define ComSafeGUIDArrayInArg(aArg)     ComSafeArrayInArg(aArg)
 
 /**
@@ -218,5 +218,5 @@
  * @param aArg Parameter name to wrap.
  */
-#define ComSafeGUIDArrayOutIsNull(aArg) ComSafeArrayOutIsNull (aArg)
+#define ComSafeGUIDArrayOutIsNull(aArg) ComSafeArrayOutIsNull(aArg)
 
 /**
@@ -224,5 +224,11 @@
  * @param aArg Parameter name to wrap.
  */
-#define ComSafeGUIDArrayOutArg(aArg)    ComSafeArrayOutArg (aArg)
+#define ComSafeGUIDArrayOutArg(aArg)    ComSafeArrayOutArg(aArg)
+
+/**
+ * Gets size of safearray parameter.
+ * @param aArg Parameter name.
+ */
+#define ComSafeArraySize(aArg)  ((aArg) == NULL ? 0 : (aArg)->rgsabound[0].cElements)
 
 /**
@@ -243,16 +249,16 @@
 #define COM_STRUCT_OR_CLASS(I)  struct I
 
-#else /* defined (RT_OS_WINDOWS) */
+#else /* defined(RT_OS_WINDOWS) */
 
 #error "VBOX_WITH_XPCOM must be defined on a platform other than Windows!"
 
-#endif /* defined (RT_OS_WINDOWS) */
-
-#else /* !defined (VBOX_WITH_XPCOM) */
+#endif /* defined(RT_OS_WINDOWS) */
+
+#else /* !defined(VBOX_WITH_XPCOM) */
 
 // XPCOM
 /////////////////////////////////////////////////////////////////////////////
 
-#if defined (RT_OS_DARWIN) || (defined (QT_VERSION) && (QT_VERSION >= 0x040000))
+#if defined(RT_OS_DARWIN) || (defined(QT_VERSION) && (QT_VERSION >= 0x040000))
   /* CFBase.h defines these &
    * qglobal.h from Qt4 defines these */
@@ -279,5 +285,5 @@
 #define FAILED      NS_FAILED
 
-#define SUCCEEDED_WARNING(rc)   (NS_SUCCEEDED (rc) && (rc) != NS_OK)
+#define SUCCEEDED_WARNING(rc)   (NS_SUCCEEDED(rc) && (rc) != NS_OK)
 
 #define FAILED_DEAD_INTERFACE(rc)  (   (rc) == NS_ERROR_ABORT \
@@ -339,11 +345,14 @@
 /* safearray input parameter macros for GUID */
 #define ComSafeGUIDArrayIn(aArg)            PRUint32 aArg##Size, const nsID **aArg
-#define ComSafeGUIDArrayInIsNull(aArg)      ComSafeArrayInIsNull (aArg)
-#define ComSafeGUIDArrayInArg(aArg)         ComSafeArrayInArg (aArg)
+#define ComSafeGUIDArrayInIsNull(aArg)      ComSafeArrayInIsNull(aArg)
+#define ComSafeGUIDArrayInArg(aArg)         ComSafeArrayInArg(aArg)
 
 /* safearray output parameter macros for GUID */
 #define ComSafeGUIDArrayOut(aArg)           PRUint32 *aArg##Size, nsID ***aArg
-#define ComSafeGUIDArrayOutIsNull(aArg)     ComSafeArrayOutIsNull (aArg)
-#define ComSafeGUIDArrayOutArg(aArg)        ComSafeArrayOutArg (aArg)
+#define ComSafeGUIDArrayOutIsNull(aArg)     ComSafeArrayOutIsNull(aArg)
+#define ComSafeGUIDArrayOutArg(aArg)        ComSafeArrayOutArg(aArg)
+
+/* safearray size */
+#define ComSafeArraySize(aArg)  ((aArg) == NULL ? 0 : (aArg##Size))
 
 /* CLSID and IID for compatibility with Win32 */
@@ -352,5 +361,5 @@
 
 /* OLE error codes */
-#define S_OK                ((nsresult) NS_OK)
+#define S_OK                ((nsresult)NS_OK)
 #define E_UNEXPECTED        NS_ERROR_UNEXPECTED
 #define E_NOTIMPL           NS_ERROR_NOT_IMPLEMENTED
@@ -363,5 +372,5 @@
 /* Note: a better analog for E_ACCESSDENIED would probably be
  * NS_ERROR_NOT_AVAILABLE, but we want binary compatibility for now. */
-#define E_ACCESSDENIED      ((nsresult) 0x80070005L)
+#define E_ACCESSDENIED      ((nsresult)0x80070005L)
 
 #define STDMETHOD(a) NS_IMETHOD a
@@ -395,12 +404,12 @@
 extern "C"
 {
-BSTR SysAllocString (const OLECHAR* sz);
-BSTR SysAllocStringByteLen (char *psz, unsigned int len);
-BSTR SysAllocStringLen (const OLECHAR *pch, unsigned int cch);
-void SysFreeString (BSTR bstr);
-int SysReAllocString (BSTR *pbstr, const OLECHAR *psz);
-int SysReAllocStringLen (BSTR *pbstr, const OLECHAR *psz, unsigned int cch);
-unsigned int SysStringByteLen (BSTR bstr);
-unsigned int SysStringLen (BSTR bstr);
+BSTR SysAllocString(const OLECHAR* sz);
+BSTR SysAllocStringByteLen(char *psz, unsigned int len);
+BSTR SysAllocStringLen(const OLECHAR *pch, unsigned int cch);
+void SysFreeString(BSTR bstr);
+int SysReAllocString(BSTR *pbstr, const OLECHAR *psz);
+int SysReAllocStringLen(BSTR *pbstr, const OLECHAR *psz, unsigned int cch);
+unsigned int SysStringByteLen(BSTR bstr);
+unsigned int SysStringLen(BSTR bstr);
 }
 
@@ -444,5 +453,5 @@
  *  'Constructor' that uses an existing getter function that gets a singleton.
  *  The getter function must have the following prototype:
- *      nsresult _GetterProc (_InstanceClass **inst)
+ *      nsresult _GetterProc(_InstanceClass **inst)
  *  This constructor, as opposed to NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR,
  *  lets the getter function return a result code that is passed back to the
@@ -482,5 +491,5 @@
 }
 
-#endif /* !defined (VBOX_WITH_XPCOM) */
+#endif /* !defined(VBOX_WITH_XPCOM) */
 
 /**
@@ -489,7 +498,7 @@
  *  @param s    expression to stringify
  */
-#if defined (_MSC_VER)
+#if defined(_MSC_VER)
 #   define WSTR_LITERAL(s)  L#s
-#elif defined (__GNUC__)
+#elif defined(__GNUC__)
 #   define WSTR_LITERAL(s)  L""#s
 #else
