wurlinc-rice 1.4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/COPYING +23 -0
  2. data/Doxyfile +1253 -0
  3. data/Makefile.am +26 -0
  4. data/README +1119 -0
  5. data/README.mingw +8 -0
  6. data/Rakefile +33 -0
  7. data/bootstrap +9 -0
  8. data/configure.ac +52 -0
  9. data/doxygen.ac +314 -0
  10. data/doxygen.am +186 -0
  11. data/extconf.rb +41 -0
  12. data/post-autoconf.rb +22 -0
  13. data/post-automake.rb +28 -0
  14. data/rice/Address_Registration_Guard.hpp +7 -0
  15. data/rice/Address_Registration_Guard.ipp +34 -0
  16. data/rice/Address_Registration_Guard_defn.hpp +65 -0
  17. data/rice/Allocation_Strategies.hpp +37 -0
  18. data/rice/Arg.hpp +8 -0
  19. data/rice/Arg_impl.hpp +127 -0
  20. data/rice/Arg_operators.cpp +21 -0
  21. data/rice/Arg_operators.hpp +19 -0
  22. data/rice/Array.hpp +220 -0
  23. data/rice/Array.ipp +263 -0
  24. data/rice/Builtin_Object.hpp +8 -0
  25. data/rice/Builtin_Object.ipp +50 -0
  26. data/rice/Builtin_Object_defn.hpp +51 -0
  27. data/rice/Class.cpp +57 -0
  28. data/rice/Class.hpp +8 -0
  29. data/rice/Class.ipp +6 -0
  30. data/rice/Class_defn.hpp +83 -0
  31. data/rice/Constructor.hpp +367 -0
  32. data/rice/Critical_Guard.hpp +40 -0
  33. data/rice/Critical_Guard.ipp +26 -0
  34. data/rice/Data_Object.hpp +8 -0
  35. data/rice/Data_Object.ipp +133 -0
  36. data/rice/Data_Object_defn.hpp +132 -0
  37. data/rice/Data_Type.cpp +54 -0
  38. data/rice/Data_Type.hpp +8 -0
  39. data/rice/Data_Type.ipp +365 -0
  40. data/rice/Data_Type_defn.hpp +261 -0
  41. data/rice/Data_Type_fwd.hpp +12 -0
  42. data/rice/Director.cpp +13 -0
  43. data/rice/Director.hpp +39 -0
  44. data/rice/Enum.hpp +117 -0
  45. data/rice/Enum.ipp +246 -0
  46. data/rice/Exception.cpp +59 -0
  47. data/rice/Exception.hpp +9 -0
  48. data/rice/Exception_Base.hpp +8 -0
  49. data/rice/Exception_Base.ipp +13 -0
  50. data/rice/Exception_Base_defn.hpp +27 -0
  51. data/rice/Exception_defn.hpp +69 -0
  52. data/rice/Hash.hpp +210 -0
  53. data/rice/Hash.ipp +338 -0
  54. data/rice/Identifier.cpp +8 -0
  55. data/rice/Identifier.hpp +50 -0
  56. data/rice/Identifier.ipp +33 -0
  57. data/rice/Jump_Tag.hpp +24 -0
  58. data/rice/Makefile.am +129 -0
  59. data/rice/Module.cpp +84 -0
  60. data/rice/Module.hpp +8 -0
  61. data/rice/Module.ipp +6 -0
  62. data/rice/Module_defn.hpp +88 -0
  63. data/rice/Module_impl.hpp +281 -0
  64. data/rice/Module_impl.ipp +348 -0
  65. data/rice/Object.cpp +160 -0
  66. data/rice/Object.hpp +8 -0
  67. data/rice/Object.ipp +19 -0
  68. data/rice/Object_defn.hpp +191 -0
  69. data/rice/Require_Guard.hpp +21 -0
  70. data/rice/String.cpp +94 -0
  71. data/rice/String.hpp +89 -0
  72. data/rice/Struct.cpp +117 -0
  73. data/rice/Struct.hpp +162 -0
  74. data/rice/Struct.ipp +26 -0
  75. data/rice/Symbol.cpp +25 -0
  76. data/rice/Symbol.hpp +66 -0
  77. data/rice/Symbol.ipp +44 -0
  78. data/rice/VM.cpp +92 -0
  79. data/rice/VM.hpp +32 -0
  80. data/rice/config.hpp.in +40 -0
  81. data/rice/detail/Arguments.hpp +118 -0
  82. data/rice/detail/Auto_Function_Wrapper.hpp +829 -0
  83. data/rice/detail/Auto_Function_Wrapper.ipp +3391 -0
  84. data/rice/detail/Auto_Member_Function_Wrapper.hpp +828 -0
  85. data/rice/detail/Auto_Member_Function_Wrapper.ipp +2503 -0
  86. data/rice/detail/Caster.hpp +103 -0
  87. data/rice/detail/Exception_Handler.hpp +8 -0
  88. data/rice/detail/Exception_Handler.ipp +68 -0
  89. data/rice/detail/Exception_Handler_defn.hpp +96 -0
  90. data/rice/detail/Iterator.hpp +93 -0
  91. data/rice/detail/Not_Copyable.hpp +25 -0
  92. data/rice/detail/Wrapped_Function.hpp +33 -0
  93. data/rice/detail/cfp.hpp +24 -0
  94. data/rice/detail/cfp.ipp +51 -0
  95. data/rice/detail/check_ruby_type.cpp +27 -0
  96. data/rice/detail/check_ruby_type.hpp +23 -0
  97. data/rice/detail/creation_funcs.hpp +37 -0
  98. data/rice/detail/creation_funcs.ipp +36 -0
  99. data/rice/detail/default_allocation_func.hpp +23 -0
  100. data/rice/detail/default_allocation_func.ipp +11 -0
  101. data/rice/detail/define_method_and_auto_wrap.hpp +31 -0
  102. data/rice/detail/define_method_and_auto_wrap.ipp +30 -0
  103. data/rice/detail/demangle.cpp +56 -0
  104. data/rice/detail/demangle.hpp +19 -0
  105. data/rice/detail/env.hpp +19 -0
  106. data/rice/detail/from_ruby.hpp +43 -0
  107. data/rice/detail/from_ruby.ipp +60 -0
  108. data/rice/detail/method_data.cpp +159 -0
  109. data/rice/detail/method_data.hpp +21 -0
  110. data/rice/detail/mininode.cpp +1220 -0
  111. data/rice/detail/mininode.hpp +320 -0
  112. data/rice/detail/node.hpp +13 -0
  113. data/rice/detail/object_call.hpp +68 -0
  114. data/rice/detail/object_call.ipp +131 -0
  115. data/rice/detail/protect.cpp +29 -0
  116. data/rice/detail/protect.hpp +34 -0
  117. data/rice/detail/ruby.hpp +93 -0
  118. data/rice/detail/ruby_version_code.hpp.in +6 -0
  119. data/rice/detail/rubysig.hpp +19 -0
  120. data/rice/detail/st.hpp +60 -0
  121. data/rice/detail/to_ruby.hpp +22 -0
  122. data/rice/detail/to_ruby.ipp +36 -0
  123. data/rice/detail/traits.hpp +43 -0
  124. data/rice/detail/win32.hpp +16 -0
  125. data/rice/detail/wrap_function.hpp +341 -0
  126. data/rice/detail/wrap_function.ipp +514 -0
  127. data/rice/global_function.hpp +33 -0
  128. data/rice/global_function.ipp +22 -0
  129. data/rice/protect.hpp +91 -0
  130. data/rice/protect.ipp +1133 -0
  131. data/rice/ruby_mark.hpp +13 -0
  132. data/rice/ruby_try_catch.hpp +86 -0
  133. data/rice/rubypp.rb +97 -0
  134. data/rice/to_from_ruby.hpp +8 -0
  135. data/rice/to_from_ruby.ipp +297 -0
  136. data/rice/to_from_ruby_defn.hpp +71 -0
  137. data/ruby/Makefile.am +1 -0
  138. data/ruby/lib/Makefile.am +3 -0
  139. data/ruby/lib/mkmf-rice.rb.in +216 -0
  140. data/ruby/lib/version.rb +3 -0
  141. data/ruby.ac +136 -0
  142. data/sample/Makefile.am +47 -0
  143. data/sample/enum/extconf.rb +3 -0
  144. data/sample/enum/sample_enum.cpp +54 -0
  145. data/sample/enum/test.rb +8 -0
  146. data/sample/inheritance/animals.cpp +98 -0
  147. data/sample/inheritance/extconf.rb +3 -0
  148. data/sample/inheritance/test.rb +7 -0
  149. data/sample/map/extconf.rb +3 -0
  150. data/sample/map/map.cpp +81 -0
  151. data/sample/map/test.rb +7 -0
  152. data/test/Makefile.am +78 -0
  153. data/test/ext/Makefile.am +43 -0
  154. data/test/ext/t1/Foo.hpp +10 -0
  155. data/test/ext/t1/extconf.rb +2 -0
  156. data/test/ext/t1/t1.cpp +15 -0
  157. data/test/ext/t2/extconf.rb +2 -0
  158. data/test/ext/t2/t2.cpp +11 -0
  159. data/test/test_Address_Registration_Guard.cpp +43 -0
  160. data/test/test_Allocation_Strategies.cpp +77 -0
  161. data/test/test_Array.cpp +241 -0
  162. data/test/test_Builtin_Object.cpp +72 -0
  163. data/test/test_Class.cpp +498 -0
  164. data/test/test_Constructor.cpp +128 -0
  165. data/test/test_Critical_Guard.cpp +51 -0
  166. data/test/test_Data_Object.cpp +275 -0
  167. data/test/test_Data_Type.cpp +348 -0
  168. data/test/test_Director.cpp +301 -0
  169. data/test/test_Enum.cpp +195 -0
  170. data/test/test_Exception.cpp +46 -0
  171. data/test/test_Hash.cpp +195 -0
  172. data/test/test_Identifier.cpp +70 -0
  173. data/test/test_Jump_Tag.cpp +17 -0
  174. data/test/test_Memory_Management.cpp +50 -0
  175. data/test/test_Module.cpp +481 -0
  176. data/test/test_Object.cpp +148 -0
  177. data/test/test_String.cpp +94 -0
  178. data/test/test_Struct.cpp +192 -0
  179. data/test/test_Symbol.cpp +63 -0
  180. data/test/test_To_From_Ruby.cpp +263 -0
  181. data/test/test_VM.cpp +26 -0
  182. data/test/test_global_functions.cpp +114 -0
  183. data/test/test_rice.rb +43 -0
  184. data/test/unittest.cpp +136 -0
  185. data/test/unittest.hpp +292 -0
  186. metadata +276 -0
