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,216 @@
1
+ # Make sure that archflags does not include ppc if we're
2
+ # on Intel x86 processor on Mac, and that we use the proper
3
+ # arch depending on 10.5 or 10.6
4
+ if `uname`.chomp == "Darwin"
5
+ arch =
6
+ if RUBY_PLATFORM =~ /darwin10/
7
+ 'x86_64'
8
+ else
9
+ `uname -p`.chomp
10
+ end
11
+
12
+ ENV["ARCHFLAGS"] = "-arch #{arch}"
13
+ end
14
+
15
+ require 'mkmf'
16
+ require 'rbconfig'
17
+
18
+ #
19
+ # A script to override some defaults in mkmf.rb for C++ code
20
+ # compilation.
21
+ #
22
+ # If this looks like a big hack, that's because it is.
23
+ #
24
+
25
+ def init_mkmf_rice(config = CONFIG)
26
+ # Set some defaults that we got from autoconf -- they're more likely
27
+ # to be correct than what Ruby was built with
28
+ $CXX = "@CXX@"
29
+ $LIBS = "@RUBY_LIBS@"
30
+ $LIBRUBYARG = "@RUBY_LIBRUBYARG@"
31
+ $LIBRUBYARG_STATIC = "@RUBY_LIBRUBYARG_STATIC@"
32
+ $RICE_CPPFLAGS = "@RICE_CPPFLAGS@"
33
+ $RICE_LDFLAGS = "@RICE_LDFLAGS@"
34
+ $RICE_PREFIX = "@prefix@"
35
+
36
+ $RICE_USING_MINGW32 = @RICE_USING_MINGW32@
37
+
38
+ # Ruby < 1.8.6 does not have $DEFLIBPATH
39
+ $DEFLIBPATH ||= []
40
+
41
+ # We use this for the samples
42
+ $DEFLIBPATH.unshift(with_config('libpath')) if with_config('libpath')
43
+
44
+ # Ruby 1.8.6 uses $preload without setting it
45
+ $preload ||= nil
46
+
47
+ $CPPFLAGS << " #{$RICE_CPPFLAGS} -I#{$RICE_PREFIX}/include"
48
+ $LDFLAGS << " #{$RICE_LDFLAGS} -L#{$RICE_PREFIX}/lib"
49
+
50
+ # Turn on debugging and verbose warnings by default on compilers that
51
+ # support it
52
+ $CXXFLAGS = ''
53
+ if $CXX == 'g++'
54
+ $CXXFLAGS << ' -Wall -g'
55
+ end
56
+
57
+ # Fix-up the linker used for confidence tests
58
+ TRY_LINK.sub!(/^#{Regexp.quote("$(CC)")}/, $CXX)
59
+ TRY_LINK.sub!(/^#{config['CC']}/, $CXX)
60
+ TRY_LINK.sub!(/#{Regexp.quote("$(CFLAGS)")}/, "$(CXXFLAGS)")
61
+
62
+ # Set $LDSHARED_CXX to the linker to be used for C++ libraries (usually
63
+ # the C++ compiler itself)
64
+ case config['target_os']
65
+ when 'darwin'
66
+ $LDSHARED_CXX = \
67
+ replace_cc_with_cxx(config['LDSHARED']) + \
68
+ ' -read_only_relocs suppress'
69
+ when 'mswin32'
70
+ if $RICE_USING_MINGW32 then
71
+ init_rice_mkmf_cross_compile_mingw2_for_vc6
72
+ end
73
+ else
74
+ $LDSHARED_CXX = \
75
+ replace_cc_with_cxx(config['LDSHARED'])
76
+ end
77
+
78
+ # Link against the rice library by default
79
+ have_library('rice') or raise
80
+ end
81
+
82
+ def replace_cc_with_cxx(str)
83
+ return str.sub(
84
+ /^(cc|\$\(CC\)|#{CONFIG['CC']})(?=\s)/,
85
+ $CXX)
86
+ end
87
+
88
+ def init_rice_mkmf_cross_compile_mingw2_for_vc6
89
+ $LDSHARED_CXX = "#{$CXX} -shared -s"
90
+ $OBJEXT = 'o'
91
+ $DLDFLAGS.gsub!(/^-link.*\.pdb$/, '')
92
+
93
+ constants = {
94
+ :TRY_LINK =>
95
+ "#{$LDSHARED_CXX} -oconftest $(INCFLAGS) $(CPPFLAGS) " + \
96
+ "$(CFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) " + \
97
+ "$(LOCAL_LIBS) $(LIBS)",
98
+ :LINK_SO =>
99
+ "#{$LDSHARED_CXX} $(DLDFLAGS) $(LIBPATH) -o$@ " + \
100
+ "$(OBJS) $(LOCAL_LIBS) $(LIBS)",
101
+ :LIBARG =>
102
+ '-l%s',
103
+ :LIBPATHFLAG =>
104
+ ' -L %s',
105
+ :COMPILE_RULES =>
106
+ %w[.%s.%s:],
107
+ :RULE_SUBST =>
108
+ '%s',
109
+ :COMPILE_CXX =>
110
+ '$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<',
111
+ :OUTFLAG =>
112
+ '-o',
113
+ }
114
+
115
+ constants.each do |name, value|
116
+ Object.instance_eval { remove_const name }
117
+ Object.const_set(name, value)
118
+ end
119
+ end
120
+
121
+ class Object
122
+ alias_method :configuration_orig, :configuration
123
+ def configuration(srcdir)
124
+ configuration = configuration_orig(srcdir)
125
+ configuration.each do |config|
126
+ # Make sure we link the extension using the C++ compiler
127
+ config.gsub!(/^LDSHARED\s*=.*$/, "LDSHARED = #{$LDSHARED_CXX}")
128
+
129
+ # Make sure set the C++ flags correctly
130
+ config.gsub!(/^CXXFLAGS\s*=.*$/, "CXXFLAGS = $(CFLAGS) #{$CXXFLAGS}")
131
+ end
132
+ configuration << "\nCXX = #{$CXX}"
133
+ return configuration
134
+ end
135
+
136
+ alias_method :link_command_orig, :link_command
137
+ def link_command(ldflags, opt='', libpath=$DEFLIBPATH|$LIBPATH)
138
+ link_command = link_command_orig(ldflags, opt, libpath)
139
+ return Config::expand(
140
+ link_command,
141
+ 'CXXFLAGS' => "#{$CXXFLAGS}")
142
+ end
143
+
144
+ alias_method :create_header_orig, :create_header
145
+ def create_header(header = 'extconf.hpp')
146
+ create_header_orig(header)
147
+ end
148
+
149
+ alias_method :create_makefile_orig, :create_makefile
150
+ def create_makefile(target, srcprefix = nil)
151
+ makefile_creator = RiceMakefileCreator.new
152
+ makefile_creator.create_makefile(target, srcprefix)
153
+ end
154
+ end
155
+
156
+ class RiceMakefileCreator
157
+ def create_makefile(target, srcprefix)
158
+ create_makefile_orig(target, srcprefix)
159
+ end
160
+
161
+ class MakefileWriter
162
+ def self.new(file, mode)
163
+ file = super(file, mode)
164
+ if block_given? then
165
+ begin
166
+ yield file
167
+ ensure
168
+ file.close if not file.closed?
169
+ end
170
+ else
171
+ return file
172
+ end
173
+ end
174
+
175
+ def initialize(file, mode)
176
+ @file = File.open(file, mode)
177
+ end
178
+
179
+ def print(*strings)
180
+ strings.each do |string|
181
+ # Make sure -lruby comes after -lrice (necessary on some
182
+ # platforms)
183
+ string = string.to_s.gsub(/^(LIBS\s*=\s*)(#{Regexp.quote($LIBRUBYARG)})\s+(.*)\s+(#{$LIBS})$/, '\1\3\2 \4')
184
+ @file.print(string)
185
+ end
186
+ end
187
+
188
+ def printf(format, *args)
189
+ @file.printf(format, *args)
190
+ end
191
+
192
+ def puts(*strings)
193
+ print(*strings.flatten.map { |s| "#{s}\n" })
194
+ end
195
+
196
+ def close
197
+ @file.close
198
+ end
199
+
200
+ def closed?
201
+ return @file.closed?
202
+ end
203
+ end
204
+
205
+ def open(file, mode, &block)
206
+ # Intercept makefile output using the MakefileWriter
207
+ if file == 'Makefile' then
208
+ return MakefileWriter.new(file, mode, &block)
209
+ else
210
+ return super(file, mode, &block)
211
+ end
212
+ end
213
+ end
214
+
215
+ init_mkmf_rice
216
+
@@ -0,0 +1,3 @@
1
+ module Rice
2
+ VERSION = "1.4.0"
3
+ end
data/ruby.ac ADDED
@@ -0,0 +1,136 @@
1
+ dnl Get a key from ruby's configuration table
2
+ AC_DEFUN([RUBY_CONFIG], [
3
+ $RUBY -rrbconfig -e "puts(Config::CONFIG[['$1']] || '')"])
4
+
5
+ AC_DEFUN([RB_INIT_RUBY], [
6
+
7
+ AC_ARG_WITH(
8
+ ruby,
9
+ AC_HELP_STRING(
10
+ --with-ruby=PATH,
11
+ [ path to the ruby interpreter [[ruby]] ]),
12
+ [ RUBY=$withval ],
13
+ [ RUBY=ruby ])
14
+ AC_ARG_WITH(
15
+ ruby_sitelibdir,
16
+ AC_HELP_STRING(
17
+ --with-ruby-sitelibdir=PATH,
18
+ [ path to install ruby scripts [[auto-detect]] ]),
19
+ [ ruby_sitelibdir=$withval ],
20
+ [ ruby_sitelibdir=NONE ])
21
+
22
+ AC_SUBST(RUBY)
23
+
24
+ RUBY_VERSION_CODE=`$RUBY -e "puts RUBY_VERSION.gsub(/\./, '')"`
25
+ AC_SUBST(RUBY_VERSION_CODE)
26
+
27
+ RUBY_CONFIG_SO_NAME=`RUBY_CONFIG(RUBY_SO_NAME)`
28
+ RUBY_CONFIG_ARCHDIR=`RUBY_CONFIG(archdir)`
29
+ RUBY_CONFIG_ARCH=`RUBY_CONFIG(arch)`
30
+ RUBY_CONFIG_LIBDIR=`RUBY_CONFIG(libdir)`
31
+ RUBY_CONFIG_BINDIR=`RUBY_CONFIG(bindir)`
32
+ RUBY_CONFIG_RUBYHDRDIR=`RUBY_CONFIG(rubyhdrdir)`
33
+ RUBY_CONFIG_CFLAGS=`RUBY_CONFIG(CFLAGS)`
34
+ RUBY_CONFIG_LIBS=`RUBY_CONFIG(LIBS)`
35
+ RUBY_CONFIG_DLDLIBS=`RUBY_CONFIG(DLDLIBS)`
36
+ RUBY_CONFIG_LDFLAGS=`RUBY_CONFIG(LDFLAGS)`
37
+ RUBY_CONFIG_LIBRUBYARG=`RUBY_CONFIG(LIBRUBYARG)`
38
+ RUBY_CONFIG_LIBRUBYARG_STATIC=`RUBY_CONFIG(LIBRUBYARG_STATIC)`
39
+ RUBY_CONFIG_CCDLFLAGS=`RUBY_CONFIG(CCDLFLAGS)`
40
+
41
+ if test "x${RUBY_CONFIG_RUBYHDRDIR}x" != "xx"; then
42
+ # 1.9
43
+ RUBY_CPPFLAGS="-I${RUBY_CONFIG_RUBYHDRDIR}"
44
+ RUBY_CPPFLAGS="${RUBY_CPPFLAGS} -I${RUBY_CONFIG_RUBYHDRDIR}/${RUBY_CONFIG_ARCH}"
45
+ else
46
+ # 1.8
47
+ RUBY_CPPFLAGS="-I${RUBY_CONFIG_ARCHDIR}"
48
+ fi
49
+ AC_SUBST(RUBY_CPPFLAGS)
50
+
51
+ RUBY_CFLAGS="${RUBY_CONFIG_CFLAGS} ${RUBY_CONFIG_CCDLFLAGS}"
52
+ AC_SUBST(RUBY_CFLAGS)
53
+
54
+ RUBY_CXXFLAGS="${RUBY_CONFIG_CFLAGS} ${RUBY_CONFIG_CCDLFLAGS}"
55
+ AC_SUBST(RUBY_CXXFLAGS)
56
+
57
+ RUBY_LDFLAGS="-L${RUBY_CONFIG_ARCHDIR} -L${RUBY_CONFIG_LIBDIR} ${RUBY_CONFIG_LDFLAGS}"
58
+ AC_SUBST(RUBY_LDFLAGS)
59
+
60
+ RUBY_LIBS="${RUBY_CONFIG_LIBS} ${RUBY_CONFIG_DLDLIBS}"
61
+ AC_SUBST(RUBY_LIBS)
62
+
63
+ RUBY_LIBRUBYARG="${RUBY_CONFIG_LIBRUBYARG}"
64
+ AC_SUBST(RUBY_LIBRUBYARG)
65
+
66
+ RUBY_LIBRUBYARG_STATIC="${RUBY_CONFIG_LIBRUBYARG_STATIC}"
67
+ AC_SUBST(RUBY_LIBRUBYARG_STATIC)
68
+
69
+ dnl If the user specified a prefix, then use it, otherwise defalut to
70
+ dnl the configured sitelibdir
71
+ if test "x${ruby_sitelibdir}x" != "xNONEx"
72
+ then
73
+ RUBY_SITELIBDIR="${ruby_sitelibdir}"
74
+ else
75
+ if test "x${prefix}x" = "xNONEx"
76
+ then
77
+ RUBY_SITELIBDIR=`RUBY_CONFIG(sitelibdir)`
78
+ else
79
+ sitelibdir_no_prefix=`$RUBY -rrbconfig \
80
+ -e "include Config; \
81
+ puts CONFIG[['sitelibdir']].sub(CONFIG[['prefix']], '')"`
82
+ RUBY_SITELIBDIR="${prefix}/${sitelibdir_no_prefix}"
83
+ fi
84
+ fi
85
+ AC_SUBST(RUBY_SITELIBDIR)
86
+
87
+ dnl The fourth parameter to AC_CHECK_HEADER keeps autoconf from
88
+ dnl searching for standard header files as a side-effect (which we want)
89
+ CPPFLAGS_save="${CPPFLAGS}"
90
+ CPPFLAGS="${CPPFLAGS} ${RUBY_CPPFLAGS}"
91
+ CXXFLAGS="${CPPFLAGS}"
92
+ AC_CHECK_HEADERS(ruby.h,,AC_MSG_ERROR(
93
+ could not find ruby.h (check config.log)),[ ])
94
+ AC_CHECK_HEADERS(node.h,,,[
95
+ #include <ruby.h>
96
+ ])
97
+ AC_CHECK_HEADERS(ruby/node.h,
98
+ [ AC_DEFINE(REALLY_HAVE_RUBY_NODE_H, [],
99
+ [ Define this macro to use ruby/node.h ]) ],
100
+ ,[
101
+ #include <ruby.h>
102
+ ])
103
+ AC_CHECK_HEADERS(version.h,,,[
104
+ #include <ruby.h>
105
+ ])
106
+ AC_CHECK_HEADERS(env.h,,,[
107
+ #include <ruby.h>
108
+ ])
109
+
110
+ CPPFLAGS="${CPPFLAGS_save}"
111
+
112
+ AC_MINGW32
113
+
114
+ if test x"${MINGW32}"x = xyesx; then
115
+ RB_FIX_MINGW_LIBS
116
+ fi
117
+
118
+ ]) dnl RB_INIT_RUBY
119
+
120
+ dnl We would like to be able to build using MingW against the one-click
121
+ dnl installer, which is built using VC6. So, we detect this situation
122
+ dnl and fix up the link step if this is the case.
123
+ dnl
124
+ dnl Static linking isn't likely to work correctly, so we disable it by
125
+ dnl default, but if the user asks for LIBRUBYARG_STATIC, they'll still
126
+ dnl get static linking.
127
+ AC_DEFUN([RB_FIX_MINGW_LIBS], [
128
+ RUBY_LIBS=`echo ${RUBY_LIBS} | sed -e "s%oldnames.lib%-lmoldname%"`
129
+ RUBY_LIBS=`echo ${RUBY_LIBS} | sed -e "s%user32.lib%-luser32%"`
130
+ RUBY_LIBS=`echo ${RUBY_LIBS} | sed -e "s%advapi32.lib%-ladvapi32%"`
131
+ RUBY_LIBS=`echo ${RUBY_LIBS} | sed -e "s%ws2_32.lib%-lws2_32%"`
132
+ RUBY_LIBRUBYARG=`echo ${RUBY_LIBRUBYARG} | sed -e "s%\(msvcrt-ruby.*\).lib%${RUBY_CONFIG_BINDIR}/\1.dll%"`
133
+ RUBY_LIBRUBYARG_STATIC=`echo ${RUBY_LIBRUBYARG_STATIC} | sed -e "s%\(msvcrt-ruby.*\).lib%${RUBY_CONFIG_LIBDIR}/\1.lib%"`
134
+ ]) dnl RB_FIX_MINGW_LIBS
135
+
136
+ dnl vim:ft=config
@@ -0,0 +1,47 @@
1
+ RUBY_EXTCONF_OPTIONS = -I@RICE_ROOT@/ruby/lib
2
+ EXTCONF_OPTIONS = --with-cppflags="-I@RICE_ROOT@" --with-libpath="@RICE_ROOT@/rice"
3
+
4
+ EXTRA_DIST = \
5
+ enum/extconf.rb \
6
+ enum/sample_enum.cpp \
7
+ enum/test.rb \
8
+ map/extconf.rb \
9
+ map/map.cpp \
10
+ map/test.rb \
11
+ inheritance/extconf.rb \
12
+ inheritance/animals.cpp \
13
+ inheritance/test.rb
14
+
15
+ enum/Makefile: enum/extconf.rb ../config.status ../ruby/lib/mkmf-rice.rb
16
+ @RUBY@ $(RUBY_EXTCONF_OPTIONS) -C enum extconf.rb $(EXTCONF_OPTIONS)
17
+
18
+ map/Makefile: map/extconf.rb ../config.status ../ruby/lib/mkmf-rice.rb
19
+ @RUBY@ $(RUBY_EXTCONF_OPTIONS) -C map extconf.rb $(EXTCONF_OPTIONS)
20
+
21
+ inheritance/Makefile: inheritance/extconf.rb ../config.status ../ruby/lib/mkmf-rice.rb
22
+ @RUBY@ $(RUBY_EXTCONF_OPTIONS) -C inheritance extconf.rb $(EXTCONF_OPTIONS)
23
+
24
+ all: enum/Makefile map/Makefile inheritance/Makefile all_extensions
25
+
26
+ all_extensions:
27
+ @for sample in $(RICE_SAMPLES); \
28
+ do \
29
+ $(MAKE) -C $${sample} all; \
30
+ done
31
+
32
+ clean: enum/Makefile map/Makefile inheritance/Makefile clean_extensions
33
+
34
+ clean_extensions:
35
+ @for sample in $(RICE_SAMPLES); \
36
+ do \
37
+ $(MAKE) -C $${sample} clean; \
38
+ done
39
+
40
+ distclean: enum/Makefile map/Makefile inheritance/Makefile distclean_extensions
41
+
42
+ distclean_extensions:
43
+ @for sample in $(RICE_SAMPLES);
44
+ do \
45
+ $(MAKE) -C $${sample} distclean; \
46
+ done
47
+
@@ -0,0 +1,3 @@
1
+ require 'mkmf-rice'
2
+ create_makefile('sample_enum')
3
+
@@ -0,0 +1,54 @@
1
+ #include "rice/Enum.hpp"
2
+ #include "rice/ruby_try_catch.hpp"
3
+
4
+ using namespace Rice;
5
+
6
+ namespace
7
+ {
8
+
9
+ enum Sample_Enum
10
+ {
11
+ SE_FOO = 1,
12
+ SE_BAR = 42,
13
+ SE_BAZ = 100,
14
+ };
15
+
16
+ Rice::Enum<Sample_Enum> sample_enum_type;
17
+
18
+ char const * description(Sample_Enum e)
19
+ {
20
+ switch(e)
21
+ {
22
+ case SE_FOO: return "Fairly Ordinary Object";
23
+ case SE_BAR: return "Beginner's All-purpose Ratchet";
24
+ case SE_BAZ: return "Better than A Zebra";
25
+ }
26
+ return "???";
27
+ }
28
+
29
+ } // namespace
30
+
31
+ template<>
32
+ Sample_Enum from_ruby<Sample_Enum>(Object x)
33
+ {
34
+ Data_Object<Sample_Enum> d(x, sample_enum_type);
35
+ return *d;
36
+ }
37
+
38
+ extern "C"
39
+ void Init_sample_enum()
40
+ {
41
+ RUBY_TRY
42
+ {
43
+ sample_enum_type =
44
+ define_enum<Sample_Enum>("Sample_Enum")
45
+ .define_value("FOO", SE_FOO)
46
+ .define_value("BAR", SE_BAR)
47
+ .define_value("BAZ", SE_BAZ);
48
+
49
+ sample_enum_type
50
+ .define_method("description", description);
51
+ }
52
+ RUBY_CATCH
53
+ }
54
+
@@ -0,0 +1,8 @@
1
+ require 'sample_enum'
2
+
3
+ Sample_Enum.each { |x| p x }
4
+ s = Sample_Enum::FOO
5
+ puts s
6
+ puts s.inspect
7
+ puts s < Sample_Enum::BAR
8
+
@@ -0,0 +1,98 @@
1
+ #include "rice/Data_Type.hpp"
2
+ #include "rice/Constructor.hpp"
3
+
4
+ using namespace Rice;
5
+
6
+ class Organism
7
+ {
8
+ public:
9
+ virtual ~Organism() = 0;
10
+ virtual char const * name() = 0;
11
+ };
12
+
13
+ Organism::
14
+ ~Organism()
15
+ {
16
+ }
17
+
18
+ class Animal
19
+ : public Organism
20
+ {
21
+ public:
22
+ virtual ~Animal() = 0;
23
+ virtual char const * speak() = 0;
24
+ };
25
+
26
+ Animal::
27
+ ~Animal()
28
+ {
29
+ }
30
+
31
+ class Bear
32
+ : public Animal
33
+ {
34
+ public:
35
+ virtual char const * name()
36
+ {
37
+ return "Bear";
38
+ }
39
+
40
+ virtual char const * speak()
41
+ {
42
+ return "I'm smarter than the average bear";
43
+ }
44
+ };
45
+
46
+ class Dog
47
+ : public Animal
48
+ {
49
+ public:
50
+ virtual char const * name()
51
+ {
52
+ return "Dog";
53
+ }
54
+
55
+ virtual char const * speak()
56
+ {
57
+ return "Woof woof";
58
+ }
59
+ };
60
+
61
+ class Rabbit
62
+ : public Animal
63
+ {
64
+ public:
65
+ virtual char const * name()
66
+ {
67
+ return "Rabbit";
68
+ }
69
+
70
+ virtual char const * speak()
71
+ {
72
+ return "What's up, doc?";
73
+ }
74
+ };
75
+
76
+ extern "C"
77
+ void Init_animals(void)
78
+ {
79
+ RUBY_TRY
80
+ {
81
+ define_class<Organism>("Organism")
82
+ .define_method("name", &Organism::name);
83
+
84
+ define_class<Animal, Organism>("Animal")
85
+ .define_method("speak", &Animal::speak);
86
+
87
+ define_class<Bear, Animal>("Bear")
88
+ .define_constructor(Constructor<Bear>());
89
+
90
+ define_class<Dog, Animal>("Dog")
91
+ .define_constructor(Constructor<Dog>());
92
+
93
+ define_class<Rabbit, Animal>("Rabbit")
94
+ .define_constructor(Constructor<Rabbit>());
95
+ }
96
+ RUBY_CATCH
97
+ }
98
+
@@ -0,0 +1,3 @@
1
+ require 'mkmf-rice'
2
+ create_makefile('animals')
3
+
@@ -0,0 +1,7 @@
1
+ require 'animals'
2
+
3
+ [ Bear, Dog, Rabbit].each do |klass|
4
+ animal = klass.new
5
+ puts "A #{animal.name} says: #{animal.speak}"
6
+ end
7
+
@@ -0,0 +1,3 @@
1
+ require 'mkmf-rice'
2
+ create_makefile('map')
3
+
@@ -0,0 +1,81 @@
1
+ #include "rice/Data_Type.hpp"
2
+ #include "rice/Constructor.hpp"
3
+
4
+ #include <map>
5
+
6
+ using namespace Rice;
7
+
8
+ namespace
9
+ {
10
+
11
+ class Map
12
+ {
13
+ private:
14
+ struct Ruby_Value_Compare
15
+ {
16
+ bool operator()(Object lhs, Object rhs) const
17
+ {
18
+ Object result = lhs.call("<", rhs);
19
+ return result.test();
20
+ }
21
+ };
22
+
23
+ typedef std::map<Object, Object, Ruby_Value_Compare> Value_Map;
24
+
25
+ public:
26
+ Object bracket(Object k)
27
+ {
28
+ Value_Map::iterator it = map_.find(k);
29
+ return it == map_.end() ? Object(Qnil) : it->second;
30
+ }
31
+
32
+ Object bracket_equals(Object k, Object v)
33
+ {
34
+ map_[k] = v;
35
+ return Qnil;
36
+ }
37
+
38
+ Value_Map::iterator begin() { return map_.begin(); }
39
+ Value_Map::iterator end() { return map_.end(); }
40
+
41
+ typedef Value_Map::value_type value_type;
42
+ typedef Value_Map::iterator iterator;
43
+
44
+ private:
45
+ Value_Map map_;
46
+ };
47
+
48
+ Data_Type<Map> rb_cMap;
49
+
50
+ } // namespace
51
+
52
+ template<>
53
+ Object to_ruby<Map::value_type>(Map::value_type const & p)
54
+ {
55
+ return protect(rb_assoc_new, p.first, p.second);
56
+ }
57
+
58
+ #include <iostream>
59
+ extern "C"
60
+ void Init_map(void)
61
+ {
62
+ RUBY_TRY
63
+ {
64
+ Map::iterator (Map::*begin)() = &Map::begin;
65
+ Map::iterator (Map::*end)() = &Map::end;
66
+ Rice::Module rb_mStd = define_module("Std");
67
+
68
+ // TODO: no delete method on the map, because I'm not sure how to
69
+ // make delete work properly while iterating
70
+ rb_cMap =
71
+ define_class_under<Map>(rb_mStd, "Map")
72
+ .define_constructor(Constructor<Map>())
73
+ .define_method("[]", &Map::bracket)
74
+ .define_method("[]=", &Map::bracket_equals)
75
+ .define_iterator(begin, end)
76
+ .include_module(rb_mEnumerable)
77
+ ;
78
+ }
79
+ RUBY_CATCH
80
+ }
81
+
@@ -0,0 +1,7 @@
1
+ require 'map'
2
+ m = Std::Map.new
3
+ m[0] = 1
4
+ m[1] = 2
5
+ m[3] = 3
6
+ m.each { |x| p x }
7
+