[xpcom] Further fixes to the array handling to support common codepath
authorKalle Vahlman <kalle.vahlman@movial.com>
Thu, 23 Apr 2009 05:19:01 +0000 (08:19 +0300)
committerKalle Vahlman <kalle.vahlman@movial.com>
Thu, 23 Apr 2009 05:19:01 +0000 (08:19 +0300)
for all containers.

xpcom-dbusservice/DBusMarshaling.cpp

index c6963aea1f7a3a41acb7392bc310744c5a6a48e7..682d0d344f3f632ad9781f3e031c95b992a13cdc 100644 (file)
@@ -45,7 +45,7 @@ void getSignatureFromVariantType(PRUint16 aType, nsCString &aResult);
 void getSignatureFromISupports(JSContext* cx, nsISupports *aISupports, nsCString &aResult);
 
 void addArrayToIter(nsIVariant *aVariant, DBusMessageIter *aIter, int aDBusType);
-void addArrayDataToIter(JSContext* cx, void *data_ptr, PRUint32 start, PRUint32 count, PRUint16 type, DBusMessageIter *aIter, DBusSignatureIter *aSigIter);
+void addArrayDataToIter(JSContext* cx, void *data_ptr, PRUint32 start, PRUint32 count, PRUint16 type, DBusMessageIter *aIter, DBusSignatureIter *aSigIter, DBusSignatureIter *containerSigIter);
 
 void addJSValueToIter(JSContext *cx, jsval *aValue, DBusMessageIter *aIter, DBusSignatureIter *aSigIter);
 void getJSValueFromIter(JSContext* cx, DBusMessageIter *aIter, int aDBusType, jsval *v);
@@ -510,18 +510,16 @@ addVariantToIter(JSContext* cx, nsIVariant *aVariant, DBusMessageIter *aIter, DB
             BDBLOG(("  %s: got %d elements of type %d\n", __FUNCTION__, count, type));
             BDBLOG(("  %s: got array signature %s\n", __FUNCTION__, array_signature));
 
-            int dbustype = dbus_signature_iter_get_current_type(&aChildSigIter);
-
             DBusMessageIter arrayIter;
             if (!dbus_message_iter_open_container(aIter, DBUS_TYPE_ARRAY,
-                                                    array_signature, &arrayIter))
+                                                  array_signature, &arrayIter))
             {
                 nsMemory::Free(data_ptr);
                 return;
             }
 
             addArrayDataToIter(cx, data_ptr, 0, count, type,
-                                &arrayIter, &aChildSigIter);
+                                &arrayIter, &aChildSigIter, aSigIter);
 
             dbus_message_iter_close_container(aIter, &arrayIter);
             nsMemory::Free(data_ptr);
@@ -578,7 +576,7 @@ addVariantToIter(JSContext* cx, nsIVariant *aVariant, DBusMessageIter *aIter, DB
                                 &data_ptr);
 
         addArrayDataToIter(cx, data_ptr, 0, count, type,
-                            &structIter, &aChildSigIter);
+                            &structIter, &aChildSigIter, aSigIter);
 
         dbus_message_iter_close_container(aIter, &structIter);
         nsMemory::Free(data_ptr);
@@ -733,7 +731,7 @@ void addBasicTypeToIter(nsIVariant *aVariant, DBusMessageIter *aIter, int aDBusT
     }
 }
 
-void addArrayDataToIter(JSContext* cx, void *data_ptr, PRUint32 start, PRUint32 count, PRUint16 type, DBusMessageIter *aIter, DBusSignatureIter *aSigIter)
+void addArrayDataToIter(JSContext* cx, void *data_ptr, PRUint32 start, PRUint32 count, PRUint16 type, DBusMessageIter *aIter, DBusSignatureIter *aSigIter, DBusSignatureIter *containerSigIter)
 {
     int aDBusType = dbus_signature_iter_get_current_type(aSigIter);
     BDBLOG(("addArrayDataToIter: appending %d elements of type %d '%c'\n", count, type, aDBusType));
@@ -803,6 +801,9 @@ void addArrayDataToIter(JSContext* cx, void *data_ptr, PRUint32 start, PRUint32
         }
         case nsIDataType::VTYPE_INTERFACE_IS:
         {
+            DBusSignatureIter childSigIter;
+            dbus_signature_iter_recurse(containerSigIter, &childSigIter);
+
             nsISupports **data = (nsISupports **)data_ptr;
             for (PRUint32 i = 0; i < count; i++)
             {
@@ -810,9 +811,12 @@ void addArrayDataToIter(JSContext* cx, void *data_ptr, PRUint32 start, PRUint32
                 nsCOMPtr<nsIVariant> variant = do_QueryInterface(data[i]);
 
                 if (variant) {
-                    addVariantToIter(cx, variant, aIter, aSigIter);
-                    dbus_signature_iter_next(aSigIter);
-                    continue;
+                    addVariantToIter(cx, variant, aIter, &childSigIter);
+
+                    /* Advance the signature iter or reset */
+                    if (!dbus_signature_iter_next(&childSigIter))
+                        dbus_signature_iter_recurse(containerSigIter, &childSigIter);
+
                 }
 
                 // We might have a wrapped JS object in the variant
@@ -820,16 +824,20 @@ void addArrayDataToIter(JSContext* cx, void *data_ptr, PRUint32 start, PRUint32
                 nsCOMPtr<nsIXPConnectWrappedJS> wrapped = do_QueryInterface(data[i]);
 
                 if (!wrapped)
-                    break;
+                    continue;
 
                 JSObject *js_obj = nsnull;
                 if (!NS_SUCCEEDED(wrapped->GetJSObject(&js_obj)))
-                    break;
+                    continue;
 
                 jsval js_obj_as_value = OBJECT_TO_JSVAL(js_obj);
                 addJSValueToIter(cx, &js_obj_as_value,
-                                    aIter, aSigIter);
-                dbus_signature_iter_next(aSigIter);
+                                    aIter, &childSigIter);
+
+                /* Advance the signature iter or reset */
+                if (!dbus_signature_iter_next(&childSigIter))
+                    dbus_signature_iter_recurse(containerSigIter, &childSigIter);
+
             }
 
             break;