]> git.0d.be Git - empathy.git/blobdiff - tools/glib-client-gen.py
libempathy-gtk: fix uninitialized variable
[empathy.git] / tools / glib-client-gen.py
index 6b0bdeba1b9413f4eabe8ea2950fab4c96b6bacf..e68e1a575f6260db90487f44f60708bd6b34aa28 100644 (file)
@@ -27,7 +27,8 @@ import os.path
 import xml.dom.minidom
 from getopt import gnu_getopt
 
-from libglibcodegen import Signature, type_to_gtype, cmp_by_name, \
+from libtpcodegen import file_set_contents, key_by_name, u
+from libglibcodegen import Signature, type_to_gtype, \
         get_docstring, xml_escape, get_deprecated
 
 
@@ -56,25 +57,29 @@ class Generator(object):
             % opts.get('--subclass', 'TpProxy'))
         if self.proxy_arg == 'void *':
             self.proxy_arg = 'gpointer '
-        self.generate_reentrant = ('--generate-reentrant' in opts or
-                '--deprecate-reentrant' in opts)
+
+        self.reentrant_symbols = set()
+        try:
+            filename = opts['--generate-reentrant']
+            with open(filename, 'r') as f:
+                for line in f.readlines():
+                    self.reentrant_symbols.add(line.strip())
+        except KeyError:
+            pass
+
         self.deprecate_reentrant = opts.get('--deprecate-reentrant', None)
         self.deprecation_attribute = opts.get('--deprecation-attribute',
                 'G_GNUC_DEPRECATED')
 
+        self.guard = opts.get('--guard', None)
+
     def h(self, s):
-        if isinstance(s, unicode):
-            s = s.encode('utf-8')
         self.__header.append(s)
 
     def b(self, s):
-        if isinstance(s, unicode):
-            s = s.encode('utf-8')
         self.__body.append(s)
 
     def d(self, s):
-        if isinstance(s, unicode):
-            s = s.encode('utf-8')
         self.__docs.append(s)
 
     def get_iface_quark(self):
@@ -139,8 +144,12 @@ class Generator(object):
             name, info, tp_type, elt = arg
             ctype, gtype, marshaller, pointer = info
 
-            self.d(' * @%s: %s' % (name,
-                xml_escape(get_docstring(elt) or '(Undocumented)')))
+            docs = get_docstring(elt) or '(Undocumented)'
+
+            if ctype == 'guint ' and tp_type != '':
+                docs +=  ' (#%s)' % ('Tp' + tp_type.replace('_', ''))
+
+            self.d(' * @%s: %s' % (name, xml_escape(docs)))
 
         self.d(' * @user_data: User-supplied data')
         self.d(' * @weak_object: User-supplied weakly referenced object')
@@ -432,9 +441,14 @@ class Generator(object):
             name, info, tp_type, elt = arg
             ctype, gtype, marshaller, pointer = info
 
+            docs = xml_escape(get_docstring(elt) or '(Undocumented)')
+
+            if ctype == 'guint ' and tp_type != '':
+                docs +=  ' (#%s)' % ('Tp' + tp_type.replace('_', ''))
+
             self.d(' * @%s: Used to return an \'out\' argument if @error is '
                    '%%NULL: %s'
-                   % (name, xml_escape(get_docstring(elt) or '(Undocumented)')))
+                   % (name, docs))
 
         self.d(' * @error: %NULL on success, or an error on failure')
         self.d(' * @user_data: user-supplied data')
@@ -687,8 +701,13 @@ class Generator(object):
             name, info, tp_type, elt = arg
             ctype, gtype, marshaller, pointer = info
 
+            docs = xml_escape(get_docstring(elt) or '(Undocumented)')
+
+            if ctype == 'guint ' and tp_type != '':
+                docs +=  ' (#%s)' % ('Tp' + tp_type.replace('_', ''))
+
             self.d(' * @%s: Used to pass an \'in\' argument: %s'
-                   % (name, xml_escape(get_docstring(elt) or '(Undocumented)')))
+                   % (name, docs))
 
         self.d(' * @callback: called when the method call succeeds or fails;')
         self.d(' *   may be %NULL to make a "fire and forget" call with no ')
@@ -758,9 +777,11 @@ class Generator(object):
         self.b('  g_return_val_if_fail (callback != NULL || '
                'weak_object == NULL, NULL);')
         self.b('')
+        self.b('  G_GNUC_BEGIN_IGNORE_DEPRECATIONS')
         self.b('  iface = tp_proxy_borrow_interface_by_id (')
         self.b('      (TpProxy *) proxy,')
         self.b('      interface, &error);')
+        self.b('  G_GNUC_END_IGNORE_DEPRECATIONS')
         self.b('')
         self.b('  if (iface == NULL)')
         self.b('    {')
@@ -832,9 +853,8 @@ class Generator(object):
         self.b('}')
         self.b('')
 
-        if self.generate_reentrant:
-            self.do_method_reentrant(method, iface_lc, member, member_lc,
-                                     in_args, out_args, collect_callback)
+        self.do_method_reentrant(method, iface_lc, member, member_lc,
+                                 in_args, out_args, collect_callback)
 
         # leave a gap for the end of the method
         self.d('')
