gobject-introspection 3.0.7-x86-mingw32 → 3.0.8-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -2
  3. data/ext/gobject-introspection/extconf.rb +1 -0
  4. data/ext/gobject-introspection/rb-gi-argument.c +123 -26
  5. data/ext/gobject-introspection/rb-gi-function-info.c +558 -19
  6. data/ext/gobject-introspection/rb-gi-repository.c +9 -0
  7. data/ext/gobject-introspection/rb-gobject-introspection.h +3 -0
  8. data/lib/2.2/gobject_introspection.so +0 -0
  9. data/lib/2.3/gobject_introspection.so +0 -0
  10. data/lib/gobject-introspection/loader.rb +1 -1
  11. data/vendor/local/bin/g-ir-compiler.exe +0 -0
  12. data/vendor/local/bin/g-ir-generate.exe +0 -0
  13. data/vendor/local/bin/libgirepository-1.0-1.dll +0 -0
  14. data/vendor/local/include/gobject-introspection-1.0/gistructinfo.h +4 -0
  15. data/vendor/local/lib/girepository-1.0/GIRepository-2.0.typelib +0 -0
  16. data/vendor/local/lib/girepository-1.0/GLib-2.0.typelib +0 -0
  17. data/vendor/local/lib/girepository-1.0/GModule-2.0.typelib +0 -0
  18. data/vendor/local/lib/girepository-1.0/GObject-2.0.typelib +0 -0
  19. data/vendor/local/lib/girepository-1.0/Gio-2.0.typelib +0 -0
  20. data/vendor/local/lib/gobject-introspection/giscanner/__init__.py +1 -1
  21. data/vendor/local/lib/gobject-introspection/giscanner/__init__.pyc +0 -0
  22. data/vendor/local/lib/gobject-introspection/giscanner/__init__.pyo +0 -0
  23. data/vendor/local/lib/gobject-introspection/giscanner/annotationmain.py +39 -11
  24. data/vendor/local/lib/gobject-introspection/giscanner/annotationmain.pyc +0 -0
  25. data/vendor/local/lib/gobject-introspection/giscanner/annotationmain.pyo +0 -0
  26. data/vendor/local/lib/gobject-introspection/giscanner/annotationparser.py +187 -164
  27. data/vendor/local/lib/gobject-introspection/giscanner/annotationparser.pyc +0 -0
  28. data/vendor/local/lib/gobject-introspection/giscanner/annotationparser.pyo +0 -0
  29. data/vendor/local/lib/gobject-introspection/giscanner/ast.py +191 -58
  30. data/vendor/local/lib/gobject-introspection/giscanner/ast.pyc +0 -0
  31. data/vendor/local/lib/gobject-introspection/giscanner/ast.pyo +0 -0
  32. data/vendor/local/lib/gobject-introspection/giscanner/cachestore.py +42 -54
  33. data/vendor/local/lib/gobject-introspection/giscanner/cachestore.pyc +0 -0
  34. data/vendor/local/lib/gobject-introspection/giscanner/cachestore.pyo +0 -0
  35. data/vendor/local/lib/gobject-introspection/giscanner/ccompiler.py +272 -82
  36. data/vendor/local/lib/gobject-introspection/giscanner/ccompiler.pyc +0 -0
  37. data/vendor/local/lib/gobject-introspection/giscanner/ccompiler.pyo +0 -0
  38. data/vendor/local/lib/gobject-introspection/giscanner/codegen.py +18 -11
  39. data/vendor/local/lib/gobject-introspection/giscanner/codegen.pyc +0 -0
  40. data/vendor/local/lib/gobject-introspection/giscanner/codegen.pyo +0 -0
  41. data/vendor/local/lib/gobject-introspection/giscanner/collections/__init__.py +4 -0
  42. data/vendor/local/lib/gobject-introspection/giscanner/collections/__init__.pyc +0 -0
  43. data/vendor/local/lib/gobject-introspection/giscanner/collections/__init__.pyo +0 -0
  44. data/vendor/local/lib/gobject-introspection/giscanner/collections/counter.pyc +0 -0
  45. data/vendor/local/lib/gobject-introspection/giscanner/collections/counter.pyo +0 -0
  46. data/vendor/local/lib/gobject-introspection/giscanner/collections/ordereddict.py +25 -13
  47. data/vendor/local/lib/gobject-introspection/giscanner/collections/ordereddict.pyc +0 -0
  48. data/vendor/local/lib/gobject-introspection/giscanner/collections/ordereddict.pyo +0 -0
  49. data/vendor/local/lib/gobject-introspection/giscanner/docmain.py +21 -19
  50. data/vendor/local/lib/gobject-introspection/giscanner/docmain.pyc +0 -0
  51. data/vendor/local/lib/gobject-introspection/giscanner/docmain.pyo +0 -0
  52. data/vendor/local/lib/gobject-introspection/giscanner/docwriter.py +19 -16
  53. data/vendor/local/lib/gobject-introspection/giscanner/docwriter.pyc +0 -0
  54. data/vendor/local/lib/gobject-introspection/giscanner/docwriter.pyo +0 -0
  55. data/vendor/local/lib/gobject-introspection/giscanner/dumper.py +148 -158
  56. data/vendor/local/lib/gobject-introspection/giscanner/dumper.pyc +0 -0
  57. data/vendor/local/lib/gobject-introspection/giscanner/dumper.pyo +0 -0
  58. data/vendor/local/lib/gobject-introspection/giscanner/gdumpparser.py +31 -21
  59. data/vendor/local/lib/gobject-introspection/giscanner/gdumpparser.pyc +0 -0
  60. data/vendor/local/lib/gobject-introspection/giscanner/gdumpparser.pyo +0 -0
  61. data/vendor/local/lib/gobject-introspection/giscanner/girparser.py +13 -5
  62. data/vendor/local/lib/gobject-introspection/giscanner/girparser.pyc +0 -0
  63. data/vendor/local/lib/gobject-introspection/giscanner/girparser.pyo +0 -0
  64. data/vendor/local/lib/gobject-introspection/giscanner/girwriter.py +12 -13
  65. data/vendor/local/lib/gobject-introspection/giscanner/girwriter.pyc +0 -0
  66. data/vendor/local/lib/gobject-introspection/giscanner/girwriter.pyo +0 -0
  67. data/vendor/local/lib/gobject-introspection/giscanner/introspectablepass.py +5 -1
  68. data/vendor/local/lib/gobject-introspection/giscanner/introspectablepass.pyc +0 -0
  69. data/vendor/local/lib/gobject-introspection/giscanner/introspectablepass.pyo +0 -0
  70. data/vendor/local/lib/gobject-introspection/giscanner/libtoolimporter.py +11 -9
  71. data/vendor/local/lib/gobject-introspection/giscanner/libtoolimporter.pyc +0 -0
  72. data/vendor/local/lib/gobject-introspection/giscanner/libtoolimporter.pyo +0 -0
  73. data/vendor/local/lib/gobject-introspection/giscanner/maintransformer.py +150 -45
  74. data/vendor/local/lib/gobject-introspection/giscanner/maintransformer.pyc +0 -0
  75. data/vendor/local/lib/gobject-introspection/giscanner/maintransformer.pyo +0 -0
  76. data/vendor/local/lib/gobject-introspection/giscanner/message.py +56 -19
  77. data/vendor/local/lib/gobject-introspection/giscanner/message.pyc +0 -0
  78. data/vendor/local/lib/gobject-introspection/giscanner/message.pyo +0 -0
  79. data/vendor/local/lib/gobject-introspection/giscanner/msvccompiler.py +101 -0
  80. data/vendor/local/lib/gobject-introspection/giscanner/msvccompiler.pyc +0 -0
  81. data/vendor/local/lib/gobject-introspection/giscanner/msvccompiler.pyo +0 -0
  82. data/vendor/local/lib/gobject-introspection/giscanner/scannermain.py +41 -22
  83. data/vendor/local/lib/gobject-introspection/giscanner/scannermain.pyc +0 -0
  84. data/vendor/local/lib/gobject-introspection/giscanner/scannermain.pyo +0 -0
  85. data/vendor/local/lib/gobject-introspection/giscanner/sectionparser.py +6 -1
  86. data/vendor/local/lib/gobject-introspection/giscanner/sectionparser.pyc +0 -0
  87. data/vendor/local/lib/gobject-introspection/giscanner/sectionparser.pyo +0 -0
  88. data/vendor/local/lib/gobject-introspection/giscanner/shlibs.py +8 -2
  89. data/vendor/local/lib/gobject-introspection/giscanner/shlibs.pyc +0 -0
  90. data/vendor/local/lib/gobject-introspection/giscanner/shlibs.pyo +0 -0
  91. data/vendor/local/lib/gobject-introspection/giscanner/sourcescanner.py +42 -56
  92. data/vendor/local/lib/gobject-introspection/giscanner/sourcescanner.pyc +0 -0
  93. data/vendor/local/lib/gobject-introspection/giscanner/sourcescanner.pyo +0 -0
  94. data/vendor/local/lib/gobject-introspection/giscanner/testcodegen.py +19 -5
  95. data/vendor/local/lib/gobject-introspection/giscanner/testcodegen.pyc +0 -0
  96. data/vendor/local/lib/gobject-introspection/giscanner/testcodegen.pyo +0 -0
  97. data/vendor/local/lib/gobject-introspection/giscanner/transformer.py +73 -37
  98. data/vendor/local/lib/gobject-introspection/giscanner/transformer.pyc +0 -0
  99. data/vendor/local/lib/gobject-introspection/giscanner/transformer.pyo +0 -0
  100. data/vendor/local/lib/gobject-introspection/giscanner/utils.py +92 -14
  101. data/vendor/local/lib/gobject-introspection/giscanner/utils.pyc +0 -0
  102. data/vendor/local/lib/gobject-introspection/giscanner/utils.pyo +0 -0
  103. data/vendor/local/lib/gobject-introspection/giscanner/xmlwriter.py +30 -11
  104. data/vendor/local/lib/gobject-introspection/giscanner/xmlwriter.pyc +0 -0
  105. data/vendor/local/lib/gobject-introspection/giscanner/xmlwriter.pyo +0 -0
  106. data/vendor/local/lib/libgirepository-1.0.a +0 -0
  107. data/vendor/local/lib/libgirepository-1.0.dll.a +0 -0
  108. data/vendor/local/lib/libgirepository-1.0.la +1 -1
  109. data/vendor/local/lib/pkgconfig/gobject-introspection-1.0.pc +1 -1
  110. data/vendor/local/lib/pkgconfig/gobject-introspection-no-export-1.0.pc +1 -1
  111. data/vendor/local/share/gir-1.0/GIRepository-2.0.gir +57 -13
  112. data/vendor/local/share/gir-1.0/GLib-2.0.gir +2018 -894
  113. data/vendor/local/share/gir-1.0/GModule-2.0.gir +2 -1
  114. data/vendor/local/share/gir-1.0/GObject-2.0.gir +1107 -674
  115. data/vendor/local/share/gir-1.0/Gio-2.0.gir +5589 -1287
  116. data/vendor/local/share/gobject-introspection-1.0/Makefile.introspection +4 -2
  117. data/vendor/local/share/gobject-introspection-1.0/gdump.c +8 -0
  118. data/vendor/local/share/gobject-introspection-1.0/tests/everything.c +273 -323
  119. data/vendor/local/share/gobject-introspection-1.0/tests/everything.h +58 -38
  120. data/vendor/local/share/gobject-introspection-1.0/tests/gimarshallingtests.c +1 -1
  121. data/vendor/local/share/gobject-introspection-1.0/tests/regress.c +177 -23
  122. data/vendor/local/share/gobject-introspection-1.0/tests/regress.h +40 -0
  123. data/vendor/local/share/man/man1/g-ir-compiler.1 +7 -7
  124. metadata +9 -7
  125. data/lib/2.0/gobject_introspection.so +0 -0
  126. data/lib/2.1/gobject_introspection.so +0 -0
