rice 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. data/COPYING +2 -2
  2. data/Doxyfile +1 -1
  3. data/Makefile.in +8 -3
  4. data/Rakefile +3 -3
  5. data/config.guess +30 -49
  6. data/config.sub +4 -22
  7. data/configure +319 -104
  8. data/configure.ac +6 -2
  9. data/doxygen.ac +2 -2
  10. data/extconf.rb +22 -0
  11. data/post-autoconf.rb +3 -3
  12. data/post-automake.rb +2 -2
  13. data/rice/Array.ipp +7 -6
  14. data/rice/Critical_Guard.hpp +6 -0
  15. data/rice/Critical_Guard.ipp +6 -0
  16. data/rice/Data_Object.hpp +1 -120
  17. data/rice/Data_Object.ipp +5 -1
  18. data/rice/Data_Object_defn.hpp +132 -0
  19. data/rice/Data_Type.ipp +18 -2
  20. data/rice/Enum.ipp +3 -3
  21. data/rice/Exception.hpp +1 -61
  22. data/rice/Exception_Base.hpp +2 -24
  23. data/rice/Exception_Base.ipp +2 -0
  24. data/rice/Exception_Base_defn.hpp +27 -0
  25. data/rice/Exception_defn.hpp +69 -0
  26. data/rice/Hash.hpp +5 -1
  27. data/rice/Hash.ipp +7 -7
  28. data/rice/Makefile.am +20 -3
  29. data/rice/Makefile.in +39 -4
  30. data/rice/Module.cpp +11 -3
  31. data/rice/Module_impl.hpp +20 -9
  32. data/rice/Module_impl.ipp +84 -87
  33. data/rice/Object.cpp +1 -1
  34. data/rice/VM.cpp +14 -1
  35. data/rice/VM.hpp +6 -1
  36. data/rice/config.hpp +24 -3
  37. data/rice/config.hpp.in +21 -0
  38. data/rice/detail/Auto_Function_Wrapper.hpp +97 -65
  39. data/rice/detail/Auto_Function_Wrapper.ipp +160 -128
  40. data/rice/detail/Auto_Member_Function_Wrapper.hpp +96 -64
  41. data/rice/detail/Auto_Member_Function_Wrapper.ipp +160 -128
  42. data/rice/detail/Exception_Handler.hpp +2 -112
  43. data/rice/detail/Exception_Handler.ipp +68 -0
  44. data/rice/detail/Exception_Handler_defn.hpp +96 -0
  45. data/rice/detail/Iterator.hpp +93 -0
  46. data/rice/detail/check_ruby_type.cpp +8 -2
  47. data/rice/detail/creation_funcs.ipp +2 -2
  48. data/rice/detail/define_method_and_auto_wrap.hpp +4 -2
  49. data/rice/detail/define_method_and_auto_wrap.ipp +14 -5
  50. data/rice/detail/env.hpp +4 -0
  51. data/rice/detail/method_data.cpp +362 -75
  52. data/rice/detail/method_data.cpp.rpp +301 -0
  53. data/rice/detail/method_data.hpp +6 -18
  54. data/rice/detail/mininode.cpp +1220 -0
  55. data/rice/detail/mininode.cpp.rpp +62 -0
  56. data/rice/detail/mininode.hpp +320 -0
  57. data/rice/detail/mininode.hpp.rpp +119 -0
  58. data/rice/detail/protect.cpp +4 -2
  59. data/rice/detail/ruby.hpp +44 -18
  60. data/rice/detail/ruby_version_code.hpp +6 -0
  61. data/rice/detail/ruby_version_code.hpp.in +6 -0
  62. data/rice/detail/rubysig.hpp +6 -0
  63. data/rice/detail/st.hpp +6 -2
  64. data/rice/detail/wrap_function.hpp +50 -48
  65. data/rice/detail/wrap_function.ipp +48 -48
  66. data/rice/generate_code.rb +43 -293
  67. data/rice/global_function.hpp +10 -4
  68. data/rice/global_function.ipp +1 -2
  69. data/rice/ruby_mark.hpp +13 -0
  70. data/rice/ruby_try_catch.hpp +1 -1
  71. data/rice/rubypp.rb +97 -0
  72. data/rice/to_from_ruby.ipp +3 -3
  73. data/ruby.ac +44 -8
  74. data/ruby/Makefile.in +2 -0
  75. data/ruby/lib/Makefile.in +2 -0
  76. data/ruby/lib/mkmf-rice.rb.in +4 -1
  77. data/ruby/lib/version.rb +3 -0
  78. data/sample/Makefile.am +2 -2
  79. data/sample/Makefile.in +4 -2
  80. data/test/Makefile.am +2 -1
  81. data/test/Makefile.in +7 -2
  82. data/test/test_Array.cpp +2 -2
  83. data/test/test_Class.cpp +4 -1
  84. data/test/test_Critical_Guard.cpp +4 -0
  85. data/test/test_Data_Object.cpp +43 -3
  86. data/test/test_Hash.cpp +3 -3
  87. data/test/test_String.cpp +8 -8
  88. data/test/test_VM.cpp +1 -1
  89. data/test/test_global_functions.cpp +45 -0
  90. data/test/test_rice.rb +5 -0
  91. metadata +115 -98
  92. data/rice/detail/Iterator_Definer.hpp +0 -98
