gobject-introspection 3.4.4 → 3.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/gobject-introspection/gobject-introspection-enum-types.c +230 -0
- data/ext/gobject-introspection/gobject-introspection-enum-types.h +42 -0
- data/ext/gobject-introspection/rb-gi-argument.c +11 -4
- data/ext/gobject-introspection/rb-gi-arguments-in.c +26 -97
- data/ext/gobject-introspection/rb-gi-arguments.c +243 -8
- data/ext/gobject-introspection/rb-gi-base-info.c +11 -1
- data/ext/gobject-introspection/rb-gi-callable-info.c +10 -2
- data/ext/gobject-introspection/rb-gi-callback.c +156 -2
- data/ext/gobject-introspection/rb-gi-conversions.h +6 -6
- data/ext/gobject-introspection/rb-gi-loader.c +53 -1
- data/ext/gobject-introspection/rb-gi-object-info.c +11 -1
- data/ext/gobject-introspection/rb-gi-private-arguments-in.h +3 -1
- data/ext/gobject-introspection/rb-gi-private-arguments.h +5 -1
- data/ext/gobject-introspection/rb-gi-private-callback.h +6 -3
- data/ext/gobject-introspection/rb-gi-private.h +1 -0
- data/ext/gobject-introspection/rb-gi-struct-info.c +13 -1
- data/ext/gobject-introspection/rb-gi-vfunc-info.c +2 -2
- data/ext/gobject-introspection/rb-gobject-introspection.c +231 -0
- data/ext/gobject-introspection/rbgiversion.h +24 -0
- data/lib/gobject-introspection/loader.rb +65 -1
- data/test/run-test.rb +4 -0
- data/test/test-base-info.rb +5 -1
- data/test/test-callable-info.rb +7 -1
- data/test/test-loader.rb +53 -7
- data/test/test-object-info.rb +5 -1
- data/test/test-struct-info.rb +6 -1
- metadata +7 -4
@@ -497,12 +497,53 @@ 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 cGLibErrorInfo = rb_const_get(mGLib, rb_intern("ErrorInfo"));
|
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
|
+
GQuark gdomain = RBG_RUBY_ERROR;
|
523
|
+
gint gcode = RBG_RUBY_ERROR_UNKNOWN;
|
524
|
+
if (RVAL2CBOOL(rb_obj_is_kind_of(rb_error, cGLibErrorInfo))) {
|
525
|
+
VALUE domain = rb_funcall(rb_error, rb_intern("domain"), 0);
|
526
|
+
VALUE code = rb_funcall(rb_error, rb_intern("code"), 0);
|
527
|
+
if (!NIL_P(domain) && !NIL_P(code)) {
|
528
|
+
gdomain = g_quark_from_string(RVAL2CSTR(domain));
|
529
|
+
gcode = NUM2INT(code);
|
530
|
+
}
|
531
|
+
}
|
532
|
+
g_set_error(gerror,
|
533
|
+
gdomain,
|
534
|
+
gcode,
|
535
|
+
"%s\n %s\n",
|
536
|
+
RVAL2CSTR(message),
|
537
|
+
RVAL2CSTR(formatted_backtrace));
|
538
|
+
}
|
539
|
+
}
|
540
|
+
|
500
541
|
static void
|
501
542
|
rb_gi_arguments_fill_raw_result_interface(RBGIArguments *args,
|
502
543
|
VALUE rb_result,
|
503
544
|
gpointer raw_result,
|
504
545
|
GITypeInfo *type_info,
|
505
|
-
|
546
|
+
GITransfer transfer,
|
506
547
|
gboolean is_return_value)
|
507
548
|
{
|
508
549
|
GIBaseInfo *interface_info;
|
@@ -542,8 +583,37 @@ rb_gi_arguments_fill_raw_result_interface(RBGIArguments *args,
|
|
542
583
|
}
|
543
584
|
break;
|
544
585
|
case GI_INFO_TYPE_FLAGS:
|
586
|
+
rb_raise(rb_eNotImpError,
|
587
|
+
"TODO: %s::%s: out raw result(interface)[%s]: <%s>",
|
588
|
+
g_base_info_get_namespace(args->info),
|
589
|
+
g_base_info_get_name(args->info),
|
590
|
+
g_info_type_to_string(interface_type),
|
591
|
+
g_base_info_get_name(interface_info));
|
592
|
+
break;
|
545
593
|
case GI_INFO_TYPE_OBJECT:
|
546
594
|
case GI_INFO_TYPE_INTERFACE:
|
595
|
+
{
|
596
|
+
GObject *value = RVAL2GOBJ(rb_result);
|
597
|
+
GType gtype = g_registered_type_info_get_g_type(interface_info);
|
598
|
+
if (gtype != G_TYPE_NONE &&
|
599
|
+
!G_TYPE_CHECK_INSTANCE_TYPE(value, gtype)) {
|
600
|
+
rb_raise(rb_eArgError,
|
601
|
+
"%s::%s: must return <%s> object: <%" PRIsVALUE ">",
|
602
|
+
g_base_info_get_namespace(args->info),
|
603
|
+
g_base_info_get_name(args->info),
|
604
|
+
g_type_name(gtype),
|
605
|
+
rb_result);
|
606
|
+
}
|
607
|
+
if (transfer == GI_TRANSFER_EVERYTHING) {
|
608
|
+
g_object_ref(value);
|
609
|
+
}
|
610
|
+
if (is_return_value) {
|
611
|
+
ffi_return_value->v_pointer = value;
|
612
|
+
} else {
|
613
|
+
*((gpointer *)raw_result) = value;
|
614
|
+
}
|
615
|
+
}
|
616
|
+
break;
|
547
617
|
case GI_INFO_TYPE_CONSTANT:
|
548
618
|
rb_raise(rb_eNotImpError,
|
549
619
|
"TODO: %s::%s: out raw result(interface)[%s]: <%s>",
|
@@ -577,6 +647,160 @@ rb_gi_arguments_fill_raw_result_interface(RBGIArguments *args,
|
|
577
647
|
g_base_info_unref(interface_info);
|
578
648
|
}
|
579
649
|
|
650
|
+
static void
|
651
|
+
rb_gi_arguments_fill_raw_result_glist_interface(
|
652
|
+
RBGIArguments *args,
|
653
|
+
VALUE rb_result,
|
654
|
+
gpointer raw_result,
|
655
|
+
GITypeInfo *type_info,
|
656
|
+
GITypeInfo *element_type_info,
|
657
|
+
G_GNUC_UNUSED GITransfer transfer /* TODO */,
|
658
|
+
gboolean is_return_value)
|
659
|
+
{
|
660
|
+
GIFFIReturnValue *ffi_return_value = raw_result;
|
661
|
+
GIBaseInfo *interface_info;
|
662
|
+
GIInfoType interface_type;
|
663
|
+
const gchar *interface_name;
|
664
|
+
GType gtype;
|
665
|
+
GList *list = NULL;
|
666
|
+
|
667
|
+
interface_info = g_type_info_get_interface(element_type_info);
|
668
|
+
interface_type = g_base_info_get_type(interface_info);
|
669
|
+
interface_name = g_info_type_to_string(interface_type);
|
670
|
+
gtype = g_registered_type_info_get_g_type(interface_info);
|
671
|
+
|
672
|
+
switch (interface_type) {
|
673
|
+
case GI_INFO_TYPE_INVALID:
|
674
|
+
case GI_INFO_TYPE_FUNCTION:
|
675
|
+
case GI_INFO_TYPE_CALLBACK:
|
676
|
+
case GI_INFO_TYPE_STRUCT:
|
677
|
+
case GI_INFO_TYPE_BOXED:
|
678
|
+
case GI_INFO_TYPE_ENUM:
|
679
|
+
case GI_INFO_TYPE_FLAGS:
|
680
|
+
g_base_info_unref(interface_info);
|
681
|
+
g_base_info_unref(element_type_info);
|
682
|
+
rb_raise(rb_eNotImpError,
|
683
|
+
"TODO: %s::%s: out raw result(glist)[interface(%s)](%s)",
|
684
|
+
g_base_info_get_namespace(args->info),
|
685
|
+
g_base_info_get_name(args->info),
|
686
|
+
interface_name,
|
687
|
+
g_type_name(gtype));
|
688
|
+
break;
|
689
|
+
case GI_INFO_TYPE_OBJECT:
|
690
|
+
list = RVAL2GOBJGLIST(rb_result);
|
691
|
+
if (transfer == GI_TRANSFER_EVERYTHING) {
|
692
|
+
g_list_foreach(list, (GFunc)g_object_ref, NULL);
|
693
|
+
}
|
694
|
+
break;
|
695
|
+
case GI_INFO_TYPE_INTERFACE:
|
696
|
+
case GI_INFO_TYPE_CONSTANT:
|
697
|
+
case GI_INFO_TYPE_INVALID_0:
|
698
|
+
case GI_INFO_TYPE_UNION:
|
699
|
+
case GI_INFO_TYPE_VALUE:
|
700
|
+
case GI_INFO_TYPE_SIGNAL:
|
701
|
+
case GI_INFO_TYPE_VFUNC:
|
702
|
+
case GI_INFO_TYPE_PROPERTY:
|
703
|
+
case GI_INFO_TYPE_FIELD:
|
704
|
+
case GI_INFO_TYPE_ARG:
|
705
|
+
case GI_INFO_TYPE_TYPE:
|
706
|
+
case GI_INFO_TYPE_UNRESOLVED:
|
707
|
+
g_base_info_unref(interface_info);
|
708
|
+
g_base_info_unref(element_type_info);
|
709
|
+
rb_raise(rb_eNotImpError,
|
710
|
+
"TODO: %s::%s: out raw result(glist)[interface(%s)](%s)",
|
711
|
+
g_base_info_get_namespace(args->info),
|
712
|
+
g_base_info_get_name(args->info),
|
713
|
+
interface_name,
|
714
|
+
g_type_name(gtype));
|
715
|
+
break;
|
716
|
+
default:
|
717
|
+
g_base_info_unref(interface_info);
|
718
|
+
g_base_info_unref(element_type_info);
|
719
|
+
g_assert_not_reached();
|
720
|
+
break;
|
721
|
+
}
|
722
|
+
|
723
|
+
if (is_return_value) {
|
724
|
+
ffi_return_value->v_ulong = (gulong)list;
|
725
|
+
} else {
|
726
|
+
*((gpointer *)raw_result) = list;
|
727
|
+
}
|
728
|
+
}
|
729
|
+
|
730
|
+
static void
|
731
|
+
rb_gi_arguments_fill_raw_result_glist(RBGIArguments *args,
|
732
|
+
VALUE rb_result,
|
733
|
+
gpointer raw_result,
|
734
|
+
GITypeInfo *type_info,
|
735
|
+
GITransfer transfer,
|
736
|
+
gboolean is_return_value)
|
737
|
+
{
|
738
|
+
GIFFIReturnValue *ffi_return_value = raw_result;
|
739
|
+
GITypeInfo *element_type_info;
|
740
|
+
GITypeTag element_type_tag;
|
741
|
+
|
742
|
+
element_type_info = g_type_info_get_param_type(type_info, 0);
|
743
|
+
element_type_tag = g_type_info_get_tag(element_type_info);
|
744
|
+
|
745
|
+
if (is_return_value) {
|
746
|
+
ffi_return_value->v_ulong = (gulong)NULL;
|
747
|
+
} else {
|
748
|
+
*((gpointer *)raw_result) = NULL;
|
749
|
+
}
|
750
|
+
|
751
|
+
switch (element_type_tag) {
|
752
|
+
case GI_TYPE_TAG_VOID:
|
753
|
+
case GI_TYPE_TAG_BOOLEAN:
|
754
|
+
case GI_TYPE_TAG_INT8:
|
755
|
+
case GI_TYPE_TAG_UINT8:
|
756
|
+
case GI_TYPE_TAG_INT16:
|
757
|
+
case GI_TYPE_TAG_UINT16:
|
758
|
+
case GI_TYPE_TAG_INT32:
|
759
|
+
case GI_TYPE_TAG_UINT32:
|
760
|
+
case GI_TYPE_TAG_INT64:
|
761
|
+
case GI_TYPE_TAG_UINT64:
|
762
|
+
case GI_TYPE_TAG_FLOAT:
|
763
|
+
case GI_TYPE_TAG_DOUBLE:
|
764
|
+
case GI_TYPE_TAG_GTYPE:
|
765
|
+
case GI_TYPE_TAG_UTF8:
|
766
|
+
case GI_TYPE_TAG_FILENAME:
|
767
|
+
case GI_TYPE_TAG_ARRAY:
|
768
|
+
g_base_info_unref(element_type_info);
|
769
|
+
rb_raise(rb_eNotImpError,
|
770
|
+
"TODO: %s::%s: out raw result(GList)[%s]",
|
771
|
+
g_base_info_get_namespace(args->info),
|
772
|
+
g_base_info_get_name(args->info),
|
773
|
+
g_type_tag_to_string(element_type_tag));
|
774
|
+
break;
|
775
|
+
case GI_TYPE_TAG_INTERFACE:
|
776
|
+
rb_gi_arguments_fill_raw_result_glist_interface(
|
777
|
+
args,
|
778
|
+
rb_result,
|
779
|
+
raw_result,
|
780
|
+
type_info,
|
781
|
+
element_type_info,
|
782
|
+
transfer,
|
783
|
+
is_return_value);
|
784
|
+
break;
|
785
|
+
case GI_TYPE_TAG_GLIST:
|
786
|
+
case GI_TYPE_TAG_GSLIST:
|
787
|
+
case GI_TYPE_TAG_GHASH:
|
788
|
+
case GI_TYPE_TAG_ERROR:
|
789
|
+
case GI_TYPE_TAG_UNICHAR:
|
790
|
+
g_base_info_unref(element_type_info);
|
791
|
+
rb_raise(rb_eNotImpError,
|
792
|
+
"TODO: %s::%s: out raw result(GList)[%s]",
|
793
|
+
g_base_info_get_namespace(args->info),
|
794
|
+
g_base_info_get_name(args->info),
|
795
|
+
g_type_tag_to_string(element_type_tag));
|
796
|
+
break;
|
797
|
+
default:
|
798
|
+
g_base_info_unref(element_type_info);
|
799
|
+
g_assert_not_reached();
|
800
|
+
break;
|
801
|
+
}
|
802
|
+
}
|
803
|
+
|
580
804
|
/*
|
581
805
|
We need to cast from different type for return value. (We don't
|
582
806
|
need it for out arguments.) Because of libffi specification:
|
@@ -695,12 +919,16 @@ rb_gi_arguments_fill_raw_result(RBGIArguments *args,
|
|
695
919
|
}
|
696
920
|
break;
|
697
921
|
case GI_TYPE_TAG_UTF8:
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
922
|
+
{
|
923
|
+
gchar *result = (gchar *)RVAL2CSTR_ACCEPT_SYMBOL(rb_result);
|
924
|
+
if (transfer == GI_TRANSFER_EVERYTHING) {
|
925
|
+
result = g_strdup(result);
|
926
|
+
}
|
927
|
+
if (is_return_value) {
|
928
|
+
ffi_return_value->v_ulong = (gulong)result;
|
929
|
+
} else {
|
930
|
+
*((gchar **)raw_result) = (gchar *)result;
|
931
|
+
}
|
704
932
|
}
|
705
933
|
break;
|
706
934
|
case GI_TYPE_TAG_FILENAME:
|
@@ -739,6 +967,13 @@ rb_gi_arguments_fill_raw_result(RBGIArguments *args,
|
|
739
967
|
is_return_value);
|
740
968
|
break;
|
741
969
|
case GI_TYPE_TAG_GLIST:
|
970
|
+
rb_gi_arguments_fill_raw_result_glist(args,
|
971
|
+
rb_result,
|
972
|
+
raw_result,
|
973
|
+
type_info,
|
974
|
+
transfer,
|
975
|
+
is_return_value);
|
976
|
+
break;
|
742
977
|
case GI_TYPE_TAG_GSLIST:
|
743
978
|
case GI_TYPE_TAG_GHASH:
|
744
979
|
rb_raise(rb_eNotImpError,
|
@@ -833,7 +1068,7 @@ rb_gi_arguments_fill_raw_results(RBGIArguments *args,
|
|
833
1068
|
rb_gi_arguments_fill_raw_result(args,
|
834
1069
|
RARRAY_AREF(rb_results, i_rb_result),
|
835
1070
|
argument->v_pointer,
|
836
|
-
|
1071
|
+
type_info,
|
837
1072
|
transfer,
|
838
1073
|
FALSE);
|
839
1074
|
i_rb_result++;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
2
|
/*
|
3
|
-
* Copyright (C) 2012 Ruby-
|
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
|
@@ -160,6 +160,15 @@ rg_namespace(VALUE self)
|
|
160
160
|
return CSTR2RVAL(g_base_info_get_namespace(info));
|
161
161
|
}
|
162
162
|
|
163
|
+
static VALUE
|
164
|
+
rg_container(VALUE self)
|
165
|
+
{
|
166
|
+
GIBaseInfo *info;
|
167
|
+
|
168
|
+
info = SELF(self);
|
169
|
+
return rb_gi_base_info_to_ruby(g_base_info_get_container(info));
|
170
|
+
}
|
171
|
+
|
163
172
|
static VALUE
|
164
173
|
rg_operator_aref(VALUE self, VALUE name)
|
165
174
|
{
|
@@ -201,6 +210,7 @@ rb_gi_base_info_init(VALUE rb_mGI)
|
|
201
210
|
RG_DEF_METHOD(type, 0);
|
202
211
|
RG_DEF_METHOD(name, 0);
|
203
212
|
RG_DEF_METHOD(namespace, 0);
|
213
|
+
RG_DEF_METHOD(container, 0);
|
204
214
|
RG_DEF_METHOD_OPERATOR("[]", aref, 1);
|
205
215
|
RG_DEF_METHOD(each, 0);
|
206
216
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
2
|
/*
|
3
|
-
* Copyright (C) 2012 Ruby-
|
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
|
@@ -21,7 +21,7 @@
|
|
21
21
|
#include "rb-gi-private.h"
|
22
22
|
|
23
23
|
#define RG_TARGET_NAMESPACE rb_cGICallableInfo
|
24
|
-
#define SELF(self) (
|
24
|
+
#define SELF(self) RVAL2GI_CALLABLE_INFO(self)
|
25
25
|
|
26
26
|
GType
|
27
27
|
gi_callable_info_get_type(void)
|
@@ -35,6 +35,13 @@ gi_callable_info_get_type(void)
|
|
35
35
|
return type;
|
36
36
|
}
|
37
37
|
|
38
|
+
static VALUE
|
39
|
+
rg_can_throw_gerror_p(VALUE self)
|
40
|
+
{
|
41
|
+
GICallableInfo *info = SELF(self);
|
42
|
+
return CBOOL2RVAL(g_callable_info_can_throw_gerror(info));
|
43
|
+
}
|
44
|
+
|
38
45
|
static VALUE
|
39
46
|
rg_return_type(VALUE self)
|
40
47
|
{
|
@@ -91,6 +98,7 @@ rb_gi_callable_info_init(VALUE rb_mGI, VALUE rb_cGIBaseInfo)
|
|
91
98
|
G_DEF_CLASS_WITH_PARENT(GI_TYPE_CALLABLE_INFO, "CallableInfo", rb_mGI,
|
92
99
|
rb_cGIBaseInfo);
|
93
100
|
|
101
|
+
RG_DEF_METHOD_P(can_throw_gerror, 0);
|
94
102
|
RG_DEF_METHOD(return_type, 0);
|
95
103
|
RG_DEF_METHOD(caller_owns, 0);
|
96
104
|
RG_DEF_METHOD_P(may_return_null, 0);
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
2
|
/*
|
3
|
-
* Copyright (C) 2012-
|
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
|
@@ -28,17 +28,171 @@ struct RBGICallbackData_ {
|
|
28
28
|
VALUE rb_owner;
|
29
29
|
};
|
30
30
|
|
31
|
+
typedef struct {
|
32
|
+
RBGIArguments *args;
|
33
|
+
RBGICallback *callback;
|
34
|
+
RBGICallbackData *callback_data;
|
35
|
+
void *return_value;
|
36
|
+
VALUE rb_return_value;
|
37
|
+
} RBGICallbackInvokeData;
|
38
|
+
|
31
39
|
static GPtrArray *callback_finders;
|
32
40
|
static VALUE mGLibObject = Qnil;
|
33
41
|
static VALUE mGI = Qnil;
|
34
42
|
|
43
|
+
static VALUE
|
44
|
+
rb_gi_callback_invoke_without_protect(VALUE user_data)
|
45
|
+
{
|
46
|
+
RBGICallbackInvokeData *data = (RBGICallbackInvokeData *)user_data;
|
47
|
+
VALUE rb_args = rb_gi_arguments_in_to_ruby(data->args);
|
48
|
+
|
49
|
+
if (data->callback->method_name) {
|
50
|
+
ID id___send__;
|
51
|
+
VALUE rb_receiver = rb_ary_shift(rb_args);
|
52
|
+
CONST_ID(id___send__, "__send__");
|
53
|
+
rb_ary_unshift(rb_args, rb_str_new_cstr(data->callback->method_name));
|
54
|
+
data->rb_return_value =
|
55
|
+
rb_funcallv(rb_receiver,
|
56
|
+
id___send__,
|
57
|
+
RARRAY_LENINT(rb_args),
|
58
|
+
RARRAY_CONST_PTR(rb_args));
|
59
|
+
} else {
|
60
|
+
ID id_call;
|
61
|
+
CONST_ID(id_call, "call");
|
62
|
+
VALUE rb_callback =
|
63
|
+
rb_gi_callback_data_get_rb_callback(data->callback_data);
|
64
|
+
data->rb_return_value =
|
65
|
+
rb_funcallv(rb_callback,
|
66
|
+
id_call,
|
67
|
+
RARRAY_LENINT(rb_args),
|
68
|
+
RARRAY_CONST_PTR(rb_args));
|
69
|
+
}
|
70
|
+
|
71
|
+
return Qnil;
|
72
|
+
}
|
73
|
+
|
74
|
+
static VALUE
|
75
|
+
rb_gi_callback_invoke_fill_raw_results(VALUE user_data)
|
76
|
+
{
|
77
|
+
RBGICallbackInvokeData *data = (RBGICallbackInvokeData *)user_data;
|
78
|
+
rb_gi_arguments_fill_raw_results(data->args,
|
79
|
+
data->rb_return_value,
|
80
|
+
data->return_value);
|
81
|
+
return Qnil;
|
82
|
+
}
|
83
|
+
|
84
|
+
static VALUE
|
85
|
+
rb_gi_callback_invoke(VALUE user_data)
|
86
|
+
{
|
87
|
+
RBGICallbackInvokeData *data = (RBGICallbackInvokeData *)user_data;
|
88
|
+
int state = 0;
|
89
|
+
rb_protect(rb_gi_callback_invoke_without_protect,
|
90
|
+
user_data,
|
91
|
+
&state);
|
92
|
+
if (state != 0) {
|
93
|
+
VALUE error = rb_errinfo();
|
94
|
+
rb_gi_arguments_fill_raw_out_gerror(data->args, error);
|
95
|
+
rb_protect(rb_gi_callback_invoke_fill_raw_results,
|
96
|
+
user_data,
|
97
|
+
&state);
|
98
|
+
} else {
|
99
|
+
rb_protect(rb_gi_callback_invoke_fill_raw_results,
|
100
|
+
user_data,
|
101
|
+
&state);
|
102
|
+
if (state != 0) {
|
103
|
+
VALUE error = rb_errinfo();
|
104
|
+
rb_gi_arguments_fill_raw_out_gerror(data->args, error);
|
105
|
+
}
|
106
|
+
}
|
107
|
+
return Qnil;
|
108
|
+
}
|
109
|
+
|
110
|
+
static void
|
111
|
+
rb_gi_ffi_closure_callback(G_GNUC_UNUSED ffi_cif *cif,
|
112
|
+
void *return_value,
|
113
|
+
void **raw_args,
|
114
|
+
void *data)
|
115
|
+
{
|
116
|
+
RBGICallback *callback = data;
|
117
|
+
RBGICallbackData *callback_data = NULL;
|
118
|
+
RBGIArguments args;
|
119
|
+
|
120
|
+
rb_gi_arguments_init(&args,
|
121
|
+
callback->callback_info,
|
122
|
+
Qnil,
|
123
|
+
Qnil,
|
124
|
+
raw_args);
|
125
|
+
{
|
126
|
+
guint i;
|
127
|
+
|
128
|
+
for (i = 0; i < args.metadata->len; i++) {
|
129
|
+
RBGIArgMetadata *metadata;
|
130
|
+
|
131
|
+
metadata = g_ptr_array_index(args.metadata, i);
|
132
|
+
if (!metadata->closure_p) {
|
133
|
+
continue;
|
134
|
+
}
|
135
|
+
|
136
|
+
callback_data = *((RBGICallbackData **)(raw_args[i]));
|
137
|
+
break;
|
138
|
+
}
|
139
|
+
|
140
|
+
if (!callback_data && args.metadata->len > 0) {
|
141
|
+
RBGIArgMetadata *metadata;
|
142
|
+
|
143
|
+
i = args.metadata->len - 1;
|
144
|
+
metadata = g_ptr_array_index(args.metadata, i);
|
145
|
+
if (metadata->type.tag == GI_TYPE_TAG_VOID &&
|
146
|
+
metadata->type.pointer_p &&
|
147
|
+
strcmp(metadata->name, "data") == 0) {
|
148
|
+
callback_data = *((RBGICallbackData **)(raw_args[i]));
|
149
|
+
}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
{
|
154
|
+
RBGICallbackInvokeData data;
|
155
|
+
data.args = &args;
|
156
|
+
data.callback = callback;
|
157
|
+
data.callback_data = callback_data;
|
158
|
+
data.return_value = return_value;
|
159
|
+
data.rb_return_value = Qnil;
|
160
|
+
rbgutil_invoke_callback(rb_gi_callback_invoke, (VALUE)&data);
|
161
|
+
}
|
162
|
+
rb_gi_arguments_clear(&args);
|
163
|
+
|
164
|
+
if (callback_data) {
|
165
|
+
RBGIArgMetadata *callback_metadata =
|
166
|
+
rb_gi_callback_data_get_metadata(callback_data);
|
167
|
+
if (callback_metadata->scope_type == GI_SCOPE_TYPE_ASYNC) {
|
168
|
+
rb_gi_callback_data_free(callback_data);
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
RBGICallback *
|
174
|
+
rb_gi_callback_new(GICallbackInfo *callback_info,
|
175
|
+
const gchar *method_name)
|
176
|
+
{
|
177
|
+
RBGICallback *callback = RB_ZALLOC(RBGICallback);
|
178
|
+
callback->callback_info = callback_info;
|
179
|
+
g_base_info_ref(callback->callback_info);
|
180
|
+
callback->method_name = g_strdup(method_name);
|
181
|
+
callback->closure =
|
182
|
+
g_callable_info_prepare_closure(callback->callback_info,
|
183
|
+
&(callback->cif),
|
184
|
+
rb_gi_ffi_closure_callback,
|
185
|
+
callback);
|
186
|
+
return callback;
|
187
|
+
}
|
188
|
+
|
35
189
|
static void
|
36
190
|
rb_gi_callback_free(RBGICallback *callback)
|
37
191
|
{
|
38
192
|
g_callable_info_free_closure(callback->callback_info,
|
39
193
|
callback->closure);
|
194
|
+
g_free(callback->method_name);
|
40
195
|
g_base_info_unref(callback->callback_info);
|
41
|
-
g_base_info_unref(callback->type_info);
|
42
196
|
xfree(callback);
|
43
197
|
}
|
44
198
|
|