@@ -853,6 +873,10 @@ class Generator(object):
         #       GError **error,
         #       GMainLoop **loop);
 
+        run_method_name = '%s_%s_run_%s' % (self.prefix_lc, iface_lc, member_lc)
+        if run_method_name not in self.reentrant_symbols:
+            return
+
         self.b('typedef struct {')
         self.b('    GMainLoop *loop;')
         self.b('    GError **error;')
@@ -930,12 +954,12 @@ class Generator(object):
         if self.deprecate_reentrant:
             self.h('#ifndef %s' % self.deprecate_reentrant)
 
-        self.h('gboolean %s_%s_run_%s (%sproxy,'
-               % (self.prefix_lc, iface_lc, member_lc, self.proxy_arg))
+        self.h('gboolean %s (%sproxy,'
+               % (run_method_name, self.proxy_arg))
         self.h('    gint timeout_ms,')
 
         self.d('/**')
-        self.d(' * %s_%s_run_%s:' % (self.prefix_lc, iface_lc, member_lc))
+        self.d(' * %s:' % run_method_name)
         self.d(' * @proxy: %s' % self.proxy_doc)
         self.d(' * @timeout_ms: Timeout in milliseconds, or -1 for default')
 
@@ -943,8 +967,13 @@ class Generator(object):
             name, info, tp_type, elt = arg
             ctype, gtype, marshaller, pointer = info
 
+            docs = xml_escape(get_docstring(elt) or '(Undocumented)')
+
+            if ctype == 'guint ' and tp_type != '':
+                docs +=  ' (#%s)' % ('Tp' + tp_type.replace('_', ''))
+
             self.d(' * @%s: Used to pass an \'in\' argument: %s'
-                   % (name, xml_escape(get_docstring(elt) or '(Undocumented)')))
+                   % (name, docs))
 
         for arg in out_args:
             name, info, tp_type, elt = arg
@@ -981,8 +1010,8 @@ class Generator(object):
         self.d(' */')
         self.d('')
 
-        self.b('gboolean\n%s_%s_run_%s (%sproxy,'
-               % (self.prefix_lc, iface_lc, member_lc, self.proxy_arg))
+        self.b('gboolean\n%s (%sproxy,'
+               % (run_method_name, self.proxy_arg))
         self.b('    gint timeout_ms,')
 
         for arg in in_args:
@@ -1031,8 +1060,10 @@ class Generator(object):
         self.b('  g_return_val_if_fail (%s (proxy), FALSE);'
                % self.proxy_assert)
         self.b('')
+        self.b('  G_GNUC_BEGIN_IGNORE_DEPRECATIONS')
         self.b('  iface = tp_proxy_borrow_interface_by_id')
         self.b('       ((TpProxy *) proxy, interface, error);')
+        self.b('  G_GNUC_END_IGNORE_DEPRECATIONS')
         self.b('')
         self.b('  if (iface == NULL)')
         self.b('    return FALSE;')
@@ -1140,6 +1171,11 @@ class Generator(object):
 
     def __call__(self):
 
+        if self.guard is not None:
+            self.h('#ifndef %s' % self.guard)
+            self.h('#define %s' % self.guard)
+            self.h('')
+
         self.h('G_BEGIN_DECLS')
         self.h('')
 
@@ -1149,7 +1185,7 @@ class Generator(object):
         self.b('')
 
         nodes = self.dom.getElementsByTagName('node')
-        nodes.sort(cmp_by_name)
+        nodes.sort(key=key_by_name)
 
         for node in nodes:
             self.do_interface(node)
@@ -1198,10 +1234,13 @@ class Generator(object):
         self.h('G_END_DECLS')
         self.h('')
 
-        open(self.basename + '.h', 'w').write('\n'.join(self.__header))
-        open(self.basename + '-body.h', 'w').write('\n'.join(self.__body))
-        open(self.basename + '-gtk-doc.h', 'w').write('\n'.join(self.__docs))
+        if self.guard is not None:
+            self.h('#endif /* defined (%s) */' % self.guard)
+            self.h('')
 
+        file_set_contents(self.basename + '.h', u('\n').join(self.__header).encode('utf-8'))
+        file_set_contents(self.basename + '-body.h', u('\n').join(self.__body).encode('utf-8'))
+        file_set_contents(self.basename + '-gtk-doc.h', u('\n').join(self.__docs).encode('utf-8'))
 
 def types_to_gtypes(types):
     return [type_to_gtype(t)[1] for t in types]
@@ -1211,8 +1250,8 @@ if __name__ == '__main__':
     options, argv = gnu_getopt(sys.argv[1:], '',
                                ['group=', 'subclass=', 'subclass-assert=',
                                 'iface-quark-prefix=', 'tp-proxy-api=',
-                                'generate-reentrant', 'deprecate-reentrant=',
-                                'deprecation-attribute='])
+                                'generate-reentrant=', 'deprecate-reentrant=',
+                                'deprecation-attribute=', 'guard='])
 
     opts = {}