@@ -18,6 +18,11 @@
18
18
  # Boston, MA 02111-1307, USA.
19
19
  #
20
20
 
21
+ from __future__ import absolute_import
22
+ from __future__ import division
23
+ from __future__ import print_function
24
+ from __future__ import unicode_literals
25
+
21
26
  import os
22
27
  import sys
23
28
  import tempfile
@@ -84,12 +89,12 @@ class GDumpParser(object):
84
89
  """
85
90
 
86
91
  # First pass: parsing
87
- for node in self._namespace.itervalues():
92
+ for node in self._namespace.values():
88
93
  if isinstance(node, ast.Function):
89
94
  self._initparse_function(node)
90
95
 
91
96
  if self._namespace.name == 'GObject' or self._namespace.name == 'GLib':
92
- for node in self._namespace.itervalues():
97
+ for node in self._namespace.values():
93
98
  if isinstance(node, ast.Record):
94
99
  self._initparse_gobject_record(node)
95
100
 
@@ -116,16 +121,16 @@ class GDumpParser(object):
116
121
  self._introspect_type(child)
117
122
 
118
123
  # Pair up boxed types and class records
119
- for name, boxed in self._boxed_types.iteritems():
124
+ for name, boxed in self._boxed_types.items():
120
125
  self._pair_boxed_type(boxed)
121
- for node in self._namespace.itervalues():
126
+ for node in self._namespace.values():
122
127
  if isinstance(node, (ast.Class, ast.Interface)):
123
128
  self._find_class_record(node)
124
129
 
125
130
  # Clear the _get_type functions out of the namespace;
126
131
  # Anyone who wants them can get them from the ast.Class/Interface/Boxed
127
132
  to_remove = []
128
- for name, node in self._namespace.iteritems():
133
+ for name, node in self._namespace.items():
129
134
  if isinstance(node, ast.Registered) and node.get_type is not None:
130
135
  get_type_name = node.get_type
131
136
  if get_type_name == 'intern':
@@ -145,19 +150,24 @@ class GDumpParser(object):
145
150
  """Load the library (or executable), returning an XML
