glib2 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/ext/glib2/extconf.rb +1 -0
  2. data/ext/glib2/glib2.def +23 -0
  3. data/ext/glib2/rbgcompat.h +19 -5
  4. data/ext/glib2/rbglib.c +607 -160
  5. data/ext/glib2/rbglib.h +81 -26
  6. data/ext/glib2/rbglib2conversions.h +57 -0
  7. data/ext/glib2/rbglib_bookmarkfile.c +117 -107
  8. data/ext/glib2/rbglib_completion.c +37 -26
  9. data/ext/glib2/rbglib_convert.c +42 -30
  10. data/ext/glib2/rbglib_error.c +20 -10
  11. data/ext/glib2/rbglib_fileutils.c +48 -37
  12. data/ext/glib2/rbglib_i18n.c +24 -14
  13. data/ext/glib2/rbglib_int64.c +24 -16
  14. data/ext/glib2/rbglib_iochannel.c +146 -204
  15. data/ext/glib2/rbglib_iochannel_win32_socket.c +56 -0
  16. data/ext/glib2/rbglib_iochannelerror.c +49 -0
  17. data/ext/glib2/rbglib_keyfile.c +171 -182
  18. data/ext/glib2/rbglib_maincontext.c +107 -92
  19. data/ext/glib2/rbglib_mainloop.c +34 -21
  20. data/ext/glib2/rbglib_messages.c +53 -44
  21. data/ext/glib2/rbglib_pollfd.c +37 -26
  22. data/ext/glib2/rbglib_shell.c +29 -22
  23. data/ext/glib2/rbglib_shellerror.c +34 -0
  24. data/ext/glib2/rbglib_source.c +49 -36
  25. data/ext/glib2/rbglib_spawn.c +50 -61
  26. data/ext/glib2/rbglib_spawnerror.c +53 -0
  27. data/ext/glib2/rbglib_threads.c +28 -16
  28. data/ext/glib2/rbglib_timer.c +35 -24
  29. data/ext/glib2/rbglib_ucs4.c +79 -0
  30. data/ext/glib2/rbglib_unichar.c +209 -0
  31. data/ext/glib2/rbglib_unicode.c +34 -584
  32. data/ext/glib2/rbglib_utf16.c +78 -0
  33. data/ext/glib2/rbglib_utf8.c +259 -0
  34. data/ext/glib2/rbglib_utils.c +95 -91
  35. data/ext/glib2/rbglib_win32.c +52 -45
  36. data/ext/glib2/rbglibdeprecated.c +56 -0
  37. data/ext/glib2/rbglibdeprecated.h +34 -0
  38. data/ext/glib2/rbgobj_boxed.c +40 -33
  39. data/ext/glib2/rbgobj_closure.c +45 -34
  40. data/ext/glib2/rbgobj_convert.c +19 -9
  41. data/ext/glib2/rbgobj_enumflags.c +109 -0
  42. data/ext/glib2/rbgobj_enums.c +67 -646
  43. data/ext/glib2/rbgobj_flags.c +522 -0
  44. data/ext/glib2/rbgobj_fundamental.c +19 -6
  45. data/ext/glib2/rbgobj_object.c +90 -81
  46. data/ext/glib2/rbgobj_param.c +78 -83
  47. data/ext/glib2/rbgobj_paramspecs.c +20 -12
  48. data/ext/glib2/rbgobj_signal.c +248 -193
  49. data/ext/glib2/rbgobj_strv.c +20 -10
  50. data/ext/glib2/rbgobj_type.c +153 -149
  51. data/ext/glib2/rbgobj_typeinstance.c +49 -39
  52. data/ext/glib2/rbgobj_typeinterface.c +37 -27
  53. data/ext/glib2/rbgobj_typemodule.c +39 -29
  54. data/ext/glib2/rbgobj_typeplugin.c +36 -26
  55. data/ext/glib2/rbgobj_value.c +41 -11
  56. data/ext/glib2/rbgobj_valuearray.c +59 -23
  57. data/ext/glib2/rbgobj_valuetypes.c +27 -17
  58. data/ext/glib2/rbgobject.c +26 -40
  59. data/ext/glib2/rbgobject.h +38 -20
  60. data/ext/glib2/rbgprivate.h +87 -5
  61. data/ext/glib2/rbgutil.c +52 -238
  62. data/ext/glib2/rbgutil.h +55 -42
  63. data/ext/glib2/rbgutil_callback.c +47 -12
  64. data/ext/glib2/rbgutil_list.c +173 -0
  65. data/ext/glib2/rbgutil_list.h +85 -0
  66. data/ext/glib2/rbgutildeprecated.c +252 -0
  67. data/ext/glib2/rbgutildeprecated.h +63 -0
  68. data/lib/glib-mkenums.rb +2 -2
  69. data/lib/glib2.rb +2 -25
  70. data/lib/glib2/deprecatable.rb +149 -0
  71. data/lib/gnome2-raketask.rb +45 -15
  72. data/lib/gnome2-win32-binary-downloader.rb +1 -1
  73. data/lib/mkmf-gnome2.rb +37 -18
  74. data/test/test_flags.rb +129 -0
  75. data/test/test_key_file.rb +6 -2
  76. data/test/test_spawn.rb +33 -0
  77. metadata +26 -7
  78. data/ChangeLog +0 -3513