data/rice/Module.cpp CHANGED
@@ -27,7 +27,16 @@ Module(VALUE v)
27
27
  Rice::String Rice::Module::
28
28
  name() const
29
29
  {
30
- return rb_mod_name(*this);
30
+ Object name = rb_mod_name(*this);
31
+ if(name.is_nil())
32
+ {
33
+ // 1.9
34
+ return String("");
35
+ }
36
+ else
37
+ {
38
+ return name;
39
+ }
31
40
  }
32
41
 
33
42
  Rice::Module Rice::
@@ -56,8 +65,7 @@ anonymous_module()
56
65
  void Rice::Module::
57
66
  swap(Rice::Module & other)
58
67
  {
59
- std::swap(handler_, other.handler_);
60
- Object::swap(other);
68
+ Module_base::swap(other);
61
69
  }
62
70
 
63
71
  Rice::Array
data/rice/Module_impl.hpp CHANGED
@@ -1,9 +1,10 @@
1
1
  #ifndef Rice__Module_impl__hpp_
2
2
  #define Rice__Module_impl__hpp_
3
3
 
4
- #include "detail/Exception_Handler.hpp"
4
+ #include "detail/Exception_Handler_defn.hpp"
5
5
  #include "detail/ruby.hpp"
6
6
  #include "Object_defn.hpp"
7
+ #include "Address_Registration_Guard_defn.hpp"
7
8
 
8
9
  namespace Rice
9
10
  {
@@ -20,11 +21,21 @@ class Module_base
20
21
  {
21
22
  public:
22
23
  Module_base(VALUE v = rb_cObject);
24
+ Module_base(Module_base const & other);
23
25
 
24
- protected: // TODO
25
- // TODO: For now, we always leak the handler, but in the future, we
26
- // should register it with the garbage collector.
27
- detail::Exception_Handler const * handler_;
26
+ Module_base & operator=(Module_base const & other);
27
+
28
+ void swap(Module_base & other);
29
+
30
+ protected:
31
+ template<typename Exception_T, typename Functor_T>
32
+ void add_handler(Functor_T functor);
33
+
34
+ Object handler() const;
35
+
36
+ private:
37
+ Object mutable handler_;
38
+ Address_Registration_Guard handler_guard_;
28
39
  };
29
40
 
30
41
  /*! An intermediate base class so we can always return the most-derived
@@ -90,7 +101,7 @@ public:
90
101
  */
91
102
  template<typename Func_T>
92
103
  Derived_T & define_method(
93
- char const * name,
104
+ Identifier name,
94
105
  Func_T func);
95
106
 
96
107
  //! Define a singleton method.
@@ -106,7 +117,7 @@ public:
106
117
  */
107
118
  template<typename Func_T>
108
119
  Derived_T & define_singleton_method(
109
- char const * name,
120
+ Identifier name,
110
121
  Func_T func);
111
122
 
112
123
  //! Define a module function.
@@ -124,7 +135,7 @@ public:
124
135
  */
125
136
  template<typename Func_T>
126
137
  Derived_T & define_module_function(
127
- char const * name,
138
+ Identifier name,
128
139
  Func_T func);
129
140
 
130
141
  //! Define an iterator.
@@ -141,7 +152,7 @@ public:
141
152
  Derived_T & define_iterator(
142
153
  Iterator_T (T::*begin)(),
143
154
  Iterator_T (T::*end)(),
144
- char const * name = "each");
155
+ Identifier name = "each");
145
156
 
146
157
  //! Include a module.
