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
@@ -1,118 +1,8 @@
1
1
  #ifndef Rice__detail__Exception_Handler__hpp_
2
2
  #define Rice__detail__Exception_Handler__hpp_
3
3
 
4
- #include "ruby.h"
5
- #undef TYPE
6
-
7
- namespace Rice
8
- {
9
-
10
- namespace detail
11
- {
12
-
13
- // A class for converting C++ exceptions to ruby exceptions. It's used
14
- // like this:
15
- //
16
- // try
17
- // {
18
- // }
19
- // catch(...)
20
- // {
21
- // handler->handle_exception();
22
- // }
23
- //
24
- // If an exception is thrown the handler will pass the exception up the
25
- // chain, then the last handler in the chain will throw the exception
26
- // down the chain until a lower handler can handle it, e.g.:
27
- //
28
- // try
29
- // {
30
- // return call_next_exception_handler();
31
- // }
32
- // catch(MyException const & ex)
33
- // {
34
- // throw Rice::Exception(rb_cMyException, "%s", ex.what());
35
- // }
36
- //
37
- class Exception_Handler
38
- {
39
- public:
40
- Exception_Handler(Exception_Handler const * next_exception_handler)
41
- : next_exception_handler_(next_exception_handler)
42
- {
43
- }
44
-
45
- virtual ~Exception_Handler()
46
- {
47
- }
48
-
49
- virtual VALUE handle_exception() const = 0;
50
-
51
- VALUE call_next_exception_handler() const
52
- {
53
- return next_exception_handler_->handle_exception();
54
- }
55
-
56
- private:
57
- Exception_Handler const * next_exception_handler_;
58
- };
59
-
60
- // The default exception handler just rethrows the exception. If there
61
- // are other handlers in the chain, they will try to handle the rethrown
62
- // exception.
63
- class Default_Exception_Handler
64
- : public Exception_Handler
65
- {
66
- public:
67
- Default_Exception_Handler()
68
- : Exception_Handler(0)
69
- {
70
- }
71
-
72
- virtual VALUE handle_exception() const
73
- {
74
- throw;
75
- }
76
- };
77
-
78
- // An exception handler that takes a functor as an argument. The
79
- // functor should throw a Rice::Exception to handle the exception. If
80
- // the functor does not handle the exception, the exception will be
81
- // re-thrown.
82
- template <typename Exception_T, typename Functor_T>
83
- class Functor_Exception_Handler
84
- : public Exception_Handler
85
- {
86
- public:
87
- Functor_Exception_Handler(
88
- Functor_T handler,
89
- Exception_Handler const * next_exception_handler)
90
- : Exception_Handler(next_exception_handler)
91
- , handler_(handler)
92
- {
93
- }
94
-
95
- private:
96
- virtual VALUE handle_exception() const
97
- {
98
- try
99
- {
100
- return call_next_exception_handler();
101
- }
102
- catch(Exception_T const & ex)
103
- {
104
- handler_(ex);
105
- throw;
106
- }
107
- }
108
-
109
- private:
110
- Functor_T handler_;
111
- };
112
-
113
- } // namespace detail
114
-
115
- } // namespace Rice
4
+ #include "Exception_Handler_defn.hpp"
5
+ #include "Exception_Handler.ipp"
116
6
 
117
7
  #endif // Rice__detail__Exception_Handler__hpp_
118
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
+
@@ -11,11 +11,17 @@ check_ruby_type(
11
11
  if( !rb_obj_is_kind_of(value, klass) ||
12
12
  (!include_super && rb_obj_class(value) != klass))
13
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
+
14
20
  throw Exception(
15
21
  rb_eTypeError,
16
22
  "wrong argument type %s (expected %s)",
17
- STR2CSTR(protect(rb_mod_name, rb_obj_class(value))),
18
- STR2CSTR(protect(rb_mod_name, klass)));
23
+ got, expected
24
+ );
19
25
  }
20
26
  }
21
27
 
@@ -21,7 +21,7 @@ inline void define_alloc_func(
21
21
  Class const & klass,
22
22
  RUBY_VALUE_FUNC allocate_func)
23
23
  {
24
- #if RUBY_VERSION_CODE < 170
24
+ #if RICE__RUBY_VERSION_CODE < 170
25
25
  klass.define_singleton_method("allocate", allocate_func);
26
26
  klass.define_singleton_method("new", ruby_16_new);
27
27
  #else
@@ -41,7 +41,7 @@ inline void define_creation_funcs(
41
41
 
42
42
  inline void undef_alloc_func(Class const & klass)
43
43
  {
44
- #if RUBY_VERSION_CODE >= 170
44
+ #if RICE__RUBY_VERSION_CODE >= 170
45
45
  rb_undef_alloc_func(klass);
46
46
  #else
47
47
  rb_undef_method(CLASS_OF(klass), "new");
@@ -2,6 +2,8 @@
2
2
  #define Rice__detail__define_method_and_auto_wrap__hpp_
3
3
 
4
4
  #include "ruby.hpp"
5
+ #include "../Data_Object.hpp"
6
+ #include "../Identifier.hpp"
5
7
 
6
8
  namespace Rice
7
9
  {
@@ -14,9 +16,9 @@ class Exception_Handler;
14
16
  template<typename Fun_T>
15
17
  void define_method_and_auto_wrap(
16
18
  VALUE klass,
17
- char const * name,
19
+ Identifier name,
18
20
  Fun_T function,
19
- Exception_Handler const * handler = 0);
21
+ Data_Object<Exception_Handler> handler);
20
22
 
21
23
  } // detail
22
24
 
@@ -3,18 +3,27 @@
3
3
 
4
4
  #include "wrap_function.hpp"
5
5
  #include "method_data.hpp"
6
- #include "Exception_Handler.hpp"
6
+ #include "Exception_Handler_defn.hpp"
7
+ #include "../protect.hpp"
7
8
 
8
9
  template<typename Fun_T>
9
10
  void Rice::detail::
10
11
  define_method_and_auto_wrap(
11
12
  VALUE klass,
12
- char const * name,
13
+ Identifier name,
13
14
  Fun_T function,
14
- Exception_Handler const * handler)
15
+ Data_Object<Exception_Handler> handler)
15
16
  {
16
- Wrapped_Function * f(wrap_function(function, handler));
17
- define_method_with_data(klass, name, f->func(), f->arity(), f);
17
+ Data_Object<Wrapped_Function> f(
18
+ wrap_function(function, handler),
19
+ rb_cObject);
20
+ Rice::protect(
21
+ define_method_with_data,
22
+ klass,
23
+ name.id(),
24
+ f->func(),
25
+ f->arity(),
26
+ f);
18
27
  }
19
28
 
20
29
  #endif // Rice__detail__define_method_and_auto_wrap__ipp_