@@ -0,0 +1,103 @@
1
+ #ifndef Rice__detail__Caster__hpp_
2
+ #define Rice__detail__Caster__hpp_
3
+
4
+ #include "../Module.hpp"
5
+ #include <stdexcept>
6
+
7
+ namespace Rice
8
+ {
9
+
10
+ namespace detail
11
+ {
12
+
13
+ class Abstract_Caster
14
+ {
15
+ public:
16
+ virtual void * cast_to_base(void * derived, Module type) const = 0;
17
+ virtual ~Abstract_Caster() { }
18
+ };
19
+
20
+ template<typename Derived_T, typename Base_T>
21
+ class Caster
22
+ : public Abstract_Caster
23
+ {
24
+ public:
25
+ Caster(Abstract_Caster * base_caster, Module type)
26
+ : base_caster_(base_caster)
27
+ , type_(type)
28
+ {
29
+ }
30
+
31
+ protected:
32
+ virtual void * cast_to_base(void * derived, Module type) const
33
+ {
34
+ if(type.value() == type_.value())
35
+ {
36
+ Derived_T * d(static_cast<Derived_T *>(derived));
37
+ return static_cast<Base_T *>(d);
38
+ }
39
+ else
40
+ {
41
+ if(base_caster_)
42
+ {
43
+ return base_caster_->cast_to_base(derived, type);
44
+ }
45
+ else
46
+ {
47
+ std::string s = "bad cast. No caster found for ";
48
+ s += type_.name().str();
49
+ throw std::runtime_error(s);
50
+ }
51
+ }
52
+ }
53
+
54
+ private:
55
+ Abstract_Caster * base_caster_;
56
+ Module type_;
57
+ };
58
+
59
+ template<typename To_T, typename From_T>
60
+ class Implicit_Caster
61
+ : public Abstract_Caster
62
+ {
63
+ public:
64
+ Implicit_Caster(Abstract_Caster * base_caster, Module type)
65
+ : base_caster_(base_caster)
66
+ , type_(type)
67
+ {
68
+ }
69
+
70
+ protected:
71
+ virtual void * cast_to_base(void * derived, Module type) const
72
+ {
73
+ if(type.value() == type_.value())
74
+ {
75
+ return new To_T( *static_cast<From_T*>(derived) );
76
+ }
77
+ else
78
+ {
79
+ if(base_caster_)
80
+ {
81
+ return base_caster_->cast_to_base(derived, type);
82
+ }
83
+ else
84
+ {
85
+ std::string s = "bad cast. No implicit caster found for ";
86
+ s += type_.name().str();
87
+ throw std::runtime_error(s);
88
+ }
89
+ }
90
+ }
91
+
92
+ private:
93
+ Abstract_Caster * base_caster_;
94
+ Module type_;
95
+ };
96
+
97
+
98
+
99
+ } // detail
100
+
101
+ } // Rice
102
+
103
+ #endif //Rice__detail__Caster__hpp_
@@ -0,0 +1,8 @@
1
+ #ifndef Rice__detail__Exception_Handler__hpp_
2
+ #define Rice__detail__Exception_Handler__hpp_
3
+
4
+ #include "Exception_Handler_defn.hpp"
5
+ #include "Exception_Handler.ipp"
6
+
7
+ #endif // Rice__detail__Exception_Handler__hpp_
8
+
@@ -0,0 +1,68 @@
1
+ #include "../Data_Type_defn.hpp"
2
+
3
+ inline
4
+ Rice::detail::Exception_Handler::
5
+ Exception_Handler(
6
+ Data_Object<Exception_Handler> next_exception_handler)
7
+ : next_exception_handler_(next_exception_handler)
8
+ , next_exception_handler_guard_(&next_exception_handler_)
9
+ {
10
+ }
11
+
12
+ inline
13
+ Rice::detail::Exception_Handler::
14
+ ~Exception_Handler()
15
+ {
16
+ }
17
+
18
+ inline
19
+ VALUE
20
+ Rice::detail::Exception_Handler::
21
+ call_next_exception_handler() const
22
+ {
23
+ return next_exception_handler_->handle_exception();
24
+ }
25
+
26
+ inline Rice::detail::Default_Exception_Handler::
27
+ Default_Exception_Handler()
28
+ : Exception_Handler(
29
+ Data_Object<Exception_Handler>(0, rb_cObject))
30
+ {
31
+ }
32
+
33
+ inline
34
+ VALUE
35
+ Rice::detail::Default_Exception_Handler::
36
+ handle_exception() const
37
+ {
38
+ throw;
39
+ }
40
+
41
+ template <typename Exception_T, typename Functor_T>
42
+ inline
43
+ Rice::detail::Functor_Exception_Handler<Exception_T, Functor_T>::
44
+ Functor_Exception_Handler(
45
+ Functor_T handler,
46
+ Data_Object<Exception_Handler> next_exception_handler)
47
+ : Exception_Handler(next_exception_handler)
48
+ , handler_(handler)
49
+ {
50
+ }
51
+
52
+ template <typename Exception_T, typename Functor_T>
53
+ inline
54
+ VALUE
55
+ Rice::detail::Functor_Exception_Handler<Exception_T, Functor_T>::
56
+ handle_exception() const
57
+ {
58
+ try
59
+ {
60
+ return call_next_exception_handler();
61
+ }
62
+ catch(Exception_T const & ex)
63
+ {
64
+ handler_(ex);
65
+ throw;
66
+ }
67
+ }
68
+
@@ -0,0 +1,96 @@
1
+ #ifndef Rice__detail__Exception_Handler_defn__hpp_
2
+ #define Rice__detail__Exception_Handler_defn__hpp_
3
+
4
+ #include "ruby.h"
5
+ #undef TYPE
6
+
7
+ #include "Not_Copyable.hpp"
8
+ #include "../Address_Registration_Guard_defn.hpp"
9
+ #include "../Data_Object_defn.hpp"
10
+
11
+ namespace Rice
12
+ {
13
+
14
+ namespace detail
15
+ {
16
+
17
+ // A class for converting C++ exceptions to ruby exceptions. It's used
18
+ // like this:
19
+ //
20
+ // try
21
+ // {
22
+ // }
23
+ // catch(...)
24
+ // {
25
+ // handler->handle_exception();
26
+ // }
27
+ //
28
+ // If an exception is thrown the handler will pass the exception up the
29
+ // chain, then the last handler in the chain will throw the exception
30
+ // down the chain until a lower handler can handle it, e.g.:
31
+ //
32
+ // try
33
+ // {
34
+ // return call_next_exception_handler();
35
+ // }
36
+ // catch(MyException const & ex)
37
+ // {
38
+ // throw Rice::Exception(rb_cMyException, "%s", ex.what());
39
+ // }
40
+ //
41
+ class Exception_Handler
42
+ : public Rice::detail::Not_Copyable
43
+ {
44
+ public:
45
+ Exception_Handler(
46
+ Data_Object<Exception_Handler> next_exception_handler);
47
+
48
+ virtual ~Exception_Handler();
49
+
50
+ virtual VALUE handle_exception() const = 0;
51
+
52
+ VALUE call_next_exception_handler() const;
53
+
54
+ private:
55
+ Data_Object<Exception_Handler> next_exception_handler_;
56
+ Address_Registration_Guard next_exception_handler_guard_;
57
+ };
58
+
59
+ // The default exception handler just rethrows the exception. If there
60
+ // are other handlers in the chain, they will try to handle the rethrown
61
+ // exception.
62
+ class Default_Exception_Handler
63
+ : public Exception_Handler
64
+ {
65
+ public:
66
+ Default_Exception_Handler();
67
+
68
+ virtual VALUE handle_exception() const;
69
+ };
70
+
71
+ // An exception handler that takes a functor as an argument. The
72
+ // functor should throw a Rice::Exception to handle the exception. If
73
+ // the functor does not handle the exception, the exception will be
74
+ // re-thrown.
75
+ template <typename Exception_T, typename Functor_T>
76
+ class Functor_Exception_Handler
77
+ : public Exception_Handler
78
+ {
79
+ public:
80
+ Functor_Exception_Handler(
81
+ Functor_T handler,
82
+ Data_Object<Exception_Handler> next_exception_handler);
83
+
84
+ private:
85
+ virtual VALUE handle_exception() const;
86
+
87
+ private:
88
+ Functor_T handler_;
89
+ };
90
+
91
+ } // namespace detail
92
+
93
+ } // namespace Rice
94
+
95
+ #endif // Rice__detail__Exception_Handler_defn__hpp_
96
+
@@ -0,0 +1,93 @@
1
+ #ifndef Rice__detail__Iterator__hpp_
2
+ #define Rice__detail__Iterator__hpp_
3
+
4
+ #include "method_data.hpp"
5
+ #include "ruby.hpp"
6
+ #include "../protect.hpp"
7
+ #include "../Data_Object.hpp"
8
+ #include "../Identifier.hpp"
9
+
10
+ namespace Rice
11
+ {
12
+
13
+ namespace detail
14
+ {
15
+
16
+ class Iterator
17
+ {
18
+ public:
19
+ virtual ~Iterator() { }
20
+
21
+ virtual VALUE call_impl(VALUE self) = 0;
22
+
23
+ static VALUE call(VALUE self)
24
+ {
25
+ VALUE data = (VALUE)method_data();
26
+ Data_Object<Iterator> iterator(
27
+ data,
28
+ Data_Type<Iterator>());
29
+ return iterator->call_impl(self);
30
+ }
31
+ };
32
+
33
+ template<typename T, typename Iterator_T>
34
+ class Iterator_Impl
35
+ : public Iterator
36
+ {
37
+ public:
38
+ Iterator_Impl(
39
+ Iterator_T (T::*begin)(),
40
+ Iterator_T (T::*end)(),
41
+ Data_Type<T> data_type)
42
+ : begin_(begin)
43
+ , end_(end)
44
+ , data_type_(data_type)
45
+ {
46
+ }
47
+
48
+ virtual VALUE call_impl(VALUE self)
49
+ {
50
+ Data_Object<T> obj(self, data_type_);
51
+ Iterator_T it = obj->begin();
52
+ Iterator_T end = obj->end();
53
+ for(; it != end; ++it)
54
+ {
55
+ Rice::protect(rb_yield, to_ruby(*it));
56
+ }
57
+ return self;
58
+ }
59
+
60
+ private:
61
+ Iterator_T (T::*begin_)();
62
+ Iterator_T (T::*end_)();
63
+ Data_Type<T> data_type_;
64
+ };
65
+
66
+ template<typename T, typename Iterator_T>
67
+ void define_iterator(
68
+ Module klass,
69
+ Identifier name,
70
+ Iterator_T (T::*begin)(),
71
+ Iterator_T (T::*end)())
72
+ {
73
+ Data_Type<Iterator> iterator_klass;
74
+ Data_Object<Iterator> iterator(
75
+ new Iterator_Impl<T, Iterator_T>(
76
+ begin,
77
+ end,
78
+ Data_Type<T>(klass)),
79
+ iterator_klass);
80
+ define_method_with_data(
81
+ klass,
82
+ name,
83
+ (RUBY_METHOD_FUNC)iterator->call,
84
+ 0,
85
+ iterator);
86
+ }
87
+
88
+ } // namespace detail
89
+
90
+ } // namespace Rice
91
+
92
+ #endif // Rice__detail__Iterator__hpp_
93
+
@@ -0,0 +1,25 @@
1
+ #ifndef Rice__Not_Copyable__hpp_
2
+ #define Rice__Not_Copyable__hpp_
3
+
4
+ namespace Rice
5
+ {
6
+
7
+ namespace detail
8
+ {
9
+
10
+ // Inherit from Not_Copyable to prevent copying instances of a class.
11
+ class Not_Copyable
12
+ {
13
+ public:
14
+ Not_Copyable() { }
15
+
16
+ private:
17
+ Not_Copyable(Not_Copyable const &);
18
+ Not_Copyable & operator=(Not_Copyable const &);
19
+ };
20
+
21
+ } // namespace detail
22
+
23
+ } // namespace Rice
24
+
25
+ #endif // Rice__Not_Copyable__hpp_
@@ -0,0 +1,33 @@
1
+ #ifndef Rice__detail__Wrapped_Function__hpp_
2
+ #define Rice__detail__Wrapped_Function__hpp_
3
+
4
+ #include "ruby.hpp"
5
+
6
+ namespace Rice
7
+ {
8
+
9
+ namespace detail
10
+ {
11
+
12
+ class Wrapped_Function
13
+ {
14
+ public:
15
+ Wrapped_Function(RUBY_METHOD_FUNC func, int arity)
16
+ : func_(func)
17
+ , arity_(arity)
18
+ {
19
+ }
20
+
21
+ RUBY_METHOD_FUNC func() const { return func_; }
22
+ int arity() const { return arity_; }
23
+
24
+ private:
25
+ RUBY_METHOD_FUNC func_;
26
+ int arity_;
27
+ };
28
+
29
+ } // detail
30
+
31
+ } // Rice
32
+
33
+ #endif // Rice__detail__Wrapped_Function__hpp_
@@ -0,0 +1,24 @@
1
+ #ifndef Rice__detail__cfp__hpp_
2
+ #define Rice__detail__cfp__hpp_
3
+
4
+ #include "ruby.hpp"
5
+
6
+ namespace Rice
7
+ {
8
+
9
+ namespace detail
10
+ {
11
+
12
+ VALUE * cfp();
13
+
14
+ VALUE & cfp_data_memo_node_and_pc(VALUE * cfp);
15
+ VALUE & cfp_self(VALUE * cfp);
16
+ VALUE & cfp_method_class(VALUE * cfp);
17
+
18
+ } // detail
19
+
20
+ } // Rice
21
+
22
+ #include "cfp.ipp"
23
+
24
+ #endif // Rice__detail__cfp__hpp_
@@ -0,0 +1,51 @@
1
+ namespace detail
2
+ {
3
+
4
+ struct rb_thread_struct
5
+ {
6
+ VALUE self;
7
+ void *vm;
8
+ VALUE *stack;
9
+ unsigned long stack_size;
10
+ VALUE *cfp;
11
+ /* ... */
12
+ };
13
+
14
+ typedef struct rb_thread_struct rb_thread_t;
15
+
16
+ } // namespace detail
17
+
18
+ extern "C" detail::rb_thread_t * ruby_current_thread;
19
+
20
+ inline
21
+ VALUE *
22
+ Rice::detail::
23
+ cfp()
24
+ {
25
+ return ruby_current_thread->cfp;
26
+ }
27
+
28
+ inline
29
+ VALUE &
30
+ Rice::detail::
31
+ cfp_data_memo_node_and_pc(VALUE * cfp)
32
+ {
33
+ return cfp[0];
34
+ }
35
+
36
+ inline
37
+ VALUE &
38
+ Rice::detail::
39
+ cfp_self(VALUE * cfp)
40
+ {
41
+ return cfp[5];
42
+ }
43
+
44
+ inline
45
+ VALUE &
46
+ Rice::detail::
47
+ cfp_method_class(VALUE * cfp)
48
+ {
49
+ return cfp[11];
50
+ }
51
+
@@ -0,0 +1,27 @@
1
+ #include "check_ruby_type.hpp"
2
+ #include "../Exception.hpp"
3
+
4
+ void Rice::detail::
5
+ check_ruby_type(
6
+ VALUE value,
7
+ VALUE klass,
8
+ bool include_super
9
+ )
10
+ {
11
+ if( !rb_obj_is_kind_of(value, klass) ||
12
+ (!include_super && rb_obj_class(value) != klass))
13
+ {
14
+ // Not sure why this stuff can't be chained
15
+ VALUE gotV = protect(rb_mod_name, rb_obj_class(value));
16
+ char* got = StringValuePtr(gotV);
17
+ VALUE exptV = protect(rb_mod_name, klass);
18
+ char* expected = StringValuePtr(exptV);
19
+
20
+ throw Exception(
21
+ rb_eTypeError,
22
+ "wrong argument type %s (expected %s)",
23
+ got, expected
24
+ );
25
+ }
26
+ }
27
+
@@ -0,0 +1,23 @@
1
+ #ifndef Rice__detail__check_ruby_type__hpp_
2
+ #define Rice__detail__check_ruby_type__hpp_
3
+
4
+ #include "ruby.hpp"
5
+
6
+ namespace Rice
7
+ {
8
+
9
+ namespace detail
10
+ {
11
+
12
+ // Throws an exception if the given object is not of type klass.
13
+ void check_ruby_type(
14
+ VALUE value,
15
+ VALUE klass,
16
+ bool include_super);
17
+
18
+ } // namespace detail
19
+
20
+ } // namespace Rice
21
+
22
+ #endif // Rice__detail__check_ruby_type__hpp_
23
+
@@ -0,0 +1,37 @@
1
+ #ifndef Rice__detail__creation_funcs__hpp_
2
+ #define Rice__detail__creation_funcs__hpp_
3
+
4
+ namespace Rice
5
+ {
6
+
7
+ class Class;
8
+
9
+ namespace detail
10
+ {
11
+
12
+ //! Like define_alloc_func, but allows the user to define an
13
+ //! "initialize" method too.
14
+ template<typename Initialize_Func_T>
15
+ void define_creation_funcs(
16
+ Class const & klass,
17
+ RUBY_VALUE_FUNC allocate_func,
18
+ Initialize_Func_T initialize_func);
19
+
20
+ //! This is just the opposite of define_alloc_func. It can be
21
+ //! used to create a class that cannot be instantiated by the user.
22
+ void undef_alloc_func(
23
+ Class const & klass);
24
+
25
+ //! This is just the opposite of define_creation_func. It can be
26
+ //! used to create a class that cannot be instantiated by the user.
27
+ void undef_creation_funcs(
28
+ Class const & klass);
29
+
30
+ } // namespace detail
31
+
32
+ } // namespace Rice
33
+
34
+ #include "creation_funcs.ipp"
35
+
36
+ #endif // Rice__detail__creation_funcs__hpp_
37
+
@@ -0,0 +1,36 @@
1
+ #ifndef Rice__detail__creation_funcs__ipp_
2
+ #define Rice__detail__creation_funcs__ipp_
3
+
4
+ namespace Rice
5
+ {
6
+
7
+ namespace detail
8
+ {
9
+
10
+ template<typename Initialize_Func_T>
11
+ inline void define_creation_funcs(
12
+ Class const & klass,
13
+ RUBY_VALUE_FUNC allocate_func,
14
+ Initialize_Func_T initialize_func)
15
+ {
16
+ rb_define_alloc_func(klass, allocate_func);
17
+ klass.define_method("initialize", initialize_func);
18
+ }
19
+
20
+ inline void undef_alloc_func(Class const & klass)
21
+ {
22
+ rb_undef_alloc_func(klass);
23
+ }
24
+
25
+ inline void undef_creation_funcs(Class const & klass)
26
+ {
27
+ undef_alloc_func(klass);
28
+ rb_undef_method(klass, "initialize");
29
+ }
30
+
31
+ } // namespace detail
32
+
33
+ } // namespace Rice
34
+
35
+ #endif // Rice__detail__creation_funcs__ipp_
36
+
@@ -0,0 +1,23 @@
1
+ #ifndef Rice__detail__default_allocation_func__hpp_
2
+ #define Rice__detail__default_allocation_func__hpp_
3
+
4
+ namespace Rice
5
+ {
6
+
7
+ namespace detail
8
+ {
9
+
10
+ //! A default implementation of an allocate_func. This function does no
11
+ //! actual allocation; the initialize_func can later do the real
12
+ //! allocation with: DATA_PTR(self) = new Type(arg1, arg2, ...)
13
+ template<typename T>
14
+ VALUE default_allocation_func(VALUE klass);
15
+
16
+ } // detail
17
+
18
+ } // Rice
19
+
20
+ #include "default_allocation_func.ipp"
21
+
22
+ #endif // Rice__detail__default_allocation_func__hpp_
23
+
@@ -0,0 +1,11 @@
1
+ #include "../Data_Object.hpp"
2
+
3
+ template<typename T>
4
+ VALUE Rice::detail::
5
+ default_allocation_func(VALUE klass)
6
+ {
7
+ Data_Object<T> m(static_cast<T*>(0), klass);
8
+ return m.value();
9
+ }
10
+
11
+
@@ -0,0 +1,31 @@
1
+ #ifndef Rice__detail__define_method_and_auto_wrap__hpp_
2
+ #define Rice__detail__define_method_and_auto_wrap__hpp_
3
+
4
+ #include "ruby.hpp"
5
+ #include "../Data_Object.hpp"
6
+ #include "../Identifier.hpp"
7
+ #include "Arguments.hpp"
8
+
9
+ namespace Rice
10
+ {
11
+
12
+ namespace detail
13
+ {
14
+
15
+ class Exception_Handler;
16
+
17
+ template<typename Fun_T>
18
+ void define_method_and_auto_wrap(
19
+ VALUE klass,
20
+ Identifier name,
21
+ Fun_T function,
22
+ Data_Object<Exception_Handler> handler,
23
+ Arguments* arguments = 0);
24
+
25
+ } // detail
26
+
27
+ } // Rice
28
+
29
+ #include "define_method_and_auto_wrap.ipp"
30
+
31
+ #endif // Rice__detail__define_method_and_auto_wrap__hpp_