147
158
  /*! \param inc the module to be included.
data/rice/Module_impl.ipp CHANGED
@@ -1,8 +1,10 @@
1
1
  #include "detail/define_method_and_auto_wrap.hpp"
2
2
  #include "Object.hpp"
3
+ #include "Address_Registration_Guard.hpp"
3
4
  #include "Data_Object.hpp"
4
5
  #include "Data_Type.hpp"
5
6
  #include "Symbol.hpp"
7
+ #include "Exception.hpp"
6
8
  #include "protect.hpp"
7
9
 
8
10
  #include "Module.hpp"
@@ -11,16 +13,77 @@
11
13
 
12
14
  #include "detail/ruby.hpp"
13
15
  #include "detail/method_data.hpp"
16
+ #include "detail/Iterator.hpp"
14
17
 
15
18
 
16
19
  inline
17
20
  Rice::Module_base::
18
21
  Module_base(VALUE v)
19
22
  : Object(v)
20
- , handler_(new Rice::detail::Default_Exception_Handler)
23
+ , handler_(Qnil)
24
+ , handler_guard_(&handler_)
21
25
  {
22
26
  }
23
27
 
28
+ inline
29
+ Rice::Module_base::
30
+ Module_base(Module_base const & other)
31
+ : Object(other)
32
+ , handler_(other.handler_)
33
+ , handler_guard_(&handler_)
34
+ {
35
+ }
36
+
37
+ inline
38
+ Rice::Module_base &
39
+ Rice::Module_base::
40
+ operator=(Module_base const & other)
41
+ {
42
+ Module_base tmp(other);
43
+ swap(tmp);
44
+ return *this;
45
+ }
46
+
47
+ inline
48
+ void
49
+ Rice::Module_base::
50
+ swap(Module_base & other)
51
+ {
52
+ std::swap(handler_, other.handler_);
53
+ Object::swap(other);
54
+ }
55
+
56
+ template<typename Exception_T, typename Functor_T>
57
+ inline
58
+ void
59
+ Rice::Module_base::
60
+ add_handler(Functor_T functor)
61
+ {
62
+ Data_Object<detail::Exception_Handler> handler(
63
+ new detail::
64
+ Functor_Exception_Handler<Exception_T, Functor_T>(
65
+ functor,
66
+ this->handler()),
67
+ rb_cObject);
68
+ this->handler_.swap(handler);
69
+ }
70
+
71
+ inline
72
+ Rice::Object
73
+ Rice::Module_base::
74
+ handler() const
75
+ {
76
+ if(!handler_.test())
77
+ {
78
+ Data_Object<Rice::detail::Default_Exception_Handler> handler(
79
+ new Rice::detail::Default_Exception_Handler,
80
+ rb_cObject);
81
+ handler_.swap(handler);
82
+ }
83
+
84
+ return handler_;
85
+ }
86
+
24
87
  template<typename Base_T, typename Derived_T>
25
88
  inline
26
89
  Rice::Module_impl<Base_T, Derived_T>::
@@ -46,11 +109,7 @@ Rice::Module_impl<Base_T, Derived_T>::
46
109
  add_handler(
47
110
  Functor_T functor)
48
111
  {
49
- this->handler_ =
50
- new Rice::detail::
51
- Functor_Exception_Handler<Exception_T, Functor_T>(
52
- functor,
53
- this->handler_);
112
+ Module_base::add_handler<Exception_T>(functor);
54
113
  return (Derived_T &)*this;
55
114
  }
56
115
 
@@ -60,99 +119,48 @@ inline
60
119
  Derived_T &
61
120
  Rice::Module_impl<Base_T, Derived_T>::
62
121
  define_method(
63
- char const * name,
122
+ Identifier name,
64
123
  Func_T func)
65
124
  {
66
125
  detail::define_method_and_auto_wrap(
67
- *this, name, func, this->handler_);
126
+ *this, name, func, this->handler());
68
127
  return (Derived_T &)*this;
69
128
  }
70
129
 
71
130
  template<typename Base_T, typename Derived_T>
72
- template<typename T>
131
+ template<typename Func_T>
73
132
  inline
74
133
  Derived_T &
75
134
  Rice::Module_impl<Base_T, Derived_T>::
76
135
  define_singleton_method(
77
- char const * name,
78
- T func)
136
+ Identifier name,
137
+ Func_T func)
79
138
  {
80
139
  detail::define_method_and_auto_wrap(
81
- rb_class_of(*this), name, func, this->handler_);
140
+ rb_class_of(*this), name, func, this->handler());
82
141
  return (Derived_T &)*this;
83
142
  }
84
143
 
85
144
  template<typename Base_T, typename Derived_T>
86
- template<typename T>
145
+ template<typename Func_T>
87
146
  inline
88
147
  Derived_T &
89
148
  Rice::Module_impl<Base_T, Derived_T>::
90
149
  define_module_function(
91
- char const * name,
92
- T func)
93
- {
94
- detail::define_method_and_auto_wrap(*this, name, func);
95
- this->call("module_function", Symbol(name));
96
- return (Derived_T &)*this;
97
- }
98
-
99
- namespace Rice
100
- {
101
-
102
- namespace detail
103
- {
104
-
105
- class Iterator
106
- {
107
- public:
108
- virtual ~Iterator() { }
109
-
110
- virtual VALUE call_impl(VALUE self) = 0;
111
-
112
- static VALUE call(VALUE self)
113
- {
114
- void * data = Rice::detail::method_data();
115
- Iterator * iterator = static_cast<Iterator *>(data);
116
- return iterator->call_impl(self);
117
- }
118
- };
119
-
120
- template<typename T, typename Iterator_T>
121
- class Iterator_Impl
122
- : public Iterator
150
+ Identifier name,
151
+ Func_T func)
123
152
  {
124
- public:
125
- Iterator_Impl(
126
- Iterator_T (T::*begin)(),
127
- Iterator_T (T::*end)(),
128
- Rice::Data_Type<T> data_type)
129
- : begin_(begin)
130
- , end_(end)
131
- , data_type_(data_type)
132
- {
133
- }
134
-
135
- virtual VALUE call_impl(VALUE self)
153
+ if(this->rb_type() != T_MODULE)
136
154
  {
137
- Rice::Data_Object<T> obj(self, data_type_);
138
- Iterator_T it = obj->begin();
139
- Iterator_T end = obj->end();
140
- for(; it != end; ++it)
141
- {
142
- protect(rb_yield, to_ruby(*it));
143
- }
144
- return self;
155
+ throw Rice::Exception(
156
+ rb_eTypeError,
157
+ "can only define module functions for modules");
145
158
  }
146
159
 
147
- private:
148
- Iterator_T (T::*begin_)();
149
- Iterator_T (T::*end_)();
150
- Rice::Data_Type<T> data_type_;
151
- };
152
-
153
- } // namespace detail
154
-
155
- } // namespace Rice
160
+ define_method(name, func);
161
+ define_singleton_method(name, func);
162
+ return (Derived_T &)*this;
163
+ }
156
164
 
157
165
  template<typename Base_T, typename Derived_T>
158
166
  template<typename T, typename Iterator_T>
@@ -162,20 +170,9 @@ Rice::Module_impl<Base_T, Derived_T>::
162
170
  define_iterator(
163
171
  Iterator_T (T::*begin)(),
164
172
  Iterator_T (T::*end)(),
165
- char const * name)
173
+ Identifier name)
166
174
  {
167
- // TODO: memory leak!!!!!!!
168
- detail::Iterator * iterator =
169
- new detail::Iterator_Impl<T, Iterator_T>(
170
- begin,
171
- end,
172
- Data_Type<T>());
173
- detail::define_method_with_data(
174
- static_cast<VALUE>(*this),
175
- name,
176
- (RUBY_METHOD_FUNC)iterator->call,
177
- 0,
178
- iterator);
175
+ detail::define_iterator(*this, name, begin, end);
179
176
  return (Derived_T &)*this;
180
177
  }
181
178
 
data/rice/Object.cpp CHANGED
@@ -101,7 +101,7 @@ vcall(
101
101
  Identifier id,
102
102
  Array args)
103
103
  {
104
- return protect(rb_funcall3, *this, id, args.size(), args->ptr);
104
+ return protect(rb_funcall3, *this, id, args.size(), args.to_c_array());
105
105
  }
106
106
 
107
107
  void Rice::Object::
data/rice/VM.cpp CHANGED
@@ -1,6 +1,7 @@
1
1
  #include "VM.hpp"
2
2
  #include "detail/ruby.hpp"
3
3
  #include "detail/env.hpp"
4
+ #include "detail/ruby_version_code.hpp"
4
5
 
5
6
  #include <stdexcept>
6
7
 
@@ -19,7 +20,7 @@ VM(int argc, char * argv[])
19
20
  }
20
21
 
21
22
  Rice::VM::
22
- VM(std::vector<char *> const & args)
23
+ VM(std::vector<const char *> const & args)
23
24
  {
24
25
  check_not_initialized();
25
26
  init_stack();
@@ -51,29 +52,41 @@ init_stack()
51
52
  void Rice::VM::
52
53
  run()
53
54
  {
55
+ #if RICE__RUBY_VERSION_CODE >= 190
56
+ ruby_run_node(node_);
57
+ #else
54
58
  ruby_run();
59
+ #endif
55
60
  }
56
61
 
57
62
  extern "C"
58
63
  {
59
64
 
65
+ #if RICE__RUBY_VERSION_CODE < 190
60
66
  RUBY_EXTERN VALUE * rb_gc_stack_start;
67
+ #endif
61
68
 
62
69
  }
63
70
 
64
71
  void Rice::VM::
65
72
  check_not_initialized() const
66
73
  {
74
+ #if RICE__RUBY_VERSION_CODE < 190
67
75
  if(rb_gc_stack_start)
68
76
  {
69
77
  throw std::runtime_error("Only one VM allowed per application");
70
78
  }
79
+ #endif
80
+ // TODO: how to do this check on 1.9?
71
81
  }
72
82
 
73
83
  void Rice::VM::
74
84
  init(int argc, char * argv[])
75
85
  {
76
86
  ruby_init();
87
+ #if RICE__RUBY_VERSION_CODE >= 190
88
+ node_ =
89
+ #endif
77
90
  ruby_options(argc, argv);
78
91
  }
79
92
 
data/rice/VM.hpp CHANGED
@@ -2,6 +2,7 @@
2
2
  #define VM__hpp
3
3
 
4
4
  #include <vector>
5
+ #include "detail/ruby_version_code.hpp"
5
6
 
6
7
  namespace Rice
7
8
  {
@@ -11,7 +12,7 @@ class VM
11
12
  public:
12
13
  VM(char * app_name);
13
14
  VM(int argc, char * argv[]);
14
- VM(std::vector<char *> const & args);
15
+ VM(std::vector<const char *> const & args);
15
16
  ~VM();
16
17
 
17
18
  void init_stack();
@@ -20,6 +21,10 @@ public:
20
21
  private:
21
22
  void check_not_initialized() const;
22
23
  void init(int argc, char * argv[]);
24
+
25
+ #if RICE__RUBY_VERSION_CODE >= 190
26
+ void * node_;
27
+ #endif
23
28
  };
24
29
 
25
30
  }
data/rice/config.hpp CHANGED
@@ -1,6 +1,24 @@
1
1
  /* rice/config.hpp. Generated from config.hpp.in by configure. */
