Fix some fd leaks in _xcb_open_*()
[free-sw/xcb/libxcb] / src / c_client.py
index 7bcf5e7..d634c27 100755 (executable)
@@ -1,7 +1,8 @@
 #!/usr/bin/env python
 from xml.etree.cElementTree import *
-from sys import argv
 from os.path import basename
+import getopt
+import sys
 import re
 
 # Jump to the bottom of this file for the main routine
@@ -182,7 +183,7 @@ def c_open(self):
         _h('extern xcb_extension_t %s;', _ns.c_ext_global_name)
 
         _c('')
-        _c('xcb_extension_t %s = { "%s" };', _ns.c_ext_global_name, _ns.ext_xname)
+        _c('xcb_extension_t %s = { "%s", 0 };', _ns.c_ext_global_name, _ns.ext_xname)
 
 def c_close(self):
     '''
@@ -634,9 +635,15 @@ def _c_complex(self):
     struct_fields = []
     maxtypelen = 0
 
+    varfield = None
     for field in self.fields:
         if not field.type.fixed_size():
-            break
+            varfield = field.c_field_name
+            continue
+        if varfield != None and not field.type.is_pad and field.wire:
+            errmsg = '%s: warning: variable field %s followed by fixed field %s\n' % (self.c_type, varfield, field.c_field_name)
+            sys.stderr.write(errmsg)
+            # sys.exit(1)
         if field.wire:
             struct_fields.append(field)
         
@@ -982,6 +989,18 @@ output = {'open'    : c_open,
 
 # Boilerplate below this point
 
+# Check for the argument that specifies path to the xcbgen python package.
+try:
+    opts, args = getopt.getopt(sys.argv[1:], 'p:')
+except getopt.GetoptError, err:
+    print str(err)
+    print 'Usage: c_client.py [-p path] file.xml'
+    sys.exit(1)
+
+for (opt, arg) in opts:
+    if opt == '-p':
+        sys.path.append(arg)
+
 # Import the module class
 try:
     from xcbgen.state import Module
@@ -989,13 +1008,14 @@ except ImportError:
     print ''
     print 'Failed to load the xcbgen Python package!'
     print 'Make sure that xcb/proto installed it on your Python path.'
-    print 'If not, you will need to create a .pth file to extend the path.'
+    print 'If not, you will need to create a .pth file or define $PYTHONPATH'
+    print 'to extend the path.'
     print 'Refer to the README file in xcb/proto for more info.'
     print ''
     raise
 
 # Parse the xml header
-module = Module(argv[1], output)
+module = Module(args[0], output)
 
 # Build type-registry and resolve type dependencies
 module.register()