gobject-introspection 3.4.4 → 3.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d072b72b786e12f881fea9bde17a9eff9a4c71bedd25f4ecdd2b18267b8ba051
4
- data.tar.gz: c9e9e78f5c492cb8fea24a1b54e05c2cedad2ec6ce877030cdb3782863340673
3
+ metadata.gz: '073080df7a1c63c600038ca2b3f5edce7e4b090c580b530bed49ab72afc02310'
4
+ data.tar.gz: 9cb1dd9c3f5badc0c0a917206d42d18783626db421a701a8737fa7398c7cefa5
5
5
  SHA512:
6
- metadata.gz: a24acd65c6f1ddfe47665819bbb37c6121e2c154183c23f64512e4e6ad3b9ba52cde4f035d06754f45071afed0a3db82024efe2ceac596b3d45eeb2027d182d2
7
- data.tar.gz: 1cdf78cd475b3401ecbd261b182b4271989600a2aef1f572e14c460fa25a84350c0c515edd301c4af7e27ad79943d9c33e24f21fa01c2d5634e7cbd9aec51d38
6
+ metadata.gz: 8e0ca0522ffbc58c6276455fb7d27c90afc1d959881af569c63b17607bd46cb6fca3463a74699ac1b8f244ec159d5c09edd736eb67641631ed5da48cebff4c8f
7
+ data.tar.gz: f2d8856c0cb47cf65cd54753a2d0dcad71a4c2519a64ccd5a9f515ba5c8eb42dfe6dea034f7498ca8eeac438e79b83ff84bae139bcc7e799693f55aeb43347b7
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2012-2019 Ruby-GNOME Project Team
3
+ * Copyright (C) 2012-2021 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
@@ -2011,11 +2011,18 @@ rb_gi_return_argument_to_ruby(GICallableInfo *callable_info,
2011
2011
  GITypeInfo return_value_info;
2012
2012
 
2013
2013
  may_return_null = g_callable_info_may_return_null(callable_info);
2014
+ g_callable_info_load_return_type(callable_info, &return_value_info);
2014
2015
  if (may_return_null && !argument->v_pointer) {
2015
- return Qnil;
2016
+ GITypeTag return_value_tag = g_type_info_get_tag(&return_value_info);
2017
+ switch (return_value_tag) {
2018
+ case GI_TYPE_TAG_GLIST:
2019
+ case GI_TYPE_TAG_GSLIST:
2020
+ return rb_ary_new();
2021
+ default:
2022
+ return Qnil;
2023
+ }
2016
2024
  }
2017
2025
 
2018
- g_callable_info_load_return_type(callable_info, &return_value_info);
2019
2026
  rb_argument = rb_gi_argument_to_ruby(argument, FALSE, &return_value_info,
2020
2027
  in_args, out_args, args_metadata);
2021
2028
  switch (g_callable_info_get_caller_owns(callable_info)) {
@@ -1,6 +1,6 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright (C) 2012-2019 Ruby-GNOME Project Team
3
+ * Copyright (C) 2012-2021 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
@@ -27,13 +27,7 @@ rb_gi_callback_data_destroy_notify(gpointer data)
27
27
  rb_gi_callback_data_free(callback_data);
28
28
  }
29
29
 
30
- typedef struct {
31
- RBGIArguments *args;
32
- RBGICallback *callback;
33
- RBGICallbackData *callback_data;
34
- } RBGICallbackInvokeData;
35
-
36
- static VALUE
30
+ VALUE
37
31
  rb_gi_arguments_in_to_ruby(RBGIArguments *args)
38
32
  {
39
33
  VALUE rb_in_args;
@@ -68,85 +62,6 @@ rb_gi_arguments_in_to_ruby(RBGIArguments *args)
68
62
  return rb_in_args;
69
63
  }
70
64
 
71
- static VALUE
72
- rb_gi_callback_invoke(VALUE user_data)
73
- {
74
- RBGICallbackInvokeData *data = (RBGICallbackInvokeData *)user_data;
75
- ID id_call;
76
- VALUE rb_callback = rb_gi_callback_data_get_rb_callback(data->callback_data);
77
- VALUE rb_args = rb_gi_arguments_in_to_ruby(data->args);
78
-
79
- CONST_ID(id_call, "call");
80
- return rb_funcallv(rb_callback,
81
- id_call,
82
- RARRAY_LENINT(rb_args),
83
- RARRAY_CONST_PTR(rb_args));
84
- }
85
-
86
- static void
87
- rb_gi_ffi_closure_callback(G_GNUC_UNUSED ffi_cif *cif,
88
- void *return_value,
89
- void **raw_args,
90
- void *data)
91
- {
92
- RBGICallback *callback = data;
93
- RBGICallbackData *callback_data = NULL;
94
- RBGIArguments args;
95
- VALUE rb_results;
96
-
97
- rb_gi_arguments_init(&args,
98
- callback->callback_info,
99
- Qnil,
100
- Qnil,
101
- raw_args);
102
- {
103
- guint i;
104
-
105
- for (i = 0; i < args.metadata->len; i++) {
106
- RBGIArgMetadata *metadata;
107
-
108
- metadata = g_ptr_array_index(args.metadata, i);
109
- if (!metadata->closure_p) {
110
- continue;
111
- }
112
-
113
- callback_data = *((RBGICallbackData **)(raw_args[i]));
114
- break;
115
- }
116
-
117
- if (!callback_data && args.metadata->len > 0) {
118
- RBGIArgMetadata *metadata;
119
-
120
- i = args.metadata->len - 1;
121
- metadata = g_ptr_array_index(args.metadata, i);
122
- if (metadata->type.tag == GI_TYPE_TAG_VOID &&
123
- metadata->type.pointer_p &&
124
- strcmp(metadata->name, "data") == 0) {
125
- callback_data = *((RBGICallbackData **)(raw_args[i]));
126
- }
127
- }
128
- }
129
-
130
- {
131
- RBGICallbackInvokeData data;
132
- data.args = &args;
133
- data.callback = callback;
134
- data.callback_data = callback_data;
135
- rb_results = rbgutil_invoke_callback(rb_gi_callback_invoke,
136
- (VALUE)&data);
137
- }
138
- rb_gi_arguments_fill_raw_results(&args, rb_results, return_value);
139
- rb_gi_arguments_clear(&args);
140
-
141
- {
142
- RBGIArgMetadata *callback_metadata =
143
- rb_gi_callback_data_get_metadata(callback_data);
144
- if (callback_metadata->scope_type == GI_SCOPE_TYPE_ASYNC) {
145
- rb_gi_callback_data_free(callback_data);
146
- }
147
- }
148
- }
149
-
150
65
  static void
151
66
  rb_gi_arguments_in_init_arg_ruby_callback(RBGIArguments *args,
152
67
  RBGIArgMetadata *metadata)
@@ -187,14 +102,11 @@ rb_gi_arguments_in_init_arg_ruby_callback(RBGIArguments *args,
187
102
  if (callback_function) {
188
103
  callback_argument->v_pointer = callback_function;
189
104
  } else {
190
- callback = RB_ZALLOC(RBGICallback);
191
- callback->type_info = g_arg_info_get_type(arg_info);
192
- callback->callback_info = g_type_info_get_interface(callback->type_info);
193
- callback->closure =
194
- g_callable_info_prepare_closure(callback->callback_info,
195
- &(callback->cif),
196
- rb_gi_ffi_closure_callback,
197
- callback);
105
+ GITypeInfo *type_info = g_arg_info_get_type(arg_info);
106
+ GICallbackInfo *callback_info = g_type_info_get_interface(type_info);
107
+ callback = rb_gi_callback_new(callback_info, NULL);
108
+ g_base_info_unref(callback_info);
109
+ g_base_info_unref(type_info);
198
110
  callback_argument->v_pointer = callback->closure;
199
111
  }
200
112
 
@@ -1007,7 +919,7 @@ rb_gi_arguments_in_init_arg_ruby_array_c(RBGIArguments *args,
1007
919
  /* Workaround for rsvg_handle_set_stylesheet():
1008
920
  https://gitlab.gnome.org/GNOME/librsvg/-/issues/596 */
1009
921
  if (strcmp(metadata->name, "css") == 0) {
1010
- metadata->in_arg->v_pointer = RVAL2CSTR(rb_arg);
922
+ metadata->in_arg->v_pointer = (char *)RVAL2CSTR(rb_arg);
1011
923
  rb_gi_arguments_in_init_arg_ruby_array_set_length(args,
1012
924
  metadata,
1013
925
  RSTRING_LEN(rb_arg));
@@ -2060,13 +1972,30 @@ rb_gi_arguments_in_init_arg_ruby(RBGIArguments *args,
2060
1972
  case GI_TYPE_TAG_UNICHAR:
2061
1973
  {
2062
1974
  gunichar *target;
1975
+ VALUE rb_unichar;
2063
1976
  if (metadata->direction == GI_DIRECTION_INOUT) {
2064
1977
  target = ALLOC(gunichar);
2065
1978
  metadata->in_arg->v_pointer = target;
2066
1979
  } else {
2067
1980
  target = &(metadata->in_arg->v_uint32);
2068
1981
  }
2069
- *target = NUM2UINT(metadata->rb_arg);
1982
+ if (RB_TYPE_P(metadata->rb_arg, RUBY_T_STRING)) {
1983
+ VALUE rb_codepoints;
1984
+ if (rb_str_strlen(metadata->rb_arg) != 1) {
1985
+ rb_raise(rb_eArgError,
1986
+ "[%s][%s] must be one character: %+" PRIsVALUE,
1987
+ metadata->name,
1988
+ g_type_tag_to_string(metadata->type.tag),
1989
+ metadata->rb_arg);
1990
+ }
1991
+ rb_codepoints = rb_funcall(metadata->rb_arg,
1992
+ rb_intern("codepoints"),
1993
+ 0);
1994
+ rb_unichar = RARRAY_PTR(rb_codepoints)[0];
1995
+ } else {
1996
+ rb_unichar = metadata->rb_arg;
1997
+ }
1998
+ *target = NUM2UINT(rb_unichar);
2070
1999
  }
2071
2000
  break;
2072
2001
  default:
@@ -497,6 +497,48 @@ rb_gi_arguments_get_rb_out_args(RBGIArguments *args)
497
497
  return rb_gi_arguments_out_to_ruby(args);
498
498
  }
499
499
 
500
+ void
501
+ rb_gi_arguments_fill_raw_out_gerror(RBGIArguments *args,
502
+ VALUE rb_error)
503
+ {
504
+ if (!g_callable_info_can_throw_gerror(args->info)) {
505
+ return;
506
+ }
507
+
508
+ gint n_args = g_callable_info_get_n_args(args->info);
509
+ /* GError ** isn't listed in args. */
510
+ GError **gerror = *((gpointer *)(args->raw_args[n_args]));
511
+ VALUE cGLibError = rb_const_get(mGLib, rb_intern("Error"));
512
+ if (NIL_P(rb_error)) {
513
+ g_set_error(gerror,
514
+ RBG_RUBY_ERROR,
515
+ RBG_RUBY_ERROR_UNKNOWN,
516
+ "Unknown error");
517
+ } else {
518
+ VALUE message = rb_funcall(rb_error, rb_intern("message"), 0);
519
+ VALUE backtrace = rb_funcall(rb_error, rb_intern("backtrace"), 0);
520
+ VALUE formatted_backtrace =
521
+ rb_ary_join(backtrace, rb_str_new_cstr(" \n"));
522
+ if (CBOOL2RVAL(rb_obj_is_kind_of(rb_error, cGLibError))) {
523
+ VALUE domain = rb_funcall(rb_error, rb_intern("domain"), 0);
524
+ VALUE code = rb_funcall(rb_error, rb_intern("code"), 0);
525
+ g_set_error(gerror,
526
+ g_quark_from_string(RVAL2CSTR(domain)),
527
+ NUM2INT(code),
528
+ "%s\n %s\n",
529
+ RVAL2CSTR(message),
530
+ RVAL2CSTR(formatted_backtrace));
531
+ } else {
532
+ g_set_error(gerror,
533
+ RBG_RUBY_ERROR,
534
+ RBG_RUBY_ERROR_UNKNOWN,
535
+ "%s\n %s\n",
536
+ RVAL2CSTR(message),
537
+ RVAL2CSTR(formatted_backtrace));
538
+ }
539
+ }
540
+ }
541
+
500
542
  static void
501
543
  rb_gi_arguments_fill_raw_result_interface(RBGIArguments *args,
502
544
  VALUE rb_result,
@@ -577,6 +619,160 @@ rb_gi_arguments_fill_raw_result_interface(RBGIArguments *args,
577
619
  g_base_info_unref(interface_info);
578
620
  }
579
621
 
622
+ static void
623
+ rb_gi_arguments_fill_raw_result_glist_interface(
624
+ RBGIArguments *args,
625
+ VALUE rb_result,
626
+ gpointer raw_result,
627
+ GITypeInfo *type_info,
628
+ GITypeInfo *element_type_info,
629
+ G_GNUC_UNUSED GITransfer transfer /* TODO */,
630
+ gboolean is_return_value)
631
+ {
632
+ GIFFIReturnValue *ffi_return_value = raw_result;
633
+ GIBaseInfo *interface_info;
634
+ GIInfoType interface_type;
635
+ const gchar *interface_name;
636
+ GType gtype;
637
+ GList *list = NULL;
638
+
639
+ interface_info = g_type_info_get_interface(element_type_info);
640
+ interface_type = g_base_info_get_type(interface_info);
641
+ interface_name = g_info_type_to_string(interface_type);
642
+ gtype = g_registered_type_info_get_g_type(interface_info);
643
+
644
+ switch (interface_type) {
645
+ case GI_INFO_TYPE_INVALID:
646
+ case GI_INFO_TYPE_FUNCTION:
647
+ case GI_INFO_TYPE_CALLBACK:
648
+ case GI_INFO_TYPE_STRUCT:
649
+ case GI_INFO_TYPE_BOXED:
650
+ case GI_INFO_TYPE_ENUM:
651
+ case GI_INFO_TYPE_FLAGS:
652
+ g_base_info_unref(interface_info);
653
+ g_base_info_unref(element_type_info);
654
+ rb_raise(rb_eNotImpError,
655
+ "TODO: %s::%s: out raw result(glist)[interface(%s)](%s)",
656
+ g_base_info_get_namespace(args->info),
657
+ g_base_info_get_name(args->info),
658
+ interface_name,
659
+ g_type_name(gtype));
660
+ break;
661
+ case GI_INFO_TYPE_OBJECT:
662
+ list = RVAL2GOBJGLIST(rb_result);
663
+ if (transfer == GI_TRANSFER_EVERYTHING) {
664
+ g_list_foreach(list, (GFunc)g_object_ref, NULL);
665
+ }
666
+ break;
667
+ case GI_INFO_TYPE_INTERFACE:
668
+ case GI_INFO_TYPE_CONSTANT:
669
+ case GI_INFO_TYPE_INVALID_0:
670
+ case GI_INFO_TYPE_UNION:
671
+ case GI_INFO_TYPE_VALUE:
672
+ case GI_INFO_TYPE_SIGNAL:
673
+ case GI_INFO_TYPE_VFUNC:
674
+ case GI_INFO_TYPE_PROPERTY:
675
+ case GI_INFO_TYPE_FIELD:
676
+ case GI_INFO_TYPE_ARG:
677
+ case GI_INFO_TYPE_TYPE:
678
+ case GI_INFO_TYPE_UNRESOLVED:
679
+ g_base_info_unref(interface_info);
680
+ g_base_info_unref(element_type_info);
681
+ rb_raise(rb_eNotImpError,
682
+ "TODO: %s::%s: out raw result(glist)[interface(%s)](%s)",
683
+ g_base_info_get_namespace(args->info),
684
+ g_base_info_get_name(args->info),
685
+ interface_name,
686
+ g_type_name(gtype));
687
+ break;
688
+ default:
689
+ g_base_info_unref(interface_info);
690
+ g_base_info_unref(element_type_info);
691
+ g_assert_not_reached();
692
+ break;
693
+ }
694
+
695
+ if (is_return_value) {
696
+ ffi_return_value->v_ulong = (gulong)list;
697
+ } else {
698
+ *((gpointer *)raw_result) = list;
699
+ }
700
+ }
701
+
702
+ static void
703
+ rb_gi_arguments_fill_raw_result_glist(RBGIArguments *args,
704
+ VALUE rb_result,
705
+ gpointer raw_result,
706
+ GITypeInfo *type_info,
707
+ GITransfer transfer,
708
+ gboolean is_return_value)
709
+ {
710
+ GIFFIReturnValue *ffi_return_value = raw_result;
711
+ GITypeInfo *element_type_info;
712
+ GITypeTag element_type_tag;
713
+
714
+ element_type_info = g_type_info_get_param_type(type_info, 0);
715
+ element_type_tag = g_type_info_get_tag(element_type_info);
716
+
717
+ if (is_return_value) {
718
+ ffi_return_value->v_ulong = (gulong)NULL;
719
+ } else {
720
+ *((gpointer *)raw_result) = NULL;
721
+ }
722
+
723
+ switch (element_type_tag) {
724
+ case GI_TYPE_TAG_VOID:
725
+ case GI_TYPE_TAG_BOOLEAN:
726
+ case GI_TYPE_TAG_INT8:
727
+ case GI_TYPE_TAG_UINT8:
728
+ case GI_TYPE_TAG_INT16:
729
+ case GI_TYPE_TAG_UINT16:
730
+ case GI_TYPE_TAG_INT32:
731
+ case GI_TYPE_TAG_UINT32:
732
+ case GI_TYPE_TAG_INT64:
733
+ case GI_TYPE_TAG_UINT64:
734
+ case GI_TYPE_TAG_FLOAT:
735
+ case GI_TYPE_TAG_DOUBLE:
736
+ case GI_TYPE_TAG_GTYPE:
737
+ case GI_TYPE_TAG_UTF8:
738
+ case GI_TYPE_TAG_FILENAME:
739
+ case GI_TYPE_TAG_ARRAY:
740
+ g_base_info_unref(element_type_info);
741
+ rb_raise(rb_eNotImpError,
742
+ "TODO: %s::%s: out raw result(GList)[%s]",
743
+ g_base_info_get_namespace(args->info),
744
+ g_base_info_get_name(args->info),
745
+ g_type_tag_to_string(element_type_tag));
746
+ break;
747
+ case GI_TYPE_TAG_INTERFACE:
748
+ rb_gi_arguments_fill_raw_result_glist_interface(
749
+ args,
750
+ rb_result,
751
+ raw_result,
752
+ type_info,
753
+ element_type_info,
754
+ transfer,
755
+ is_return_value);
756
+ break;
757
+ case GI_TYPE_TAG_GLIST:
758
+ case GI_TYPE_TAG_GSLIST:
759
+ case GI_TYPE_TAG_GHASH:
760
+ case GI_TYPE_TAG_ERROR:
761
+ case GI_TYPE_TAG_UNICHAR:
762
+ g_base_info_unref(element_type_info);
763
+ rb_raise(rb_eNotImpError,
764
+ "TODO: %s::%s: out raw result(GList)[%s]",
765
+ g_base_info_get_namespace(args->info),
766
+ g_base_info_get_name(args->info),
767
+ g_type_tag_to_string(element_type_tag));
768
+ break;
769
+ default:
770
+ g_base_info_unref(element_type_info);
771
+ g_assert_not_reached();
772
+ break;
773
+ }
774
+ }
775
+
580
776
  /*
581
777
  We need to cast from different type for return value. (We don't
582
778
  need it for out arguments.) Because of libffi specification:
@@ -695,12 +891,16 @@ rb_gi_arguments_fill_raw_result(RBGIArguments *args,
695
891
  }
696
892
  break;
697
893
  case GI_TYPE_TAG_UTF8:
698
- if (is_return_value) {
699
- ffi_return_value->v_ulong =
700
- (gulong)RVAL2CSTR_ACCEPT_SYMBOL(rb_result);
701
- } else {
702
- *((gchar **)raw_result) =
703
- (gchar *)RVAL2CSTR_ACCEPT_SYMBOL(rb_result);
894
+ {
895
+ gchar *result = (gchar *)RVAL2CSTR_ACCEPT_SYMBOL(rb_result);
896
+ if (transfer == GI_TRANSFER_EVERYTHING) {
897
+ result = g_strdup(result);
898
+ }
899
+ if (is_return_value) {
900
+ ffi_return_value->v_ulong = (gulong)result;
901
+ } else {
902
+ *((gchar **)raw_result) = (gchar *)result;
903
+ }
704
904
  }
705
905
  break;
706
906
  case GI_TYPE_TAG_FILENAME:
@@ -739,6 +939,13 @@ rb_gi_arguments_fill_raw_result(RBGIArguments *args,
739
939
  is_return_value);
740
940
  break;
741
941
  case GI_TYPE_TAG_GLIST:
942
+ rb_gi_arguments_fill_raw_result_glist(args,
943
+ rb_result,
944
+ raw_result,
945
+ type_info,
946
+ transfer,
947
+ is_return_value);
948
+ break;
742
949
  case GI_TYPE_TAG_GSLIST:
743
950
  case GI_TYPE_TAG_GHASH:
744
951
  rb_raise(rb_eNotImpError,
@@ -833,7 +1040,7 @@ rb_gi_arguments_fill_raw_results(RBGIArguments *args,
833
1040
  rb_gi_arguments_fill_raw_result(args,
834
1041
  RARRAY_AREF(rb_results, i_rb_result),
835
1042
  argument->v_pointer,
836
- return_type_info,
1043
+ type_info,
837
1044
  transfer,
838
1045
  FALSE);
839
1046
  i_rb_result++;