@@ -1,10 +1,23 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
- /************************************************
3
-
4
- rbgobj_fundamental.c -
5
-
6
- Copyright (C) 2007 Ruby-GNOME2 Project Team
7
- ************************************************/
2
+ /*
3
+ * Copyright (C) 2011 Ruby-GNOME2 Project Team
4
+ * Copyright (C) 2007 Ruby-GNOME2 Project Team
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
+ * MA 02110-1301 USA
20
+ */
8
21
 
9
22
  #include "rbgobject.h"
10
23
  #include "rbgprivate.h"
@@ -1,36 +1,44 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
- /**********************************************************************
3
-
4
- rbgobj_object.c -
5
-
6
- $Author: sakai $
7
- $Date: 2007/07/19 22:03:44 $
8
-
9
- Copyright (C) 2002-2004 Ruby-GNOME2 Project Team
10
- Copyright (C) 2002-2003 Masahiro Sakai
11
-
12
- This file is derived from rbgtkobject.c in Ruby/Gtk distribution.
13
- rbgtkobject.c -
14
- Copyright (C) 1998-2000 Yukihiro Matsumoto,
15
- Daisuke Kanda,
16
- Hiroshi Igarashi
17
-
18
- **********************************************************************/
2
+ /*
3
+ * Copyright (C) 2011 Ruby-GNOME2 Project Team
4
+ * Copyright (C) 2002-2004 Ruby-GNOME2 Project Team
5
+ * Copyright (C) 2002-2003 Masahiro Sakai
6
+ * Copyright (C) 1998-2000 Yukihiro Matsumoto,
7
+ * Daisuke Kanda,
8
+ * Hiroshi Igarashi
9
+ *
10
+ * This library is free software; you can redistribute it and/or
11
+ * modify it under the terms of the GNU Lesser General Public
12
+ * License as published by the Free Software Foundation; either
13
+ * version 2.1 of the License, or (at your option) any later version.
14
+ *
15
+ * This library is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
+ * Lesser General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU Lesser General Public
21
+ * License along with this library; if not, write to the Free Software
22
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23
+ * MA 02110-1301 USA
24
+ */
19
25
 
20
26
  #include "rbgprivate.h"
21
27
 
22
- VALUE rbgobj_cObject;
28
+ #define RG_TARGET_NAMESPACE rbgobj_cObject
29
+
30
+ VALUE RG_TARGET_NAMESPACE;
23
31
  static VALUE eNoPropertyError;
24
32
  static GQuark RUBY_GOBJECT_OBJ_KEY;
25
33
 
26
34
  /* deperecated */
27
35
  void
28
- rbgobj_add_abstract_but_create_instance_class(GType gtype)
36
+ rbgobj_add_abstract_but_create_instance_class(G_GNUC_UNUSED GType gtype)
29
37
  {
30
38
  }
31
39
 
32
40
  static void
33
- weak_notify(gpointer data, GObject *where_the_object_was)
41
+ weak_notify(gpointer data, G_GNUC_UNUSED GObject *where_the_object_was)
34
42
  {
35
43
  gobj_holder *holder = data;
36
44
 
@@ -56,7 +64,7 @@ holder_free(gobj_holder *holder)
56
64
  if (!holder->destroyed) {
57
65
  g_object_set_qdata(holder->gobj, RUBY_GOBJECT_OBJ_KEY, NULL);
58
66
  g_object_weak_unref(holder->gobj, (GWeakNotify)weak_notify, holder);
59
- weak_notify(holder, holder->gobj);
67
+ weak_notify(holder, holder->gobj);
60
68
  }
61
69
  holder->gobj = NULL;
62
70
  }
@@ -121,7 +129,7 @@ rbgobj_get_ruby_object_from_gobject(GObject* gobj, gboolean alloc)
121
129
  } else if (alloc) {
122
130
  VALUE obj;
123
131
 
124
- obj = gobj_s_allocate(GTYPE2CLASS(G_OBJECT_TYPE(gobj)));
132
+ obj = gobj_s_allocate(GTYPE2CLASS(G_OBJECT_TYPE(gobj)));
125
133
  gobj = g_object_ref(gobj);
126
134
  rbgobj_gobject_initialize(obj, (gpointer)gobj);
127
135
  return obj;
@@ -183,7 +191,7 @@ gobj_mark(gpointer ptr)
183
191
  GObject* gobj = ptr;
184
192
  guint n_properties;
185
193
  GParamSpec** properties;
186
- GValue gval = {0,};
194
+ GValue gval = G_VALUE_INIT;
187
195
  guint i;
188
196
 
189
197
  properties = g_object_class_list_properties(G_OBJECT_GET_CLASS(gobj), &n_properties);
@@ -207,7 +215,7 @@ gobj_mark(gpointer ptr)
207
215
  }
208
216
 