146
151
  blob containing data gleaned from GObject's primitive introspection."""
147
152
  in_path = os.path.join(self._binary.tmpdir, 'functions.txt')
148
- f = open(in_path, 'w')
149
- for func in self._get_type_functions:
150
- f.write('get-type:')
151
- f.write(func)
152
- f.write('\n')
153
- for func in self._error_quark_functions:
154
- f.write('error-quark:')
155
- f.write(func)
156
- f.write('\n')
157
- f.close()
153
+ with open(in_path, 'w') as f:
154
+ for func in self._get_type_functions:
155
+ f.write('get-type:')
156
+ f.write(func)
157
+ f.write('\n')
158
+ for func in self._error_quark_functions:
159
+ f.write('error-quark:')
160
+ f.write(func)
161
+ f.write('\n')
158
162
  out_path = os.path.join(self._binary.tmpdir, 'dump.xml')
159
163
 
160
164
  args = []
165
+
166
+ # Prepend the launcher command and arguments, if defined
167
+ launcher = os.environ.get('GI_CROSS_LAUNCHER')
168
+ if launcher:
169
+ args.extend(launcher.split())
170
+
161
171
  args.extend(self._binary.args)
162
172
  args.append('--introspect-dump=%s,%s' % (in_path, out_path))
163
173
 
@@ -203,7 +213,7 @@ blob containing data gleaned from GObject's primitive introspection."""
203
213
 
204
214
  def _initparse_gobject_record(self, record):
205
215
  if (record.name.startswith('ParamSpec')
206
- and not record.name in ('ParamSpecPool', 'ParamSpecClass', 'ParamSpecTypeInfo')):
216
+ and record.name not in ('ParamSpecPool', 'ParamSpecClass', 'ParamSpecTypeInfo')):
207
217
  parent = None
208
218
  if record.name != 'ParamSpec':
209
219
  parent = ast.Type(target_giname='GObject.ParamSpec')
@@ -297,7 +307,7 @@ blob containing data gleaned from GObject's primitive introspection."""
297
307
  (ns, name) = self._transformer.split_csymbol(get_type)
298
308
  assert ns is self._namespace
299
309
  if name in ('get_type', '_get_gtype'):