2
2
  /* rice/config.hpp.in. Generated from configure.ac by autoheader. */
3
3
 
4
+ /* Define to 1 if you have the <env.h> header file. */
5
+ #define HAVE_ENV_H 1
6
+
7
+ /* Define to 1 if you have the <node.h> header file. */
8
+ #define HAVE_NODE_H 1
9
+
10
+ /* Define this macro if rb_class_boot is defined */
11
+ #define HAVE_RB_CLASS_BOOT
12
+
13
+ /* Define to 1 if you have the <ruby.h> header file. */
14
+ #define HAVE_RUBY_H 1
15
+
16
+ /* Define to 1 if you have the <ruby/node.h> header file. */
17
+ /* #undef HAVE_RUBY_NODE_H */
18
+
19
+ /* Define to 1 if you have the <version.h> header file. */
20
+ #define HAVE_VERSION_H 1
21
+
4
22
  /* Name of package */
5
23
  #define PACKAGE "rice"
6
24
 
@@ -11,13 +29,16 @@
11
29
  #define PACKAGE_NAME "rice"
12
30
 
13
31
  /* Define to the full name and version of this package. */
14
- #define PACKAGE_STRING "rice 1.0"
32
+ #define PACKAGE_STRING "rice 1.1"
15
33
 
16
34
  /* Define to the one symbol short name of this package. */
17
35
  #define PACKAGE_TARNAME "rice"
18
36
 
19
37
  /* Define to the version of this package. */
20
- #define PACKAGE_VERSION "1.0"
38
+ #define PACKAGE_VERSION "1.1"
39
+
40
+ /* Define this macro to use ruby/node.h */
41
+ /* #undef REALLY_HAVE_RUBY_NODE_H */
21
42
 
22
43
  /* Version number of package */
23
- #define VERSION "1.0"
44
+ #define VERSION "1.1"