209
217
  static VALUE
210
- gobj_s_gobject_new(int argc, VALUE *argv, VALUE self)
218
+ rg_s_new_bang(int argc, VALUE *argv, VALUE self)
211
219
  {
212
220
  const RGObjClassInfo* cinfo = rbgobj_lookup_class(self);
213
221
  VALUE params_hash;
@@ -337,7 +345,7 @@ rbgobj_gobject_new(GType gtype, VALUE params_hash)
337
345
  }
338
346
 
339
347
  static VALUE
340
- gobj_s_install_property(int argc, VALUE* argv, VALUE self)
348
+ rg_s_install_property(int argc, VALUE* argv, VALUE self)
341
349
  {
342
350
  const RGObjClassInfo* cinfo = rbgobj_lookup_class(self);
343
351
  gpointer gclass;
@@ -431,8 +439,8 @@ rbgobj_register_property_setter(GType gtype, const char *name, RValueToGValueFun
431
439
 
432
440
  oclass = g_type_class_ref(gtype);
433
441
  pspec = g_object_class_find_property(oclass, name);
434
-
435
- rb_hash_aset(table, rb_str_new2(g_param_spec_get_name(pspec)),
442
+
443
+ rb_hash_aset(table, CSTR2RVAL(g_param_spec_get_name(pspec)),
436
444
  Data_Wrap_Struct(rb_cData, NULL, NULL, func));
437
445
 
438
446
  g_type_class_unref(oclass);
@@ -453,12 +461,14 @@ rbgobj_register_property_getter(GType gtype, const char *name, GValueToRValueFun
453
461
  oclass = g_type_class_ref(gtype);
454
462
  pspec = g_object_class_find_property(oclass, name);
455
463
 
456
- rb_hash_aset(table, rb_str_new2(g_param_spec_get_name(pspec)),
464
+ rb_hash_aset(table, CSTR2RVAL(g_param_spec_get_name(pspec)),
457
465
  Data_Wrap_Struct(rb_cData, NULL, NULL, func));
466
+
467
+ g_type_class_unref(oclass);
458
468
  }
459
469
 
460
470
  static VALUE
461
- gobj_set_property(VALUE self, VALUE prop_name, VALUE val)
471
+ rg_set_property(VALUE self, VALUE prop_name, VALUE val)
462
472
  {
463
473
  GParamSpec* pspec;
464
474
  const char* name;
@@ -476,7 +486,7 @@ gobj_set_property(VALUE self, VALUE prop_name, VALUE val)
476
486
  else {
477
487
  // FIXME: use rb_ensure to call g_value_unset()
478
488
  RValueToGValueFunc setter = NULL;
479
- GValue gval = {0,};
489
+ GValue gval = G_VALUE_INIT;
480
490
 
481
491
  g_value_init(&gval, G_PARAM_SPEC_VALUE_TYPE(pspec));
482
492
 
@@ -484,7 +494,7 @@ gobj_set_property(VALUE self, VALUE prop_name, VALUE val)
484
494
  VALUE table = rb_hash_aref(type_to_prop_setter_table,
485
495
  INT2FIX(pspec->owner_type));
486
496
  if (!NIL_P(table)){
487
- VALUE obj = rb_hash_aref(table, rb_intern(g_param_spec_get_name(pspec)));
497
+ VALUE obj = rb_hash_aref(table, CSTR2RVAL(g_param_spec_get_name(pspec)));
488
498
  if (!NIL_P(obj))
489
499
  Data_Get_Struct(obj, void, setter);
490
500
  }
@@ -505,7 +515,7 @@ gobj_set_property(VALUE self, VALUE prop_name, VALUE val)
505
515
  }
506
516
 
507
517
  static VALUE
508
- gobj_get_property(VALUE self, VALUE prop_name)
518
+ rg_get_property(VALUE self, VALUE prop_name)
509
519
  {
510
520
  GParamSpec* pspec;
511
521
  const char* name;
@@ -523,7 +533,7 @@ gobj_get_property(VALUE self, VALUE prop_name)
523
533
  else {
524
534
  // FIXME: use rb_ensure to call g_value_unset()
525
535
  GValueToRValueFunc getter = NULL;
526
- GValue gval = {0,};
536
+ GValue gval = G_VALUE_INIT;
527
537
  VALUE ret;
528
538
 
529
539
  {
@@ -548,34 +558,34 @@ gobj_get_property(VALUE self, VALUE prop_name)
548
558
  }
549
559
  }
550
560
 
551
- static VALUE gobj_thaw_notify(VALUE self);
561
+ static VALUE rg_thaw_notify(VALUE self);
552
562
 
553
563
  static VALUE
554
- gobj_freeze_notify(VALUE self)
564
+ rg_freeze_notify(VALUE self)
555
565
  {
556
566
  g_object_freeze_notify(RVAL2GOBJ(self));
557
567
  if (rb_block_given_p()) {
558
- return rb_ensure(rb_yield, self, gobj_thaw_notify, self);
568
+ return rb_ensure(rb_yield, self, rg_thaw_notify, self);
559
569
  }
560
570
  return self;
561
571
  }
562
572
 
563
573
  static VALUE
564
- gobj_notify(VALUE self, VALUE property_name)
574
+ rg_notify(VALUE self, VALUE property_name)
565
575
  {
566
576
  g_object_notify(RVAL2GOBJ(self), StringValuePtr(property_name));
567
577
  return self;
568
578
  }
569
579
 
570
580
  static VALUE
571
- gobj_thaw_notify(VALUE self)
581
+ rg_thaw_notify(VALUE self)
572
582
  {
573
583
  g_object_thaw_notify(RVAL2GOBJ(self));
574
584
  return self;
575
585
  }
576
586
 
577
587
  static VALUE
578
- gobj_is_destroyed(VALUE self)
588
+ rg_destroyed_p(VALUE self)
579
589
  {
580
590
  gobj_holder* holder;
581
591
 
@@ -588,7 +598,7 @@ gobj_is_destroyed(VALUE self)
588
598
  }
589
599
 
590
600
  static VALUE
591
- gobj_inspect(VALUE self)
601
+ rg_inspect(VALUE self)
592
602
  {
593
603
  gobj_holder* holder;
594
604
  const char *class_name;
@@ -600,7 +610,7 @@ gobj_inspect(VALUE self)
600
610
  class_name = rb_class2name(CLASS_OF(self));
601
611
  if (!holder->destroyed)
602
612
  s = g_strdup_printf("#<%s:%p ptr=%p>", class_name, (void *)self,
603
- holder->gobj);
613
+ holder->gobj);
604
614
  else
605
615
  s = g_strdup_printf("#<%s:%p destroyed>", class_name, (void *)self);
606
616
 
@@ -611,11 +621,17 @@ gobj_inspect(VALUE self)
611
621
  }
612
622
 
613
623
  static VALUE
614
- gobj_initialize(int argc, VALUE *argv, VALUE self)
624
+ rg_type_name(VALUE self)
625
+ {
626
+ return CSTR2RVAL(G_OBJECT_TYPE_NAME(RVAL2GOBJ(self)));
627
+ }
628
+
629
+ static VALUE
630
+ rg_initialize(int argc, VALUE *argv, VALUE self)
615
631
  {
616
632
  VALUE params_hash;
617
633
  GObject* gobj;
618
-
634
+
619
635
  rb_scan_args(argc, argv, "01", &params_hash);
620
636
 
621
637
  if (!NIL_P(params_hash))
@@ -651,7 +667,7 @@ static GQuark q_ruby_getter;
651
667
  // FIXME: use rb_protect
652
668
  static void
653
669
  get_prop_func(GObject* object,
654
- guint property_id,
670
+ G_GNUC_UNUSED guint property_id,
655
671
  GValue* value,
656
672
  GParamSpec* pspec)
657
673
  {
@@ -677,7 +693,7 @@ get_prop_func(GObject* object,
677
693
  // FIXME: use rb_protect
678
694
  static void
679
695
  set_prop_func(GObject* object,
680
- guint property_id,
696
+ G_GNUC_UNUSED guint property_id,
681
697
  const GValue* value,
682
698
  GParamSpec* pspec)
683
699
  {
@@ -699,7 +715,7 @@ set_prop_func(GObject* object,
699
715
 
700
716
  // FIXME: use rb_protect
701
717
  static void
702
- class_init_func(gpointer g_class_, gpointer class_data)
718
+ class_init_func(gpointer g_class_, G_GNUC_UNUSED gpointer class_data)
703
719
  {
704
720
  GObjectClass* g_class = G_OBJECT_CLASS(g_class_);
705
721
 
@@ -714,7 +730,7 @@ class_init_func(gpointer g_class_, gpointer class_data)
714
730
  }
715
731
 
716
732
  static VALUE
717
- type_register(int argc, VALUE* argv, VALUE self)
733
+ rg_s_type_register(int argc, VALUE* argv, VALUE self)
718
734
  {
719
735
  VALUE type_name, flags;
720
736
  volatile VALUE class_init_proc = Qnil;
@@ -752,6 +768,8 @@ type_register(int argc, VALUE* argv, VALUE self)
752
768
  GTypeQuery query;
753
769
  g_type_query(parent_type, &query);
754
770
 
771
+ /* TODO: Why new? g_type_register_static() doesn’t retain a copy, so
772
+ * this should be allocated on the stack. */
755
773
  info = g_new0(GTypeInfo, 1);
756
774
  info->class_size = query.class_size;
757
775
  info->base_init = NULL;
@@ -785,7 +803,7 @@ type_register(int argc, VALUE* argv, VALUE self)
785
803
  VALUE m = rb_define_module_under(self, RubyGObjectHookModule);
786
804
 
787
805
  if (! (cinfo->flags & RBGOBJ_DEFINED_BY_RUBY)) {
788
- rb_define_method(m, "initialize", gobj_initialize, -1);
806
+ rb_define_method(m, "initialize", rg_initialize, -1);
789
807
  }
790
808
 
791
809
  rb_include_module(self, m);
@@ -795,26 +813,13 @@ type_register(int argc, VALUE* argv, VALUE self)
795
813
  }
796
814
  }
797
815
 
798
- static void
799
- Init_gobject_subclass()
800
- {
801
- VALUE cGObject = GTYPE2CLASS(G_TYPE_OBJECT);
802
- rb_define_singleton_method(cGObject, "type_register", type_register, -1);
803
-
804
- rb_global_variable(&proc_mod_eval);
805
- proc_mod_eval = rb_eval_string("lambda{|obj,proc| obj.module_eval(&proc)}");
806
- }
807
-
808
816
  /**********************************************************************/
809
817
 
810
818
  void
811
- Init_gobject_gobject()
819
+ Init_gobject_gobject(void)
812
820
  {
813
- VALUE cGObject;
814
-
815
- rbgobj_cObject = G_DEF_CLASS_WITH_GC_FUNC(G_TYPE_OBJECT, "Object", mGLib,
816
- gobj_mark, NULL);
817
- cGObject = rbgobj_cObject;
821
+ RG_TARGET_NAMESPACE = G_DEF_CLASS_WITH_GC_FUNC(G_TYPE_OBJECT, "Object", mGLib,
822
+ gobj_mark, NULL);
818
823
 
819
824
  #ifdef G_TYPE_INITIALLY_UNOWNED
820
825
  G_DEF_CLASS(G_TYPE_INITIALLY_UNOWNED, "InitiallyUnowned", mGLib);
@@ -822,26 +827,27 @@ Init_gobject_gobject()
822
827
 
823
828
  RUBY_GOBJECT_OBJ_KEY = g_quark_from_static_string("__ruby_gobject_object__");
824
829
 
825
- rb_define_alloc_func(cGObject, (VALUE(*)_((VALUE)))gobj_s_allocate);
826
- rb_define_singleton_method(cGObject, "new!", gobj_s_gobject_new, -1);
830
+ rb_define_alloc_func(RG_TARGET_NAMESPACE, (VALUE(*)_((VALUE)))gobj_s_allocate);
831
+ RG_DEF_SMETHOD_BANG(new, -1);
827
832
 
828
- rb_define_singleton_method(cGObject, "property", &gobj_s_property, 1);
829
- rb_define_singleton_method(cGObject, "properties", &gobj_s_properties, -1);
830
- rb_define_singleton_method(cGObject, "install_property", gobj_s_install_property, -1);
833
+ rb_define_singleton_method(RG_TARGET_NAMESPACE, "property", &gobj_s_property, 1);
834
+ rb_define_singleton_method(RG_TARGET_NAMESPACE, "properties", &gobj_s_properties, -1);
835
+ RG_DEF_SMETHOD(install_property, -1);
831
836
  q_ruby_getter = g_quark_from_static_string("__ruby_getter");
832
837
  q_ruby_setter = g_quark_from_static_string("__ruby_setter");
833
838
 
834
- rb_define_method(cGObject, "set_property", gobj_set_property, 2);
835
- rb_define_method(cGObject, "get_property", gobj_get_property, 1);
836
- rb_define_method(cGObject, "freeze_notify", gobj_freeze_notify, 0);
837
- rb_undef_method(cGObject, "notify");
838
- rb_define_method(cGObject, "notify", gobj_notify, 1);
839
- rb_define_method(cGObject, "thaw_notify", gobj_thaw_notify, 0);
840
- rb_define_method(cGObject, "destroyed?", gobj_is_destroyed, 0);
839
+ RG_DEF_METHOD(set_property, 2);
840
+ RG_DEF_METHOD(get_property, 1);
841
+ RG_DEF_METHOD(freeze_notify, 0);
842
+ rb_undef_method(RG_TARGET_NAMESPACE, "notify");
843
+ RG_DEF_METHOD(notify, 1);
844
+ RG_DEF_METHOD(thaw_notify, 0);
845
+ RG_DEF_METHOD_P(destroyed, 0);
841
846
 
842
- rb_define_method(cGObject, "initialize", gobj_initialize, -1);
843
- rb_define_method(cGObject, "ref_count", gobj_ref_count, 0); /* for debugging */
844
- rb_define_method(cGObject, "inspect", gobj_inspect, 0);
847
+ RG_DEF_METHOD(initialize, -1);
848
+ rb_define_method(RG_TARGET_NAMESPACE, "ref_count", gobj_ref_count, 0); /* for debugging */
849
+ RG_DEF_METHOD(inspect, 0);
850
+ RG_DEF_METHOD(type_name, 0);
845
851
 
846
852
  eNoPropertyError = rb_define_class_under(mGLib, "NoPropertyError",
847
853
  rb_eNameError);
@@ -851,6 +857,9 @@ Init_gobject_gobject()
851
857
  type_to_prop_setter_table = rb_hash_new();
852
858
  type_to_prop_getter_table = rb_hash_new();
853
859
 
854
- Init_gobject_subclass();
855
- }
860
+ /* subclass */
861
+ RG_DEF_SMETHOD(type_register, -1);
856
862
 
863
+ rb_global_variable(&proc_mod_eval);
864
+ proc_mod_eval = rb_eval_string("lambda{|obj,proc| obj.module_eval(&proc)}");
865
+ }
@@ -1,19 +1,29 @@
1
1
  /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
- /**********************************************************************
3
-
4
- rbgobj_param.c -
5
-
6
- $Author: ggc $
7
- $Date: 2007/07/13 16:07:28 $
8
- created at: Sun Jun 9 20:31:47 JST 2002
9
-
10
- Copyright (C) 2002,2003 Masahiro Sakai
11
-
12
- **********************************************************************/
2
+ /*
3
+ * Copyright (C) 2011 Ruby-GNOME2 Project Team
4
+ * Copyright (C) 2002,2003 Masahiro Sakai
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
+ * MA 02110-1301 USA
20
+ */
13
21
 
14
22
  #include "rbgprivate.h"
15
23
 
16
- VALUE rbgobj_cParam;
24
+ #define RG_TARGET_NAMESPACE rbgobj_cParam
25
+
26
+ VALUE RG_TARGET_NAMESPACE;
17
27
  static GQuark qparamspec;
18
28
 
19
29
  static VALUE pspec_s_allocate(VALUE klass);
@@ -100,7 +110,7 @@ pspec_s_allocate(VALUE klass)
100
110
  }
101
111
 
102
112
  static VALUE
103
- inspect(VALUE self)
113
+ rg_inspect(VALUE self)
104
114
  {
105
115
  GParamSpec* pspec = rbgobj_get_param_spec(self);
106
116
  VALUE v = rb_inspect(GTYPE2CLASS(pspec->owner_type));
@@ -114,53 +124,53 @@ inspect(VALUE self)
114
124
  }
115
125
 
116
126
  static VALUE
117
- get_name(VALUE self)
127
+ rg_name(VALUE self)
118
128
  {
119
129
  return rb_str_new2(g_param_spec_get_name(rbgobj_get_param_spec(self)));
120
130
  }
121
131
 
122
132
  static VALUE
123
- get_nick(VALUE self)
133
+ rg_nick(VALUE self)
124
134
  {
125
135
  const gchar* str = g_param_spec_get_nick(rbgobj_get_param_spec(self));
126
136
  return str ? rb_str_new2(str) : Qnil;
127
137
  }
128
138
 
129
139
  static VALUE
130
- get_blurb(VALUE self)
140
+ rg_blurb(VALUE self)
131
141
  {
132
142
  const gchar* str = g_param_spec_get_blurb(rbgobj_get_param_spec(self));
133
143
  return str ? rb_str_new2(str) : Qnil;
134
144
  }
135
145
 
136
146
  static VALUE
137
- get_flags(VALUE self)
147
+ rg_flags(VALUE self)
138
148
  {
139
149
  return INT2NUM(rbgobj_get_param_spec(self)->flags);
140
150
  }
141
151
 
142
152
  static VALUE
143
- get_value_type(VALUE self)
153
+ rg_value_type(VALUE self)
144
154
  {
145
155
  return rbgobj_gtype_new(G_PARAM_SPEC_VALUE_TYPE(rbgobj_get_param_spec(self)));
146
156
  }
147
157
 
148
158
  static VALUE
149
- get_owner_type(VALUE self)
159
+ rg_owner_type(VALUE self)
150
160
  {
151
161
  return rbgobj_gtype_new(rbgobj_get_param_spec(self)->owner_type);
152
162
  }
153
163
 
154
164
  static VALUE
155
- get_owner(VALUE self)
165
+ rg_owner(VALUE self)
156
166
  {
157
167
  return GTYPE2CLASS(rbgobj_get_param_spec(self)->owner_type);
158
168
  }
159
169
 
160
170
  static VALUE
161
- value_default(VALUE self)
171
+ rg_value_default(VALUE self)
162
172
  {
163
- GValue tmp = {0,};
173
+ GValue tmp = G_VALUE_INIT;
164
174
  VALUE result;
165
175
 
166
176
  g_value_init(&tmp,
@@ -174,7 +184,7 @@ value_default(VALUE self)
174
184
 
175
185
  #if 0
176
186
  static VALUE
177
- value_defaults(VALUE self, VALUE val)
187
+ rg_value_defaults_p(VALUE self, VALUE val)
178
188
  {
179
189
  GValue tmp = {0,};
180
190
  gboolean result;
@@ -190,7 +200,6 @@ value_defaults(VALUE self, VALUE val)
190
200
  }
191
201
  #endif
192
202
 
193
-
194
203
  struct validate_arg{
195
204
  GParamSpec* pspec;
196
205
  GValue* value;
@@ -217,10 +226,10 @@ value_validate_ensure(struct validate_arg* arg)
217
226
  }
218
227
 
219
228
  static VALUE
220
- value_validate(VALUE self, VALUE obj)
229
+ rg_value_validate(VALUE self, VALUE obj)
221
230
  {
222
231
  struct validate_arg arg;
223
- GValue value = {0,};
232
+ GValue value = G_VALUE_INIT;
224
233
 
225
234
  arg.pspec = rbgobj_get_param_spec(self);
226
235
  arg.value = &value;
@@ -232,16 +241,15 @@ value_validate(VALUE self, VALUE obj)
232
241
  value_validate_ensure, (VALUE)&arg);
233
242
  }
234
243
 
235
-
236
244
  static VALUE
237
- value_convert(int argc, VALUE* argv, VALUE self)
245
+ rg_value_convert(int argc, VALUE* argv, VALUE self)
238
246
  {
239
247
  GParamSpec* pspec = rbgobj_get_param_spec(self);
240
248
  VALUE src, strict_validation;
241
249
  VALUE src_type;
242
250
  VALUE result = Qnil;
243
- GValue src_value = {0,};
244
- GValue dest_value = {0,};
251
+ GValue src_value = G_VALUE_INIT;
252
+ GValue dest_value = G_VALUE_INIT;
245
253
  gboolean b;
246
254
 
247
255
  rb_scan_args(argc, argv, "21", &src, &src_type, &strict_validation);
@@ -269,12 +277,12 @@ value_convert(int argc, VALUE* argv, VALUE self)
269
277
  }
270
278
 
271
279
  static VALUE
272
- values_compare(VALUE self, VALUE a, VALUE b)
280
+ rg_value_compare(VALUE self, VALUE a, VALUE b)
273
281
  {
274
282
  GParamSpec* pspec = rbgobj_get_param_spec(self);
275
283
  GType type = G_PARAM_SPEC_VALUE_TYPE(pspec);
276
- GValue v1 = {0,};
277
- GValue v2 = {0,};
284
+ GValue v1 = G_VALUE_INIT;
285
+ GValue v2 = G_VALUE_INIT;
278
286
  gint result;
279
287
 
280
288
  g_value_init(&v1, type);
@@ -292,14 +300,12 @@ values_compare(VALUE self, VALUE a, VALUE b)
292
300
  return INT2NUM(result);
293
301
  }
294
302
 
295
-
296
303
  static VALUE
297
- get_ref_count(VALUE self)
304
+ rg_ref_count(VALUE self)
298
305
  {
299
306
  return INT2NUM(G_PARAM_SPEC(rbgobj_get_param_spec(self))->ref_count);
300
307
  }
301
308
 
302
-
303
309
  #define param_is_flag(flag) \
304
310
  static VALUE \
305
311
  param_is_##flag(VALUE self) \
@@ -318,66 +324,55 @@ param_is_flag(G_PARAM_READWRITE)
318
324
 
319
325
  /**********************************************************************/
320
326
 
321
- static void
322
- Init_gobject_gparam_spec()
327
+ void
328
+ Init_gobject_gparam(void)
323
329
  {
324
- VALUE cParamSpec;
325
-
326
330
  qparamspec = g_quark_from_static_string("__ruby_gobject_param_spec__");
327
- rbgobj_cParam = G_DEF_CLASS(G_TYPE_PARAM, "Param", mGLib);
328
- cParamSpec = rbgobj_cParam;
331
+ RG_TARGET_NAMESPACE = G_DEF_CLASS(G_TYPE_PARAM, "Param", mGLib);
329
332
 
330
333
  /* GParamFlags */
331
- rb_define_const(cParamSpec, "READABLE", INT2FIX(G_PARAM_READABLE));
332
- rb_define_const(cParamSpec, "WRITABLE", INT2FIX(G_PARAM_WRITABLE));
333
- rb_define_const(cParamSpec, "CONSTRUCT", INT2FIX(G_PARAM_CONSTRUCT));
334
- rb_define_const(cParamSpec, "CONSTRUCT_ONLY", INT2FIX(G_PARAM_CONSTRUCT_ONLY));
335
- rb_define_const(cParamSpec, "LAX_VALIDATION", INT2FIX(G_PARAM_LAX_VALIDATION));
336
- rb_define_const(cParamSpec, "PRIVATE", INT2FIX(G_PARAM_PRIVATE));
337
- rb_define_const(cParamSpec, "READWRITE", INT2FIX(G_PARAM_READWRITE));
338
- rb_define_const(cParamSpec, "MASK", INT2FIX(G_PARAM_MASK));
339
- rb_define_const(cParamSpec, "USER_SHIFT", INT2FIX(G_PARAM_USER_SHIFT));
334
+ rb_define_const(RG_TARGET_NAMESPACE, "READABLE", INT2FIX(G_PARAM_READABLE));
335
+ rb_define_const(RG_TARGET_NAMESPACE, "WRITABLE", INT2FIX(G_PARAM_WRITABLE));
336
+ rb_define_const(RG_TARGET_NAMESPACE, "CONSTRUCT", INT2FIX(G_PARAM_CONSTRUCT));
337
+ rb_define_const(RG_TARGET_NAMESPACE, "CONSTRUCT_ONLY", INT2FIX(G_PARAM_CONSTRUCT_ONLY));
338
+ rb_define_const(RG_TARGET_NAMESPACE, "LAX_VALIDATION", INT2FIX(G_PARAM_LAX_VALIDATION));
339
+ rb_define_const(RG_TARGET_NAMESPACE, "PRIVATE", INT2FIX(G_PARAM_PRIVATE));
340
+ rb_define_const(RG_TARGET_NAMESPACE, "READWRITE", INT2FIX(G_PARAM_READWRITE));
341
+ rb_define_const(RG_TARGET_NAMESPACE, "MASK", INT2FIX(G_PARAM_MASK));
342
+ rb_define_const(RG_TARGET_NAMESPACE, "USER_SHIFT", INT2FIX(G_PARAM_USER_SHIFT));
340
343
 
341
- rb_define_alloc_func(cParamSpec, pspec_s_allocate);
344
+ rb_define_alloc_func(RG_TARGET_NAMESPACE, pspec_s_allocate);
342
345
 
343
- rb_define_method(cParamSpec, "inspect", inspect, 0);
346
+ RG_DEF_METHOD(inspect, 0);
344
347
 
345
- rb_define_method(cParamSpec, "name", get_name, 0);
346
- rb_define_method(cParamSpec, "nick", get_nick, 0);
347
- rb_define_method(cParamSpec, "blurb", get_blurb, 0);
348
+ RG_DEF_METHOD(name, 0);
349
+ RG_DEF_METHOD(nick, 0);
350
+ RG_DEF_METHOD(blurb, 0);
348
351
 
349
- rb_define_method(cParamSpec, "flags", get_flags, 0);
350
- rb_define_method(cParamSpec, "value_type", get_value_type, 0);
351
- rb_define_method(cParamSpec, "owner_type", get_owner_type, 0);
352
- rb_define_method(cParamSpec, "owner", get_owner, 0);
352
+ RG_DEF_METHOD(flags, 0);
353
+ RG_DEF_METHOD(value_type, 0);
354
+ RG_DEF_METHOD(owner_type, 0);
355
+ RG_DEF_METHOD(owner, 0);
353
356
 
354
- rb_define_method(cParamSpec, "value_default", value_default, 0);
355
- rb_define_alias(cParamSpec, "default", "value_default");
357
+ RG_DEF_METHOD(value_default, 0);
358
+ RG_DEF_ALIAS("default", "value_default");
356
359
 
357
360
  // FIXME: better name
358
361
  #if 0
359
- rb_define_method(cParamSpec, "value_defaults?", value_defaults, 1);
362
+ RG_DEF_METHOD_P(value_defaults, 1);
360
363
  #endif
361
- rb_define_method(cParamSpec, "value_validate", value_validate, 1);
362
- rb_define_method(cParamSpec, "value_convert", value_convert, -1);
363
- rb_define_method(cParamSpec, "value_compare", values_compare, 2);
364
+ RG_DEF_METHOD(value_validate, 1);
365
+ RG_DEF_METHOD(value_convert, -1);
366
+ RG_DEF_METHOD(value_compare, 2);
364
367
 
365
368
  /* for debugging */
366
- rb_define_method(cParamSpec, "ref_count", get_ref_count, 0);
367
-
368
- rb_define_method(cParamSpec, "readable?", param_is_G_PARAM_READABLE, 0);
369
- rb_define_method(cParamSpec, "writable?", param_is_G_PARAM_WRITABLE, 0);
370
- rb_define_method(cParamSpec, "construct?", param_is_G_PARAM_CONSTRUCT, 0);
371
- rb_define_method(cParamSpec, "construct_only?", param_is_G_PARAM_CONSTRUCT_ONLY, 0);
372
- rb_define_method(cParamSpec, "lax_validation?", param_is_G_PARAM_LAX_VALIDATION, 0);
373
- rb_define_method(cParamSpec, "private?", param_is_G_PARAM_PRIVATE, 0);
374
- rb_define_method(cParamSpec, "readwrite?", param_is_G_PARAM_READWRITE, 0);
375
- }
376
-
377
- /**********************************************************************/
378
-
379
- void
380
- Init_gobject_gparam()
381
- {
382
- Init_gobject_gparam_spec();
369
+ RG_DEF_METHOD(ref_count, 0);
370
+
371
+ rb_define_method(RG_TARGET_NAMESPACE, "readable?", param_is_G_PARAM_READABLE, 0);
372
+ rb_define_method(RG_TARGET_NAMESPACE, "writable?", param_is_G_PARAM_WRITABLE, 0);
373
+ rb_define_method(RG_TARGET_NAMESPACE, "construct?", param_is_G_PARAM_CONSTRUCT, 0);
374
+ rb_define_method(RG_TARGET_NAMESPACE, "construct_only?", param_is_G_PARAM_CONSTRUCT_ONLY, 0);
375
+ rb_define_method(RG_TARGET_NAMESPACE, "lax_validation?", param_is_G_PARAM_LAX_VALIDATION, 0);
376
+ rb_define_method(RG_TARGET_NAMESPACE, "private?", param_is_G_PARAM_PRIVATE, 0);
377
+ rb_define_method(RG_TARGET_NAMESPACE, "readwrite?", param_is_G_PARAM_READWRITE, 0);
383
378
  }