gobject-introspection 3.3.8 → 3.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/ext/gobject-introspection/extconf.rb +4 -4
  3. data/ext/gobject-introspection/gobject_introspection.def +2 -1
  4. data/ext/gobject-introspection/rb-gi-arg-info.c +33 -1
  5. data/ext/gobject-introspection/rb-gi-argument.c +384 -3291
  6. data/ext/gobject-introspection/rb-gi-arguments-in.c +2229 -0
  7. data/ext/gobject-introspection/rb-gi-arguments-out.c +929 -0
  8. data/ext/gobject-introspection/rb-gi-arguments.c +850 -0
  9. data/ext/gobject-introspection/rb-gi-array-type.c +54 -0
  10. data/ext/gobject-introspection/rb-gi-callback.c +242 -0
  11. data/ext/gobject-introspection/rb-gi-conversions.h +0 -43
  12. data/ext/gobject-introspection/rb-gi-direction.c +36 -0
  13. data/ext/gobject-introspection/rb-gi-field-info.c +172 -81
  14. data/ext/gobject-introspection/rb-gi-function-info.c +15 -1404
  15. data/ext/gobject-introspection/rb-gi-private-arg-info.h +24 -0
  16. data/ext/gobject-introspection/rb-gi-private-arguments-in.h +26 -0
  17. data/ext/gobject-introspection/rb-gi-private-arguments-out.h +28 -0
  18. data/ext/gobject-introspection/rb-gi-private-arguments.h +107 -0
  19. data/ext/gobject-introspection/rb-gi-private-array-type.h +26 -0
  20. data/ext/gobject-introspection/rb-gi-private-callback.h +41 -0
  21. data/ext/gobject-introspection/rb-gi-private-direction.h +24 -0
  22. data/ext/gobject-introspection/rb-gi-private-transfer.h +24 -0
  23. data/ext/gobject-introspection/rb-gi-private.h +11 -5
  24. data/ext/gobject-introspection/rb-gi-struct-info.c +2 -0
  25. data/ext/gobject-introspection/rb-gi-transfer.c +36 -0
  26. data/ext/gobject-introspection/rb-gi-type-info.c +1 -13
  27. data/ext/gobject-introspection/rb-gobject-introspection.c +4 -1
  28. data/ext/gobject-introspection/rb-gobject-introspection.h +5 -23
  29. data/lib/gobject-introspection/arg-info.rb +2 -0
  30. data/lib/gobject-introspection/callable-info.rb +1 -1
  31. data/lib/gobject-introspection/loader.rb +0 -39
  32. data/lib/gobject-introspection/type-tag.rb +39 -2
  33. metadata +21 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce2773caef8d28da88dd1ed2dfdf50fb20ada6db54107376328245119a7c43e1
4
- data.tar.gz: e465986398c01171ea645d4e544abc2649bbffb1cd06ad00ede6ab4f903df981
3
+ metadata.gz: 63b8621d7aa520ba998438e4930c7d6e69398c520e589adafea823aa7597790b
4
+ data.tar.gz: 4b3b7409538ab5cdbcf237a1e107d25b276eaa61f4ca56cf771764e3a1343aa3
5
5
  SHA512:
6
- metadata.gz: 464ce3a16ac291fe676b7dc6bb8af918aa706cb3685985309b3bdf8dad13387349ebd4f243e599e89d95151edc927720a9d7cf46a6cabafc58d13a97c46894d8
7
- data.tar.gz: 671033bd5e52f2bf7792ea7d86a2797a9c437bb62cc4da1c1ce8264fbc489398e7cc22823695abe7f3c4c2d07564a82800da3c0482452430ba7bb6338ddddafb
6
+ metadata.gz: ddce980ec3e2abf3a95c16ceb6e48489af7cddd03d59e135485c1adfbe61263b6349ee4d0b53025df9d5ec0f6140721c2ec61604bf6dd2f9304446069e0482e1
7
+ data.tar.gz: dec6cddf5c698e47b511913e0f827f29fac841fffee0d3566bdda09f98aab2fd24d84534d695cf2ea6da767402afcc56b789bb9b937f49d6f345755e985b9f6f
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # Copyright (C) 2012-2013 Ruby-GNOME2 Project Team
3
+ # Copyright (C) 2012-2019 Ruby-GNOME Project Team
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -37,7 +37,7 @@ $LOAD_PATH.unshift(mkmf_gnome2_dir.to_s)
37
37
  module_name = "gobject_introspection"
38
38
  package_id = "gobject-introspection-1.0"
39
39
 
40
- require "mkmf-gnome2"
40
+ require "mkmf-gnome"
41
41
 
42
42
  ["glib2"].each do |package|
43
43
  directory = "#{package}#{version_suffix}"