300
- message.fatal("""The GObject name %r isn't compatible
310
+ message.fatal("""The GObject name '%s' isn't compatible
301
311
  with the configured identifier prefixes:
302
312
  %r
303
313
  The class would have no name. Most likely you want to specify a
@@ -350,7 +360,7 @@ different --identifier-prefix.""" % (xmlnode.attrib['name'], self._namespace.ide
350
360
  if isinstance(record, ast.Record):
351
361
  node.ctype = record.ctype
352
362
  else:
353
- message.warn_node(node, "Couldn't find associated structure for '%r'" % (node.name, ))
363
+ message.warn_node(node, "Couldn't find associated structure for '%s'" % (node.name, ))
354
364
 
355
365
  # GtkFileChooserEmbed is an example of a private interface, we
356
366
  # just filter them out
@@ -359,7 +369,7 @@ different --identifier-prefix.""" % (xmlnode.attrib['name'], self._namespace.ide
359
369
  else:
360
370
  self._namespace.append(node, replace=True)
361
371
 
362
- ## WORKAROUND ##
372
+ # WORKAROUND
363
373
  # https://bugzilla.gnome.org/show_bug.cgi?id=550616
364
374
  def _introspect_boxed_gstreamer_workaround(self, xmlnode):
365
375
  node = ast.Boxed('ParamSpecMiniObject', gtype_name='GParamSpecMiniObject',
@@ -439,8 +449,8 @@ different --identifier-prefix.""" % (xmlnode.attrib['name'], self._namespace.ide
439
449
  def _parse_parents(self, xmlnode, node):
440
450
  parents_str = xmlnode.attrib.get('parents', '')
441
451
  if parents_str != '':
442
- parent_types = map(lambda s: ast.Type.create_from_gtype_name(s),
443
- parents_str.split(','))
452
+ parent_types = list(map(lambda s: ast.Type.create_from_gtype_name(s),
453
+ parents_str.split(',')))
444
454
  else:
445
455
  parent_types = []
446
456
  node.parent_chain = parent_types
@@ -18,6 +18,11 @@
18
18
  # Boston, MA 02111-1307, USA.
19
19
  #
20
20
 
21
+ from __future__ import absolute_import
22
+ from __future__ import division
23
+ from __future__ import print_function
24
+ from __future__ import unicode_literals
25
+
21
26
  import os
22
27
 
23
28
  from xml.etree.cElementTree import parse
@@ -313,7 +318,7 @@ class GIRParser(object):
313
318
  raise ValueError('node %r has no return-value' % (name, ))
314
319
  transfer = returnnode.attrib.get('transfer-ownership')
315
320
  nullable = returnnode.attrib.get('nullable') == '1'
316
- retval = ast.Return(self._parse_type(returnnode), nullable, transfer)
321
+ retval = ast.Return(self._parse_type(returnnode), nullable, False, transfer)
317
322
  self._parse_generic_attribs(returnnode, retval)
318
323
  parameters = []
319
324
 
@@ -366,6 +371,9 @@ class GIRParser(object):
366
371
 
367
372
  self._parse_type_array_length(parameters, returnnode, retval.type)
368
373
 
374
+ # Re-set the function's parameters to notify it of changes to the list.
375
+ func.parameters = parameters
376
+
369
377
  self._parse_generic_attribs(node, func)
370
378
 
371
379
  self._namespace.track(func)
@@ -455,8 +463,8 @@ class GIRParser(object):
455
463
  return ast.Type(ctype=ctype)
456
464
  elif name in ['GLib.List', 'GLib.SList']:
457
465
  subchild = self._find_first_child(typenode,
458
- map(_corens, ('callback', 'array',
459
- 'varargs', 'type')))
466
+ list(map(_corens, ('callback', 'array',
467
+ ' varargs', 'type'))))
460
468
  if subchild is not None:
461
469
  element_type = self._parse_type(typenode)
462
470
  else:
@@ -464,7 +472,7 @@ class GIRParser(object):
464
472
  return ast.List(name, element_type, ctype=ctype)
465
473
  elif name == 'GLib.HashTable':
466
474
  subchildren = self._find_children(typenode, _corens('type'))
467
- subchildren_types = map(self._parse_type_simple, subchildren)
475
+ subchildren_types = list(map(self._parse_type_simple, subchildren))
468
476
  while len(subchildren_types) < 2:
469
477
  subchildren_types.append(ast.TYPE_ANY)
470
478
  return ast.Map(subchildren_types[0], subchildren_types[1], ctype=ctype)
@@ -489,7 +497,7 @@ class GIRParser(object):
489
497
  lenidx = typenode.attrib.get('length')
490
498
  if lenidx is not None:
491
499
  idx = int(lenidx)
492
- assert idx < len(siblings), "%r %d >= %d" % (parent, idx, len(siblings))
500
+ assert idx < len(siblings), "%r %d >= %d" % (siblings, idx, len(siblings))
493
501
  if isinstance(siblings[idx], ast.Field):
494
502
  typeval.length_param_name = siblings[idx].name
495
503
  else:
@@ -20,6 +20,10 @@
20
20
  #
21
21
 
22
22
  from __future__ import with_statement
23
+ from __future__ import absolute_import
24
+ from __future__ import division
25
+ from __future__ import print_function
26
+ from __future__ import unicode_literals
23
27
 
24
28
  from . import ast
25
29
  from .xmlwriter import XMLWriter
@@ -78,17 +82,12 @@ class GIRWriter(XMLWriter):
78
82
  # We define a custom sorting function here because
79
83
  # we want aliases to be first. They're a bit
80
84
  # special because the typelib compiler expands them.
81
- def nscmp(a, b):
82
- if isinstance(a, ast.Alias):
83
- if isinstance(b, ast.Alias):
84
- return cmp(a.name, b.name)
85
- else:
86
- return -1
87
- elif isinstance(b, ast.Alias):
88
- return 1
85
+ def nscmp(val):
86
+ if isinstance(val, ast.Alias):
87
+ return 0, val
89
88
  else:
90
- return cmp(a, b)
91
- for node in sorted(namespace.itervalues(), cmp=nscmp):
89
+ return 1, val
90
+ for node in sorted(namespace.values(), key=nscmp):
92
91
  self._write_node(node)
93
92
 
94
93
  def _write_node(self, node):
@@ -116,7 +115,7 @@ class GIRWriter(XMLWriter):
116
115
  elif isinstance(node, ast.Constant):
117
116
  self._write_constant(node)
118
117
  else:
119
- print 'WRITER: Unhandled node', node
118
+ print('WRITER: Unhandled node', node)
120
119
 
121
120
  def _append_version(self, node, attrs):
122
121
  if node.version:
@@ -215,7 +214,7 @@ class GIRWriter(XMLWriter):
215
214
  attrs.append(('transfer-ownership', return_.transfer))
216
215
  if return_.skip:
217
216
  attrs.append(('skip', '1'))
218
- if return_.nullable:
217
+ if return_.nullable and not return_.not_nullable:
219
218
  attrs.append(('nullable', '1'))
220
219
  with self.tagcontext('return-value', attrs):
221
220
  self._write_generic(return_)
@@ -241,7 +240,7 @@ class GIRWriter(XMLWriter):
241
240
  if parameter.transfer:
242
241
  attrs.append(('transfer-ownership',
243
242
  parameter.transfer))
244
- if parameter.nullable:
243
+ if parameter.nullable and not parameter.not_nullable:
245
244
  attrs.append(('nullable', '1'))
246
245
  if parameter.direction != ast.PARAM_DIRECTION_OUT:
247
246
  attrs.append(('allow-none', '1'))
@@ -16,6 +16,10 @@
16
16
  # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
17
  # Boston, MA 02111-1307, USA.
18
18
  #
19
+ from __future__ import absolute_import
20
+ from __future__ import division
21
+ from __future__ import print_function
22
+ from __future__ import unicode_literals
19
23
 
20
24
  from . import ast
21
25
  from . import message
@@ -96,7 +100,7 @@ class IntrospectablePass(object):
96
100
 
97
101
  if (is_parameter
98
102
  and isinstance(target, ast.Callback)
99
- and not node.type.target_giname in ('GLib.DestroyNotify', 'Gio.AsyncReadyCallback')
103
+ and node.type.target_giname not in ('GLib.DestroyNotify', 'Gio.AsyncReadyCallback')
100
104
  and node.scope is None):
101
105
  self._parameter_warning(
102
106
  parent,
@@ -18,9 +18,13 @@
18
18
  # Boston, MA 02111-1307, USA.
19
19
  #
20
20
 
21
+ from __future__ import absolute_import
22
+ from __future__ import division
23
+ from __future__ import print_function
24
+ from __future__ import unicode_literals
25
+
21
26
  import imp
22
27
  import os
23
- import platform
24
28
  import sys
25
29
 
26
30
  from .utils import extract_libtool
@@ -54,16 +58,14 @@ class LibtoolImporter(object):
54
58
 
55
59
  def load_module(self, name):
56
60
  realpath = extract_libtool(self.path)
57
- platform_system = platform.system()
58
61
 
59
- if platform_system == 'Darwin':
60
- extension = '.dylib'
61
- elif platform_system == 'Windows':
62
- extension = '.dll'
63
- else:
64
- extension = '.so'
62
+ # The first item of the suffix tuple (which can be, depending on platform,
63
+ # one or more valid filename extensions used to name c extension modules)
64
+ # is ignored by imp.load_module(). Thus, there is no use in pretending it
65
+ # is important and we set it to an empty string.
66
+ suffix = ('', 'rb', imp.C_EXTENSION)
65
67
 
66
- mod = imp.load_module(name, open(realpath), realpath, (extension, 'rb', 3))
68
+ mod = imp.load_module(name, open(realpath), realpath, suffix)
67
69
  mod.__loader__ = self
68
70
  return mod
69
71
 
@@ -17,6 +17,11 @@
17
17
  # Boston, MA 02111-1307, USA.
18
18
  #
19
19
 
20
+ from __future__ import absolute_import
21
+ from __future__ import division
22
+ from __future__ import print_function
23
+ from __future__ import unicode_literals
24
+
20
25
  import re
21
26
 
22
27
  from . import ast
@@ -27,10 +32,11 @@ from .annotationparser import (ANN_ALLOW_NONE, ANN_ARRAY, ANN_ATTRIBUTES, ANN_CL
27
32
  ANN_GET_VALUE_FUNC, ANN_IN, ANN_INOUT, ANN_METHOD, ANN_OUT,
28
33
  ANN_REF_FUNC, ANN_RENAME_TO, ANN_SCOPE, ANN_SET_VALUE_FUNC,
29
34
  ANN_SKIP, ANN_TRANSFER, ANN_TYPE, ANN_UNREF_FUNC, ANN_VALUE,
30
- ANN_VFUNC, ANN_NULLABLE, ANN_OPTIONAL)
35
+ ANN_VFUNC, ANN_NULLABLE, ANN_OPTIONAL, ANN_NOT)
31
36
  from .annotationparser import (OPT_ARRAY_FIXED_SIZE, OPT_ARRAY_LENGTH, OPT_ARRAY_ZERO_TERMINATED,
32
37
  OPT_OUT_CALLEE_ALLOCATES, OPT_OUT_CALLER_ALLOCATES,
33
- OPT_TRANSFER_FLOATING, OPT_TRANSFER_NONE)
38
+ OPT_TRANSFER_CONTAINER, OPT_TRANSFER_FLOATING, OPT_TRANSFER_NONE,
39
+ OPT_NOT_NULLABLE)
34
40
 
35
41
  from .utils import to_underscores_noprefix
36
42
 
@@ -74,14 +80,14 @@ class MainTransformer(object):
74
80
  self._namespace.walk(self._pass_type_resolution)
75
81
 
76
82
  # Generate a reverse mapping "bar_baz" -> BarBaz
77
- for node in self._namespace.itervalues():
83
+ for node in self._namespace.values():
78
84
  if isinstance(node, ast.Registered) and node.get_type is not None:
79
85
  self._uscore_type_names[node.c_symbol_prefix] = node
80
86
  elif isinstance(node, (ast.Record, ast.Union)):
81
87
  uscored = to_underscores_noprefix(node.name).lower()
82
88
  self._uscore_type_names[uscored] = node
83
89
 
84
- for node in list(self._namespace.itervalues()):
90
+ for node in list(self._namespace.values()):
85
91
  if isinstance(node, ast.Function):
86
92
  # Discover which toplevel functions are actually methods
87
93
  self._pair_function(node)
@@ -126,7 +132,7 @@ class MainTransformer(object):
126
132
  origin_name = 'return value'
127
133
  message.log_node(
128
134
  message.FATAL, parent,
129
- "can't find parameter %s referenced by %s of %r"
135
+ "can't find parameter %s referenced by %s of '%s'"
130
136
  % (param_name, origin_name, parent.name))
131
137
 
132
138
  return param.argname
@@ -140,7 +146,7 @@ class MainTransformer(object):
140
146
  origin_name = 'field %s' % (origin.name, )
141
147
  message.log_node(
142
148
  message.FATAL, parent,
143
- "can't find field %s referenced by %s of %r"
149
+ "can't find field %s referenced by %s of '%s'"
144
150
  % (field_name, origin_name, parent.name))
145
151
 
146
152
  return field.name
@@ -155,17 +161,17 @@ class MainTransformer(object):
155
161
  target = self._namespace.get_by_symbol(rename_to)
156
162
  if not target:
157
163
  message.warn_node(node,
158
- "Can't find symbol %r referenced by \"rename-to\" annotation" % (rename_to, ))
164
+ "Can't find symbol '%s' referenced by \"rename-to\" annotation" % (rename_to, ))
159
165
  elif target.shadowed_by:
160
166
  message.warn_node(node,
161
- "Function %r already shadowed by %r, can't overwrite "
162
- "with %r" % (target.symbol,
167
+ "Function '%s' already shadowed by '%s', can't overwrite "
168
+ "with '%s'" % (target.symbol,
163
169
  target.shadowed_by,
164
170
  rename_to))
165
171
  elif target.shadows:
166
172
  message.warn_node(node,
167
- "Function %r already shadows %r, can't multiply shadow "
168
- "with %r" % (target.symbol,
173
+ "Function '%s' already shadows '%s', can't multiply shadow "
174
+ "with '%s'" % (target.symbol,
169
175
  target.shadows,
170
176
  rename_to))
171
177
  else:
@@ -203,7 +209,7 @@ class MainTransformer(object):
203
209
  elif isinstance(node, ast.Registered) and node.gtype_name is not None:
204
210
  return node.gtype_name
205
211
  return node.c_name
206
- raise AssertionError("Unhandled node %r" % (node, ))
212
+ raise AssertionError("Unhandled node '%s'" % (node, ))
207
213
 
208
214
  def _get_block(self, node):
209
215
  return self._blocks.get(self._get_annotation_name(node))
@@ -293,7 +299,7 @@ class MainTransformer(object):
293
299
  elif isinstance(base, ast.Map) and len(rest) == 2:
294
300
  return ast.Map(*rest)
295
301
  message.warn(
296
- "Too many parameters in type specification %r" % (type_str, ))
302
+ "Too many parameters in type specification '%s'" % (type_str, ))
297
303
  return base
298
304
 
299
305
  def top_combiner(base, *rest):
@@ -303,7 +309,7 @@ class MainTransformer(object):
303
309
 
304
310
  result, rest = grab_one(type_str, resolver, top_combiner, combiner)
305
311
  if rest:
306
- message.warn("Trailing components in type specification %r" % (
312
+ message.warn("Trailing components in type specification '%s'" % (
307
313
  type_str, ))
308
314
 
309
315
  if not result.resolved:
@@ -313,7 +319,7 @@ class MainTransformer(object):
313
319
  position = self._get_position(parent, node)
314
320
  else:
315
321
  text = type_str
316
- message.warn_node(parent, "%s: Unknown type: %r" %
322
+ message.warn_node(parent, "%s: Unknown type: '%s'" %
317
323
  (text, type_str), positions=position)
318
324
  return result
319
325
 
@@ -349,7 +355,7 @@ class MainTransformer(object):
349
355
  # (except enums and flags) or basic types that are
350
356
  # as big as a gpointer
351
357
  if array_type == ast.Array.GLIB_PTRARRAY:
352
- if ((element_type in ast.BASIC_GIR_TYPES and not element_type in ast.POINTER_TYPES)
358
+ if ((element_type in ast.BASIC_GIR_TYPES and element_type not in ast.POINTER_TYPES)
353
359
  or isinstance(element_type, (ast.Enum, ast.Bitfield))):
354
360
  message.warn("invalid (element-type) for a GPtrArray, "
355
361
  "must be a pointer", annotations.position)
@@ -358,7 +364,7 @@ class MainTransformer(object):
358
364
  if array_type == ast.Array.GLIB_BYTEARRAY:
359
365
  if element_type == ast.TYPE_ANY:
360
366
  array.element_type = ast.TYPE_UINT8
361
- elif not element_type in [ast.TYPE_UINT8, ast.TYPE_INT8, ast.TYPE_CHAR]:
367
+ elif element_type not in [ast.TYPE_UINT8, ast.TYPE_INT8, ast.TYPE_CHAR]:
362
368
  message.warn("invalid (element-type) for a GByteArray, "
363
369
  "must be one of guint8, gint8 or gchar",
364
370
  annotations.position)
@@ -467,7 +473,7 @@ class MainTransformer(object):
467
473
  def _get_transfer_default_returntype_basic(self, typeval):
468
474
  if (typeval.is_equiv(ast.BASIC_GIR_TYPES)
469
475
  or typeval.is_const
470
- or typeval.is_equiv(ast.TYPE_NONE)):
476
+ or typeval.is_equiv((ast.TYPE_ANY, ast.TYPE_NONE))):
471
477
  return ast.PARAM_TRANSFER_NONE
472
478
  elif typeval.is_equiv(ast.TYPE_STRING):
473
479
  # Non-const strings default to FULL
@@ -508,7 +514,11 @@ class MainTransformer(object):
508
514
  elif isinstance(parent, ast.Function) and parent.is_constructor:
509
515
  if isinstance(target, ast.Class):
510
516
  initially_unowned_type = ast.Type(target_giname='GObject.InitiallyUnowned')
511
- initially_unowned = self._transformer.lookup_typenode(initially_unowned_type)
517
+ try:
518
+ initially_unowned = self._transformer.lookup_typenode(initially_unowned_type)
519
+ except KeyError as e:
520
+ message.error_node(node, "constructor found but GObject is not in includes")
521
+ return None
512
522
  if initially_unowned and self._is_gi_subclass(typeval, initially_unowned_type):
513
523
  return ast.PARAM_TRANSFER_NONE
514
524
  else:
@@ -537,6 +547,63 @@ class MainTransformer(object):
537
547
  else:
538
548
  raise AssertionError(node)
539
549
 
550
+ def _is_pointer_type(self, node, annotations):
551
+ if (not isinstance(node, ast.Return) and
552
+ node.direction in (ast.PARAM_DIRECTION_OUT,
553
+ ast.PARAM_DIRECTION_INOUT)):
554
+ return True
555
+
556
+ target = self._transformer.lookup_typenode(node.type)
557
+ target = self._transformer.resolve_aliases(target)
558
+ target = node.type if target is None else target
559
+
560
+ return (not isinstance(target, ast.Type) or
561
+ target not in ast.BASIC_TYPES or
562
+ target.ctype.endswith('*'))
563
+
564
+ def _apply_transfer_annotation(self, parent, node, annotations):
565
+ transfer_annotation = annotations.get(ANN_TRANSFER)
566
+ if not transfer_annotation or len(transfer_annotation) != 1:
567
+ return
568
+
569
+ transfer = transfer_annotation[0]
570
+
571
+ target = self._transformer.lookup_typenode(node.type)
572
+ target = self._transformer.resolve_aliases(target)
573
+ target = node.type if target is None else target
574
+ node_type = target if isinstance(target, ast.Type) else node.type
575
+
576
+ if transfer == OPT_TRANSFER_FLOATING:
577
+ transfer = OPT_TRANSFER_NONE
578
+
579
+ if (not isinstance(target, (ast.Class, ast.Interface))
580
+ and node_type.target_giname != 'GLib.Variant'):
581
+ message.warn('invalid "transfer" annotation for {0}: '
582
+ 'only valid for object and GVariant types'.format(target),
583
+ annotations.position)
584
+ return
585
+
586
+ elif transfer == OPT_TRANSFER_CONTAINER:
587
+ if (ANN_ARRAY not in annotations and
588
+ not isinstance(target, (ast.Array, ast.List, ast.Map))):
589
+ message.warn('invalid "transfer" annotation for {0}: '
590
+ 'only valid for container types'.format(target),
591
+ annotations.position)
592
+ return
593
+
594
+ elif (not self._is_pointer_type(node, annotations) and
595
+ node_type not in (ast.TYPE_STRING, ast.TYPE_FILENAME) and
596
+ not isinstance(target, (ast.Array, ast.List, ast.Map,
597
+ ast.Record, ast.Compound, ast.Boxed,
598
+ ast.Class, ast.Interface))):
599
+ message.warn('invalid "transfer" annotation for {0}: '
600
+ 'only valid for array, struct, union, boxed, '
601
+ 'object and interface types'.format(target),
602
+ annotations.position)
603
+ return
604
+
605
+ node.transfer = transfer
606
+
540
607
  def _apply_annotations_param_ret_common(self, parent, node, tag):
541
608
  annotations = tag.annotations if tag else {}
542
609
 
@@ -577,32 +644,55 @@ class MainTransformer(object):
577
644
  # Also reset the transfer default if we're toggling direction
578
645
  node.transfer = self._get_transfer_default(parent, node)
579
646
 
580
- transfer_annotation = annotations.get(ANN_TRANSFER)
581
- if transfer_annotation and len(transfer_annotation) == 1:
582
- transfer = transfer_annotation[0]
583
- if transfer == OPT_TRANSFER_FLOATING:
584
- transfer = OPT_TRANSFER_NONE
585
- node.transfer = transfer
586
-
647
+ self._apply_transfer_annotation(parent, node, annotations)
587
648
  self._adjust_container_type(parent, node, annotations)
588
649
 
589
- if ANN_NULLABLE in annotations:
650
+ # gpointer parameters and return values are always nullable unless:
651
+ # - annotated with (type) and not also with (nullable); or
652
+ # - annotated with (element-type) and not also with (nullable); or
653
+ # - annotated (not nullable)
654
+ # See: https://bugzilla.gnome.org/show_bug.cgi?id=719966#c22
655
+ if node.type.is_equiv(ast.TYPE_ANY):
590
656
  node.nullable = True
657
+ if ANN_NULLABLE in annotations:
658
+ if self._is_pointer_type(node, annotations):
659
+ node.nullable = True
660
+ node.not_nullable = False
661
+ else:
662
+ message.warn('invalid "nullable" annotation: '
663
+ 'only valid for pointer types and out parameters',
664
+ annotations.position)
591
665
 
592
666
  if ANN_OPTIONAL in annotations:
593
- node.optional = True
667
+ if (not isinstance(node, ast.Return) and
668
+ node.direction == ast.PARAM_DIRECTION_OUT):
669
+ node.optional = True
670
+ else:
671
+ message.warn('invalid "optional" annotation: '
672
+ 'only valid for out parameters',
673
+ annotations.position)
594
674
 
595
675
  if ANN_ALLOW_NONE in annotations:
596
- if node.direction == ast.PARAM_DIRECTION_OUT:
676
+ if (node.direction == ast.PARAM_DIRECTION_OUT and
677
+ not isinstance(node, ast.Return)):
597
678
  node.optional = True
598
- else:
679
+ elif self._is_pointer_type(node, annotations):
599
680
  node.nullable = True
681
+ else:
682
+ message.warn('invalid "allow-none" annotation: '
683
+ 'only valid for pointer types and out parameters',
684
+ annotations.position)
600
685
 
601
686
  if (node.direction != ast.PARAM_DIRECTION_OUT and
602
687
  (node.type.target_giname == 'Gio.AsyncReadyCallback' or
603
688
  node.type.target_giname == 'Gio.Cancellable')):
604
689
  node.nullable = True
605
690
 
691
+ # Final override for nullability
692
+ if ANN_NOT in annotations:
693
+ node.nullable = False
694
+ node.not_nullable = True
695
+
606
696
  if tag and tag.description:
607
697
  node.doc = tag.description
608
698
 
@@ -708,6 +798,12 @@ class MainTransformer(object):
708
798
  tag = block.tags.get(TAG_RETURNS)
709
799
  else:
710
800
  tag = None
801
+
802
+ if tag is not None and return_.type == ast.TYPE_NONE:
803
+ message.warn('%s: invalid return annotation' % (block.name,),
804
+ tag.position)
805
+ tag = None
806
+
711
807
  self._apply_annotations_param_ret_common(parent, return_, tag)
712
808
 
713
809
  def _apply_annotations_params(self, parent, params, block):
@@ -740,13 +836,14 @@ class MainTransformer(object):
740
836
  text = ''
741
837
  elif len(unused) == 1:
742
838
  (param, ) = unused
743
- text = ', should be %r' % (param, )
839
+ text = ", should be '%s'" % (param, )
744
840
  else:
745
- text = ', should be one of %s' % (', '.join(repr(p) for p in unused), )
841
+ text = ", should be one of %s" % \
842
+ (', '.join("'%s'" % p for p in sorted(unused)), )
746
843
 
747
844
  param = block.params.get(doc_name)
748
- message.warn('%s: unknown parameter %r in documentation '
749
- 'comment%s' % (block.name, doc_name, text),
845
+ message.warn("%s: unknown parameter '%s' in documentation "
846
+ "comment%s" % (block.name, doc_name, text),
750
847
  param.position)
751
848
 
752
849
  def _apply_annotations_callable(self, node, chain, block):
@@ -767,7 +864,7 @@ class MainTransformer(object):
767
864
  try:
768
865
  self._adjust_container_type(parent, field, tag.annotations)
769
866
  except AttributeError as ex:
770
- print ex
867
+ print(ex)
771
868
 
772
869
  def _apply_annotations_property(self, parent, prop):
773
870
  prefix = self._get_annotation_name(parent)
@@ -794,7 +891,6 @@ class MainTransformer(object):
794
891
 
795
892
  if block:
796
893
  self._apply_annotations_annotated(signal, block)
797
-
798
894
  # We're only attempting to name the signal parameters if
799
895
  # the number of parameters (@foo) is the same or greater
800
896
  # than the number of signal parameters
@@ -865,7 +961,7 @@ class MainTransformer(object):
865
961
  break
866
962
  if not matched:
867
963
  message.warn_node(node,
868
- "Virtual slot %r not found for %r annotation" % (invoker_name,
964
+ "Virtual slot '%s' not found for '%s' annotation" % (invoker_name,
869
965
  ANN_VFUNC))
870
966
  return True
871
967
 
@@ -925,14 +1021,14 @@ the ones that failed to resolve removed."""
925
1021
  # but only covers enums that are registered as GObject enums.
926
1022
  # Create a fallback mapping based on all known enums in this module.
927
1023
  uscore_enums = {}
928
- for enum in self._namespace.itervalues():
1024
+ for enum in self._namespace.values():
929
1025
  if not isinstance(enum, ast.Enum):
930
1026
  continue
931
1027
  uscored = to_underscores_noprefix(enum.name).lower()
932
1028
  uscore_enums[uscored] = enum
933
1029
  uscore_enums[enum.name] = enum
934
1030
 
935
- for node in self._namespace.itervalues():
1031
+ for node in self._namespace.values():
936
1032
  if not isinstance(node, ast.ErrorQuarkFunction):
937
1033
  continue
938
1034
  full = node.symbol[:-len('_quark')]
@@ -1196,7 +1292,7 @@ method or constructor of some type."""
1196
1292
  if func.is_constructor:
1197
1293
  message.warn_node(
1198
1294
  func,
1199
- "Can't find matching type for constructor; symbol=%r" % (func.symbol, ))
1295
+ "Can't find matching type for constructor; symbol='%s'" % (func.symbol, ))
1200
1296
  return False
1201
1297
 
1202
1298
  # Some sanity checks; only objects and boxeds can have ctors
@@ -1229,7 +1325,7 @@ method or constructor of some type."""
1229
1325
  if parent is None:
1230
1326
  message.warn_node(func,
1231
1327
  "Return value is not superclass for constructor; "
1232
- "symbol=%r constructed=%r return=%r" %
1328
+ "symbol='%s' constructed='%s' return='%s'" %
1233
1329
  (func.symbol,
1234
1330
  str(origin_node.create_type()),
1235
1331
  str(func.retval.type)))
@@ -1237,8 +1333,8 @@ method or constructor of some type."""
1237
1333
  else:
1238
1334
  if origin_node != target:
1239
1335
  message.warn_node(func,
1240
- "Constructor return type mismatch symbol=%r "
1241
- "constructed=%r return=%r" %
1336
+ "Constructor return type mismatch symbol='%s' "
1337
+ "constructed='%s' return='%s'" %
1242
1338
  (func.symbol,
1243
1339
  str(origin_node.create_type()),
1244
1340
  str(func.retval.type)))
@@ -1250,8 +1346,8 @@ method or constructor of some type."""
1250
1346
  """Look for virtual methods from the class structure."""
1251
1347
  if not node.glib_type_struct:
1252
1348
  # https://bugzilla.gnome.org/show_bug.cgi?id=629080
1253
- #message.warn_node(node,
1254
- # "Failed to find class structure for %r" % (node.name, ))
1349
+ # message.warn_node(node,
1350
+ # "Failed to find class structure for '%s'" % (node.name, ))
1255
1351
  return
1256
1352
 
1257
1353
  node_type = node.create_type()
@@ -1357,6 +1453,15 @@ method or constructor of some type."""
1357
1453
  param.argname.endswith('data')):
1358
1454
  callback_param.closure_name = param.argname
1359
1455
 
1456
+ for param in params:
1457
+ # By convention, closure user_data parameters are always nullable.
1458
+ if param.closure_name is not None:
1459
+ idx = node.get_parameter_index(param.closure_name)
1460
+ assert idx >= 0
1461
+ closure_param = params[idx]
1462
+ if not closure_param.not_nullable:
1463
+ closure_param.nullable = True
1464
+
1360
1465
  def _pass3_callable_throws(self, node):
1361
1466
  """Check to see if we have anything that looks like a
1362
1467
  callback+user_data+GDestroyNotify set."""