diff libpurple/dbus-analyze-functions.py @ 18118:ab6d2763b8d8

Re-fix the DBus list handling code by killing const GList* / const GSList* everywhere. Now we maintain a list of functions which return a GList or GSList which must not be freed. Ideally at some point this will be replaced with code that looks at the Doxygen comment for the function and honors @constreturn, which I've declared as a macro around @return that prints a @note about not modifying or freeing the returned value.
author Richard Laager <rlaager@wiktel.com>
date Sat, 16 Jun 2007 19:44:59 +0000
parents cd81f8f36788
children d955d9bd7ea7
line wrap: on
line diff
--- a/libpurple/dbus-analyze-functions.py	Sat Jun 16 19:21:06 2007 +0000
+++ b/libpurple/dbus-analyze-functions.py	Sat Jun 16 19:44:59 2007 +0000
@@ -32,8 +32,8 @@
     "purple_log_read",
     ]
 
-# This is a list of functions that return a GList* whose elements are
-# string, not pointers to objects.
+# This is a list of functions that return a GList* or GSList * whose elements
+# are strings, not pointers to objects.
 stringlists = [
     "purple_prefs_get_path_list",
     "purple_prefs_get_string_list",
@@ -41,6 +41,32 @@
     "purple_uri_list_extract_uris",
 ]
 
+# This is a list of functions that return a GList* or GSList* that should
+# not be freed.  Ideally, this information should be obtained from the Doxygen
+# documentation at some point.
+constlists = [
+    "purple_account_get_status_types",
+    "purple_accounts_get_all",
+    "purple_account_option_get_list",
+    "purple_connections_get_all",
+    "purple_connections_get_connecting",
+    "purple_get_conversations",
+    "purple_get_ims",
+    "purple_get_chats",
+    "purple_conv_chat_get_users",
+    "purple_conv_chat_get_ignored",
+    "purple_mime_document_get_fields",
+    "purple_mime_document_get_parts",
+    "purple_mime_part_get_fields",
+    "purple_notify_user_info_get_entries",
+    "purple_request_fields_get_required",
+    "purple_request_field_list_get_selected",
+    "purple_request_field_list_get_items",
+    "purple_savedstatuses_get_all",
+    "purple_status_type_get_attrs",
+    "purple_presence_get_statuses",
+]
+
 pointer = "#pointer#"
 myexception = "My Exception"
 
@@ -152,7 +178,7 @@
                 return self.outputpurplestructure(type, name)
 
             if type[0] in ["GList", "GSList"]:
-                return self.outputlist(type, name, const)
+                return self.outputlist(type, name)
 
         raise myexception
     
@@ -254,7 +280,7 @@
         self.returncode.append("return (%s*) GINT_TO_POINTER(%s);" % (type[0], name));
         self.definepurplestructure(type)
 
-    def outputlist(self, type, name, const):
+    def outputlist(self, type, name):
         self.functiontype = "%s*" % type[0]
         self.decls.append("GArray *%s;" % name)
         self.outputparams.append(('dbus_g_type_get_collection("GArray", G_TYPE_INT)', name))
@@ -390,28 +416,20 @@
 
     # GList*, GSList*, assume that list is a list of objects
     # unless the function is in stringlists
-    def outputlist(self, type, name, const):
+    def outputlist(self, type, name):
         self.cdecls.append("\tdbus_int32_t %s_LEN;" % name)
         self.ccodeout.append("\tg_free(%s);" % name)
 
-        if const:
-            const_prefix = "const_"
-        else:
-            const_prefix = ""
-
-        if (const):
-            self.cdecls.append("\tconst %s *list;" % type[0]);
-        else:
-            self.cdecls.append("\t%s *list;" % type[0]);
+        self.cdecls.append("\t%s *list;" % type[0]);
 
         if self.function.name in stringlists:
             self.cdecls.append("\tchar **%s;" % name)
             self.ccode.append("\tlist = %s;" % self.call)
-            self.ccode.append("\t%s = (char **)purple_const_%s_to_array(list, &%s_LEN);" % \
+            self.ccode.append("\t%s = (char **)purple_%s_to_array(list, FALSE, &%s_LEN);" % \
                          (name, type[0], name))
             self.cparamsout.append("DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &%s, %s_LEN" \
                           % (name, name))
-            if (not const):
+            if (not (self.function.name in constlists)):
                 type_name = type[0].lower()[1:]
                 self.ccodeout.append("\tg_%s_foreach(list, (GFunc)g_free, NULL);" % type_name)
                 self.ccodeout.append("\tg_%s_free(list);" % type_name)
@@ -419,9 +437,9 @@
         else:
             self.cdecls.append("\tdbus_int32_t *%s;" % name)
             self.ccode.append("\tlist = %s;" % self.call)
-            self.ccode.append("\t%s = purple_dbusify_const_%s(list, &%s_LEN);" % \
+            self.ccode.append("\t%s = purple_dbusify_%s(list, FALSE, &%s_LEN);" % \
                          (name, type[0], name))
-            if (not const):
+            if (not (self.function.name in constlists)):
                 self.ccode.append("\tg_%s_free(list);" % type[0].lower()[1:])
             self.cparamsout.append("DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &%s, %s_LEN" \
                               % (name, name))