@@ -51,7 +51,7 @@ end
51
51
  unless required_pkg_config_package(package_id,
52
52
  :alt_linux => "gobject-introspection-devel",
53
53
  :debian => "libgirepository1.0-dev",
54
- :redhat => "gobject-introspection-devel",
54
+ :redhat => "pkgconfig(gobject-introspection-1.0)",
55
55
  :homebrew => "gobject-introspection",
56
56
  :arch_linux => "gobject-introspection",
57
57
  :macports => "gobject-introspection",
@@ -73,7 +73,7 @@ end
73
73
  glib_mkenums(enum_type_prefix, headers, "G_TYPE_", ["girepository.h"])
74
74
 
75
75
  create_pkg_config_file("Ruby/GObjectIntrospection",
76
- package_id, ruby_gnome2_version,
76
+ package_id, ruby_gnome_version,
77
77
  "ruby-gobject-introspection.pc")
78
78
 
79
79
  ensure_objs
@@ -1,10 +1,11 @@
1
1
  EXPORTS
2
2
  Init_gobject_introspection
3
3
 
4
- rb_gi_callback_register_finder
5
4
  rb_gi_callback_data_free
6
5
  rb_gi_callback_data_get_metadata
7
6
  rb_gi_callback_data_get_rb_callback
8
7
 
8
+ rb_gi_callback_register_finder
9
+
9
10
  rb_gi_struct_new_raw
10
11
  rb_gi_struct_get_raw
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2012 Ruby-GNOME2 Project Team
3
+ * Copyright (C) 2012-2019 Ruby-GNOME Project Team
4
4
  *
5
5
  * This library is free software; you can redistribute it and/or
6
6
  * modify it under the terms of the GNU Lesser General Public
@@ -23,6 +23,29 @@
23
23
  #define RG_TARGET_NAMESPACE rb_cGIArgInfo
24
24
  #define SELF(self) (RVAL2GI_ARG_INFO(self))
25
25
 
26
+ gboolean
27
+ rb_gi_arg_info_is_output_buffer(GIArgInfo *info)
28
+ {
29
+ if (g_arg_info_get_direction(info) != GI_DIRECTION_OUT) {
30
+ return FALSE;
31
+ }
32
+
33
+ if (!g_arg_info_is_caller_allocates(info)) {
34
+ return FALSE;
35
+ }
36
+
37
+ GITypeInfo type_info;
38
+ g_arg_info_load_type(info, &type_info);
39
+ if (g_type_info_get_tag(&type_info) != GI_TYPE_TAG_ARRAY) {
40
+ return FALSE;
41
+ }
42
+
43
+ GITypeInfo *element_type_info = g_type_info_get_param_type(&type_info, 0);
44
+ GITypeTag element_type_tag = g_type_info_get_tag(element_type_info);
45
+ g_base_info_unref(element_type_info);
46
+ return element_type_tag == GI_TYPE_TAG_UINT8;
47
+ }
48
+
26
49
  GType
27
50
  gi_arg_info_get_type(void)
28
51
  {
@@ -125,6 +148,13 @@ rg_type(VALUE self)
125
148
  return GI_BASE_INFO2RVAL_WITH_UNREF(g_arg_info_get_type(info));
126
149
  }
127
150
 
151
+ static VALUE
152
+ rg_output_buffer_p(VALUE self)
153
+ {
154
+ GIArgInfo *info = SELF(self);
155
+ return CBOOL2RVAL(rb_gi_arg_info_is_output_buffer(info));
156
+ }
157
+
128
158
  void
129
159
  rb_gi_arg_info_init(VALUE rb_mGI, VALUE rb_cGIBaseInfo)
130
160
  {
@@ -145,6 +175,8 @@ rb_gi_arg_info_init(VALUE rb_mGI, VALUE rb_cGIBaseInfo)
145
175
  RG_DEF_METHOD(destroy, 0);
146
176
  RG_DEF_METHOD(type, 0);
147
177
 
178
+ RG_DEF_METHOD_P(output_buffer, 0);
179
+
148
180
  G_DEF_CLASS(G_TYPE_I_DIRECTION, "Direction", rb_mGI);
149
181
  G_DEF_CLASS(G_TYPE_I_SCOPE_TYPE, "ScopeType", rb_mGI);
150
182
  G_DEF_CLASS(G_TYPE_I_TRANSFER, "Transfer", rb_mGI);
@@ -25,36 +25,6 @@ static VALUE rb_cGLibBytes = Qnil;
25
25
  static VALUE rb_cGLibObject = Qnil;
26
26
  static VALUE rb_cGLibValue = Qnil;
27
27
 
28
- static gboolean
29
- rb_gi_arg_info_may_be_null(GIArgInfo *arg_info)
30
- {
31
- #if GI_CHECK_VERSION(1, 42, 0)
32
- return g_arg_info_may_be_null(arg_info);
33
- #else
34
- /*
35
- GObject Introspection < 1.42 doesn't support "(nullable)" yet.
36
- So, we assume that all argument may be NULL. It's danger but
37
- convenient.
38
- */
39
- return TRUE;
40
- #endif
41
- }
42
-
43
- static const gchar *
44
- rb_gi_transfer_to_string(GITransfer transfer)
45
- {
46
- switch(transfer) {
47
- case GI_TRANSFER_NOTHING:
48
- return "nothing";
49
- case GI_TRANSFER_CONTAINER:
50
- return "container";
51
- case GI_TRANSFER_EVERYTHING:
52
- return "everything";
53
- default:
54
- return "unknown";
55
- }
56
- }
57
-
58
28
  static void
59
29
  array_c_to_ruby_sized_interface(gconstpointer *elements,
60
30
  gint64 n_elements,
@@ -722,17 +692,14 @@ rb_gi_argument_to_ruby_interface(GIArgument *argument,
722
692
  static void
723
693
  normalize_out_array_length(GIArgument *normalized_argument,
724
694
  GIArgument *argument,
725
- GITypeInfo *type_info)
695
+ RBGIArgMetadata *metadata)
726
696
  {
727
- GITypeTag type_tag;
728
-
729
- type_tag = g_type_info_get_tag(type_info);
730
- switch (type_tag) {
697
+ switch (metadata->type.tag) {
731
698
  case GI_TYPE_TAG_VOID:
732
699
  case GI_TYPE_TAG_BOOLEAN:
733
700
  rb_raise(rb_eNotImpError,
734
701
  "TODO: invalid out array length argument?: <%s>",
735
- g_type_tag_to_string(type_tag));
702
+ g_type_tag_to_string(metadata->type.tag));
736
703
  break;
737
704
  case GI_TYPE_TAG_INT8:
738
705
  normalized_argument->v_int8 = *((gint8 *)argument->v_pointer);
@@ -772,7 +739,7 @@ normalize_out_array_length(GIArgument *normalized_argument,
772
739
  case GI_TYPE_TAG_UNICHAR:
773
740
  rb_raise(rb_eNotImpError,
774
741
  "TODO: invalid out array length argument?: <%s>",
775
- g_type_tag_to_string(type_tag));
742
+ g_type_tag_to_string(metadata->type.tag));
776
743
  break;
777
744
  default:
778
745
  g_assert_not_reached();
@@ -791,21 +758,15 @@ rb_gi_argument_to_ruby_array(GIArgument *array_argument,
791
758
  gint length_index;
792
759
  GIArgument *length_argument = NULL;
793
760
  GIArgument normalized_length_argument;
794
- GITypeInfo raw_length_type_info;
795
761
  GITypeInfo *length_type_info = NULL;
796
762
 
797
763
  length_index = g_type_info_get_array_length(array_type_info);
798
764
  if (length_index != -1) {
799
765
  RBGIArgMetadata *length_metadata;
800
- GIArgInfo *length_arg_info = NULL;
801
766
  GIArgument *raw_length_argument = NULL;
802
767
 
803
768
  length_metadata = g_ptr_array_index(args_metadata, length_index);
804
- length_arg_info = &(length_metadata->arg_info);
805
-
806
- g_arg_info_load_type(length_arg_info, &raw_length_type_info);
807
- length_type_info = &raw_length_type_info;
808
-
769
+ length_type_info = length_metadata->type.info;
809
770
  if (length_metadata->direction == GI_DIRECTION_OUT) {
810
771
  raw_length_argument = &g_array_index(out_args, GIArgument,
811
772
  length_metadata->out_arg_index);
@@ -815,10 +776,15 @@ rb_gi_argument_to_ruby_array(GIArgument *array_argument,
815
776
  }
816
777
 
817
778
  if (raw_length_argument) {
818
- normalize_out_array_length(&normalized_length_argument,
819
- raw_length_argument,
820
- length_type_info);
821
- length_argument = &normalized_length_argument;
779
+ if (length_metadata->array_metadata &&
780
+ length_metadata->array_metadata->output_buffer_p) {
781
+ length_argument = raw_length_argument;
782
+ } else {
783
+ normalize_out_array_length(&normalized_length_argument,
784
+ raw_length_argument,
785
+ length_metadata);
786
+ length_argument = &normalized_length_argument;
787
+ }
822
788
  } else {
823
789
  length_argument = &g_array_index(in_args, GIArgument,
824
790
  length_metadata->in_arg_index);
@@ -1418,158 +1384,79 @@ rb_gi_argument_to_ruby(GIArgument *argument,
1418
1384
  }
1419
1385
 
1420
1386
  static void
1421
- rb_gi_out_argument_init_array_c(GIArgument *argument,
1422
- G_GNUC_UNUSED GIArgInfo *arg_info,
1423
- G_GNUC_UNUSED GITypeInfo *array_type_info,
1424
- GITypeInfo *element_type_info)
1387
+ rb_gi_return_argument_free_container(GIArgument *argument,
1388
+ GITypeInfo *type_info)
1425
1389
  {
1426
- GITypeTag element_type_tag;
1390
+ GITypeTag type_tag;
1427
1391
 
1428
- element_type_tag = g_type_info_get_tag(element_type_info);
1392
+ type_tag = g_type_info_get_tag(type_info);
1429
1393
 
1430
- switch (element_type_tag) {
1431
- case GI_TYPE_TAG_VOID:
1432
- case GI_TYPE_TAG_BOOLEAN:
1433
- case GI_TYPE_TAG_INT8:
1434
- g_base_info_unref(element_type_info);
1435
- rb_raise(rb_eNotImpError,
1436
- "TODO: allocates GIArgument(array)[c][%s] for output",
1437
- g_type_tag_to_string(element_type_tag));
1438
- break;
1439
- case GI_TYPE_TAG_UINT8:
1440
- argument->v_pointer = xmalloc(sizeof(guint8 *));
1441
- break;
1442
- case GI_TYPE_TAG_INT16:
1443
- case GI_TYPE_TAG_UINT16:
1444
- case GI_TYPE_TAG_INT32:
1445
- case GI_TYPE_TAG_UINT32:
1446
- case GI_TYPE_TAG_INT64:
1447
- case GI_TYPE_TAG_UINT64:
1448
- case GI_TYPE_TAG_FLOAT:
1449
- case GI_TYPE_TAG_DOUBLE:
1450
- case GI_TYPE_TAG_GTYPE:
1451
- g_base_info_unref(element_type_info);
1452
- rb_raise(rb_eNotImpError,
1453
- "TODO: allocates GIArgument(array)[c][%s] for output",
1454
- g_type_tag_to_string(element_type_tag));
1455
- break;
1456
- case GI_TYPE_TAG_UTF8:
1457
- argument->v_pointer = xmalloc(sizeof(gchar **));
1458
- break;
1459
- case GI_TYPE_TAG_FILENAME:
1460
- case GI_TYPE_TAG_ARRAY:
1461
- g_base_info_unref(element_type_info);
1394
+ switch (type_tag) {
1395
+ case GI_TYPE_TAG_VOID:
1396
+ case GI_TYPE_TAG_BOOLEAN:
1397
+ case GI_TYPE_TAG_INT8:
1398
+ case GI_TYPE_TAG_UINT8:
1399
+ case GI_TYPE_TAG_INT16:
1400
+ case GI_TYPE_TAG_UINT16:
1401
+ case GI_TYPE_TAG_INT32:
1402
+ case GI_TYPE_TAG_UINT32:
1403
+ case GI_TYPE_TAG_INT64:
1404
+ case GI_TYPE_TAG_UINT64:
1405
+ case GI_TYPE_TAG_FLOAT:
1406
+ case GI_TYPE_TAG_DOUBLE:
1407
+ case GI_TYPE_TAG_GTYPE:
1408
+ case GI_TYPE_TAG_UTF8:
1409
+ case GI_TYPE_TAG_FILENAME:
1462
1410
  rb_raise(rb_eNotImpError,
1463
- "TODO: allocates GIArgument(array)[c][%s] for output",
1464
- g_type_tag_to_string(element_type_tag));
1411
+ "TODO: free GIArgument(%s) as container",
1412
+ g_type_tag_to_string(type_tag));
1465
1413
  break;
1466
- case GI_TYPE_TAG_INTERFACE:
1467
- argument->v_pointer = xmalloc(sizeof(gpointer *));
1414
+ case GI_TYPE_TAG_ARRAY:
1415
+ g_free(argument->v_pointer);
1468
1416
  break;
1469
- case GI_TYPE_TAG_GLIST:
1470
- case GI_TYPE_TAG_GSLIST:
1471
- case GI_TYPE_TAG_GHASH:
1472
- case GI_TYPE_TAG_ERROR:
1473
- case GI_TYPE_TAG_UNICHAR:
1474
- g_base_info_unref(element_type_info);
1417
+ case GI_TYPE_TAG_INTERFACE:
1475
1418
  rb_raise(rb_eNotImpError,
1476
- "TODO: allocates GIArgument(array)[c][%s] for output",
1477
- g_type_tag_to_string(element_type_tag));
1419
+ "TODO: free GIArgument(%s) as container",
1420
+ g_type_tag_to_string(type_tag));
1478
1421
  break;
1479
- default:
1480
- g_base_info_unref(element_type_info);
1481
- g_assert_not_reached();
1422
+ case GI_TYPE_TAG_GLIST:
1423
+ g_list_free(argument->v_pointer);
1482
1424
  break;
1483
- }
1484
- }
1485
-
1486
- static void
1487
- rb_gi_out_argument_init_array_array_interface(GIArgument *argument,
1488
- G_GNUC_UNUSED GIArgInfo *arg_info,
1489
- GITypeInfo *array_type_info,
1490
- GITypeInfo *element_type_info)
1491
- {
1492
- gboolean zero_terminated_p;
1493
- GIBaseInfo *interface_info;
1494
- GIInfoType interface_type;
1495
- GType gtype;
1496
- const char *interface_name;
1497
-
1498
- zero_terminated_p = g_type_info_is_zero_terminated(array_type_info);
1499
- interface_info = g_type_info_get_interface(element_type_info);
1500
- interface_type = g_base_info_get_type(interface_info);
1501
- gtype = g_registered_type_info_get_g_type(interface_info);
1502
-
1503
- switch (interface_type) {
1504
- case GI_INFO_TYPE_INVALID:
1505
- case GI_INFO_TYPE_FUNCTION:
1506
- case GI_INFO_TYPE_CALLBACK:
1507
- interface_name = g_info_type_to_string(interface_type);
1508
- g_base_info_unref(interface_info);
1509
- g_base_info_unref(element_type_info);
1510
- rb_raise(rb_eNotImpError,
1511
- "TODO: GIArgument(array)[array][interface(%s)](%s) -> Ruby",
1512
- interface_name,
1513
- g_type_name(gtype));
1425
+ case GI_TYPE_TAG_GSLIST:
1426
+ g_slist_free(argument->v_pointer);
1514
1427
  break;
1515
- case GI_INFO_TYPE_STRUCT:
1516
- {
1517
- gsize raw_struct_size;
1518
- guint struct_size;
1519
-
1520
- raw_struct_size = g_struct_info_get_size(interface_info);
1521
- struct_size = (guint)raw_struct_size;
1522
- argument->v_pointer = g_array_new(zero_terminated_p,
1523
- TRUE,
1524
- struct_size);
1428
+ case GI_TYPE_TAG_GHASH:
1429
+ g_hash_table_unref(argument->v_pointer);
1525
1430
  break;
1526
- }
1527
- case GI_INFO_TYPE_BOXED:
1528
- case GI_INFO_TYPE_ENUM:
1529
- case GI_INFO_TYPE_FLAGS:
1530
- case GI_INFO_TYPE_OBJECT:
1531
- case GI_INFO_TYPE_INTERFACE:
1532
- case GI_INFO_TYPE_CONSTANT:
1533
- case GI_INFO_TYPE_INVALID_0:
1534
- case GI_INFO_TYPE_UNION:
1535
- case GI_INFO_TYPE_VALUE:
1536
- case GI_INFO_TYPE_SIGNAL:
1537
- case GI_INFO_TYPE_VFUNC:
1538
- case GI_INFO_TYPE_PROPERTY:
1539
- case GI_INFO_TYPE_FIELD:
1540
- case GI_INFO_TYPE_ARG:
1541
- case GI_INFO_TYPE_TYPE:
1542
- case GI_INFO_TYPE_UNRESOLVED:
1543
- interface_name = g_info_type_to_string(interface_type);
1544
- g_base_info_unref(interface_info);
1545
- g_base_info_unref(element_type_info);
1431
+ case GI_TYPE_TAG_ERROR:
1432
+ case GI_TYPE_TAG_UNICHAR:
1546
1433
  rb_raise(rb_eNotImpError,
1547
- "TODO: GIArgument(array)[array][interface(%s)](%s) -> Ruby",
1548
- interface_name,
1549
- g_type_name(gtype));
1434
+ "TODO: free GIArgument(%s) as container",
1435
+ g_type_tag_to_string(type_tag));
1550
1436
  break;
1551
1437
  default:
1552
- g_base_info_unref(interface_info);
1553
- g_base_info_unref(element_type_info);
1554
1438
  g_assert_not_reached();
1555
1439
  break;
1556
1440
  }
1557
-
1558
- g_base_info_unref(interface_info);
1559
1441
  }
1560
1442
 
1561
1443
  static void
1562
- rb_gi_out_argument_init_array_array(GIArgument *argument,
1563
- GIArgInfo *arg_info,
1564
- GITypeInfo *array_type_info,
1565
- GITypeInfo *element_type_info)
1444
+ rb_gi_return_argument_free_everything_array_c(GIArgument *argument,
1445
+ GITypeInfo *type_info)
1566
1446
  {
1447
+ GITypeInfo *element_type_info;
1567
1448
  GITypeTag element_type_tag;
1568
1449
 
1450
+ element_type_info = g_type_info_get_param_type(type_info, 0);
1569
1451
  element_type_tag = g_type_info_get_tag(element_type_info);
1452
+ g_base_info_unref(element_type_info);
1570
1453
 
1571
1454
  switch (element_type_tag) {
1572
1455
  case GI_TYPE_TAG_VOID:
1456
+ rb_raise(rb_eNotImpError,
1457
+ "TODO: free GIArgument(array)[c][%s] everything",
1458
+ g_type_tag_to_string(element_type_tag));
1459
+ break;
1573
1460
  case GI_TYPE_TAG_BOOLEAN:
1574
1461
  case GI_TYPE_TAG_INT8:
1575
1462
  case GI_TYPE_TAG_UINT8:
@@ -1581,2753 +1468,250 @@ rb_gi_out_argument_init_array_array(GIArgument *argument,
1581
1468
  case GI_TYPE_TAG_UINT64:
1582
1469
  case GI_TYPE_TAG_FLOAT:
1583
1470
  case GI_TYPE_TAG_DOUBLE:
1471
+ g_free(argument->v_pointer);
1472
+ break;
1584
1473
  case GI_TYPE_TAG_GTYPE:
1585
- case GI_TYPE_TAG_UTF8:
1586
- case GI_TYPE_TAG_FILENAME:
1587
- case GI_TYPE_TAG_ARRAY:
1588
- g_base_info_unref(element_type_info);
1589
1474
  rb_raise(rb_eNotImpError,
1590
- "TODO: allocates GIArgument(array)[array][%s] for output",
1475
+ "TODO: free GIArgument(array)[c][%s] everything",
1591
1476
  g_type_tag_to_string(element_type_tag));
1592
1477
  break;
1593
- case GI_TYPE_TAG_INTERFACE:
1594
- rb_gi_out_argument_init_array_array_interface(argument,
1595
- arg_info,
1596
- array_type_info,
1597
- element_type_info);
1478
+ case GI_TYPE_TAG_UTF8:
1479
+ g_strfreev(argument->v_pointer);
1480
+ break;
1481
+ case GI_TYPE_TAG_FILENAME:
1482
+ g_strfreev(argument->v_pointer);
1598
1483
  break;
1484
+ case GI_TYPE_TAG_ARRAY:
1485
+ case GI_TYPE_TAG_INTERFACE:
1599
1486
  case GI_TYPE_TAG_GLIST:
1600
1487
  case GI_TYPE_TAG_GSLIST:
1601
1488
  case GI_TYPE_TAG_GHASH:
1602
1489
  case GI_TYPE_TAG_ERROR:
1603
1490
  case GI_TYPE_TAG_UNICHAR:
1604
- g_base_info_unref(element_type_info);
1605
1491
  rb_raise(rb_eNotImpError,
1606
- "TODO: allocates GIArgument(array)[array][%s] for output",
1492
+ "TODO: free GIArgument(array)[c][%s] everything",
1607
1493
  g_type_tag_to_string(element_type_tag));
1608
1494
  break;
1609
1495
  default:
1610
- g_base_info_unref(element_type_info);
1611
1496
  g_assert_not_reached();
1612
1497
  break;
1613
1498
  }
1614
1499
  }
1615
1500
 
1616
1501
  static void
1617
- rb_gi_out_argument_init_array(GIArgument *argument, GIArgInfo *arg_info,
1618
- GITypeInfo *array_type_info)
1502
+ rb_gi_return_argument_free_everything_array(GIArgument *argument,
1503
+ GITypeInfo *type_info)
1619
1504
  {
1620
- GIArrayType array_type;
1621
- GITypeInfo *element_type_info;
1622
- GITypeTag element_type_tag;
1623
-
1624
- array_type = g_type_info_get_array_type(array_type_info);
1625
- element_type_info = g_type_info_get_param_type(array_type_info, 0);
1626
- element_type_tag = g_type_info_get_tag(element_type_info);
1627
-
1628
- switch (array_type) {
1505
+ switch (g_type_info_get_array_type(type_info)) {
1629
1506
  case GI_ARRAY_TYPE_C:
1630
- rb_gi_out_argument_init_array_c(argument,
1631
- arg_info,
1632
- array_type_info,
1633
- element_type_info);
1507
+ rb_gi_return_argument_free_everything_array_c(argument, type_info);
1634
1508
  break;
1635
1509
  case GI_ARRAY_TYPE_ARRAY:
1636
- rb_gi_out_argument_init_array_array(argument,
1637
- arg_info,
1638
- array_type_info,
1639
- element_type_info);
1510
+ g_array_free(argument->v_pointer, TRUE);
1640
1511
  break;
1641
1512
  case GI_ARRAY_TYPE_PTR_ARRAY:
1642
- g_base_info_unref(element_type_info);
1643
- rb_raise(rb_eNotImpError,
1644
- "TODO: allocates GIArgument(array)[ptr-array][%s] for output",
1645
- g_type_tag_to_string(element_type_tag));
1513
+ g_ptr_array_free(argument->v_pointer, TRUE);
1646
1514
  break;
1647
1515
  case GI_ARRAY_TYPE_BYTE_ARRAY:
1648
- g_base_info_unref(element_type_info);
1649
- rb_raise(rb_eNotImpError,
1650
- "TODO: allocates GIArgument(array)[byte-array][%s] for output",
1651
- g_type_tag_to_string(element_type_tag));
1516
+ g_ptr_array_free(argument->v_pointer, TRUE);
1652
1517
  break;
1653
1518
  default:
1654
- g_base_info_unref(element_type_info);
1655
1519
  g_assert_not_reached();
1656
1520
  break;
1657
1521
  }
1522
+ }
1658
1523
 
1659
- g_base_info_unref(element_type_info);
1524
+ static void
1525
+ rb_gi_return_argument_free_everything_interface_struct(GIArgument *argument,
1526
+ GType gtype)
1527
+ {
1528
+ if (!argument->v_pointer) {
1529
+ return;
1530
+ }
1531
+
1532
+ if (!gtype) {
1533
+ xfree(argument->v_pointer);
1534
+ }
1535
+
1536
+ if (G_TYPE_IS_BOXED(gtype)) {
1537
+ g_boxed_free(gtype, argument->v_pointer);
1538
+ } else {
1539
+ rbgobj_instance_unref(argument->v_pointer);
1540
+ }
1660
1541
  }
1661
1542
 
1662
1543
  static void
1663
- rb_gi_out_argument_init_interface(GIArgument *argument,
1664
- G_GNUC_UNUSED GIArgInfo *arg_info,
1665
- GITypeInfo *type_info)
1544
+ rb_gi_return_argument_free_everything_interface(GIArgument *argument,
1545
+ GITypeInfo *type_info)
1666
1546
  {
1667
1547
  GIBaseInfo *interface_info;
1668
1548
  GIInfoType interface_type;
1669
-
1670
- /* TODO: Can we use the following code? */
1671
- /*
1672
- if (!g_arg_info_is_caller_allocates(arg_info)) {
1673
- argument->v_pointer = ALLOC(gpointer);
1674
- return;
1675
- }
1676
- */
1549
+ GType gtype;
1677
1550
 
1678
1551
  interface_info = g_type_info_get_interface(type_info);
1679
1552
  interface_type = g_base_info_get_type(interface_info);
1553
+ gtype = g_registered_type_info_get_g_type(interface_info);
1554
+ g_base_info_unref(interface_info);
1680
1555
 
1681
1556
  switch (interface_type) {
1682
1557
  case GI_INFO_TYPE_INVALID:
1558
+ rb_raise(rb_eNotImpError,
1559
+ "TODO: free GIArgument(interface)[invalid] everything");
1560
+ break;
1683
1561
  case GI_INFO_TYPE_FUNCTION:
1562
+ rb_raise(rb_eNotImpError,
1563
+ "TODO: free GIArgument(interface)[function] everything");
1564
+ break;
1684
1565
  case GI_INFO_TYPE_CALLBACK:
1685
1566
  rb_raise(rb_eNotImpError,
1686
- "TODO: allocates GIArgument(interface)[%s] for output",
1687
- g_info_type_to_string(interface_type));
1567
+ "TODO: free GIArgument(interface)[callback] everything");
1688
1568
  break;
1689
1569
  case GI_INFO_TYPE_STRUCT:
1690
- {
1691
- gsize struct_size;
1692
-
1693
- /* Should we care gtype?
1694
- Related: rb_gi_out_argument_fin_interface() */
1695
- struct_size = g_struct_info_get_size(interface_info);
1696
- argument->v_pointer = xmalloc(struct_size);
1697
- memset(argument->v_pointer, 0, struct_size);
1698
- }
1699
- break;
1570
+ rb_gi_return_argument_free_everything_interface_struct(argument, gtype);
1571
+ break;
1700
1572
  case GI_INFO_TYPE_BOXED:
1701
- rb_raise(rb_eNotImpError,
1702
- "TODO: allocates GIArgument(interface)[%s] for output",
1703
- g_info_type_to_string(interface_type));
1704
- break;
1573
+ rb_raise(rb_eNotImpError,
1574
+ "TODO: free GIArgument(interface)[boxed] everything");
1575
+ break;
1705
1576
  case GI_INFO_TYPE_ENUM:
1706
- {
1707
- gint *pointer = ALLOC(gint);
1708
- *pointer = 0;
1709
- argument->v_pointer = pointer;
1710
- }
1711
- break;
1577
+ rb_raise(rb_eNotImpError,
1578
+ "TODO: free GIArgument(interface)[enum] everything");
1579
+ break;
1712
1580
  case GI_INFO_TYPE_FLAGS:
1713
- {
1714
- guint *pointer = ALLOC(guint);
1715
- *pointer = 0;
1716
- argument->v_pointer = pointer;
1717
- }
1718
- break;
1581
+ rb_raise(rb_eNotImpError,
1582
+ "TODO: free GIArgument(interface)[flags] everything");
1583
+ break;
1719
1584
  case GI_INFO_TYPE_OBJECT:
1720
- case GI_INFO_TYPE_INTERFACE:
1721
- {
1722
- gpointer *pointer = ALLOC(gpointer);
1723
- *pointer = NULL;
1724
- argument->v_pointer = pointer;
1725
- }
1726
- break;
1727
- case GI_INFO_TYPE_CONSTANT:
1728
- case GI_INFO_TYPE_INVALID_0:
1729
- case GI_INFO_TYPE_UNION:
1730
- case GI_INFO_TYPE_VALUE:
1731
- case GI_INFO_TYPE_SIGNAL:
1732
- case GI_INFO_TYPE_VFUNC:
1733
- case GI_INFO_TYPE_PROPERTY:
1734
- case GI_INFO_TYPE_FIELD:
1735
- case GI_INFO_TYPE_ARG:
1736
- case GI_INFO_TYPE_TYPE:
1737
- case GI_INFO_TYPE_UNRESOLVED:
1738
- rb_raise(rb_eNotImpError,
1739
- "TODO: allocates GIArgument(interface)[%s] for output",
1740
- g_info_type_to_string(interface_type));
1741
- break;
1742
- default:
1743
- g_assert_not_reached();
1744
- break;
1745
- }
1746
-
1747
- g_base_info_unref(interface_info);
1748
- }
1749
-
1750
- void
1751
- rb_gi_out_argument_init(GIArgument *argument, GIArgInfo *arg_info)
1752
- {
1753
- GITypeInfo type_info;
1754
- GITypeTag type_tag;
1755
-
1756
- memset(argument, 0, sizeof(GIArgument));
1757
-
1758
- g_arg_info_load_type(arg_info, &type_info);
1759
- type_tag = g_type_info_get_tag(&type_info);
1760
- switch (type_tag) {
1761
- case GI_TYPE_TAG_VOID:
1762
- if (g_type_info_is_pointer(&type_info)) {
1763
- gpointer *pointer = ALLOC(gpointer);
1764
- *pointer = NULL;
1765
- argument->v_pointer = pointer;
1766
- }
1767
- break;
1768
- case GI_TYPE_TAG_BOOLEAN:
1769
- {
1770
- gboolean *pointer = ALLOC(gboolean);
1771
- *pointer = FALSE;
1772
- argument->v_pointer = pointer;
1773
- }
1774
- break;
1775
- case GI_TYPE_TAG_INT8:
1776
- {
1777
- gint8 *pointer = ALLOC(gint8);
1778
- *pointer = 0;
1779
- argument->v_pointer = pointer;
1780
- }
1781
- break;
1782
- case GI_TYPE_TAG_UINT8:
1783
- {
1784
- guint8 *pointer = ALLOC(guint8);
1785
- *pointer = 0;
1786
- argument->v_pointer = pointer;
1787
- }
1788
- break;
1789
- case GI_TYPE_TAG_INT16:
1790
- {
1791
- gint16 *pointer = ALLOC(gint16);
1792
- *pointer = 0;
1793
- argument->v_pointer = pointer;
1794
- }
1795
- break;
1796
- case GI_TYPE_TAG_UINT16:
1797
- {
1798
- guint16 *pointer = ALLOC(guint16);
1799
- *pointer = 0;
1800
- argument->v_pointer = pointer;
1801
- }
1802
- break;
1803
- case GI_TYPE_TAG_INT32:
1804
- {
1805
- gint32 *pointer = ALLOC(gint32);
1806
- *pointer = 0;
1807
- argument->v_pointer = pointer;
1808
- }
1809
- break;
1810
- case GI_TYPE_TAG_UINT32:
1811
- {
1812
- guint32 *pointer = ALLOC(guint32);
1813
- *pointer = 0;
1814
- argument->v_pointer = pointer;
1815
- }
1816
- break;
1817
- case GI_TYPE_TAG_INT64:
1818
- {
1819
- gint64 *pointer = ALLOC(gint64);
1820
- *pointer = 0;
1821
- argument->v_pointer = pointer;
1822
- }
1823
- break;
1824
- case GI_TYPE_TAG_UINT64:
1825
- {
1826
- guint64 *pointer = ALLOC(guint64);
1827
- *pointer = 0;
1828
- argument->v_pointer = pointer;
1829
- }
1830
- break;
1831
- case GI_TYPE_TAG_FLOAT:
1832
- {
1833
- gfloat *pointer = ALLOC(gfloat);
1834
- *pointer = 0.0;
1835
- argument->v_pointer = pointer;
1836
- }
1837
- break;
1838
- case GI_TYPE_TAG_DOUBLE:
1839
- {
1840
- gdouble *pointer = ALLOC(gdouble);
1841
- *pointer = 0.0;
1842
- argument->v_pointer = pointer;
1843
- }
1844
- break;
1845
- case GI_TYPE_TAG_GTYPE:
1846
- {
1847
- GType *pointer = ALLOC(GType);
1848
- *pointer = G_TYPE_INVALID;
1849
- argument->v_pointer = pointer;
1850
- }
1851
- break;
1852
- case GI_TYPE_TAG_UTF8:
1853
- case GI_TYPE_TAG_FILENAME:
1854
- {
1855
- gchar **pointer = ALLOC(gchar *);
1856
- *pointer = NULL;
1857
- argument->v_pointer = pointer;
1858
- }
1859
- break;
1860
- case GI_TYPE_TAG_ARRAY:
1861
- rb_gi_out_argument_init_array(argument, arg_info, &type_info);
1862
- break;
1863
- case GI_TYPE_TAG_INTERFACE:
1864
- rb_gi_out_argument_init_interface(argument, arg_info, &type_info);
1865
- break;
1866
- case GI_TYPE_TAG_GLIST:
1867
- case GI_TYPE_TAG_GSLIST:
1868
- case GI_TYPE_TAG_GHASH:
1869
- {
1870
- gpointer *pointer = ALLOC(gpointer);
1871
- *pointer = NULL;
1872
- argument->v_pointer = pointer;
1873
- }
1874
- break;
1875
- case GI_TYPE_TAG_ERROR:
1876
- {
1877
- GError **pointer = ALLOC(GError *);
1878
- *pointer = NULL;
1879
- argument->v_pointer = pointer;
1880
- }
1881
- break;
1882
- case GI_TYPE_TAG_UNICHAR:
1883
- {
1884
- gunichar *pointer = ALLOC(gunichar);
1885
- *pointer = 0;
1886
- argument->v_pointer = pointer;
1887
- }
1888
- break;
1889
- default:
1890
- g_assert_not_reached();
1891
- break;
1892
- }
1893
- }
1894
-
1895
- VALUE
1896
- rb_gi_out_argument_to_ruby(GIArgument *argument,
1897
- GIArgInfo *arg_info,
1898
- GArray *in_args,
1899
- GArray *out_args,
1900
- GPtrArray *args_metadata)
1901
- {
1902
- GIArgument normalized_argument;
1903
- GITypeInfo type_info;
1904
- GITypeTag type_tag;
1905
- gboolean duplicate = FALSE;
1906
-
1907
- memset(&normalized_argument, 0, sizeof(GIArgument));
1908
- g_arg_info_load_type(arg_info, &type_info);
1909
- type_tag = g_type_info_get_tag(&type_info);
1910
- switch (type_tag) {
1911
- case GI_TYPE_TAG_VOID:
1912
- if (g_type_info_is_pointer(&type_info)) {
1913
- normalized_argument.v_pointer = *((gpointer *)(argument->v_pointer));
1914
- }
1915
- break;
1916
- case GI_TYPE_TAG_BOOLEAN:
1917
- normalized_argument.v_boolean = *((gboolean *)(argument->v_pointer));
1918
- break;
1919
- case GI_TYPE_TAG_INT8:
1920
- normalized_argument.v_int8 = *((gint8 *)(argument->v_pointer));
1921
- break;
1922
- case GI_TYPE_TAG_UINT8:
1923
- normalized_argument.v_uint8 = *((guint8 *)(argument->v_pointer));
1924
- break;
1925
- case GI_TYPE_TAG_INT16:
1926
- normalized_argument.v_int16 = *((gint16 *)(argument->v_pointer));
1927
- break;
1928
- case GI_TYPE_TAG_UINT16:
1929
- normalized_argument.v_uint16 = *((guint16 *)(argument->v_pointer));
1930
- break;
1931
- case GI_TYPE_TAG_INT32:
1932
- normalized_argument.v_int32 = *((gint32 *)(argument->v_pointer));
1933
- break;
1934
- case GI_TYPE_TAG_UINT32:
1935
- normalized_argument.v_uint32 = *((guint32 *)(argument->v_pointer));
1936
- break;
1937
- case GI_TYPE_TAG_INT64:
1938
- normalized_argument.v_int64 = *((gint64 *)(argument->v_pointer));
1939
- break;
1940
- case GI_TYPE_TAG_UINT64:
1941
- normalized_argument.v_uint64 = *((guint64 *)(argument->v_pointer));
1942
- break;
1943
- case GI_TYPE_TAG_FLOAT:
1944
- normalized_argument.v_float = *((gfloat *)(argument->v_pointer));
1945
- break;
1946
- case GI_TYPE_TAG_DOUBLE:
1947
- normalized_argument.v_double = *((gdouble *)(argument->v_pointer));
1948
- break;
1949
- case GI_TYPE_TAG_GTYPE:
1950
- normalized_argument.v_size = *((GType *)(argument->v_pointer));
1951
- break;
1952
- case GI_TYPE_TAG_UTF8:
1953
- case GI_TYPE_TAG_FILENAME:
1954
- normalized_argument.v_string = *((gchar **)(argument->v_pointer));
1955
- break;
1956
- case GI_TYPE_TAG_ARRAY:
1957
- case GI_TYPE_TAG_INTERFACE:
1958
- case GI_TYPE_TAG_GLIST:
1959
- case GI_TYPE_TAG_GSLIST:
1960
- case GI_TYPE_TAG_GHASH:
1961
- if (g_arg_info_is_caller_allocates(arg_info)) {
1962
- duplicate = TRUE;
1963
- normalized_argument.v_pointer = argument->v_pointer;
1964
- } else {
1965
- normalized_argument.v_pointer = *((gpointer *)(argument->v_pointer));
1966
- }
1967
- break;
1968
- case GI_TYPE_TAG_ERROR:
1969
- normalized_argument.v_pointer = *((GError **)(argument->v_pointer));
1970
- break;
1971
- case GI_TYPE_TAG_UNICHAR:
1972
- normalized_argument.v_uint32 = *((guint32 *)(argument->v_pointer));
1973
- break;
1974
- default:
1975
- g_assert_not_reached();
1976
- break;
1977
- }
1978
-
1979
- return rb_gi_argument_to_ruby(&normalized_argument,
1980
- duplicate,
1981
- &type_info,
1982
- in_args,
1983
- out_args,
1984
- args_metadata);
1985
- }
1986
-
1987
-
1988
- static void
1989
- rb_gi_out_argument_fin_array_c(GIArgument *argument,
1990
- G_GNUC_UNUSED GIArgInfo *arg_info,
1991
- G_GNUC_UNUSED GITypeInfo *array_type_info,
1992
- GITypeInfo *element_type_info,
1993
- GITransfer transfer)
1994
- {
1995
- GITypeTag element_type_tag;
1996
-
1997
- element_type_tag = g_type_info_get_tag(element_type_info);
1998
-
1999
- switch (element_type_tag) {
2000
- case GI_TYPE_TAG_VOID:
2001
- case GI_TYPE_TAG_BOOLEAN:
2002
- case GI_TYPE_TAG_INT8:
2003
- g_base_info_unref(element_type_info);
2004
- rb_raise(rb_eNotImpError,
2005
- "TODO: free out GIArgument(array)[c][%s]",
2006
- g_type_tag_to_string(element_type_tag));
2007
- break;
2008
- case GI_TYPE_TAG_UINT8:
2009
- if (transfer == GI_TRANSFER_EVERYTHING) {
2010
- g_free(*((guint8 **)(argument->v_pointer)));
2011
- }
2012
- xfree(argument->v_pointer);
2013
- break;
2014
- case GI_TYPE_TAG_INT16:
2015
- case GI_TYPE_TAG_UINT16:
2016
- case GI_TYPE_TAG_INT32:
2017
- case GI_TYPE_TAG_UINT32:
2018
- case GI_TYPE_TAG_INT64:
2019
- case GI_TYPE_TAG_UINT64:
2020
- case GI_TYPE_TAG_FLOAT:
2021
- case GI_TYPE_TAG_DOUBLE:
2022
- case GI_TYPE_TAG_GTYPE:
2023
- g_base_info_unref(element_type_info);
2024
- rb_raise(rb_eNotImpError,
2025
- "TODO: free out GIArgument(array)[c][%s]",
2026
- g_type_tag_to_string(element_type_tag));
2027
- break;
2028
- case GI_TYPE_TAG_UTF8:
2029
- if (transfer != GI_TRANSFER_NOTHING) {
2030
- g_free(*((gchar **)argument->v_pointer));
2031
- }
2032
- xfree(argument->v_pointer);
2033
- break;
2034
- case GI_TYPE_TAG_FILENAME:
2035
- case GI_TYPE_TAG_ARRAY:
2036
- g_base_info_unref(element_type_info);
2037
- rb_raise(rb_eNotImpError,
2038
- "TODO: free out GIArgument(array)[c][%s]",
2039
- g_type_tag_to_string(element_type_tag));
2040
- break;
2041
- case GI_TYPE_TAG_INTERFACE:
2042
- if (transfer == GI_TRANSFER_EVERYTHING) {
2043
- g_base_info_unref(element_type_info);
2044
- rb_raise(rb_eNotImpError,
2045
- "TODO: free out transfer GIArgument(array)[c][%s][%s]",
2046
- g_type_tag_to_string(element_type_tag),
2047
- rb_gi_transfer_to_string(transfer));
2048
- }
2049
- if (transfer != GI_TRANSFER_NOTHING) {
2050
- g_free(*((gpointer *)argument->v_pointer));
2051
- }
2052
- xfree(argument->v_pointer);
2053
- break;
2054
- case GI_TYPE_TAG_GLIST:
2055
- case GI_TYPE_TAG_GSLIST:
2056
- case GI_TYPE_TAG_GHASH:
2057
- case GI_TYPE_TAG_ERROR:
2058
- case GI_TYPE_TAG_UNICHAR:
2059
- g_base_info_unref(element_type_info);
2060
- rb_raise(rb_eNotImpError,
2061
- "TODO: free out GIArgument(array)[c][%s]",
2062
- g_type_tag_to_string(element_type_tag));
2063
- break;
2064
- default:
2065
- g_base_info_unref(element_type_info);
2066
- g_assert_not_reached();
2067
- break;
2068
- }
2069
- }
2070
-
2071
- static void
2072
- rb_gi_out_argument_fin_array(GIArgument *argument,
2073
- GIArgInfo *arg_info,
2074
- GITypeInfo *array_type_info,
2075
- GITransfer transfer)
2076
- {
2077
- GIArrayType array_type;
2078
- GITypeInfo *element_type_info;
2079
- GITypeTag element_type_tag;
2080
-
2081
- array_type = g_type_info_get_array_type(array_type_info);
2082
- element_type_info = g_type_info_get_param_type(array_type_info, 0);
2083
- element_type_tag = g_type_info_get_tag(element_type_info);
2084
-
2085
- switch (array_type) {
2086
- case GI_ARRAY_TYPE_C:
2087
- rb_gi_out_argument_fin_array_c(argument,
2088
- arg_info,
2089
- array_type_info,
2090
- element_type_info,
2091
- transfer);
2092
- break;
2093
- case GI_ARRAY_TYPE_ARRAY:
2094
- if (transfer != GI_TRANSFER_NOTHING) {
2095
- g_base_info_unref(element_type_info);
2096
- rb_raise(rb_eNotImpError,
2097
- "TODO: free out transfer GIArgument(array)[ptr-array][%s][%s]",
2098
- g_type_tag_to_string(element_type_tag),
2099
- rb_gi_transfer_to_string(transfer));
2100
- }
2101
- g_array_free(argument->v_pointer, TRUE);
2102
- break;
2103
- case GI_ARRAY_TYPE_PTR_ARRAY:
2104
- g_base_info_unref(element_type_info);
2105
- rb_raise(rb_eNotImpError,
2106
- "TODO: free out GIArgument(array)[ptr-array][%s]",
2107
- g_type_tag_to_string(element_type_tag));
2108
- break;
2109
- case GI_ARRAY_TYPE_BYTE_ARRAY:
2110
- g_base_info_unref(element_type_info);
2111
- rb_raise(rb_eNotImpError,
2112
- "TODO: free out GIArgument(array)[byte-array][%s]",
2113
- g_type_tag_to_string(element_type_tag));
2114
- break;
2115
- default:
2116
- g_base_info_unref(element_type_info);
2117
- g_assert_not_reached();
2118
- break;
2119
- }
2120
-
2121
- g_base_info_unref(element_type_info);
2122
- }
2123
-
2124
- static void
2125
- rb_gi_out_argument_fin_interface(GIArgument *argument,
2126
- G_GNUC_UNUSED GIArgInfo *arg_info,
2127
- GITypeInfo *interface_type_info,
2128
- GITransfer transfer)
2129
- {
2130
- GIBaseInfo *interface_info;
2131
- GIInfoType interface_type;
2132
-
2133
- interface_info = g_type_info_get_interface(interface_type_info);
2134
- interface_type = g_base_info_get_type(interface_info);
2135
- g_base_info_unref(interface_info);
2136
-
2137
- switch (interface_type) {
2138
- case GI_INFO_TYPE_INVALID:
2139
- case GI_INFO_TYPE_FUNCTION:
2140
- case GI_INFO_TYPE_CALLBACK:
2141
- rb_raise(rb_eNotImpError,
2142
- "TODO: free out transfer GIArgument(interface)[%s][%s]",
2143
- g_info_type_to_string(interface_type),
2144
- rb_gi_transfer_to_string(transfer));
2145
- break;
2146
- case GI_INFO_TYPE_STRUCT:
2147
- /* Should we care gtype?
2148
- Related: rb_gi_out_argument_init_interface() */
2149
- xfree(argument->v_pointer);
2150
- break;
2151
- case GI_INFO_TYPE_BOXED:
2152
- rb_raise(rb_eNotImpError,
2153
- "TODO: free out transfer GIArgument(interface)[%s][%s]",
2154
- g_info_type_to_string(interface_type),
2155
- rb_gi_transfer_to_string(transfer));
2156
- break;
2157
- case GI_INFO_TYPE_ENUM:
2158
- case GI_INFO_TYPE_FLAGS:
2159
- break;
2160
- case GI_INFO_TYPE_OBJECT:
2161
- switch (transfer) {
2162
- case GI_TRANSFER_NOTHING:
2163
- break;
2164
- case GI_TRANSFER_CONTAINER:
2165
- case GI_TRANSFER_EVERYTHING:
2166
- {
2167
- GObject *object = *((GObject **)argument->v_pointer);
2168
- if (object) {
2169
- g_object_unref(object);
2170
- }
2171
- }
2172
- break;
2173
- default:
2174
- rb_raise(rb_eNotImpError,
2175
- "TODO: free out transfer GIArgument(interface)[%s][%s]",
2176
- g_info_type_to_string(interface_type),
2177
- rb_gi_transfer_to_string(transfer));
2178
- break;
2179
- }
2180
- xfree(argument->v_pointer);
2181
- break;
2182
- case GI_INFO_TYPE_INTERFACE:
2183
- if (transfer != GI_TRANSFER_NOTHING) {
2184
- rb_raise(rb_eNotImpError,
2185
- "TODO: free out transfer GIArgument(interface)[%s][%s]",
2186
- g_info_type_to_string(interface_type),
2187
- rb_gi_transfer_to_string(transfer));
2188
- }
2189
- xfree(argument->v_pointer);
2190
- break;
2191
- case GI_INFO_TYPE_CONSTANT:
2192
- case GI_INFO_TYPE_INVALID_0:
2193
- case GI_INFO_TYPE_UNION:
2194
- case GI_INFO_TYPE_VALUE:
2195
- case GI_INFO_TYPE_SIGNAL:
2196
- case GI_INFO_TYPE_VFUNC:
2197
- case GI_INFO_TYPE_PROPERTY:
2198
- case GI_INFO_TYPE_FIELD:
2199
- case GI_INFO_TYPE_ARG:
2200
- case GI_INFO_TYPE_TYPE:
2201
- case GI_INFO_TYPE_UNRESOLVED:
2202
- rb_raise(rb_eNotImpError,
2203
- "TODO: free out transfer GIArgument(interface)[%s][%s]",
2204
- g_info_type_to_string(interface_type),
2205
- rb_gi_transfer_to_string(transfer));
2206
- break;
2207
- default:
2208
- g_assert_not_reached();
2209
- break;
2210
- }
2211
- }
2212
-
2213
- void
2214
- rb_gi_out_argument_fin(GIArgument *argument, GIArgInfo *arg_info)
2215
- {
2216
- GITypeInfo type_info;
2217
- GITypeTag type_tag;
2218
- GITransfer transfer;
2219
-
2220
- if (g_arg_info_get_direction(arg_info) != GI_DIRECTION_OUT) {
2221
- return;
2222
- }
2223
-
2224
- g_arg_info_load_type(arg_info, &type_info);
2225
- type_tag = g_type_info_get_tag(&type_info);
2226
- transfer = g_arg_info_get_ownership_transfer(arg_info);
2227
-
2228
- switch (type_tag) {
2229
- case GI_TYPE_TAG_VOID:
2230
- case GI_TYPE_TAG_BOOLEAN:
2231
- case GI_TYPE_TAG_INT8:
2232
- case GI_TYPE_TAG_UINT8:
2233
- case GI_TYPE_TAG_INT16:
2234
- case GI_TYPE_TAG_UINT16:
2235
- case GI_TYPE_TAG_INT32:
2236
- case GI_TYPE_TAG_UINT32:
2237
- case GI_TYPE_TAG_INT64:
2238
- case GI_TYPE_TAG_UINT64:
2239
- case GI_TYPE_TAG_FLOAT:
2240
- case GI_TYPE_TAG_DOUBLE:
2241
- case GI_TYPE_TAG_GTYPE:
2242
- xfree(argument->v_pointer);
2243
- break;
2244
- case GI_TYPE_TAG_UTF8:
2245
- if (transfer != GI_TRANSFER_NOTHING) {
2246
- g_free(*((gchar **)argument->v_pointer));
2247
- }
2248
- xfree(argument->v_pointer);
2249
- break;
2250
- case GI_TYPE_TAG_FILENAME:
2251
- rb_raise(rb_eNotImpError,
2252
- "TODO: free out GIArgument(%s)",
2253
- g_type_tag_to_string(type_tag));
2254
- break;
2255
- case GI_TYPE_TAG_ARRAY:
2256
- rb_gi_out_argument_fin_array(argument, arg_info, &type_info, transfer);
2257
- break;
2258
- case GI_TYPE_TAG_INTERFACE:
2259
- rb_gi_out_argument_fin_interface(argument,
2260
- arg_info,
2261
- &type_info,
2262
- transfer);
2263
- break;
2264
- case GI_TYPE_TAG_GLIST:
2265
- if (transfer == GI_TRANSFER_EVERYTHING) {
2266
- rb_raise(rb_eNotImpError,
2267
- "TODO: free out transfer GIArgument(%s)[%s]",
2268
- g_type_tag_to_string(type_tag),
2269
- rb_gi_transfer_to_string(transfer));
2270
- }
2271
- if (transfer != GI_TRANSFER_NOTHING) {
2272
- g_list_free(*((GList **)argument->v_pointer));
2273
- }
2274
- xfree(argument->v_pointer);
2275
- break;
2276
- case GI_TYPE_TAG_GSLIST:
2277
- case GI_TYPE_TAG_GHASH:
2278
- case GI_TYPE_TAG_ERROR:
2279
- if (transfer != GI_TRANSFER_NOTHING) {
2280
- rb_raise(rb_eNotImpError,
2281
- "TODO: free out transfer GIArgument(%s)[%s]",
2282
- g_type_tag_to_string(type_tag),
2283
- rb_gi_transfer_to_string(transfer));
2284
- }
2285
- xfree(argument->v_pointer);
2286
- break;
2287
- case GI_TYPE_TAG_UNICHAR:
2288
- xfree(argument->v_pointer);
2289
- break;
2290
- default:
2291
- g_assert_not_reached();
2292
- break;
2293
- }
2294
- }
2295
-
2296
- static void
2297
- rb_gi_return_argument_free_container(GIArgument *argument,
2298
- GITypeInfo *type_info)
2299
- {
2300
- GITypeTag type_tag;
2301
-
2302
- type_tag = g_type_info_get_tag(type_info);
2303
-
2304
- switch (type_tag) {
2305
- case GI_TYPE_TAG_VOID:
2306
- case GI_TYPE_TAG_BOOLEAN:
2307
- case GI_TYPE_TAG_INT8:
2308
- case GI_TYPE_TAG_UINT8:
2309
- case GI_TYPE_TAG_INT16:
2310
- case GI_TYPE_TAG_UINT16:
2311
- case GI_TYPE_TAG_INT32:
2312
- case GI_TYPE_TAG_UINT32:
2313
- case GI_TYPE_TAG_INT64:
2314
- case GI_TYPE_TAG_UINT64:
2315
- case GI_TYPE_TAG_FLOAT:
2316
- case GI_TYPE_TAG_DOUBLE:
2317
- case GI_TYPE_TAG_GTYPE:
2318
- case GI_TYPE_TAG_UTF8:
2319
- case GI_TYPE_TAG_FILENAME:
2320
- rb_raise(rb_eNotImpError,
2321
- "TODO: free GIArgument(%s) as container",
2322
- g_type_tag_to_string(type_tag));
2323
- break;
2324
- case GI_TYPE_TAG_ARRAY:
2325
- g_free(argument->v_pointer);
2326
- break;
2327
- case GI_TYPE_TAG_INTERFACE:
2328
- rb_raise(rb_eNotImpError,
2329
- "TODO: free GIArgument(%s) as container",
2330
- g_type_tag_to_string(type_tag));
2331
- break;
2332
- case GI_TYPE_TAG_GLIST:
2333
- g_list_free(argument->v_pointer);
2334
- break;
2335
- case GI_TYPE_TAG_GSLIST:
2336
- g_slist_free(argument->v_pointer);
2337
- break;
2338
- case GI_TYPE_TAG_GHASH:
2339
- g_hash_table_unref(argument->v_pointer);
2340
- break;
2341
- case GI_TYPE_TAG_ERROR:
2342
- case GI_TYPE_TAG_UNICHAR:
2343
- rb_raise(rb_eNotImpError,
2344
- "TODO: free GIArgument(%s) as container",
2345
- g_type_tag_to_string(type_tag));
2346
- break;
2347
- default:
2348
- g_assert_not_reached();
2349
- break;
2350
- }
2351
- }
2352
-
2353
- static void
2354
- rb_gi_return_argument_free_everything_array_c(GIArgument *argument,
2355
- GITypeInfo *type_info)
2356
- {
2357
- GITypeInfo *element_type_info;
2358
- GITypeTag element_type_tag;
2359
-
2360
- element_type_info = g_type_info_get_param_type(type_info, 0);
2361
- element_type_tag = g_type_info_get_tag(element_type_info);
2362
- g_base_info_unref(element_type_info);
2363
-
2364
- switch (element_type_tag) {
2365
- case GI_TYPE_TAG_VOID:
2366
- rb_raise(rb_eNotImpError,
2367
- "TODO: free GIArgument(array)[c][%s] everything",
2368
- g_type_tag_to_string(element_type_tag));
2369
- break;
2370
- case GI_TYPE_TAG_BOOLEAN:
2371
- case GI_TYPE_TAG_INT8:
2372
- case GI_TYPE_TAG_UINT8:
2373
- case GI_TYPE_TAG_INT16:
2374
- case GI_TYPE_TAG_UINT16:
2375
- case GI_TYPE_TAG_INT32:
2376
- case GI_TYPE_TAG_UINT32:
2377
- case GI_TYPE_TAG_INT64:
2378
- case GI_TYPE_TAG_UINT64:
2379
- case GI_TYPE_TAG_FLOAT:
2380
- case GI_TYPE_TAG_DOUBLE:
2381
- g_free(argument->v_pointer);
2382
- break;
2383
- case GI_TYPE_TAG_GTYPE:
2384
- rb_raise(rb_eNotImpError,
2385
- "TODO: free GIArgument(array)[c][%s] everything",
2386
- g_type_tag_to_string(element_type_tag));
2387
- break;
2388
- case GI_TYPE_TAG_UTF8:
2389
- g_strfreev(argument->v_pointer);
2390
- break;
2391
- case GI_TYPE_TAG_FILENAME:
2392
- g_strfreev(argument->v_pointer);
2393
- break;
2394
- case GI_TYPE_TAG_ARRAY:
2395
- case GI_TYPE_TAG_INTERFACE:
2396
- case GI_TYPE_TAG_GLIST:
2397
- case GI_TYPE_TAG_GSLIST:
2398
- case GI_TYPE_TAG_GHASH:
2399
- case GI_TYPE_TAG_ERROR:
2400
- case GI_TYPE_TAG_UNICHAR:
2401
- rb_raise(rb_eNotImpError,
2402
- "TODO: free GIArgument(array)[c][%s] everything",
2403
- g_type_tag_to_string(element_type_tag));
2404
- break;
2405
- default:
2406
- g_assert_not_reached();
2407
- break;
2408
- }
2409
- }
2410
-
2411
- static void
2412
- rb_gi_return_argument_free_everything_array(GIArgument *argument,
2413
- GITypeInfo *type_info)
2414
- {
2415
- switch (g_type_info_get_array_type(type_info)) {
2416
- case GI_ARRAY_TYPE_C:
2417
- rb_gi_return_argument_free_everything_array_c(argument, type_info);
2418
- break;
2419
- case GI_ARRAY_TYPE_ARRAY:
2420
- g_array_free(argument->v_pointer, TRUE);
2421
- break;
2422
- case GI_ARRAY_TYPE_PTR_ARRAY:
2423
- g_ptr_array_free(argument->v_pointer, TRUE);
2424
- break;
2425
- case GI_ARRAY_TYPE_BYTE_ARRAY:
2426
- g_ptr_array_free(argument->v_pointer, TRUE);
2427
- break;
2428
- default:
2429
- g_assert_not_reached();
2430
- break;
2431
- }
2432
- }
2433
-
2434
- static void
2435
- rb_gi_return_argument_free_everything_interface_struct(GIArgument *argument,
2436
- GType gtype)
2437
- {
2438
- if (!argument->v_pointer) {
2439
- return;
2440
- }
2441
-
2442
- if (!gtype) {
2443
- xfree(argument->v_pointer);
2444
- }
2445
-
2446
- if (G_TYPE_IS_BOXED(gtype)) {
2447
- g_boxed_free(gtype, argument->v_pointer);
2448
- } else {
2449
- rbgobj_instance_unref(argument->v_pointer);
2450
- }
2451
- }
2452
-
2453
- static void
2454
- rb_gi_return_argument_free_everything_interface(GIArgument *argument,
2455
- GITypeInfo *type_info)
2456
- {
2457
- GIBaseInfo *interface_info;
2458
- GIInfoType interface_type;
2459
- GType gtype;
2460
-
2461
- interface_info = g_type_info_get_interface(type_info);
2462
- interface_type = g_base_info_get_type(interface_info);
2463
- gtype = g_registered_type_info_get_g_type(interface_info);
2464
- g_base_info_unref(interface_info);
2465
-
2466
- switch (interface_type) {
2467
- case GI_INFO_TYPE_INVALID:
2468
- rb_raise(rb_eNotImpError,
2469
- "TODO: free GIArgument(interface)[invalid] everything");
2470
- break;
2471
- case GI_INFO_TYPE_FUNCTION:
2472
- rb_raise(rb_eNotImpError,
2473
- "TODO: free GIArgument(interface)[function] everything");
2474
- break;
2475
- case GI_INFO_TYPE_CALLBACK:
2476
- rb_raise(rb_eNotImpError,
2477
- "TODO: free GIArgument(interface)[callback] everything");
2478
- break;
2479
- case GI_INFO_TYPE_STRUCT:
2480
- rb_gi_return_argument_free_everything_interface_struct(argument, gtype);
2481
- break;
2482
- case GI_INFO_TYPE_BOXED:
2483
- rb_raise(rb_eNotImpError,
2484
- "TODO: free GIArgument(interface)[boxed] everything");
2485
- break;
2486
- case GI_INFO_TYPE_ENUM:
2487
- rb_raise(rb_eNotImpError,
2488
- "TODO: free GIArgument(interface)[enum] everything");
2489
- break;
2490
- case GI_INFO_TYPE_FLAGS:
2491
- rb_raise(rb_eNotImpError,
2492
- "TODO: free GIArgument(interface)[flags] everything");
2493
- break;
2494
- case GI_INFO_TYPE_OBJECT:
2495
- if (argument->v_pointer) {
2496
- GObject *object = argument->v_pointer;
2497
- if (g_object_is_floating(object)) {
2498
- g_object_ref_sink(object);
2499
- }
2500
- g_object_unref(object);
2501
- }
2502
- break;
2503
- case GI_INFO_TYPE_INTERFACE:
2504
- if (argument->v_pointer) {
2505
- g_object_unref(argument->v_pointer);
2506
- }
2507
- break;
2508
- case GI_INFO_TYPE_CONSTANT:
2509
- rb_raise(rb_eNotImpError,
2510
- "TODO: free GIArgument(interface)[constant] everything");
2511
- break;
2512
- case GI_INFO_TYPE_INVALID_0:
2513
- g_assert_not_reached();
2514
- break;
2515
- case GI_INFO_TYPE_UNION:
2516
- if (gtype == G_TYPE_NONE) {
2517
- rb_raise(rb_eNotImpError,
2518
- "TODO: free GIArgument(interface)[union] everything");
2519
- } else {
2520
- g_boxed_free(gtype, argument->v_pointer);
2521
- }
2522
- break;
2523
- case GI_INFO_TYPE_VALUE:
2524
- rb_raise(rb_eNotImpError,
2525
- "TODO: free GIArgument(interface)[value] everything");
2526
- break;
2527
- case GI_INFO_TYPE_SIGNAL:
2528
- rb_raise(rb_eNotImpError,
2529
- "TODO: free GIArgument(interface)[signal] everything");
2530
- break;
2531
- case GI_INFO_TYPE_VFUNC:
2532
- rb_raise(rb_eNotImpError,
2533
- "TODO: free GIArgument(interface)[vfunc] everything");
2534
- break;
2535
- case GI_INFO_TYPE_PROPERTY:
2536
- rb_raise(rb_eNotImpError,
2537
- "TODO: free GIArgument(interface)[property] everything");
2538
- break;
2539
- case GI_INFO_TYPE_FIELD:
2540
- rb_raise(rb_eNotImpError,
2541
- "TODO: free GIArgument(interface)[field] everything");
2542
- break;
2543
- case GI_INFO_TYPE_ARG:
2544
- rb_raise(rb_eNotImpError,
2545
- "TODO: free GIArgument(interface)[arg] everything");
2546
- break;
2547
- case GI_INFO_TYPE_TYPE:
2548
- rb_raise(rb_eNotImpError,
2549
- "TODO: free GIArgument(interface)[type] everything");
2550
- break;
2551
- case GI_INFO_TYPE_UNRESOLVED:
2552
- rb_raise(rb_eNotImpError,
2553
- "TODO: free GIArgument(interface)[unresolved] everything");
2554
- break;
2555
- default:
2556
- g_assert_not_reached();
2557
- break;
2558
- }
2559
- }
2560
-
2561
- static void
2562
- rb_gi_boxed_free_callback(gpointer boxed, gpointer user_data)
2563
- {
2564
- GType *gtype = user_data;
2565
-
2566
- g_boxed_free(*gtype, boxed);
2567
- }
2568
-
2569
-
2570
- static void
2571
- rb_gi_return_argument_free_everything_glist_interface(GIArgument *argument,
2572
- G_GNUC_UNUSED GITypeInfo *type_info,
2573
- GITypeInfo *element_type_info)
2574
- {
2575
- GIBaseInfo *interface_info;
2576
- GIInfoType interface_type;
2577
- const gchar *interface_name;
2578
- GType gtype;
2579
-
2580
- interface_info = g_type_info_get_interface(element_type_info);
2581
- interface_type = g_base_info_get_type(interface_info);
2582
- interface_name = g_info_type_to_string(interface_type);
2583
- gtype = g_registered_type_info_get_g_type(interface_info);
2584
- g_base_info_unref(interface_info);
2585
- g_base_info_unref(element_type_info);
2586
-
2587
- switch (interface_type) {
2588
- case GI_INFO_TYPE_INVALID:
2589
- case GI_INFO_TYPE_FUNCTION:
2590
- case GI_INFO_TYPE_CALLBACK:
2591
- rb_raise(rb_eNotImpError,
2592
- "TODO: free GIArgument(GList)[interface(%s)](%s) everything",
2593
- interface_name,
2594
- g_type_name(gtype));
2595
- break;
2596
- case GI_INFO_TYPE_STRUCT:
2597
- if (gtype == G_TYPE_NONE) {
2598
- rb_raise(rb_eNotImpError,
2599
- "TODO: free GIArgument(GList)[interface(%s)](%s) everything",
2600
- interface_name,
2601
- g_type_name(gtype));
2602
- } else {
2603
- g_list_foreach(argument->v_pointer,
2604
- rb_gi_boxed_free_callback,
2605
- &gtype);
2606
- g_list_free(argument->v_pointer);
2607
- }
2608
- break;
2609
- case GI_INFO_TYPE_BOXED:
2610
- g_list_foreach(argument->v_pointer, rb_gi_boxed_free_callback, &gtype);
2611
- g_list_free(argument->v_pointer);
2612
- break;
2613
- case GI_INFO_TYPE_ENUM:
2614
- case GI_INFO_TYPE_FLAGS:
2615
- rb_raise(rb_eNotImpError,
2616
- "TODO: free GIArgument(GList)[interface(%s)](%s) everything",
2617
- interface_name,
2618
- g_type_name(gtype));
2619
- break;
2620
- case GI_INFO_TYPE_OBJECT:
2621
- case GI_INFO_TYPE_INTERFACE:
2622
- g_list_foreach(argument->v_pointer, (GFunc)g_object_unref, NULL);
2623
- g_list_free(argument->v_pointer);
2624
- break;
2625
- case GI_INFO_TYPE_CONSTANT:
2626
- case GI_INFO_TYPE_INVALID_0:
2627
- case GI_INFO_TYPE_UNION:
2628
- case GI_INFO_TYPE_VALUE:
2629
- case GI_INFO_TYPE_SIGNAL:
2630
- case GI_INFO_TYPE_VFUNC:
2631
- case GI_INFO_TYPE_PROPERTY:
2632
- case GI_INFO_TYPE_FIELD:
2633
- case GI_INFO_TYPE_ARG:
2634
- case GI_INFO_TYPE_TYPE:
2635
- case GI_INFO_TYPE_UNRESOLVED:
2636
- rb_raise(rb_eNotImpError,
2637
- "TODO: free GIArgument(GList)[interface(%s)](%s) everything",
2638
- interface_name,
2639
- g_type_name(gtype));
2640
- break;
2641
- default:
2642
- g_assert_not_reached();
2643
- break;
2644
- }
2645
- }
2646
-
2647
- static void
2648
- rb_gi_return_argument_free_everything_glist(GIArgument *argument,
2649
- GITypeInfo *type_info)
2650
- {
2651
- GITypeInfo *element_type_info;
2652
- GITypeTag element_type_tag;
2653
-
2654
- element_type_info = g_type_info_get_param_type(type_info, 0);
2655
- element_type_tag = g_type_info_get_tag(element_type_info);
2656
-
2657
- switch (element_type_tag) {
2658
- case GI_TYPE_TAG_VOID:
2659
- case GI_TYPE_TAG_BOOLEAN:
2660
- case GI_TYPE_TAG_INT8:
2661
- case GI_TYPE_TAG_UINT8:
2662
- case GI_TYPE_TAG_INT16:
2663
- case GI_TYPE_TAG_UINT16:
2664
- case GI_TYPE_TAG_INT32:
2665
- case GI_TYPE_TAG_UINT32:
2666
- case GI_TYPE_TAG_INT64:
2667
- case GI_TYPE_TAG_UINT64:
2668
- case GI_TYPE_TAG_FLOAT:
2669
- case GI_TYPE_TAG_DOUBLE:
2670
- case GI_TYPE_TAG_GTYPE:
2671
- g_base_info_unref(element_type_info);
2672
- rb_raise(rb_eNotImpError,
2673
- "TODO: free GIArgument(GList)[%s] everything",
2674
- g_type_tag_to_string(element_type_tag));
2675
- break;
2676
- case GI_TYPE_TAG_UTF8:
2677
- g_base_info_unref(element_type_info);
2678
- g_list_foreach(argument->v_pointer, (GFunc)g_free, NULL);
2679
- g_list_free(argument->v_pointer);
2680
- break;
2681
- case GI_TYPE_TAG_FILENAME:
2682
- case GI_TYPE_TAG_ARRAY:
2683
- g_base_info_unref(element_type_info);
2684
- rb_raise(rb_eNotImpError,
2685
- "TODO: free GIArgument(GList)[%s] everything",
2686
- g_type_tag_to_string(element_type_tag));
2687
- break;
2688
- case GI_TYPE_TAG_INTERFACE:
2689
- rb_gi_return_argument_free_everything_glist_interface(argument,
2690
- type_info,
2691
- element_type_info);
2692
- break;
2693
- case GI_TYPE_TAG_GLIST:
2694
- case GI_TYPE_TAG_GSLIST:
2695
- case GI_TYPE_TAG_GHASH:
2696
- case GI_TYPE_TAG_ERROR:
2697
- case GI_TYPE_TAG_UNICHAR:
2698
- g_base_info_unref(element_type_info);
2699
- rb_raise(rb_eNotImpError,
2700
- "TODO: free GIArgument(GList)[%s] everything",
2701
- g_type_tag_to_string(element_type_tag));
2702
- break;
2703
- default:
2704
- g_base_info_unref(element_type_info);
2705
- g_assert_not_reached();
2706
- break;
2707
- }
2708
- }
2709
-
2710
- static void
2711
- rb_gi_return_argument_free_everything_gslist_interface(GIArgument *argument,
2712
- G_GNUC_UNUSED GITypeInfo *type_info,
2713
- GITypeInfo *element_type_info)
2714
- {
2715
- GIBaseInfo *interface_info;
2716
- GIInfoType interface_type;
2717
- const gchar *interface_name;
2718
- GType gtype;
2719
-
2720
- interface_info = g_type_info_get_interface(element_type_info);
2721
- interface_type = g_base_info_get_type(interface_info);
2722
- interface_name = g_info_type_to_string(interface_type);
2723
- gtype = g_registered_type_info_get_g_type(interface_info);
2724
- g_base_info_unref(interface_info);
2725
- g_base_info_unref(element_type_info);
2726
-
2727
- switch (interface_type) {
2728
- case GI_INFO_TYPE_INVALID:
2729
- case GI_INFO_TYPE_FUNCTION:
2730
- case GI_INFO_TYPE_CALLBACK:
2731
- rb_raise(rb_eNotImpError,
2732
- "TODO: free GIArgument(GSList)[interface(%s)](%s) everything",
2733
- interface_name,
2734
- g_type_name(gtype));
2735
- break;
2736
- case GI_INFO_TYPE_STRUCT:
2737
- if (gtype == G_TYPE_NONE) {
2738
- rb_raise(rb_eNotImpError,
2739
- "TODO: free GIArgument(GSList)[interface(%s)](%s) everything",
2740
- interface_name,
2741
- g_type_name(gtype));
2742
- } else {
2743
- g_slist_foreach(argument->v_pointer,
2744
- rb_gi_boxed_free_callback,
2745
- &gtype);
2746
- g_slist_free(argument->v_pointer);
2747
- }
2748
- break;
2749
- case GI_INFO_TYPE_BOXED:
2750
- g_slist_foreach(argument->v_pointer, rb_gi_boxed_free_callback, &gtype);
2751
- g_slist_free(argument->v_pointer);
2752
- break;
2753
- case GI_INFO_TYPE_ENUM:
2754
- case GI_INFO_TYPE_FLAGS:
2755
- rb_raise(rb_eNotImpError,
2756
- "TODO: free GIArgument(GSList)[interface(%s)](%s) everything",
2757
- interface_name,
2758
- g_type_name(gtype));
2759
- break;
2760
- case GI_INFO_TYPE_OBJECT:
2761
- case GI_INFO_TYPE_INTERFACE:
2762
- g_slist_foreach(argument->v_pointer, (GFunc)g_object_unref, NULL);
2763
- g_slist_free(argument->v_pointer);
2764
- break;
2765
- case GI_INFO_TYPE_CONSTANT:
2766
- case GI_INFO_TYPE_INVALID_0:
2767
- case GI_INFO_TYPE_UNION:
2768
- case GI_INFO_TYPE_VALUE:
2769
- case GI_INFO_TYPE_SIGNAL:
2770
- case GI_INFO_TYPE_VFUNC:
2771
- case GI_INFO_TYPE_PROPERTY:
2772
- case GI_INFO_TYPE_FIELD:
2773
- case GI_INFO_TYPE_ARG:
2774
- case GI_INFO_TYPE_TYPE:
2775
- case GI_INFO_TYPE_UNRESOLVED:
2776
- rb_raise(rb_eNotImpError,
2777
- "TODO: free GIArgument(GSList)[interface(%s)](%s) everything",
2778
- interface_name,
2779
- g_type_name(gtype));
2780
- break;
2781
- default:
2782
- g_assert_not_reached();
2783
- break;
2784
- }
2785
- }
2786
-
2787
- static void
2788
- rb_gi_return_argument_free_everything_gslist(GIArgument *argument,
2789
- GITypeInfo *type_info)
2790
- {
2791
- GITypeInfo *element_type_info;
2792
- GITypeTag element_type_tag;
2793
-
2794
- if (!argument->v_pointer)
2795
- return;
2796
-
2797
- element_type_info = g_type_info_get_param_type(type_info, 0);
2798
- element_type_tag = g_type_info_get_tag(element_type_info);
2799
-
2800
- switch (element_type_tag) {
2801
- case GI_TYPE_TAG_VOID:
2802
- case GI_TYPE_TAG_BOOLEAN:
2803
- case GI_TYPE_TAG_INT8:
2804
- case GI_TYPE_TAG_UINT8:
2805
- case GI_TYPE_TAG_INT16:
2806
- case GI_TYPE_TAG_UINT16:
2807
- case GI_TYPE_TAG_INT32:
2808
- case GI_TYPE_TAG_UINT32:
2809
- case GI_TYPE_TAG_INT64:
2810
- case GI_TYPE_TAG_UINT64:
2811
- case GI_TYPE_TAG_FLOAT:
2812
- case GI_TYPE_TAG_DOUBLE:
2813
- case GI_TYPE_TAG_GTYPE:
2814
- g_base_info_unref(element_type_info);
2815
- rb_raise(rb_eNotImpError,
2816
- "TODO: free GIArgument(GSList)[%s] everything",
2817
- g_type_tag_to_string(element_type_tag));
2818
- break;
2819
- case GI_TYPE_TAG_UTF8:
2820
- case GI_TYPE_TAG_FILENAME:
2821
- g_base_info_unref(element_type_info);
2822
- g_slist_foreach(argument->v_pointer, (GFunc)g_free, NULL);
2823
- g_slist_free(argument->v_pointer);
2824
- break;
2825
- case GI_TYPE_TAG_ARRAY:
2826
- g_base_info_unref(element_type_info);
2827
- rb_raise(rb_eNotImpError,
2828
- "TODO: free GIArgument(GSList)[%s] everything",
2829
- g_type_tag_to_string(element_type_tag));
2830
- break;
2831
- case GI_TYPE_TAG_INTERFACE:
2832
- rb_gi_return_argument_free_everything_gslist_interface(argument,
2833
- type_info,
2834
- element_type_info);
2835
- break;
2836
- case GI_TYPE_TAG_GLIST:
2837
- case GI_TYPE_TAG_GSLIST:
2838
- case GI_TYPE_TAG_GHASH:
2839
- case GI_TYPE_TAG_ERROR:
2840
- case GI_TYPE_TAG_UNICHAR:
2841
- g_base_info_unref(element_type_info);
2842
- rb_raise(rb_eNotImpError,
2843
- "TODO: free GIArgument(GSList)[%s] everything",
2844
- g_type_tag_to_string(element_type_tag));
2845
- break;
2846
- default:
2847
- g_base_info_unref(element_type_info);
2848
- g_assert_not_reached();
2849
- break;
2850
- }
2851
- }
2852
-
2853
- static void
2854
- rb_gi_return_argument_free_everything(GIArgument *argument,
2855
- GITypeInfo *type_info)
2856
- {
2857
- GITypeTag type_tag;
2858
-
2859
- type_tag = g_type_info_get_tag(type_info);
2860
- switch (type_tag) {
2861
- case GI_TYPE_TAG_VOID:
2862
- break;
2863
- case GI_TYPE_TAG_BOOLEAN:
2864
- case GI_TYPE_TAG_INT8:
2865
- case GI_TYPE_TAG_UINT8:
2866
- case GI_TYPE_TAG_INT16:
2867
- case GI_TYPE_TAG_UINT16:
2868
- case GI_TYPE_TAG_INT32:
2869
- case GI_TYPE_TAG_UINT32:
2870
- case GI_TYPE_TAG_INT64:
2871
- case GI_TYPE_TAG_UINT64:
2872
- case GI_TYPE_TAG_FLOAT:
2873
- case GI_TYPE_TAG_DOUBLE:
2874
- case GI_TYPE_TAG_GTYPE:
2875
- rb_raise(rb_eNotImpError,
2876
- "TODO: free GIArgument(%s) everything",
2877
- g_type_tag_to_string(type_tag));
2878
- break;
2879
- case GI_TYPE_TAG_UTF8:
2880
- g_free(argument->v_string);
2881
- break;
2882
- case GI_TYPE_TAG_FILENAME:
2883
- g_free(argument->v_string);
2884
- break;
2885
- case GI_TYPE_TAG_ARRAY:
2886
- rb_gi_return_argument_free_everything_array(argument, type_info);
2887
- break;
2888
- case GI_TYPE_TAG_INTERFACE:
2889
- rb_gi_return_argument_free_everything_interface(argument, type_info);
2890
- break;
2891
- case GI_TYPE_TAG_GLIST:
2892
- rb_gi_return_argument_free_everything_glist(argument, type_info);
2893
- break;
2894
- case GI_TYPE_TAG_GSLIST:
2895
- rb_gi_return_argument_free_everything_gslist(argument, type_info);
2896
- break;
2897
- case GI_TYPE_TAG_GHASH:
2898
- g_hash_table_unref(argument->v_pointer);
2899
- break;
2900
- case GI_TYPE_TAG_ERROR:
2901
- case GI_TYPE_TAG_UNICHAR:
2902
- rb_raise(rb_eNotImpError,
2903
- "TODO: free GIArgument(%s) everything",
2904
- g_type_tag_to_string(type_tag));
2905
- break;
2906
- default:
2907
- g_assert_not_reached();
2908
- break;
2909
- }
2910
- }
2911
-
2912
- VALUE
2913
- rb_gi_return_argument_to_ruby(GICallableInfo *callable_info,
2914
- GIArgument *argument,
2915
- GArray *in_args,
2916
- GArray *out_args,
2917
- GPtrArray *args_metadata)
2918
- {
2919
- VALUE rb_argument;
2920
- gboolean may_return_null;
2921
- GITypeInfo return_value_info;
2922
-
2923
- may_return_null = g_callable_info_may_return_null(callable_info);
2924
- if (may_return_null && !argument->v_pointer) {
2925
- return Qnil;
2926
- }
2927
-
2928
- g_callable_info_load_return_type(callable_info, &return_value_info);
2929
- rb_argument = rb_gi_argument_to_ruby(argument, FALSE, &return_value_info,
2930
- in_args, out_args, args_metadata);
2931
- switch (g_callable_info_get_caller_owns(callable_info)) {
2932
- case GI_TRANSFER_NOTHING:
2933
- break;
2934
- case GI_TRANSFER_CONTAINER:
2935
- rb_gi_return_argument_free_container(argument, &return_value_info);
2936
- break;
2937
- case GI_TRANSFER_EVERYTHING:
2938
- rb_gi_return_argument_free_everything(argument, &return_value_info);
2939
- break;
2940
- default:
2941
- g_assert_not_reached();
2942
- break;
2943
- }
2944
- return rb_argument;
2945
- }
2946
-
2947
- static void
2948
- rb_gi_value_argument_from_ruby_interface(GIArgument *argument,
2949
- GITypeInfo *type_info,
2950
- VALUE rb_argument,
2951
- VALUE self)
2952
- {
2953
- GIBaseInfo *interface_info;
2954
- GIInfoType interface_type;
2955
- GType gtype;
2956
-
2957
- interface_info = g_type_info_get_interface(type_info);
2958
- interface_type = g_base_info_get_type(interface_info);
2959
-
2960
- switch (interface_type) {
2961
- case GI_INFO_TYPE_INVALID:
2962
- case GI_INFO_TYPE_FUNCTION:
2963
- case GI_INFO_TYPE_CALLBACK:
2964
- rb_raise(rb_eNotImpError,
2965
- "TODO: Ruby -> GIArgument(interface)[%s]: <%s>",
2966
- g_info_type_to_string(interface_type),
2967
- g_base_info_get_name(interface_info));
2968
- break;
2969
- case GI_INFO_TYPE_STRUCT:
2970
- gtype = g_registered_type_info_get_g_type(interface_info);
2971
- if (gtype == G_TYPE_NONE) {
2972
- argument->v_pointer = rb_gi_struct_get_raw(rb_argument, gtype);
2973
- } else if (gtype == G_TYPE_VALUE) {
2974
- GValue *gvalue;
2975
- if (RVAL2CBOOL(rb_obj_is_kind_of(rb_argument, rb_cGLibValue))) {
2976
- gvalue = RVAL2BOXED(rb_argument, G_TYPE_VALUE);
2977
- } else {
2978
- gvalue = ALLOC(GValue);
2979
- memset(gvalue, 0, sizeof(GValue));
2980
- rbgobj_initialize_gvalue(gvalue, rb_argument);
2981
- }
2982
- argument->v_pointer = gvalue;
2983
- } else if (gtype == G_TYPE_BYTES) {
2984
- if (RVAL2CBOOL(rb_obj_is_kind_of(rb_argument, rb_cGLibBytes))) {
2985
- argument->v_pointer = RVAL2BOXED(rb_argument, G_TYPE_BYTES);
2986
- g_bytes_ref(argument->v_pointer);
2987
- } else {
2988
- VALUE rb_string;
2989
- GBytes *gbytes;
2990
-
2991
- rb_string = StringValue(rb_argument);
2992
- gbytes = g_bytes_new(RSTRING_PTR(rb_string),
2993
- RSTRING_LEN(rb_string));
2994
- argument->v_pointer = gbytes;
2995
- }
2996
- } else if (gtype == G_TYPE_CLOSURE) {
2997
- GClosure *rclosure = NULL;
2998
-
2999
- rclosure = g_rclosure_new(rb_argument, Qnil, NULL);
3000
- g_rclosure_attach(rclosure, self);
3001
- argument->v_pointer = rclosure;
3002
- } else if (gtype == G_TYPE_VARIANT) {
3003
- argument->v_pointer = rbg_variant_from_ruby(rb_argument);
3004
- } else {
3005
- argument->v_pointer = RVAL2BOXED(rb_argument, gtype);
3006
- }
3007
- break;
3008
- case GI_INFO_TYPE_BOXED:
3009
- rb_raise(rb_eNotImpError,
3010
- "TODO: Ruby -> GIArgument(interface)[%s]: <%s>",
3011
- g_info_type_to_string(interface_type),
3012
- g_base_info_get_name(interface_info));
3013
- break;
3014
- case GI_INFO_TYPE_ENUM:
3015
- gtype = g_registered_type_info_get_g_type(interface_info);
3016
- if (gtype == G_TYPE_NONE) {
3017
- argument->v_int32 = NUM2INT(rb_argument);
3018
- } else {
3019
- argument->v_int32 = RVAL2GENUM(rb_argument, gtype);
3020
- }
3021
- break;
3022
- case GI_INFO_TYPE_FLAGS:
3023
- gtype = g_registered_type_info_get_g_type(interface_info);
3024
- if (gtype == G_TYPE_NONE) {
3025
- argument->v_int32 = NUM2INT(rb_argument);
3026
- } else {
3027
- argument->v_int32 = RVAL2GFLAGS(rb_argument, gtype);
3028
- }
3029
- break;
3030
- case GI_INFO_TYPE_OBJECT:
3031
- case GI_INFO_TYPE_INTERFACE:
3032
- gtype = g_registered_type_info_get_g_type(interface_info);
3033
- argument->v_pointer = RVAL2GOBJ(rb_argument);
3034
- if (argument->v_pointer &&
3035
- gtype != G_TYPE_NONE &&
3036
- !G_TYPE_CHECK_INSTANCE_TYPE(argument->v_pointer, gtype)) {
3037
- rb_raise(rb_eArgError,
3038
- "must be <%s> object: <%" PRIsVALUE ">",
3039
- g_type_name(gtype),
3040
- rb_argument);
3041
- }
3042
- break;
3043
- case GI_INFO_TYPE_CONSTANT:
3044
- rb_raise(rb_eNotImpError,
3045
- "TODO: Ruby -> GIArgument(interface)[%s]: <%s>",
3046
- g_info_type_to_string(interface_type),
3047
- g_base_info_get_name(interface_info));
3048
- break;
3049
- case GI_INFO_TYPE_INVALID_0:
3050
- g_assert_not_reached();
3051
- break;
3052
- case GI_INFO_TYPE_UNION:
3053
- gtype = g_registered_type_info_get_g_type(interface_info);
3054
- if (gtype == G_TYPE_NONE) {
3055
- rb_raise(rb_eNotImpError,
3056
- "TODO: Ruby -> GIArgument(interface)[%s]: <%s>"
3057
- "(G_TYPE_NONE)",
3058
- g_info_type_to_string(interface_type),
3059
- g_base_info_get_name(interface_info));
3060
- } else {
3061
- argument->v_pointer = RVAL2BOXED(rb_argument, gtype);
3062
- }
3063
- break;
3064
- case GI_INFO_TYPE_VALUE:
3065
- case GI_INFO_TYPE_SIGNAL:
3066
- case GI_INFO_TYPE_VFUNC:
3067
- case GI_INFO_TYPE_PROPERTY:
3068
- case GI_INFO_TYPE_FIELD:
3069
- case GI_INFO_TYPE_ARG:
3070
- case GI_INFO_TYPE_TYPE:
3071
- case GI_INFO_TYPE_UNRESOLVED:
3072
- default:
3073
- rb_raise(rb_eNotImpError,
3074
- "TODO: Ruby -> GIArgument(interface)[%s]: <%s>",
3075
- g_info_type_to_string(interface_type),
3076
- g_base_info_get_name(interface_info));
3077
- break;
3078
- }
3079
-
3080
- g_base_info_unref(interface_info);
3081
- }
3082
-
3083
- static void
3084
- rb_gi_value_argument_from_ruby_glist(GIArgument *argument,
3085
- GITypeInfo *type_info,
3086
- VALUE rb_argument,
3087
- G_GNUC_UNUSED VALUE self)
3088
- {
3089
- GITypeInfo *element_type_info;
3090
- GITypeTag element_type_tag;
3091
- GType gtype = G_TYPE_NONE;
3092
-
3093
- element_type_info = g_type_info_get_param_type(type_info, 0);
3094
- element_type_tag = g_type_info_get_tag(element_type_info);
3095
- if (element_type_tag == GI_TYPE_TAG_INTERFACE) {
3096
- GIBaseInfo *interface_info;
3097
- interface_info = g_type_info_get_interface(element_type_info);
3098
- gtype = g_registered_type_info_get_g_type(interface_info);
3099
- g_base_info_unref(interface_info);
3100
- }
3101
- g_base_info_unref(element_type_info);
3102
-
3103
- switch (element_type_tag) {
3104
- case GI_TYPE_TAG_VOID:
3105
- case GI_TYPE_TAG_BOOLEAN:
3106
- case GI_TYPE_TAG_INT8:
3107
- case GI_TYPE_TAG_UINT8:
3108
- case GI_TYPE_TAG_INT16:
3109
- case GI_TYPE_TAG_UINT16:
3110
- case GI_TYPE_TAG_INT32:
3111
- case GI_TYPE_TAG_UINT32:
3112
- case GI_TYPE_TAG_INT64:
3113
- case GI_TYPE_TAG_UINT64:
3114
- case GI_TYPE_TAG_FLOAT:
3115
- case GI_TYPE_TAG_DOUBLE:
3116
- case GI_TYPE_TAG_GTYPE:
3117
- case GI_TYPE_TAG_UTF8:
3118
- case GI_TYPE_TAG_FILENAME:
3119
- case GI_TYPE_TAG_ARRAY:
3120
- rb_raise(rb_eNotImpError,
3121
- "TODO: Ruby -> GIArgument(GList)[%s]",
3122
- g_type_tag_to_string(element_type_tag));
3123
- break;
3124
- case GI_TYPE_TAG_INTERFACE:
3125
- argument->v_pointer = RVAL2GOBJGLIST(rb_argument);
3126
- if (gtype != G_TYPE_NONE) {
3127
- GList *node;
3128
- for (node = argument->v_pointer; node; node = g_list_next(node)) {
3129
- GObject *object = node->data;
3130
- if (!G_TYPE_CHECK_INSTANCE_TYPE(object, gtype)) {
3131
- g_list_free(argument->v_pointer);
3132
- rb_raise(rb_eArgError,
3133
- "must be <%s> objects: <%" PRIsVALUE ">",
3134
- g_type_name(gtype),
3135
- rb_argument);
3136
- }
3137
- }
3138
- }
3139
- break;
3140
- case GI_TYPE_TAG_GLIST:
3141
- case GI_TYPE_TAG_GSLIST:
3142
- case GI_TYPE_TAG_GHASH:
3143
- case GI_TYPE_TAG_ERROR:
3144
- case GI_TYPE_TAG_UNICHAR:
3145
- rb_raise(rb_eNotImpError,
3146
- "TODO: Ruby -> GIArgument(GList)[%s]",
3147
- g_type_tag_to_string(element_type_tag));
3148
- break;
3149
- default:
3150
- g_assert_not_reached();
3151
- break;
3152
- }
3153
- }
3154
-
3155
- static void
3156
- rb_gi_value_argument_from_ruby_gslist(GIArgument *argument,
3157
- GITypeInfo *type_info,
3158
- VALUE rb_argument,
3159
- G_GNUC_UNUSED VALUE self)
3160
- {
3161
- GITypeInfo *element_type_info;
3162
- GITypeTag element_type_tag;
3163
- GType gtype = G_TYPE_NONE;
3164
-
3165
- element_type_info = g_type_info_get_param_type(type_info, 0);
3166
- element_type_tag = g_type_info_get_tag(element_type_info);
3167
- if (element_type_tag == GI_TYPE_TAG_INTERFACE) {
3168
- GIBaseInfo *interface_info;
3169
- interface_info = g_type_info_get_interface(element_type_info);
3170
- gtype = g_registered_type_info_get_g_type(interface_info);
3171
- g_base_info_unref(interface_info);
3172
- }
3173
- g_base_info_unref(element_type_info);
3174
-
3175
- switch (element_type_tag) {
3176
- case GI_TYPE_TAG_VOID:
3177
- case GI_TYPE_TAG_BOOLEAN:
3178
- case GI_TYPE_TAG_INT8:
3179
- case GI_TYPE_TAG_UINT8:
3180
- case GI_TYPE_TAG_INT16:
3181
- case GI_TYPE_TAG_UINT16:
3182
- case GI_TYPE_TAG_INT32:
3183
- case GI_TYPE_TAG_UINT32:
3184
- case GI_TYPE_TAG_INT64:
3185
- case GI_TYPE_TAG_UINT64:
3186
- case GI_TYPE_TAG_FLOAT:
3187
- case GI_TYPE_TAG_DOUBLE:
3188
- case GI_TYPE_TAG_GTYPE:
3189
- case GI_TYPE_TAG_UTF8:
3190
- case GI_TYPE_TAG_FILENAME:
3191
- case GI_TYPE_TAG_ARRAY:
3192
- rb_raise(rb_eNotImpError,
3193
- "TODO: Ruby -> GIArgument(GSList)[%s]",
3194
- g_type_tag_to_string(element_type_tag));
3195
- break;
3196
- case GI_TYPE_TAG_INTERFACE:
3197
- argument->v_pointer = RVAL2GOBJGSLIST(rb_argument);
3198
- if (gtype != G_TYPE_NONE) {
3199
- GSList *node;
3200
- for (node = argument->v_pointer; node; node = g_slist_next(node)) {
3201
- GObject *object = node->data;
3202
- if (!G_TYPE_CHECK_INSTANCE_TYPE(object, gtype)) {
3203
- g_slist_free(argument->v_pointer);
3204
- rb_raise(rb_eArgError,
3205
- "must be <%s> objects: <%" PRIsVALUE ">",
3206
- g_type_name(gtype),
3207
- rb_argument);
3208
- }
3209
- }
3210
- }
3211
- break;
3212
- case GI_TYPE_TAG_GLIST:
3213
- case GI_TYPE_TAG_GSLIST:
3214
- case GI_TYPE_TAG_GHASH:
3215
- case GI_TYPE_TAG_ERROR:
3216
- case GI_TYPE_TAG_UNICHAR:
3217
- rb_raise(rb_eNotImpError,
3218
- "TODO: Ruby -> GIArgument(GSList)[%s]",
3219
- g_type_tag_to_string(element_type_tag));
3220
- break;
3221
- default:
3222
- g_assert_not_reached();
3223
- break;
3224
- }
3225
- }
3226
-
3227
- typedef struct {
3228
- VALUE rb_value;
3229
- GType gtype;
3230
- const gchar *context;
3231
- } RubyToCData;
3232
-
3233
- typedef gpointer (*RubyToCFunc)(RubyToCData *data);
3234
-
3235
- static gpointer
3236
- ruby_to_c_utf8(RubyToCData *data)
3237
- {
3238
- return g_strdup(RVAL2CSTR(data->rb_value));
3239
- }
3240
-
3241
- static gpointer
3242
- ruby_to_c_interface_enum(RubyToCData *data)
3243
- {
3244
- gint32 value;
3245
- if (data->gtype == G_TYPE_NONE) {
3246
- value = NUM2INT(data->rb_value);
3247
- } else {
3248
- value = RVAL2GENUM(data->rb_value, data->gtype);
3249
- }
3250
- return GINT_TO_POINTER(value);
3251
- }
3252
-
3253
- typedef struct {
3254
- GIArgument *argument;
3255
- GITypeInfo *type_info;
3256
- VALUE rb_argument;
3257
- VALUE self;
3258
- } ArgumentFromRubyData;
3259
-
3260
- typedef struct {
3261
- GHashTable *hash_table;
3262
- RubyToCFunc key_ruby_to_c_func;
3263
- RubyToCData *key_ruby_to_c_data;
3264
- RubyToCFunc value_ruby_to_c_func;
3265
- RubyToCData *value_ruby_to_c_data;
3266
- } ArgumentFromRubyGHashData;
3267
-
3268
- static int
3269
- rb_gi_value_argument_from_ruby_ghash_convert(VALUE rb_key,
3270
- VALUE rb_value,
3271
- VALUE user_data)
3272
- {
3273
- ArgumentFromRubyGHashData *data = (ArgumentFromRubyGHashData *)user_data;
3274
- gpointer key;
3275
- gpointer value;
3276
- data->key_ruby_to_c_data->rb_value = rb_key;
3277
- key = data->key_ruby_to_c_func(data->key_ruby_to_c_data);
3278
- data->value_ruby_to_c_data->rb_value = rb_value;
3279
- value = data->key_ruby_to_c_func(data->value_ruby_to_c_data);
3280
- g_hash_table_insert(data->hash_table, key, value);
3281
- return ST_CONTINUE;
3282
- }
3283
-
3284
- static VALUE
3285
- rb_gi_value_argument_from_ruby_ghash_body(VALUE value_data)
3286
- {
3287
- ArgumentFromRubyData *data = (ArgumentFromRubyData *)value_data;
3288
- GIArgument *argument = data->argument;
3289
- GITypeInfo *type_info = data->type_info;
3290
- VALUE rb_argument = data->rb_argument;
3291
- GHashFunc hash_func = NULL;
3292
- GEqualFunc equal_func = NULL;
3293
- GDestroyNotify key_destroy_func = NULL;
3294
- GDestroyNotify value_destroy_func = NULL;
3295
- GITypeInfo *key_type_info;
3296
- GITypeTag key_type_tag;
3297
- GIInfoType key_interface_type = GI_INFO_TYPE_INVALID;
3298
- RubyToCFunc key_ruby_to_c_func = NULL;
3299
- RubyToCData key_ruby_to_c_data;
3300
- GITypeInfo *value_type_info;
3301
- GITypeTag value_type_tag;
3302
- GIInfoType value_interface_type = GI_INFO_TYPE_INVALID;
3303
- RubyToCFunc value_ruby_to_c_func = NULL;
3304
- RubyToCData value_ruby_to_c_data;
3305
- ArgumentFromRubyGHashData convert_data;
3306
-
3307
- key_type_info = g_type_info_get_param_type(type_info, 0);
3308
- key_type_tag = g_type_info_get_tag(key_type_info);
3309
- key_ruby_to_c_data.gtype = G_TYPE_NONE;
3310
- if (key_type_tag == GI_TYPE_TAG_INTERFACE) {
3311
- GIBaseInfo *interface_info;
3312
- interface_info = g_type_info_get_interface(key_type_info);
3313
- key_ruby_to_c_data.gtype =
3314
- g_registered_type_info_get_g_type(interface_info);
3315
- key_interface_type = g_base_info_get_type(interface_info);
3316
- g_base_info_unref(interface_info);
3317
- }
3318
- g_base_info_unref(key_type_info);
3319
-
3320
- value_type_info = g_type_info_get_param_type(type_info, 1);
3321
- value_type_tag = g_type_info_get_tag(value_type_info);
3322
- value_ruby_to_c_data.gtype = G_TYPE_NONE;
3323
- if (value_type_tag == GI_TYPE_TAG_INTERFACE) {
3324
- GIBaseInfo *interface_info;
3325
- interface_info = g_type_info_get_interface(value_type_info);
3326
- value_ruby_to_c_data.gtype =
3327
- g_registered_type_info_get_g_type(interface_info);
3328
- value_interface_type = g_base_info_get_type(interface_info);
3329
- g_base_info_unref(interface_info);
3330
- }
3331
- g_base_info_unref(value_type_info);
3332
-
3333
- switch (key_type_tag) {
3334
- case GI_TYPE_TAG_VOID:
3335
- case GI_TYPE_TAG_BOOLEAN:
3336
- case GI_TYPE_TAG_INT8:
3337
- case GI_TYPE_TAG_UINT8:
3338
- case GI_TYPE_TAG_INT16:
3339
- case GI_TYPE_TAG_UINT16:
3340
- case GI_TYPE_TAG_INT32:
3341
- case GI_TYPE_TAG_UINT32:
3342
- case GI_TYPE_TAG_INT64:
3343
- case GI_TYPE_TAG_UINT64:
3344
- case GI_TYPE_TAG_FLOAT:
3345
- case GI_TYPE_TAG_DOUBLE:
3346
- case GI_TYPE_TAG_GTYPE:
3347
- rb_raise(rb_eNotImpError,
3348
- "TODO: Ruby -> GIArgument(GHash)[key][%s]",
3349
- g_type_tag_to_string(key_type_tag));
3350
- break;
3351
- case GI_TYPE_TAG_UTF8:
3352
- hash_func = g_str_hash;
3353
- equal_func = g_str_equal;
3354
- key_destroy_func = g_free;
3355
- key_ruby_to_c_func = ruby_to_c_utf8;
3356
- key_ruby_to_c_data.context = "Ruby -> GIArgument(GHash)[key][utf8]";
3357
- break;
3358
- case GI_TYPE_TAG_FILENAME:
3359
- case GI_TYPE_TAG_ARRAY:
3360
- case GI_TYPE_TAG_INTERFACE:
3361
- case GI_TYPE_TAG_GLIST:
3362
- case GI_TYPE_TAG_GSLIST:
3363
- case GI_TYPE_TAG_GHASH:
3364
- case GI_TYPE_TAG_ERROR:
3365
- case GI_TYPE_TAG_UNICHAR:
3366
- rb_raise(rb_eNotImpError,
3367
- "TODO: Ruby -> GIArgument(GHash)[key][%s]",
3368
- g_type_tag_to_string(key_type_tag));
3369
- break;
3370
- default:
3371
- g_assert_not_reached();
3372
- break;
3373
- }
3374
-
3375
- switch (value_type_tag) {
3376
- case GI_TYPE_TAG_VOID:
3377
- case GI_TYPE_TAG_BOOLEAN:
3378
- case GI_TYPE_TAG_INT8:
3379
- case GI_TYPE_TAG_UINT8:
3380
- case GI_TYPE_TAG_INT16:
3381
- case GI_TYPE_TAG_UINT16:
3382
- case GI_TYPE_TAG_INT32:
3383
- case GI_TYPE_TAG_UINT32:
3384
- case GI_TYPE_TAG_INT64:
3385
- case GI_TYPE_TAG_UINT64:
3386
- case GI_TYPE_TAG_FLOAT:
3387
- case GI_TYPE_TAG_DOUBLE:
3388
- case GI_TYPE_TAG_GTYPE:
3389
- case GI_TYPE_TAG_UTF8:
3390
- case GI_TYPE_TAG_FILENAME:
3391
- case GI_TYPE_TAG_ARRAY:
3392
- rb_raise(rb_eNotImpError,
3393
- "TODO: Ruby -> GIArgument(GHash)[value][%s]",
3394
- g_type_tag_to_string(value_type_tag));
3395
- break;
3396
- case GI_TYPE_TAG_INTERFACE:
3397
- switch (value_interface_type) {
3398
- case GI_INFO_TYPE_INVALID:
3399
- case GI_INFO_TYPE_FUNCTION:
3400
- case GI_INFO_TYPE_CALLBACK:
3401
- case GI_INFO_TYPE_STRUCT:
3402
- case GI_INFO_TYPE_BOXED:
3403
- rb_raise(rb_eNotImpError,
3404
- "TODO: Ruby -> GIArgument(GHash)[value][%s][%s]",
3405
- g_type_tag_to_string(value_type_tag),
3406
- g_info_type_to_string(value_interface_type));
3407
- break;
3408
- case GI_INFO_TYPE_ENUM:
3409
- value_destroy_func = NULL;
3410
- value_ruby_to_c_func = ruby_to_c_interface_enum;
3411
- value_ruby_to_c_data.context =
3412
- "Ruby -> GIArgument(GHash)[value][interface]";
3413
- break;
3414
- case GI_INFO_TYPE_FLAGS:
3415
- case GI_INFO_TYPE_OBJECT:
3416
- case GI_INFO_TYPE_INTERFACE:
3417
- case GI_INFO_TYPE_CONSTANT:
3418
- case GI_INFO_TYPE_INVALID_0:
3419
- case GI_INFO_TYPE_UNION:
3420
- case GI_INFO_TYPE_VALUE:
3421
- case GI_INFO_TYPE_SIGNAL:
3422
- case GI_INFO_TYPE_VFUNC:
3423
- case GI_INFO_TYPE_PROPERTY:
3424
- case GI_INFO_TYPE_FIELD:
3425
- case GI_INFO_TYPE_ARG:
3426
- case GI_INFO_TYPE_TYPE:
3427
- case GI_INFO_TYPE_UNRESOLVED:
3428
- rb_raise(rb_eNotImpError,
3429
- "TODO: Ruby -> GIArgument(GHash)[value][%s][%s]",
3430
- g_type_tag_to_string(value_type_tag),
3431
- g_info_type_to_string(value_interface_type));
3432
- break;
3433
- default:
3434
- g_assert_not_reached();
3435
- break;
3436
- }
3437
- break;
3438
- case GI_TYPE_TAG_GLIST:
3439
- case GI_TYPE_TAG_GSLIST:
3440
- case GI_TYPE_TAG_GHASH:
3441
- case GI_TYPE_TAG_ERROR:
3442
- case GI_TYPE_TAG_UNICHAR:
3443
- rb_raise(rb_eNotImpError,
3444
- "TODO: Ruby -> GIArgument(GHash)[value][%s]",
3445
- g_type_tag_to_string(value_type_tag));
3446
- break;
3447
- default:
3448
- g_assert_not_reached();
3449
- break;
3450
- }
3451
-
3452
- argument->v_pointer = g_hash_table_new_full(hash_func,
3453
- equal_func,
3454
- key_destroy_func,
3455
- value_destroy_func);
3456
- convert_data.hash_table = argument->v_pointer;
3457
- convert_data.key_ruby_to_c_func = key_ruby_to_c_func;
3458
- convert_data.key_ruby_to_c_data = &key_ruby_to_c_data;
3459
- convert_data.value_ruby_to_c_func = value_ruby_to_c_func;
3460
- convert_data.value_ruby_to_c_data = &value_ruby_to_c_data;
3461
- rb_hash_foreach(rb_argument,
3462
- rb_gi_value_argument_from_ruby_ghash_convert,
3463
- (VALUE)&convert_data);
3464
-
3465
- return Qnil;
3466
- }
3467
-
3468
- static VALUE
3469
- rb_gi_value_argument_from_ruby_ghash_rescue(VALUE value_data,
3470
- VALUE exception)
3471
- {
3472
- ArgumentFromRubyData *data = (ArgumentFromRubyData *)value_data;
3473
- GIArgument *argument = data->argument;
3474
-
3475
- if (argument->v_pointer) {
3476
- g_hash_table_unref(argument->v_pointer);
3477
- argument->v_pointer = NULL;
3478
- }
3479
-
3480
- rb_exc_raise(exception);
3481
-
3482
- return Qnil;
3483
- }
3484
-
3485
- static void
3486
- rb_gi_value_argument_from_ruby_ghash(GIArgument *argument,
3487
- GITypeInfo *type_info,
3488
- VALUE rb_argument,
3489
- VALUE self)
3490
- {
3491
- ArgumentFromRubyData data;
3492
- argument->v_pointer = NULL;
3493
- data.argument = argument;
3494
- data.type_info = type_info;
3495
- data.rb_argument = rb_argument;
3496
- data.self = self;
3497
- rb_rescue(rb_gi_value_argument_from_ruby_ghash_body, (VALUE)&data,
3498
- rb_gi_value_argument_from_ruby_ghash_rescue, (VALUE)&data);
3499
- }
3500
-
3501
- static void
3502
- rb_gi_value_argument_from_ruby_void(GIArgument *argument, GITypeInfo *type_info,
3503
- VALUE rb_argument)
3504
- {
3505
- if (!g_type_info_is_pointer(type_info)) {
3506
- return;
3507
- }
3508
-
3509
- if (RB_TYPE_P(rb_argument, RUBY_T_STRING)) {
3510
- argument->v_pointer = RSTRING_PTR(rb_argument);
3511
- } else if (RVAL2CBOOL(rb_obj_is_kind_of(rb_argument, rb_cGLibObject))) {
3512
- argument->v_pointer = RVAL2GOBJ(rb_argument);
3513
- } else {
3514
- argument->v_pointer = GUINT_TO_POINTER(NUM2ULONG(rb_argument));
3515
- }
3516
- }
3517
-
3518
- static GType
3519
- rb_gi_value_argument_from_ruby_gtype(VALUE rb_argument)
3520
- {
3521
- ID id_gtype;
3522
- VALUE rb_gtype;
3523
-
3524
- if (RB_TYPE_P(rb_argument, RUBY_T_STRING)) {
3525
- GType gtype;
3526
- gtype = g_type_from_name(RVAL2CSTR(rb_argument));
3527
- if (gtype == 0) {
3528
- rb_raise(rb_eArgError,
3529
- "unknown GType name: <%s>",
3530
- RVAL2CSTR(rb_argument));
3531
- }
3532
- return gtype;
3533
- }
3534
-
3535
- CONST_ID(id_gtype, "gtype");
3536
-
3537
- if (rb_respond_to(rb_argument, id_gtype)) {
3538
- rb_gtype = rb_funcall(rb_argument, id_gtype, 0);
3539
- } else {
3540
- rb_gtype = rb_argument;
3541
- }
3542
-
3543
- return NUM2ULONG(rb_gtype);
3544
- }
3545
-
3546
- GIArgument *
3547
- rb_gi_value_argument_from_ruby(GIArgument *argument, GITypeInfo *type_info,
3548
- VALUE rb_argument, VALUE self)
3549
- {
3550
- GITypeTag type_tag;
3551
-
3552
- memset(argument, 0, sizeof(GIArgument));
3553
-
3554
- type_tag = g_type_info_get_tag(type_info);
3555
- switch (type_tag) {
3556
- case GI_TYPE_TAG_VOID:
3557
- rb_gi_value_argument_from_ruby_void(argument, type_info, rb_argument);
3558
- break;
3559
- case GI_TYPE_TAG_BOOLEAN:
3560
- argument->v_boolean = RVAL2CBOOL(rb_argument);
3561
- break;
3562
- case GI_TYPE_TAG_INT8:
3563
- argument->v_int8 = NUM2CHR(rb_argument);
3564
- break;
3565
- case GI_TYPE_TAG_UINT8:
3566
- argument->v_uint8 = (guint8)NUM2CHR(rb_argument);
3567
- break;
3568
- case GI_TYPE_TAG_INT16:
3569
- argument->v_int16 = NUM2SHORT(rb_argument);
3570
- break;
3571
- case GI_TYPE_TAG_UINT16:
3572
- argument->v_uint16 = NUM2USHORT(rb_argument);
3573
- break;
3574
- case GI_TYPE_TAG_INT32:
3575
- argument->v_int32 = NUM2INT(rb_argument);
3576
- break;
3577
- case GI_TYPE_TAG_UINT32:
3578
- argument->v_uint32 = NUM2UINT(rb_argument);
3579
- break;
3580
- case GI_TYPE_TAG_INT64:
3581
- argument->v_int64 = NUM2LL(rb_argument);
3582
- break;
3583
- case GI_TYPE_TAG_UINT64:
3584
- argument->v_uint64 = NUM2ULL(rb_argument);
3585
- break;
3586
- case GI_TYPE_TAG_FLOAT:
3587
- argument->v_float = NUM2DBL(rb_argument);
3588
- break;
3589
- case GI_TYPE_TAG_DOUBLE:
3590
- argument->v_double = NUM2DBL(rb_argument);
3591
- break;
3592
- case GI_TYPE_TAG_GTYPE:
3593
- argument->v_size = rb_gi_value_argument_from_ruby_gtype(rb_argument);
3594
- break;
3595
- case GI_TYPE_TAG_UTF8:
3596
- /* TODO: support UTF-8 convert like rb_argument.encode("UTF-8"). */
3597
- argument->v_string = (gchar *)RVAL2CSTR_ACCEPT_SYMBOL(rb_argument);
3598
- break;
3599
- case GI_TYPE_TAG_FILENAME:
3600
- argument->v_string = (gchar *)RVAL2CSTR(rb_argument);
3601
- break;
3602
- case GI_TYPE_TAG_ARRAY:
3603
- rb_raise(rb_eNotImpError,
3604
- "should not be reached: Ruby -> GIArgument(%s)",
3605
- g_type_tag_to_string(type_tag));
3606
- break;
3607
- case GI_TYPE_TAG_INTERFACE:
3608
- rb_gi_value_argument_from_ruby_interface(argument, type_info,
3609
- rb_argument, self);
3610
- break;
3611
- case GI_TYPE_TAG_GLIST:
3612
- rb_gi_value_argument_from_ruby_glist(argument, type_info,
3613
- rb_argument, self);
3614
- break;
3615
- case GI_TYPE_TAG_GSLIST:
3616
- rb_gi_value_argument_from_ruby_gslist(argument, type_info,
3617
- rb_argument, self);
3618
- break;
3619
- case GI_TYPE_TAG_GHASH:
3620
- rb_gi_value_argument_from_ruby_ghash(argument, type_info,
3621
- rb_argument, self);
3622
- break;
3623
- case GI_TYPE_TAG_ERROR:
3624
- rb_raise(rb_eNotImpError,
3625
- "TODO: Ruby -> GIArgument(%s)",
3626
- g_type_tag_to_string(type_tag));
3627
- break;
3628
- case GI_TYPE_TAG_UNICHAR:
3629
- if (NIL_P(rb_argument)) {
3630
- argument->v_uint32 = 0;
3631
- } else {
3632
- argument->v_uint32 = NUM2UINT(rb_argument);
3633
- }
3634
- break;
3635
- default:
3636
- g_assert_not_reached();
3637
- break;
3638
- }
3639
-
3640
- return argument;
3641
- }
3642
-
3643
- static void
3644
- rb_gi_inout_argument_from_ruby(GIArgument *argument,
3645
- G_GNUC_UNUSED GIArgInfo *arg_info,
3646
- GITypeInfo *type_info,
3647
- VALUE rb_argument,
3648
- VALUE self)
3649
- {
3650
- GIArgument in_argument;
3651
- GITypeTag type_tag;
3652
-
3653
- rb_gi_value_argument_from_ruby(&in_argument, type_info, rb_argument, self);
3654
-
3655
- type_tag = g_type_info_get_tag(type_info);
3656
- switch (type_tag) {
3657
- case GI_TYPE_TAG_VOID:
3658
- break;
3659
- case GI_TYPE_TAG_BOOLEAN:
3660
- argument->v_pointer = ALLOC(gboolean);
3661
- *((gboolean *)argument->v_pointer) = in_argument.v_boolean;
3662
- break;
3663
- case GI_TYPE_TAG_INT8:
3664
- argument->v_pointer = ALLOC(gint8);
3665
- *((gint8 *)argument->v_pointer) = in_argument.v_int8;
3666
- break;
3667
- case GI_TYPE_TAG_UINT8:
3668
- argument->v_pointer = ALLOC(guint8);
3669
- *((guint8 *)argument->v_pointer) = in_argument.v_uint8;
3670
- break;
3671
- case GI_TYPE_TAG_INT16:
3672
- argument->v_pointer = ALLOC(gint16);
3673
- *((gint16 *)argument->v_pointer) = in_argument.v_int16;
3674
- break;
3675
- case GI_TYPE_TAG_UINT16:
3676
- argument->v_pointer = ALLOC(guint16);
3677
- *((guint16 *)argument->v_pointer) = in_argument.v_uint16;
3678
- break;
3679
- case GI_TYPE_TAG_INT32:
3680
- argument->v_pointer = ALLOC(gint32);
3681
- *((gint32 *)argument->v_pointer) = in_argument.v_int32;
3682
- break;
3683
- case GI_TYPE_TAG_UINT32:
3684
- argument->v_pointer = ALLOC(guint32);
3685
- *((guint32 *)argument->v_pointer) = in_argument.v_uint32;
3686
- break;
3687
- case GI_TYPE_TAG_INT64:
3688
- argument->v_pointer = ALLOC(gint64);
3689
- *((gint64 *)argument->v_pointer) = in_argument.v_int64;
3690
- break;
3691
- case GI_TYPE_TAG_UINT64:
3692
- argument->v_pointer = ALLOC(guint64);
3693
- *((guint64 *)argument->v_pointer) = in_argument.v_uint64;
3694
- break;
3695
- case GI_TYPE_TAG_FLOAT:
3696
- argument->v_pointer = ALLOC(gfloat);
3697
- *((gfloat *)argument->v_pointer) = in_argument.v_float;
3698
- break;
3699
- case GI_TYPE_TAG_DOUBLE:
3700
- argument->v_pointer = ALLOC(gdouble);
3701
- *((gdouble *)argument->v_pointer) = in_argument.v_double;
3702
- break;
3703
- case GI_TYPE_TAG_GTYPE:
3704
- argument->v_pointer = ALLOC(gsize);
3705
- *((gsize *)argument->v_pointer) = in_argument.v_size;
3706
- break;
3707
- case GI_TYPE_TAG_UTF8:
3708
- case GI_TYPE_TAG_FILENAME:
3709
- argument->v_pointer = ALLOC(gchar *);
3710
- *((gchar **)argument->v_pointer) = in_argument.v_string;
3711
- break;
3712
- case GI_TYPE_TAG_ARRAY:
3713
- rb_raise(rb_eNotImpError,
3714
- "should not be reached: Ruby -> GIArgument(%s)",
3715
- g_type_tag_to_string(type_tag));
3716
- break;
3717
- case GI_TYPE_TAG_INTERFACE:
3718
- case GI_TYPE_TAG_GLIST:
3719
- case GI_TYPE_TAG_GSLIST:
3720
- case GI_TYPE_TAG_GHASH:
3721
- argument->v_pointer = ALLOC(gpointer);
3722
- *((gpointer *)argument->v_pointer) = in_argument.v_pointer;
3723
- break;
3724
- case GI_TYPE_TAG_ERROR:
3725
- argument->v_pointer = ALLOC(GError *);
3726
- *((GError **)argument->v_pointer) = in_argument.v_pointer;
3727
- break;
3728
- case GI_TYPE_TAG_UNICHAR:
3729
- argument->v_pointer = ALLOC(gunichar);
3730
- *((gunichar *)argument->v_pointer) = in_argument.v_uint32;
3731
- break;
3732
- default:
3733
- g_assert_not_reached();
3734
- break;
3735
- }
3736
- }
3737
-
3738
- static void
3739
- rb_gi_in_argument_transfer_interface(GIArgument *argument,
3740
- G_GNUC_UNUSED GITransfer transfer,
3741
- GITypeInfo *type_info,
3742
- VALUE rb_argument)
3743
- {
3744
- GIBaseInfo *interface_info;
3745
- GIInfoType interface_type;
3746
- G_GNUC_UNUSED GType gtype;
3747
-
3748
- interface_info = g_type_info_get_interface(type_info);
3749
- interface_type = g_base_info_get_type(interface_info);
3750
- gtype = g_registered_type_info_get_g_type(interface_info);
3751
- g_base_info_unref(interface_info);
3752
-
3753
- switch (interface_type) {
3754
- case GI_INFO_TYPE_INVALID:
3755
- case GI_INFO_TYPE_FUNCTION:
3756
- case GI_INFO_TYPE_CALLBACK:
3757
- rb_raise(rb_eNotImpError,
3758
- "TODO: in transfer (interface) [%s]",
3759
- g_info_type_to_string(interface_type));
3760
- break;
3761
- case GI_INFO_TYPE_STRUCT:
3762
- rbgobj_boxed_unown(rb_argument);
3763
- break;
3764
- case GI_INFO_TYPE_BOXED:
3765
- case GI_INFO_TYPE_ENUM:
3766
- case GI_INFO_TYPE_FLAGS:
3767
- rb_raise(rb_eNotImpError,
3768
- "TODO: in transfer (interface) [%s]",
3769
- g_info_type_to_string(interface_type));
3770
- break;
3771
- case GI_INFO_TYPE_OBJECT:
3772
- g_object_ref(argument->v_pointer);
1585
+ if (argument->v_pointer) {
1586
+ GObject *object = argument->v_pointer;
1587
+ if (g_object_is_floating(object)) {
1588
+ g_object_ref_sink(object);
1589
+ }
1590
+ g_object_unref(object);
1591
+ }
3773
1592
  break;
3774
1593
  case GI_INFO_TYPE_INTERFACE:
1594
+ if (argument->v_pointer) {
1595
+ g_object_unref(argument->v_pointer);
1596
+ }
1597
+ break;
3775
1598
  case GI_INFO_TYPE_CONSTANT:
3776
1599
  rb_raise(rb_eNotImpError,
3777
- "TODO: in transfer (interface) [%s]",
3778
- g_info_type_to_string(interface_type));
1600
+ "TODO: free GIArgument(interface)[constant] everything");
3779
1601
  break;
3780
1602
  case GI_INFO_TYPE_INVALID_0:
3781
1603
  g_assert_not_reached();
3782
1604
  break;
3783
1605
  case GI_INFO_TYPE_UNION:
1606
+ if (gtype == G_TYPE_NONE) {
1607
+ rb_raise(rb_eNotImpError,
1608
+ "TODO: free GIArgument(interface)[union] everything");
1609
+ } else {
1610
+ g_boxed_free(gtype, argument->v_pointer);
1611
+ }
1612
+ break;
3784
1613
  case GI_INFO_TYPE_VALUE:
3785
- case GI_INFO_TYPE_SIGNAL:
3786
- case GI_INFO_TYPE_VFUNC:
3787
- case GI_INFO_TYPE_PROPERTY:
3788
- case GI_INFO_TYPE_FIELD:
3789
- case GI_INFO_TYPE_ARG:
3790
- case GI_INFO_TYPE_TYPE:
3791
- case GI_INFO_TYPE_UNRESOLVED:
3792
- rb_raise(rb_eNotImpError,
3793
- "TODO: in transfer (interface) [%s]",
3794
- g_info_type_to_string(interface_type));
3795
- break;
3796
- default:
3797
- g_assert_not_reached();
3798
- break;
3799
- }
3800
- }
3801
-
3802
- static void
3803
- rb_gi_in_argument_transfer(GIArgument *argument, GITransfer transfer,
3804
- GITypeInfo *type_info, VALUE rb_argument)
3805
- {
3806
- GITypeTag type_tag;
3807
-
3808
- if (transfer == GI_TRANSFER_NOTHING) {
3809
- return;
3810
- }
3811
-
3812
- type_tag = g_type_info_get_tag(type_info);
3813
- switch (type_tag) {
3814
- case GI_TYPE_TAG_VOID:
3815
- case GI_TYPE_TAG_BOOLEAN:
3816
- case GI_TYPE_TAG_INT8:
3817
- case GI_TYPE_TAG_UINT8:
3818
- case GI_TYPE_TAG_INT16:
3819
- case GI_TYPE_TAG_UINT16:
3820
- case GI_TYPE_TAG_INT32:
3821
- case GI_TYPE_TAG_UINT32:
3822
- case GI_TYPE_TAG_INT64:
3823
- case GI_TYPE_TAG_UINT64:
3824
- case GI_TYPE_TAG_FLOAT:
3825
- case GI_TYPE_TAG_DOUBLE:
3826
- case GI_TYPE_TAG_GTYPE:
3827
- break;
3828
- case GI_TYPE_TAG_UTF8:
3829
- case GI_TYPE_TAG_FILENAME:
3830
- case GI_TYPE_TAG_ARRAY:
3831
- rb_raise(rb_eNotImpError,
3832
- "TODO: in transfer (%s)",
3833
- g_type_tag_to_string(type_tag));
3834
- break;
3835
- case GI_TYPE_TAG_INTERFACE:
3836
- rb_gi_in_argument_transfer_interface(argument, transfer,
3837
- type_info, rb_argument);
3838
- break;
3839
- case GI_TYPE_TAG_GLIST:
3840
- case GI_TYPE_TAG_GSLIST:
3841
- case GI_TYPE_TAG_GHASH:
3842
- case GI_TYPE_TAG_ERROR:
3843
- case GI_TYPE_TAG_UNICHAR:
3844
- rb_raise(rb_eNotImpError,
3845
- "TODO: in transfer (%s)",
3846
- g_type_tag_to_string(type_tag));
3847
- default:
3848
- g_assert_not_reached();
3849
- break;
3850
- }
3851
- }
3852
-
3853
- GIArgument *
3854
- rb_gi_in_argument_from_ruby(GICallableInfo *callable_info,
3855
- GIArgument *argument,
3856
- GIArgInfo *arg_info,
3857
- guint nth_rb_argument,
3858
- VALUE rb_argument,
3859
- VALUE self)
3860
- {
3861
- GITypeInfo type_info;
3862
-
3863
- if (NIL_P(rb_argument)) {
3864
- if (rb_gi_arg_info_may_be_null(arg_info)) {
3865
- memset(argument, 0, sizeof(GIArgument));
3866
- return argument;
3867
- } else {
3868
- const char *module_name;
3869
- GIBaseInfo *klass;
3870
- const char *suffix;
3871
-
3872
- module_name = g_base_info_get_namespace(callable_info);
3873
- klass = g_base_info_get_container(callable_info);
3874
- if (nth_rb_argument == 1) {
3875
- suffix = "st";
3876
- } else if (nth_rb_argument == 2) {
3877
- suffix = "nd";
3878
- } else if (nth_rb_argument == 3) {
3879
- suffix = "rd";
3880
- } else {
3881
- suffix = "th";
3882
- }
3883
- rb_raise(rb_eArgError,
3884
- "<%s%s%s%s%s>: the %u%s argument must not nil: <%s>",
3885
- module_name,
3886
- klass ? "::" : "",
3887
- klass ? g_base_info_get_name(klass) : "",
3888
- klass ? "#" : ".",
3889
- g_base_info_get_name(callable_info),
3890
- nth_rb_argument,
3891
- suffix,
3892
- g_base_info_get_name(arg_info));
3893
- }
3894
- }
3895
-
3896
- g_arg_info_load_type(arg_info, &type_info);
3897
- if (g_arg_info_get_direction(arg_info) == GI_DIRECTION_INOUT) {
3898
- rb_gi_inout_argument_from_ruby(argument, arg_info, &type_info,
3899
- rb_argument, self);
3900
- } else {
3901
- rb_gi_value_argument_from_ruby(argument, &type_info, rb_argument, self);
3902
- rb_gi_in_argument_transfer(argument,
3903
- g_arg_info_get_ownership_transfer(arg_info),
3904
- &type_info,
3905
- rb_argument);
3906
- }
3907
-
3908
- return argument;
3909
- }
3910
-
3911
- static void
3912
- set_in_array_length_argument(GIArgument *argument,
3913
- GITypeInfo *type_info,
3914
- gint64 length)
3915
- {
3916
- GITypeTag type_tag;
3917
-
3918
- if (!argument) {
3919
- return;
3920
- }
3921
-
3922
- type_tag = g_type_info_get_tag(type_info);
3923
- switch (type_tag) {
3924
- case GI_TYPE_TAG_VOID:
3925
- case GI_TYPE_TAG_BOOLEAN:
3926
- rb_raise(rb_eNotImpError,
3927
- "TODO: invalid argument?: length[%s]",
3928
- g_type_tag_to_string(type_tag));
3929
- break;
3930
- case GI_TYPE_TAG_INT8:
3931
- argument->v_int8 = length;
3932
- break;
3933
- case GI_TYPE_TAG_UINT8:
3934
- argument->v_uint8 = length;
3935
- break;
3936
- case GI_TYPE_TAG_INT16:
3937
- argument->v_int16 = length;
3938
- break;
3939
- case GI_TYPE_TAG_UINT16:
3940
- argument->v_uint16 = length;
3941
- break;
3942
- case GI_TYPE_TAG_INT32:
3943
- argument->v_int32 = (gint32)length;
3944
- break;
3945
- case GI_TYPE_TAG_UINT32:
3946
- argument->v_uint32 = (guint32)length;
3947
- break;
3948
- case GI_TYPE_TAG_INT64:
3949
- argument->v_int64 = length;
3950
- break;
3951
- case GI_TYPE_TAG_UINT64:
3952
- argument->v_uint64 = length;
3953
- break;
3954
- case GI_TYPE_TAG_FLOAT:
3955
- case GI_TYPE_TAG_DOUBLE:
3956
- case GI_TYPE_TAG_GTYPE:
3957
- case GI_TYPE_TAG_UTF8:
3958
- case GI_TYPE_TAG_FILENAME:
3959
- case GI_TYPE_TAG_ARRAY:
3960
- case GI_TYPE_TAG_INTERFACE:
3961
- case GI_TYPE_TAG_GLIST:
3962
- case GI_TYPE_TAG_GSLIST:
3963
- case GI_TYPE_TAG_GHASH:
3964
- case GI_TYPE_TAG_ERROR:
3965
- case GI_TYPE_TAG_UNICHAR:
3966
1614
  rb_raise(rb_eNotImpError,
3967
- "TODO: invalid argument?: length[%s]",
3968
- g_type_tag_to_string(type_tag));
3969
- break;
3970
- default:
3971
- g_assert_not_reached();
1615
+ "TODO: free GIArgument(interface)[value] everything");
1616
+ break;
1617
+ case GI_INFO_TYPE_SIGNAL:
1618
+ rb_raise(rb_eNotImpError,
1619
+ "TODO: free GIArgument(interface)[signal] everything");
1620
+ break;
1621
+ case GI_INFO_TYPE_VFUNC:
1622
+ rb_raise(rb_eNotImpError,
1623
+ "TODO: free GIArgument(interface)[vfunc] everything");
1624
+ break;
1625
+ case GI_INFO_TYPE_PROPERTY:
1626
+ rb_raise(rb_eNotImpError,
1627
+ "TODO: free GIArgument(interface)[property] everything");
1628
+ break;
1629
+ case GI_INFO_TYPE_FIELD:
1630
+ rb_raise(rb_eNotImpError,
1631
+ "TODO: free GIArgument(interface)[field] everything");
1632
+ break;
1633
+ case GI_INFO_TYPE_ARG:
1634
+ rb_raise(rb_eNotImpError,
1635
+ "TODO: free GIArgument(interface)[arg] everything");
1636
+ break;
1637
+ case GI_INFO_TYPE_TYPE:
1638
+ rb_raise(rb_eNotImpError,
1639
+ "TODO: free GIArgument(interface)[type] everything");
1640
+ break;
1641
+ case GI_INFO_TYPE_UNRESOLVED:
1642
+ rb_raise(rb_eNotImpError,
1643
+ "TODO: free GIArgument(interface)[unresolved] everything");
1644
+ break;
1645
+ default:
1646
+ g_assert_not_reached();
3972
1647
  break;
3973
1648
  }
3974
1649
  }
3975
1650
 
3976
1651
  static void
3977
- set_in_array_boolean_arguments_from_ruby(GIArgument *array_argument,
3978
- VALUE rb_boolean_array)
3979
- {
3980
- gboolean *booleans;
3981
- long i, n_args;
3982
-
3983
- n_args = RARRAY_LEN(rb_boolean_array);
3984
- booleans = ALLOC_N(gboolean, n_args);
3985
- for (i = 0; i < n_args; i++) {
3986
- booleans[i] = RVAL2CBOOL(RARRAY_PTR(rb_boolean_array)[i]);
3987
- }
3988
-
3989
- array_argument->v_pointer = booleans;
3990
- }
3991
-
3992
- static void
3993
- set_in_array_int8_arguments_from_ruby(GIArgument *array_argument,
3994
- VALUE rb_number_array)
3995
- {
3996
- gint8 *numbers;
3997
- long i, n_args;
3998
-
3999
- n_args = RARRAY_LEN(rb_number_array);
4000
- numbers = ALLOC_N(gint8, n_args);
4001
- for (i = 0; i < n_args; i++) {
4002
- numbers[i] = NUM2CHR(RARRAY_PTR(rb_number_array)[i]);
4003
- }
4004
-
4005
- array_argument->v_pointer = numbers;
4006
- }
4007
-
4008
- static void
4009
- set_in_array_uint8_arguments_from_ruby(GIArgument *array_argument,
4010
- VALUE rb_number_array)
4011
- {
4012
- guint8 *numbers;
4013
- long i, n_args;
4014
-
4015
- n_args = RARRAY_LEN(rb_number_array);
4016
- numbers = ALLOC_N(guint8, n_args);
4017
- for (i = 0; i < n_args; i++) {
4018
- numbers[i] = (guint8)NUM2CHR(RARRAY_PTR(rb_number_array)[i]);
4019
- }
4020
-
4021
- array_argument->v_pointer = numbers;
4022
- }
4023
-
4024
- static void
4025
- set_in_array_int16_arguments_from_ruby(GIArgument *array_argument,
4026
- VALUE rb_number_array)
4027
- {
4028
- gint16 *numbers;
4029
- long i, n_args;
4030
-
4031
- n_args = RARRAY_LEN(rb_number_array);
4032
- numbers = ALLOC_N(gint16, n_args);
4033
- for (i = 0; i < n_args; i++) {
4034
- numbers[i] = NUM2SHORT(RARRAY_PTR(rb_number_array)[i]);
4035
- }
4036
-
4037
- array_argument->v_pointer = numbers;
4038
- }
4039
-
4040
- static void
4041
- set_in_array_uint16_arguments_from_ruby(GIArgument *array_argument,
4042
- VALUE rb_number_array)
4043
- {
4044
- guint16 *numbers;
4045
- long i, n_args;
4046
-
4047
- n_args = RARRAY_LEN(rb_number_array);
4048
- numbers = ALLOC_N(guint16, n_args);
4049
- for (i = 0; i < n_args; i++) {
4050
- numbers[i] = NUM2USHORT(RARRAY_PTR(rb_number_array)[i]);
4051
- }
4052
-
4053
- array_argument->v_pointer = numbers;
4054
- }
4055
-
4056
- static void
4057
- set_in_array_int32_arguments_from_ruby(GIArgument *array_argument,
4058
- VALUE rb_number_array)
4059
- {
4060
- gint32 *numbers;
4061
- long i, n_args;
4062
-
4063
- n_args = RARRAY_LEN(rb_number_array);
4064
- numbers = ALLOC_N(gint32, n_args);
4065
- for (i = 0; i < n_args; i++) {
4066
- numbers[i] = NUM2INT(RARRAY_PTR(rb_number_array)[i]);
4067
- }
4068
-
4069
- array_argument->v_pointer = numbers;
4070
- }
4071
-
4072
- static void
4073
- set_in_array_uint32_arguments_from_ruby(GIArgument *array_argument,
4074
- VALUE rb_number_array)
4075
- {
4076
- guint32 *numbers;
4077
- long i, n_args;
4078
-
4079
- n_args = RARRAY_LEN(rb_number_array);
4080
- numbers = ALLOC_N(guint32, n_args);
4081
- for (i = 0; i < n_args; i++) {
4082
- numbers[i] = NUM2UINT(RARRAY_PTR(rb_number_array)[i]);
4083
- }
4084
-
4085
- array_argument->v_pointer = numbers;
4086
- }
4087
-
4088
- static void
4089
- set_in_array_int64_arguments_from_ruby(GIArgument *array_argument,
4090
- VALUE rb_number_array)
4091
- {
4092
- gint64 *numbers;
4093
- long i, n_args;
4094
-
4095
- n_args = RARRAY_LEN(rb_number_array);
4096
- numbers = ALLOC_N(gint64, n_args);
4097
- for (i = 0; i < n_args; i++) {
4098
- numbers[i] = NUM2LL(RARRAY_PTR(rb_number_array)[i]);
4099
- }
4100
-
4101
- array_argument->v_pointer = numbers;
4102
- }
4103
-
4104
- static void
4105
- set_in_array_uint64_arguments_from_ruby(GIArgument *array_argument,
4106
- VALUE rb_number_array)
4107
- {
4108
- guint64 *numbers;
4109
- long i, n_args;
4110
-
4111
- n_args = RARRAY_LEN(rb_number_array);
4112
- numbers = ALLOC_N(guint64, n_args);
4113
- for (i = 0; i < n_args; i++) {
4114
- numbers[i] = NUM2ULL(RARRAY_PTR(rb_number_array)[i]);
4115
- }
4116
-
4117
- array_argument->v_pointer = numbers;
4118
- }
4119
-
4120
- static void
4121
- set_in_array_float_arguments_from_ruby(GIArgument *array_argument,
4122
- VALUE rb_number_array)
4123
- {
4124
- gfloat *numbers;
4125
- long i, n_args;
4126
-
4127
- n_args = RARRAY_LEN(rb_number_array);
4128
- numbers = ALLOC_N(gfloat, n_args);
4129
- for (i = 0; i < n_args; i++) {
4130
- numbers[i] = NUM2DBL(RARRAY_PTR(rb_number_array)[i]);
4131
- }
4132
-
4133
- array_argument->v_pointer = numbers;
4134
- }
4135
-
4136
- static void
4137
- set_in_array_double_arguments_from_ruby(GIArgument *array_argument,
4138
- VALUE rb_number_array)
4139
- {
4140
- gdouble *numbers;
4141
- long i, n_args;
4142
-
4143
- n_args = RARRAY_LEN(rb_number_array);
4144
- numbers = ALLOC_N(gdouble, n_args);
4145
- for (i = 0; i < n_args; i++) {
4146
- numbers[i] = NUM2DBL(RARRAY_PTR(rb_number_array)[i]);
4147
- }
4148
-
4149
- array_argument->v_pointer = numbers;
4150
- }
4151
-
4152
- static void
4153
- set_in_array_gtype_arguments_from_ruby(GIArgument *array_argument,
4154
- VALUE rb_types)
4155
- {
4156
- GType *types;
4157
- long i, n_types;
4158
-
4159
- n_types = RARRAY_LEN(rb_types);
4160
- types = ALLOC_N(GType, n_types);
4161
- for (i = 0; i < n_types; i++) {
4162
- VALUE rb_type = RARRAY_PTR(rb_types)[i];
4163
- types[i] = rbgobj_gtype_get(rb_type);
4164
- }
4165
-
4166
- array_argument->v_pointer = types;
4167
- }
4168
-
4169
- typedef struct {
4170
- GIStructInfo *struct_info;
4171
- VALUE rb_argument;
4172
- long n_args;
4173
- gchar *values;
4174
- } ArrayInterfaceStructFromRubyData;
4175
-
4176
- static VALUE
4177
- set_in_array_interface_struct_arguments_from_ruby_body(VALUE value)
4178
- {
4179
- ArrayInterfaceStructFromRubyData *data;
4180
- gsize size;
4181
- gint i;
4182
-
4183
- data = (ArrayInterfaceStructFromRubyData *)value;
4184
- size = g_struct_info_get_size(data->struct_info);
4185
- data->values = xmalloc(size * data->n_args);
4186
-
4187
- for (i = 0; i < data->n_args; i++) {
4188
- VALUE rb_element;
4189
- gpointer element;
4190
-
4191
- rb_element = RARRAY_PTR(data->rb_argument)[i];
4192
- element = rb_gi_struct_info_from_ruby(data->struct_info, rb_element);
4193
- memcpy(data->values + (size * i),
4194
- element,
4195
- size);
4196
- }
4197
-
4198
- return Qnil;
4199
- }
4200
-
4201
- static G_GNUC_NORETURN VALUE
4202
- set_in_array_interface_struct_arguments_from_ruby_rescue(VALUE value)
4203
- {
4204
- ArrayInterfaceStructFromRubyData *data;
4205
-
4206
- data = (ArrayInterfaceStructFromRubyData *)value;
4207
- g_base_info_unref((GIBaseInfo *)(data->struct_info));
4208
- xfree(data->values);
4209
-
4210
- rb_exc_raise(rb_errinfo());
4211
- }
4212
-
4213
- static void
4214
- set_in_array_interface_struct_arguments_from_ruby(GIArgument *array_argument,
4215
- GIStructInfo *struct_info,
4216
- VALUE rb_argument)
4217
- {
4218
- ArrayInterfaceStructFromRubyData data;
4219
-
4220
- data.struct_info = struct_info;
4221
- data.rb_argument = rb_argument;
4222
- data.n_args = RARRAY_LEN(rb_argument);
4223
- data.values = NULL;
4224
- rb_rescue(set_in_array_interface_struct_arguments_from_ruby_body,
4225
- (VALUE)&data,
4226
- set_in_array_interface_struct_arguments_from_ruby_rescue,
4227
- (VALUE)&data);
4228
- array_argument->v_pointer = data.values;
4229
- }
4230
-
4231
- typedef struct {
4232
- VALUE rb_argument;
4233
- long n_args;
4234
- gpointer *values;
4235
- } ArrayInterfaceObjectFromRubyData;
4236
-
4237
- static VALUE
4238
- set_in_array_interface_object_arguments_from_ruby_body(VALUE value)
4239
- {
4240
- ArrayInterfaceObjectFromRubyData *data;
4241
- gint i;
4242
-
4243
- data = (ArrayInterfaceObjectFromRubyData *)value;
4244
- data->values = xmalloc(sizeof(gpointer) * data->n_args);
4245
-
4246
- for (i = 0; i < data->n_args; i++) {
4247
- VALUE rb_element;
4248
-
4249
- rb_element = RARRAY_AREF(data->rb_argument, i);
4250
- data->values[i] = RVAL2GOBJ(rb_element);
4251
- }
4252
-
4253
- return Qnil;
4254
- }
4255
-
4256
- static G_GNUC_NORETURN VALUE
4257
- set_in_array_interface_object_arguments_from_ruby_rescue(VALUE value)
1652
+ rb_gi_boxed_free_callback(gpointer boxed, gpointer user_data)
4258
1653
  {
4259
- ArrayInterfaceObjectFromRubyData *data;
4260
-
4261
- data = (ArrayInterfaceObjectFromRubyData *)value;
4262
- xfree(data->values);
1654
+ GType *gtype = user_data;
4263
1655
 
4264
- rb_exc_raise(rb_errinfo());
1656
+ g_boxed_free(*gtype, boxed);
4265
1657
  }
4266
1658
 
4267
- static void
4268
- set_in_array_interface_object_arguments_from_ruby(GIArgument *array_argument,
4269
- VALUE rb_argument)
4270
- {
4271
- ArrayInterfaceObjectFromRubyData data;
4272
-
4273
- data.rb_argument = rb_argument;
4274
- data.n_args = RARRAY_LEN(rb_argument);
4275
- data.values = NULL;
4276
- rb_rescue(set_in_array_interface_object_arguments_from_ruby_body,
4277
- (VALUE)&data,
4278
- set_in_array_interface_object_arguments_from_ruby_rescue,
4279
- (VALUE)&data);
4280
- array_argument->v_pointer = data.values;
4281
- }
4282
1659
 
4283
1660
  static void
4284
- set_in_array_interface_arguments_from_ruby(GIArgument *array_argument,
4285
- GITypeInfo *element_type_info,
4286
- VALUE rb_argument)
1661
+ rb_gi_return_argument_free_everything_glist_interface(GIArgument *argument,
1662
+ G_GNUC_UNUSED GITypeInfo *type_info,
1663
+ GITypeInfo *element_type_info)
4287
1664
  {
4288
1665
  GIBaseInfo *interface_info;
4289
1666
  GIInfoType interface_type;
1667
+ const gchar *interface_name;
4290
1668
  GType gtype;
4291
- const char *interface_name;
4292
1669
 
4293
1670
  interface_info = g_type_info_get_interface(element_type_info);
4294
1671
  interface_type = g_base_info_get_type(interface_info);
1672
+ interface_name = g_info_type_to_string(interface_type);
4295
1673
  gtype = g_registered_type_info_get_g_type(interface_info);
1674
+ g_base_info_unref(interface_info);
1675
+ g_base_info_unref(element_type_info);
4296
1676
 
4297
1677
  switch (interface_type) {
4298
1678
  case GI_INFO_TYPE_INVALID:
4299
1679
  case GI_INFO_TYPE_FUNCTION:
4300
1680
  case GI_INFO_TYPE_CALLBACK:
4301
- interface_name = g_info_type_to_string(interface_type);
4302
- g_base_info_unref(interface_info);
4303
1681
  rb_raise(rb_eNotImpError,
4304
- "TODO: Ruby -> GIArgument(array)[interface(%s)](%s)",
1682
+ "TODO: free GIArgument(GList)[interface(%s)](%s) everything",
4305
1683
  interface_name,
4306
1684
  g_type_name(gtype));
4307
1685
  break;
4308
1686
  case GI_INFO_TYPE_STRUCT:
4309
- {
4310
- GIStructInfo *struct_info = (GIStructInfo *)interface_info;
4311
- set_in_array_interface_struct_arguments_from_ruby(array_argument,
4312
- struct_info,
4313
- rb_argument);
1687
+ if (gtype == G_TYPE_NONE) {
1688
+ rb_raise(rb_eNotImpError,
1689
+ "TODO: free GIArgument(GList)[interface(%s)](%s) everything",
1690
+ interface_name,
1691
+ g_type_name(gtype));
1692
+ } else {
1693
+ g_list_foreach(argument->v_pointer,
1694
+ rb_gi_boxed_free_callback,
1695
+ &gtype);
1696
+ g_list_free(argument->v_pointer);
4314
1697
  }
4315
1698
  break;
4316
1699
  case GI_INFO_TYPE_BOXED:
1700
+ g_list_foreach(argument->v_pointer, rb_gi_boxed_free_callback, &gtype);
1701
+ g_list_free(argument->v_pointer);
1702
+ break;
4317
1703
  case GI_INFO_TYPE_ENUM:
4318
1704
  case GI_INFO_TYPE_FLAGS:
4319
- interface_name = g_info_type_to_string(interface_type);
4320
- g_base_info_unref(interface_info);
4321
1705
  rb_raise(rb_eNotImpError,
4322
- "TODO: Ruby -> GIArgument(array)[interface(%s)](%s)",
1706
+ "TODO: free GIArgument(GList)[interface(%s)](%s) everything",
4323
1707
  interface_name,
4324
1708
  g_type_name(gtype));
4325
1709
  break;
4326
1710
  case GI_INFO_TYPE_OBJECT:
4327
- set_in_array_interface_object_arguments_from_ruby(array_argument,
4328
- rb_argument);
4329
- break;
4330
1711
  case GI_INFO_TYPE_INTERFACE:
1712
+ g_list_foreach(argument->v_pointer, (GFunc)g_object_unref, NULL);
1713
+ g_list_free(argument->v_pointer);
1714
+ break;
4331
1715
  case GI_INFO_TYPE_CONSTANT:
4332
1716
  case GI_INFO_TYPE_INVALID_0:
4333
1717
  case GI_INFO_TYPE_UNION:
@@ -4339,10 +1723,8 @@ set_in_array_interface_arguments_from_ruby(GIArgument *array_argument,
4339
1723
  case GI_INFO_TYPE_ARG:
4340
1724
  case GI_INFO_TYPE_TYPE:
4341
1725
  case GI_INFO_TYPE_UNRESOLVED:
4342
- interface_name = g_info_type_to_string(interface_type);
4343
- g_base_info_unref(interface_info);
4344
1726
  rb_raise(rb_eNotImpError,
4345
- "TODO: Ruby -> GIArgument(array)[interface(%s)](%s)",
1727
+ "TODO: free GIArgument(GList)[interface(%s)](%s) everything",
4346
1728
  interface_name,
4347
1729
  g_type_name(gtype));
4348
1730
  break;
@@ -4353,347 +1735,20 @@ set_in_array_interface_arguments_from_ruby(GIArgument *array_argument,
4353
1735
  }
4354
1736
 
4355
1737
  static void
4356
- in_array_c_argument_from_ruby(GIArgument *array_argument,
4357
- GIArgument *length_argument,
4358
- G_GNUC_UNUSED GITypeInfo *array_type_info,
4359
- GITypeInfo *length_type_info,
4360
- GITypeInfo *element_type_info,
4361
- VALUE rb_argument)
4362
- {
4363
- GITypeTag element_type_tag;
4364
-
4365
- element_type_tag = g_type_info_get_tag(element_type_info);
4366
- switch (element_type_tag) {
4367
- case GI_TYPE_TAG_VOID:
4368
- rb_raise(rb_eNotImpError,
4369
- "TODO: Ruby -> GIArgument(array)[%s]",
4370
- g_type_tag_to_string(element_type_tag));
4371
- break;
4372
- case GI_TYPE_TAG_BOOLEAN:
4373
- rb_argument = rbg_to_array(rb_argument);
4374
- set_in_array_boolean_arguments_from_ruby(array_argument, rb_argument);
4375
- set_in_array_length_argument(length_argument, length_type_info,
4376
- RARRAY_LEN(rb_argument));
4377
- break;
4378
- case GI_TYPE_TAG_INT8:
4379
- if (RB_TYPE_P(rb_argument, RUBY_T_STRING)) {
4380
- array_argument->v_pointer = RSTRING_PTR(rb_argument);
4381
- set_in_array_length_argument(length_argument, length_type_info,
4382
- RSTRING_LEN(rb_argument));
4383
- } else {
4384
- rb_argument = rbg_to_array(rb_argument);
4385
- set_in_array_int8_arguments_from_ruby(array_argument, rb_argument);
4386
- set_in_array_length_argument(length_argument, length_type_info,
4387
- RARRAY_LEN(rb_argument));
4388
- }
4389
- break;
4390
- case GI_TYPE_TAG_UINT8:
4391
- if (RB_TYPE_P(rb_argument, RUBY_T_STRING)) {
4392
- array_argument->v_pointer = RSTRING_PTR(rb_argument);
4393
- set_in_array_length_argument(length_argument, length_type_info,
4394
- RSTRING_LEN(rb_argument));
4395
- } else {
4396
- rb_argument = rbg_to_array(rb_argument);
4397
- set_in_array_uint8_arguments_from_ruby(array_argument, rb_argument);
4398
- set_in_array_length_argument(length_argument, length_type_info,
4399
- RARRAY_LEN(rb_argument));
4400
- }
4401
- break;
4402
- case GI_TYPE_TAG_INT16:
4403
- rb_argument = rbg_to_array(rb_argument);
4404
- set_in_array_int16_arguments_from_ruby(array_argument, rb_argument);
4405
- set_in_array_length_argument(length_argument, length_type_info,
4406
- RARRAY_LEN(rb_argument));
4407
- break;
4408
- case GI_TYPE_TAG_UINT16:
4409
- rb_argument = rbg_to_array(rb_argument);
4410
- set_in_array_uint16_arguments_from_ruby(array_argument, rb_argument);
4411
- set_in_array_length_argument(length_argument, length_type_info,
4412
- RARRAY_LEN(rb_argument));
4413
- break;
4414
- case GI_TYPE_TAG_INT32:
4415
- rb_argument = rbg_to_array(rb_argument);
4416
- set_in_array_int32_arguments_from_ruby(array_argument, rb_argument);
4417
- set_in_array_length_argument(length_argument, length_type_info,
4418
- RARRAY_LEN(rb_argument));
4419
- break;
4420
- case GI_TYPE_TAG_UINT32:
4421
- rb_argument = rbg_to_array(rb_argument);
4422
- set_in_array_uint32_arguments_from_ruby(array_argument, rb_argument);
4423
- set_in_array_length_argument(length_argument, length_type_info,
4424
- RARRAY_LEN(rb_argument));
4425
- break;
4426
- case GI_TYPE_TAG_INT64:
4427
- rb_argument = rbg_to_array(rb_argument);
4428
- set_in_array_int64_arguments_from_ruby(array_argument, rb_argument);
4429
- set_in_array_length_argument(length_argument, length_type_info,
4430
- RARRAY_LEN(rb_argument));
4431
- break;
4432
- case GI_TYPE_TAG_UINT64:
4433
- rb_argument = rbg_to_array(rb_argument);
4434
- set_in_array_uint64_arguments_from_ruby(array_argument, rb_argument);
4435
- set_in_array_length_argument(length_argument, length_type_info,
4436
- RARRAY_LEN(rb_argument));
4437
- break;
4438
- case GI_TYPE_TAG_FLOAT:
4439
- rb_argument = rbg_to_array(rb_argument);
4440
- set_in_array_float_arguments_from_ruby(array_argument, rb_argument);
4441
- set_in_array_length_argument(length_argument, length_type_info,
4442
- RARRAY_LEN(rb_argument));
4443
- break;
4444
- case GI_TYPE_TAG_DOUBLE:
4445
- rb_argument = rbg_to_array(rb_argument);
4446
- set_in_array_double_arguments_from_ruby(array_argument, rb_argument);
4447
- set_in_array_length_argument(length_argument, length_type_info,
4448
- RARRAY_LEN(rb_argument));
4449
- break;
4450
- case GI_TYPE_TAG_GTYPE:
4451
- rb_argument = rbg_to_array(rb_argument);
4452
- set_in_array_gtype_arguments_from_ruby(array_argument,
4453
- rb_argument);
4454
- set_in_array_length_argument(length_argument, length_type_info,
4455
- RARRAY_LEN(rb_argument));
4456
- break;
4457
- case GI_TYPE_TAG_UTF8:
4458
- case GI_TYPE_TAG_FILENAME:
4459
- rb_argument = rbg_to_array(rb_argument);
4460
- array_argument->v_pointer = RVAL2STRV(rb_argument);
4461
- set_in_array_length_argument(length_argument, length_type_info,
4462
- RARRAY_LEN(rb_argument));
4463
- break;
4464
- case GI_TYPE_TAG_ARRAY:
4465
- rb_raise(rb_eNotImpError,
4466
- "TODO: Ruby -> GIArgument(array)[%s]",
4467
- g_type_tag_to_string(element_type_tag));
4468
- break;
4469
- case GI_TYPE_TAG_INTERFACE:
4470
- rb_argument = rbg_to_array(rb_argument);
4471
- set_in_array_interface_arguments_from_ruby(array_argument,
4472
- element_type_info,
4473
- rb_argument);
4474
- set_in_array_length_argument(length_argument, length_type_info,
4475
- RARRAY_LEN(rb_argument));
4476
- break;
4477
- case GI_TYPE_TAG_GLIST:
4478
- case GI_TYPE_TAG_GSLIST:
4479
- case GI_TYPE_TAG_GHASH:
4480
- case GI_TYPE_TAG_ERROR:
4481
- case GI_TYPE_TAG_UNICHAR:
4482
- rb_raise(rb_eNotImpError,
4483
- "TODO: Ruby -> GIArgument(array)[%s]",
4484
- g_type_tag_to_string(element_type_tag));
4485
- break;
4486
- default:
4487
- g_assert_not_reached();
4488
- break;
4489
- }
4490
- }
4491
-
4492
- static void
4493
- in_array_argument_from_ruby(GIArgument *array_argument,
4494
- GIArgument *length_argument,
4495
- GITypeInfo *array_type_info,
4496
- GITypeInfo *length_type_info,
4497
- VALUE rb_argument)
4498
- {
4499
- GIArrayType array_type;
4500
- GITypeInfo *element_type_info;
4501
-
4502
- array_type = g_type_info_get_array_type(array_type_info);
4503
- element_type_info = g_type_info_get_param_type(array_type_info, 0);
4504
- switch (array_type) {
4505
- case GI_ARRAY_TYPE_C:
4506
- in_array_c_argument_from_ruby(array_argument,
4507
- length_argument,
4508
- array_type_info,
4509
- length_type_info,
4510
- element_type_info,
4511
- rb_argument);
4512
- break;
4513
- case GI_ARRAY_TYPE_ARRAY:
4514
- case GI_ARRAY_TYPE_PTR_ARRAY:
4515
- case GI_ARRAY_TYPE_BYTE_ARRAY:
4516
- rb_raise(rb_eNotImpError,
4517
- "TODO: Ruby -> GIArgument(array)[%s]",
4518
- g_type_tag_to_string(g_type_info_get_tag(element_type_info)));
4519
- break;
4520
- default:
4521
- g_assert_not_reached();
4522
- break;
4523
- }
4524
- g_base_info_unref(element_type_info);
4525
- }
4526
-
4527
- static void
4528
- set_inout_array_length_argument(GIArgument *argument,
4529
- GITypeInfo *type_info,
4530
- GIArgument *length)
4531
- {
4532
- GITypeTag type_tag;
4533
-
4534
- if (!argument) {
4535
- return;
4536
- }
4537
-
4538
- type_tag = g_type_info_get_tag(type_info);
4539
- switch (type_tag) {
4540
- case GI_TYPE_TAG_VOID:
4541
- case GI_TYPE_TAG_BOOLEAN:
4542
- rb_raise(rb_eNotImpError,
4543
- "TODO: invalid argument?: length[%s]",
4544
- g_type_tag_to_string(type_tag));
4545
- break;
4546
- case GI_TYPE_TAG_INT8:
4547
- argument->v_pointer = ALLOC(gint8);
4548
- *((gint8 *)argument->v_pointer) = length->v_int8;
4549
- break;
4550
- case GI_TYPE_TAG_UINT8:
4551
- argument->v_pointer = ALLOC(guint8);
4552
- *((guint8 *)argument->v_pointer) = length->v_uint8;
4553
- break;
4554
- case GI_TYPE_TAG_INT16:
4555
- argument->v_pointer = ALLOC(gint16);
4556
- *((gint16 *)argument->v_pointer) = length->v_int16;
4557
- break;
4558
- case GI_TYPE_TAG_UINT16:
4559
- argument->v_pointer = ALLOC(guint16);
4560
- *((guint16 *)argument->v_pointer) = length->v_uint16;
4561
- break;
4562
- case GI_TYPE_TAG_INT32:
4563
- argument->v_pointer = ALLOC(gint32);
4564
- *((gint32 *)argument->v_pointer) = length->v_int32;
4565
- break;
4566
- case GI_TYPE_TAG_UINT32:
4567
- argument->v_pointer = ALLOC(guint32);
4568
- *((guint32 *)argument->v_pointer) = length->v_uint32;
4569
- break;
4570
- case GI_TYPE_TAG_INT64:
4571
- argument->v_pointer = ALLOC(gint64);
4572
- *((gint64 *)argument->v_pointer) = length->v_int64;
4573
- break;
4574
- case GI_TYPE_TAG_UINT64:
4575
- argument->v_pointer = ALLOC(guint64);
4576
- *((guint64 *)argument->v_pointer) = length->v_uint64;
4577
- break;
4578
- case GI_TYPE_TAG_FLOAT:
4579
- case GI_TYPE_TAG_DOUBLE:
4580
- case GI_TYPE_TAG_GTYPE:
4581
- case GI_TYPE_TAG_UTF8:
4582
- case GI_TYPE_TAG_FILENAME:
4583
- case GI_TYPE_TAG_ARRAY:
4584
- case GI_TYPE_TAG_INTERFACE:
4585
- case GI_TYPE_TAG_GLIST:
4586
- case GI_TYPE_TAG_GSLIST:
4587
- case GI_TYPE_TAG_GHASH:
4588
- case GI_TYPE_TAG_ERROR:
4589
- case GI_TYPE_TAG_UNICHAR:
4590
- rb_raise(rb_eNotImpError,
4591
- "TODO: invalid argument?: length[%s]",
4592
- g_type_tag_to_string(type_tag));
4593
- break;
4594
- default:
4595
- g_assert_not_reached();
4596
- break;
4597
- }
4598
- }
4599
-
4600
- static void
4601
- inout_array_argument_from_ruby(GIArgument *array_argument,
4602
- GIArgument *length_argument,
4603
- GITypeInfo *array_type_info,
4604
- GITypeInfo *length_type_info,
4605
- VALUE rb_argument)
4606
- {
4607
- GIArgument in_array_argument;
4608
- GIArgument in_length_argument;
4609
-
4610
- in_array_argument_from_ruby(&in_array_argument,
4611
- &in_length_argument,
4612
- array_type_info,
4613
- length_type_info,
4614
- rb_argument);
4615
-
4616
- array_argument->v_pointer = ALLOC(gpointer);
4617
- *((gpointer *)array_argument->v_pointer) = in_array_argument.v_pointer;
4618
- set_inout_array_length_argument(length_argument,
4619
- length_type_info,
4620
- &in_length_argument);
4621
- }
4622
-
4623
- GIArgument *
4624
- rb_gi_in_array_argument_from_ruby(GIArgument *array_argument,
4625
- GIArgument *length_argument,
4626
- GIArgInfo *array_arg_info,
4627
- GIArgInfo *length_arg_info,
4628
- VALUE rb_argument)
4629
- {
4630
- GITypeInfo array_type_info;
4631
- GITypeInfo length_type_info;
4632
- GITypeInfo *length_type_info_arg = NULL;
4633
-
4634
- if (NIL_P(rb_argument) && rb_gi_arg_info_may_be_null(array_arg_info)) {
4635
- memset(array_argument, 0, sizeof(GIArgument));
4636
- if (length_argument) {
4637
- memset(length_argument, 0, sizeof(GIArgument));
4638
- }
4639
- return array_argument;
4640
- }
4641
-
4642
- g_arg_info_load_type(array_arg_info, &array_type_info);
4643
- if (length_arg_info) {
4644
- g_arg_info_load_type(length_arg_info, &length_type_info);
4645
- length_type_info_arg = &length_type_info;
4646
- }
4647
- if (g_arg_info_get_direction(array_arg_info) == GI_DIRECTION_INOUT) {
4648
- inout_array_argument_from_ruby(array_argument,
4649
- length_argument,
4650
- &array_type_info,
4651
- length_type_info_arg,
4652
- rb_argument);
4653
- } else {
4654
- GITransfer transfer;
4655
-
4656
- in_array_argument_from_ruby(array_argument,
4657
- length_argument,
4658
- &array_type_info,
4659
- length_type_info_arg,
4660
- rb_argument);
4661
- transfer = g_arg_info_get_ownership_transfer(array_arg_info);
4662
- rb_gi_in_argument_transfer(array_argument,
4663
- transfer,
4664
- &array_type_info,
4665
- rb_argument);
4666
- }
4667
-
4668
- return array_argument;
4669
- }
4670
-
4671
- static void
4672
- rb_gi_value_argument_free_array_c(VALUE rb_argument,
4673
- GIArgument *argument,
4674
- G_GNUC_UNUSED GITypeInfo *type_info,
4675
- GITypeInfo *element_type_info)
1738
+ rb_gi_return_argument_free_everything_glist(GIArgument *argument,
1739
+ GITypeInfo *type_info)
4676
1740
  {
1741
+ GITypeInfo *element_type_info;
4677
1742
  GITypeTag element_type_tag;
4678
1743
 
1744
+ element_type_info = g_type_info_get_param_type(type_info, 0);
4679
1745
  element_type_tag = g_type_info_get_tag(element_type_info);
1746
+
4680
1747
  switch (element_type_tag) {
4681
1748
  case GI_TYPE_TAG_VOID:
4682
- rb_raise(rb_eNotImpError,
4683
- "TODO: free GIArgument(array)[%s]",
4684
- g_type_tag_to_string(element_type_tag));
4685
- break;
4686
1749
  case GI_TYPE_TAG_BOOLEAN:
4687
- xfree(argument->v_pointer);
4688
- break;
4689
1750
  case GI_TYPE_TAG_INT8:
4690
1751
  case GI_TYPE_TAG_UINT8:
4691
- if (RB_TYPE_P(rb_argument, RUBY_T_STRING)) {
4692
- /* Do nothing */
4693
- } else {
4694
- xfree(argument->v_pointer);
4695
- }
4696
- break;
4697
1752
  case GI_TYPE_TAG_INT16:
4698
1753
  case GI_TYPE_TAG_UINT16:
4699
1754
  case GI_TYPE_TAG_INT32:
@@ -4703,101 +1758,136 @@ rb_gi_value_argument_free_array_c(VALUE rb_argument,
4703
1758
  case GI_TYPE_TAG_FLOAT:
4704
1759
  case GI_TYPE_TAG_DOUBLE:
4705
1760
  case GI_TYPE_TAG_GTYPE:
4706
- xfree(argument->v_pointer);
1761
+ g_base_info_unref(element_type_info);
1762
+ rb_raise(rb_eNotImpError,
1763
+ "TODO: free GIArgument(GList)[%s] everything",
1764
+ g_type_tag_to_string(element_type_tag));
4707
1765
  break;
4708
1766
  case GI_TYPE_TAG_UTF8:
4709
- case GI_TYPE_TAG_FILENAME:
4710
- g_free(argument->v_pointer);
1767
+ g_base_info_unref(element_type_info);
1768
+ g_list_foreach(argument->v_pointer, (GFunc)g_free, NULL);
1769
+ g_list_free(argument->v_pointer);
4711
1770
  break;
1771
+ case GI_TYPE_TAG_FILENAME:
4712
1772
  case GI_TYPE_TAG_ARRAY:
1773
+ g_base_info_unref(element_type_info);
4713
1774
  rb_raise(rb_eNotImpError,
4714
- "TODO: free GIArgument(array)[%s]",
1775
+ "TODO: free GIArgument(GList)[%s] everything",
4715
1776
  g_type_tag_to_string(element_type_tag));
4716
1777
  break;
4717
1778
  case GI_TYPE_TAG_INTERFACE:
4718
- xfree(argument->v_pointer);
1779
+ rb_gi_return_argument_free_everything_glist_interface(argument,
1780
+ type_info,
1781
+ element_type_info);
4719
1782
  break;
4720
1783
  case GI_TYPE_TAG_GLIST:
4721
1784
  case GI_TYPE_TAG_GSLIST:
4722
1785
  case GI_TYPE_TAG_GHASH:
4723
1786
  case GI_TYPE_TAG_ERROR:
4724
1787
  case GI_TYPE_TAG_UNICHAR:
1788
+ g_base_info_unref(element_type_info);
4725
1789
  rb_raise(rb_eNotImpError,
4726
- "TODO: free GIArgument(array)[%s]",
1790
+ "TODO: free GIArgument(GList)[%s] everything",
4727
1791
  g_type_tag_to_string(element_type_tag));
4728
1792
  break;
4729
1793
  default:
1794
+ g_base_info_unref(element_type_info);
4730
1795
  g_assert_not_reached();
4731
1796
  break;
4732
1797
  }
4733
1798
  }
4734
1799
 
4735
1800
  static void
4736
- rb_gi_value_argument_free_array(VALUE rb_argument,
4737
- GIArgument *argument,
4738
- GITypeInfo *type_info)
1801
+ rb_gi_return_argument_free_everything_gslist_interface(GIArgument *argument,
1802
+ G_GNUC_UNUSED GITypeInfo *type_info,
1803
+ GITypeInfo *element_type_info)
4739
1804
  {
4740
- GIArrayType array_type;
4741
- GITypeInfo *element_type_info;
1805
+ GIBaseInfo *interface_info;
1806
+ GIInfoType interface_type;
1807
+ const gchar *interface_name;
1808
+ GType gtype;
4742
1809
 
4743
- array_type = g_type_info_get_array_type(type_info);
4744
- element_type_info = g_type_info_get_param_type(type_info, 0);
4745
- switch (array_type) {
4746
- case GI_ARRAY_TYPE_C:
4747
- rb_gi_value_argument_free_array_c(rb_argument,
4748
- argument,
4749
- type_info,
4750
- element_type_info);
1810
+ interface_info = g_type_info_get_interface(element_type_info);
1811
+ interface_type = g_base_info_get_type(interface_info);
1812
+ interface_name = g_info_type_to_string(interface_type);
1813
+ gtype = g_registered_type_info_get_g_type(interface_info);
1814
+ g_base_info_unref(interface_info);
1815
+ g_base_info_unref(element_type_info);
1816
+
1817
+ switch (interface_type) {
1818
+ case GI_INFO_TYPE_INVALID:
1819
+ case GI_INFO_TYPE_FUNCTION:
1820
+ case GI_INFO_TYPE_CALLBACK:
1821
+ rb_raise(rb_eNotImpError,
1822
+ "TODO: free GIArgument(GSList)[interface(%s)](%s) everything",
1823
+ interface_name,
1824
+ g_type_name(gtype));
4751
1825
  break;
4752
- case GI_ARRAY_TYPE_ARRAY:
4753
- case GI_ARRAY_TYPE_PTR_ARRAY:
4754
- case GI_ARRAY_TYPE_BYTE_ARRAY:
1826
+ case GI_INFO_TYPE_STRUCT:
1827
+ if (gtype == G_TYPE_NONE) {
1828
+ rb_raise(rb_eNotImpError,
1829
+ "TODO: free GIArgument(GSList)[interface(%s)](%s) everything",
1830
+ interface_name,
1831
+ g_type_name(gtype));
1832
+ } else {
1833
+ g_slist_foreach(argument->v_pointer,
1834
+ rb_gi_boxed_free_callback,
1835
+ &gtype);
1836
+ g_slist_free(argument->v_pointer);
1837
+ }
4755
1838
  break;
4756
- default:
1839
+ case GI_INFO_TYPE_BOXED:
1840
+ g_slist_foreach(argument->v_pointer, rb_gi_boxed_free_callback, &gtype);
1841
+ g_slist_free(argument->v_pointer);
1842
+ break;
1843
+ case GI_INFO_TYPE_ENUM:
1844
+ case GI_INFO_TYPE_FLAGS:
1845
+ rb_raise(rb_eNotImpError,
1846
+ "TODO: free GIArgument(GSList)[interface(%s)](%s) everything",
1847
+ interface_name,
1848
+ g_type_name(gtype));
1849
+ break;
1850
+ case GI_INFO_TYPE_OBJECT:
1851
+ case GI_INFO_TYPE_INTERFACE:
1852
+ g_slist_foreach(argument->v_pointer, (GFunc)g_object_unref, NULL);
1853
+ g_slist_free(argument->v_pointer);
1854
+ break;
1855
+ case GI_INFO_TYPE_CONSTANT:
1856
+ case GI_INFO_TYPE_INVALID_0:
1857
+ case GI_INFO_TYPE_UNION:
1858
+ case GI_INFO_TYPE_VALUE:
1859
+ case GI_INFO_TYPE_SIGNAL:
1860
+ case GI_INFO_TYPE_VFUNC:
1861
+ case GI_INFO_TYPE_PROPERTY:
1862
+ case GI_INFO_TYPE_FIELD:
1863
+ case GI_INFO_TYPE_ARG:
1864
+ case GI_INFO_TYPE_TYPE:
1865
+ case GI_INFO_TYPE_UNRESOLVED:
1866
+ rb_raise(rb_eNotImpError,
1867
+ "TODO: free GIArgument(GSList)[interface(%s)](%s) everything",
1868
+ interface_name,
1869
+ g_type_name(gtype));
1870
+ break;
1871
+ default:
4757
1872
  g_assert_not_reached();
4758
1873
  break;
4759
1874
  }
4760
- g_base_info_unref(element_type_info);
4761
1875
  }
4762
1876
 
4763
1877
  static void
4764
- rb_gi_value_argument_free_interface(VALUE rb_argument,
4765
- GIArgument *argument,
4766
- GITypeInfo *type_info)
1878
+ rb_gi_return_argument_free_everything_gslist(GIArgument *argument,
1879
+ GITypeInfo *type_info)
4767
1880
  {
4768
- GIBaseInfo *interface_info;
4769
- GIInfoType interface_type;
4770
-
4771
- interface_info = g_type_info_get_interface(type_info);
4772
- interface_type = g_base_info_get_type(interface_info);
4773
-
4774
- if (interface_type == GI_INFO_TYPE_STRUCT) {
4775
- GType gtype;
4776
- gtype = g_registered_type_info_get_g_type(interface_info);
4777
-
4778
- if (gtype == G_TYPE_VALUE) {
4779
- if (!RVAL2CBOOL(rb_obj_is_kind_of(rb_argument, rb_cGLibValue))) {
4780
- GValue *gvalue = argument->v_pointer;
4781
- g_value_unset(gvalue);
4782
- xfree(argument->v_pointer);
4783
- }
4784
- } else if (gtype == G_TYPE_BYTES) {
4785
- g_bytes_unref(argument->v_pointer);
4786
- }
4787
- }
1881
+ GITypeInfo *element_type_info;
1882
+ GITypeTag element_type_tag;
4788
1883
 
4789
- g_base_info_unref(interface_info);
4790
- }
1884
+ if (!argument->v_pointer)
1885
+ return;
4791
1886
 
4792
- void
4793
- rb_gi_value_argument_free(VALUE rb_argument,
4794
- GIArgument *argument,
4795
- GITypeInfo *type_info)
4796
- {
4797
- GITypeTag type_tag;
1887
+ element_type_info = g_type_info_get_param_type(type_info, 0);
1888
+ element_type_tag = g_type_info_get_tag(element_type_info);
4798
1889
 
4799
- type_tag = g_type_info_get_tag(type_info);
4800
- switch (type_tag) {
1890
+ switch (element_type_tag) {
4801
1891
  case GI_TYPE_TAG_VOID:
4802
1892
  case GI_TYPE_TAG_BOOLEAN:
4803
1893
  case GI_TYPE_TAG_INT8:
@@ -4811,134 +1901,137 @@ rb_gi_value_argument_free(VALUE rb_argument,
4811
1901
  case GI_TYPE_TAG_FLOAT:
4812
1902
  case GI_TYPE_TAG_DOUBLE:
4813
1903
  case GI_TYPE_TAG_GTYPE:
1904
+ g_base_info_unref(element_type_info);
1905
+ rb_raise(rb_eNotImpError,
1906
+ "TODO: free GIArgument(GSList)[%s] everything",
1907
+ g_type_tag_to_string(element_type_tag));
1908
+ break;
4814
1909
  case GI_TYPE_TAG_UTF8:
4815
1910
  case GI_TYPE_TAG_FILENAME:
1911
+ g_base_info_unref(element_type_info);
1912
+ g_slist_foreach(argument->v_pointer, (GFunc)g_free, NULL);
1913
+ g_slist_free(argument->v_pointer);
4816
1914
  break;
4817
1915
  case GI_TYPE_TAG_ARRAY:
4818
- rb_gi_value_argument_free_array(rb_argument, argument, type_info);
1916
+ g_base_info_unref(element_type_info);
1917
+ rb_raise(rb_eNotImpError,
1918
+ "TODO: free GIArgument(GSList)[%s] everything",
1919
+ g_type_tag_to_string(element_type_tag));
4819
1920
  break;
4820
1921
  case GI_TYPE_TAG_INTERFACE:
4821
- rb_gi_value_argument_free_interface(rb_argument, argument, type_info);
1922
+ rb_gi_return_argument_free_everything_gslist_interface(argument,
1923
+ type_info,
1924
+ element_type_info);
4822
1925
  break;
4823
1926
  case GI_TYPE_TAG_GLIST:
4824
1927
  case GI_TYPE_TAG_GSLIST:
4825
1928
  case GI_TYPE_TAG_GHASH:
4826
1929
  case GI_TYPE_TAG_ERROR:
4827
1930
  case GI_TYPE_TAG_UNICHAR:
1931
+ g_base_info_unref(element_type_info);
1932
+ rb_raise(rb_eNotImpError,
1933
+ "TODO: free GIArgument(GSList)[%s] everything",
1934
+ g_type_tag_to_string(element_type_tag));
4828
1935
  break;
4829
1936
  default:
1937
+ g_base_info_unref(element_type_info);
4830
1938
  g_assert_not_reached();
4831
1939
  break;
4832
1940
  }
4833
1941
  }
4834
1942
 
4835
1943
  static void
4836
- rb_gi_inout_argument_free(VALUE rb_argument,
4837
- GIArgument *argument,
4838
- GITypeInfo *type_info)
1944
+ rb_gi_return_argument_free_everything(GIArgument *argument,
1945
+ GITypeInfo *type_info)
4839
1946
  {
4840
- GIArgument in_argument;
4841
1947
  GITypeTag type_tag;
4842
1948
 
4843
- memset(&in_argument, 0, sizeof(GIArgument));
4844
1949
  type_tag = g_type_info_get_tag(type_info);
4845
1950
  switch (type_tag) {
4846
- case GI_TYPE_TAG_VOID:
4847
- break;
4848
- case GI_TYPE_TAG_BOOLEAN:
4849
- in_argument.v_boolean = *((gboolean *)(argument->v_pointer));
4850
- break;
4851
- case GI_TYPE_TAG_INT8:
4852
- in_argument.v_int8 = *((gint8 *)(argument->v_pointer));
4853
- break;
4854
- case GI_TYPE_TAG_UINT8:
4855
- /* TODO!!! */
4856
- in_argument.v_uint8 = *((guint8 *)(argument->v_pointer));
4857
- argument->v_pointer = ALLOC(guint8);
4858
- *((guint8 *)argument->v_pointer) = in_argument.v_uint8;
4859
- break;
4860
- case GI_TYPE_TAG_INT16:
4861
- in_argument.v_int16 = *((gint16 *)(argument->v_pointer));
4862
- argument->v_pointer = ALLOC(gint16);
4863
- *((gint16 *)argument->v_pointer) = in_argument.v_int16;
4864
- break;
4865
- case GI_TYPE_TAG_UINT16:
4866
- in_argument.v_uint16 = *((guint16 *)(argument->v_pointer));
4867
- argument->v_pointer = ALLOC(guint16);
4868
- *((guint16 *)argument->v_pointer) = in_argument.v_uint16;
4869
- break;
4870
- case GI_TYPE_TAG_INT32:
4871
- in_argument.v_int32 = *((gint32 *)(argument->v_pointer));
4872
- argument->v_pointer = ALLOC(gint32);
4873
- *((gint32 *)argument->v_pointer) = in_argument.v_int32;
4874
- break;
4875
- case GI_TYPE_TAG_UINT32:
4876
- in_argument.v_uint32 = *((guint32 *)(argument->v_pointer));
4877
- argument->v_pointer = ALLOC(guint32);
4878
- *((guint32 *)argument->v_pointer) = in_argument.v_uint32;
1951
+ case GI_TYPE_TAG_VOID:
4879
1952
  break;
4880
- case GI_TYPE_TAG_INT64:
4881
- in_argument.v_int64 = *((gint64 *)(argument->v_pointer));
4882
- argument->v_pointer = ALLOC(gint64);
4883
- *((gint64 *)argument->v_pointer) = in_argument.v_int64;
1953
+ case GI_TYPE_TAG_BOOLEAN:
1954
+ case GI_TYPE_TAG_INT8:
1955
+ case GI_TYPE_TAG_UINT8:
1956
+ case GI_TYPE_TAG_INT16:
1957
+ case GI_TYPE_TAG_UINT16:
1958
+ case GI_TYPE_TAG_INT32:
1959
+ case GI_TYPE_TAG_UINT32:
1960
+ case GI_TYPE_TAG_INT64:
1961
+ case GI_TYPE_TAG_UINT64:
1962
+ case GI_TYPE_TAG_FLOAT:
1963
+ case GI_TYPE_TAG_DOUBLE:
1964
+ case GI_TYPE_TAG_GTYPE:
1965
+ rb_raise(rb_eNotImpError,
1966
+ "TODO: free GIArgument(%s) everything",
1967
+ g_type_tag_to_string(type_tag));
4884
1968
  break;
4885
- case GI_TYPE_TAG_UINT64:
4886
- in_argument.v_uint64 = *((guint64 *)(argument->v_pointer));
4887
- argument->v_pointer = ALLOC(guint64);
4888
- *((guint64 *)argument->v_pointer) = in_argument.v_uint64;
1969
+ case GI_TYPE_TAG_UTF8:
1970
+ g_free(argument->v_string);
4889
1971
  break;
4890
- case GI_TYPE_TAG_FLOAT:
4891
- in_argument.v_float = *((gfloat *)(argument->v_pointer));
4892
- argument->v_pointer = ALLOC(gfloat);
4893
- *((gfloat *)argument->v_pointer) = in_argument.v_float;
1972
+ case GI_TYPE_TAG_FILENAME:
1973
+ g_free(argument->v_string);
4894
1974
  break;
4895
- case GI_TYPE_TAG_DOUBLE:
4896
- in_argument.v_double = *((gdouble *)(argument->v_pointer));
4897
- argument->v_pointer = ALLOC(gdouble);
4898
- *((gdouble *)argument->v_pointer) = in_argument.v_double;
1975
+ case GI_TYPE_TAG_ARRAY:
1976
+ rb_gi_return_argument_free_everything_array(argument, type_info);
4899
1977
  break;
4900
- case GI_TYPE_TAG_GTYPE:
4901
- in_argument.v_size = *((gsize *)(argument->v_pointer));
1978
+ case GI_TYPE_TAG_INTERFACE:
1979
+ rb_gi_return_argument_free_everything_interface(argument, type_info);
4902
1980
  break;
4903
- case GI_TYPE_TAG_UTF8:
4904
- case GI_TYPE_TAG_FILENAME:
4905
- in_argument.v_string = *((gchar **)(argument->v_pointer));
1981
+ case GI_TYPE_TAG_GLIST:
1982
+ rb_gi_return_argument_free_everything_glist(argument, type_info);
4906
1983
  break;
4907
- case GI_TYPE_TAG_ARRAY:
4908
- case GI_TYPE_TAG_INTERFACE:
4909
- case GI_TYPE_TAG_GLIST:
4910
- case GI_TYPE_TAG_GSLIST:
4911
- case GI_TYPE_TAG_GHASH:
4912
- in_argument.v_pointer = *((gpointer *)(argument->v_pointer));
1984
+ case GI_TYPE_TAG_GSLIST:
1985
+ rb_gi_return_argument_free_everything_gslist(argument, type_info);
4913
1986
  break;
4914
- case GI_TYPE_TAG_ERROR:
4915
- in_argument.v_pointer = *((GError **)(argument->v_pointer));
1987
+ case GI_TYPE_TAG_GHASH:
1988
+ g_hash_table_unref(argument->v_pointer);
4916
1989
  break;
4917
- case GI_TYPE_TAG_UNICHAR:
4918
- in_argument.v_uint32 = *((gunichar *)(argument->v_pointer));
1990
+ case GI_TYPE_TAG_ERROR:
1991
+ case GI_TYPE_TAG_UNICHAR:
1992
+ rb_raise(rb_eNotImpError,
1993
+ "TODO: free GIArgument(%s) everything",
1994
+ g_type_tag_to_string(type_tag));
4919
1995
  break;
4920
- default:
1996
+ default:
4921
1997
  g_assert_not_reached();
4922
1998
  break;
4923
1999
  }
4924
-
4925
- rb_gi_value_argument_free(rb_argument, &in_argument, type_info);
4926
- xfree(argument->v_pointer);
4927
2000
  }
4928
2001
 
4929
- void
4930
- rb_gi_in_argument_free(VALUE rb_argument,
4931
- GIArgument *argument,
4932
- GIArgInfo *arg_info)
2002
+ VALUE
2003
+ rb_gi_return_argument_to_ruby(GICallableInfo *callable_info,
2004
+ GIArgument *argument,
2005
+ GArray *in_args,
2006
+ GArray *out_args,
2007
+ GPtrArray *args_metadata)
4933
2008
  {
4934
- GITypeInfo type_info;
2009
+ VALUE rb_argument;
2010
+ gboolean may_return_null;
2011
+ GITypeInfo return_value_info;
4935
2012
 
4936
- g_arg_info_load_type(arg_info, &type_info);
4937
- if (g_arg_info_get_direction(arg_info) == GI_DIRECTION_INOUT) {
4938
- rb_gi_inout_argument_free(rb_argument, argument, &type_info);
4939
- } else {
4940
- rb_gi_value_argument_free(rb_argument, argument, &type_info);
2013
+ may_return_null = g_callable_info_may_return_null(callable_info);
2014
+ if (may_return_null && !argument->v_pointer) {
2015
+ return Qnil;
2016
+ }
2017
+
2018
+ g_callable_info_load_return_type(callable_info, &return_value_info);
2019
+ rb_argument = rb_gi_argument_to_ruby(argument, FALSE, &return_value_info,
2020
+ in_args, out_args, args_metadata);
2021
+ switch (g_callable_info_get_caller_owns(callable_info)) {
2022
+ case GI_TRANSFER_NOTHING:
2023
+ break;
2024
+ case GI_TRANSFER_CONTAINER:
2025
+ rb_gi_return_argument_free_container(argument, &return_value_info);
2026
+ break;
2027
+ case GI_TRANSFER_EVERYTHING:
2028
+ rb_gi_return_argument_free_everything(argument, &return_value_info);
2029
+ break;
2030
+ default:
2031
+ g_assert_not_reached();
2032
+ break;
4941
2033
  }
2034
+ return rb_argument;
4942
2035
  }
4943
2036
 
4944
2037
  void