rb_cdio 0.1.0 → 0.1.1

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 (101) hide show
  1. data/ChangeLog.txt +26 -0
  2. data/LICENSE +340 -0
  3. data/README.EXT +1051 -0
  4. data/README.txt +16 -0
  5. data/VERSION +1 -0
  6. data/doc/classes/CdIo.html +523 -0
  7. data/doc/classes/CdIo.src/M000001.html +17 -0
  8. data/doc/classes/CdIo.src/M000002.html +17 -0
  9. data/doc/classes/CdIo.src/M000003.html +17 -0
  10. data/doc/classes/CdIo.src/M000004.html +17 -0
  11. data/doc/classes/CdIo.src/M000005.html +17 -0
  12. data/doc/classes/CdIo.src/M000006.html +17 -0
  13. data/doc/classes/CdIo.src/M000007.html +17 -0
  14. data/doc/classes/CdIo.src/M000008.html +17 -0
  15. data/doc/classes/CdIo.src/M000009.html +17 -0
  16. data/doc/classes/CdIo.src/M000010.html +17 -0
  17. data/doc/classes/CdIo.src/M000011.html +17 -0
  18. data/doc/classes/CdIo.src/M000012.html +17 -0
  19. data/doc/classes/CdIo.src/M000013.html +17 -0
  20. data/doc/classes/CdIo.src/M000014.html +17 -0
  21. data/doc/classes/CdIo.src/M000015.html +17 -0
  22. data/doc/classes/CdIo.src/M000016.html +17 -0
  23. data/doc/classes/CdIo/Cd.html +348 -0
  24. data/doc/classes/CdIo/Cd.src/M000011.html +17 -0
  25. data/doc/classes/CdIo/Cd.src/M000012.html +17 -0
  26. data/doc/classes/CdIo/Cd.src/M000013.html +17 -0
  27. data/doc/classes/CdIo/Cd.src/M000014.html +17 -0
  28. data/doc/classes/CdIo/Cd.src/M000015.html +17 -0
  29. data/doc/classes/CdIo/Cd.src/M000016.html +17 -0
  30. data/doc/classes/CdIo/Cd.src/M000017.html +17 -0
  31. data/doc/classes/CdIo/Cd.src/M000018.html +17 -0
  32. data/doc/classes/CdIo/Cd.src/M000019.html +17 -0
  33. data/doc/classes/CdIo/Cd.src/M000021.html +17 -0
  34. data/doc/classes/CdIo/Cd.src/M000022.html +17 -0
  35. data/doc/classes/CdIo/Cd.src/M000023.html +17 -0
  36. data/doc/classes/CdIo/Cd.src/M000024.html +17 -0
  37. data/doc/classes/CdIo/Cd.src/M000025.html +17 -0
  38. data/doc/classes/CdIo/Cd.src/M000026.html +17 -0
  39. data/doc/classes/CdIo/Cd.src/M000027.html +17 -0
  40. data/doc/classes/CdIo/Cd.src/M000028.html +17 -0
  41. data/doc/classes/CdIo/Cd.src/M000029.html +17 -0
  42. data/doc/classes/CdIo/Cd.src/M000030.html +17 -0
  43. data/doc/classes/CdIo/Cd.src/M000031.html +17 -0
  44. data/doc/classes/CdIo/Cd.src/M000032.html +17 -0
  45. data/doc/classes/CdIo/Cd.src/M000033.html +17 -0
  46. data/doc/classes/CdIo/Cd.src/M000034.html +17 -0
  47. data/doc/classes/CdIo/Cd.src/M000035.html +17 -0
  48. data/doc/classes/CdIo/Cd.src/M000036.html +17 -0
  49. data/doc/classes/CdIo/CdText.html +111 -0
  50. data/doc/classes/CdIo/Device.html +111 -0
  51. data/doc/classes/CdIo/Track.html +246 -0
  52. data/doc/classes/CdIo/Track.src/M000009.html +17 -0
  53. data/doc/classes/CdIo/Track.src/M000010.html +17 -0
  54. data/doc/classes/CdIo/Track.src/M000011.html +17 -0
  55. data/doc/classes/CdIo/Track.src/M000017.html +17 -0
  56. data/doc/classes/CdIo/Track.src/M000018.html +17 -0
  57. data/doc/classes/CdIo/Track.src/M000019.html +17 -0
  58. data/doc/classes/CdIo/Track.src/M000020.html +17 -0
  59. data/doc/classes/CdIo/TrackIso9660.html +159 -0
  60. data/doc/classes/CdIo/Tracks.html +199 -0
  61. data/doc/classes/CdIo/Tracks.src/M000020.html +17 -0
  62. data/doc/classes/CdIo/Tracks.src/M000021.html +17 -0
  63. data/doc/classes/CdIo/Tracks.src/M000022.html +17 -0
  64. data/doc/created.rid +1 -0
  65. data/doc/files/rb_cdio_def_rb.html +169 -0
  66. data/doc/files/test/testall_rb.html +110 -0
  67. data/doc/fr_class_index.html +31 -0
  68. data/doc/fr_file_index.html +27 -0
  69. data/doc/fr_method_index.html +48 -0
  70. data/doc/index.html +24 -0
  71. data/ext/CdIo.c +41 -20
  72. data/ext/CdIo.h +19 -9
  73. data/ext/CdIo_Cd.c +35 -52
  74. data/ext/CdIo_Common.c +56 -12
  75. data/ext/CdIo_Modulo.c +54 -34
  76. data/ext/CdIo_Track.c +24 -7
  77. data/ext/CdIo_TrackIso9660.c +1 -1
  78. data/ext/CdIo_Tracks.c +66 -0
  79. data/mkmf.log +26 -0
  80. data/rb_cdio.def.rb +187 -0
  81. data/svn-commit.tmp +5 -0
  82. data/tags +47 -0
  83. data/test/testclose.rb +19 -0
  84. data/test/testmethods.rb +28 -0
  85. metadata +253 -20
  86. data/ext/CdIo.o +0 -0
  87. data/ext/CdIo_Cd.o +0 -0
  88. data/ext/CdIo_Common.o +0 -0
  89. data/ext/CdIo_Modulo.o +0 -0
  90. data/ext/CdIo_Track.o +0 -0
  91. data/ext/CdIo_TrackIso9660.o +0 -0
  92. data/ext/Makefile +0 -127
  93. data/test/data/Makefile +0 -677
  94. data/test/data/Makefile.am +0 -78
  95. data/test/data/Makefile.in +0 -677
  96. data/test/data/testassert +0 -117
  97. data/test/data/testbincue +0 -117
  98. data/test/data/testdefault +0 -117
  99. data/test/data/testischar +0 -117
  100. data/test/data/testiso9660 +0 -117
  101. data/test/data/testtoc +0 -117
data/ChangeLog.txt ADDED
@@ -0,0 +1,26 @@
1
+ <b>Release 0.1.1</b>
2
+
3
+ * Deleted all "get_" at the begin of methods
4
+ * Unit tests on test dir
5
+ * New class CdIo::Tracks
6
+ * Added constants for tracks formats
7
+ * <i>CdIo::Track</i>
8
+ * Verification for track number
9
+ * New attribute @leadout
10
+
11
+ <b>Release 0.1.0 (2005.05.24)</b>
12
+
13
+ * Library packaged as rubygem
14
+
15
+ <b>Release 0.0.2 (2005.05.22)</b>
16
+
17
+ * Indentation of C files changed to KR style
18
+ * New file: CdIo_Common.c
19
+ * Better CdIo_test.rb
20
+ * Implemented:
21
+ - CdIo.open
22
+ - CdIo::Cd.get_hwinfo
23
+ - CdIo::Cd.close
24
+ - CdIo::Cd.get_cdtext
25
+ - CdIo::Track.get_cdtext
26
+
data/LICENSE ADDED
@@ -0,0 +1,340 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Library General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) 19yy <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License
307
+ along with this program; if not, write to the Free Software
308
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
309
+
310
+
311
+ Also add information on how to contact you by electronic and paper mail.
312
+
313
+ If the program is interactive, make it output a short notice like this
314
+ when it starts in an interactive mode:
315
+
316
+ Gnomovision version 69, Copyright (C) 19yy name of author
317
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318
+ This is free software, and you are welcome to redistribute it
319
+ under certain conditions; type `show c' for details.
320
+
321
+ The hypothetical commands `show w' and `show c' should show the appropriate
322
+ parts of the General Public License. Of course, the commands you use may
323
+ be called something other than `show w' and `show c'; they could even be
324
+ mouse-clicks or menu items--whatever suits your program.
325
+
326
+ You should also get your employer (if you work as a programmer) or your
327
+ school, if any, to sign a "copyright disclaimer" for the program, if
328
+ necessary. Here is a sample; alter the names:
329
+
330
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
332
+
333
+ <signature of Ty Coon>, 1 April 1989
334
+ Ty Coon, President of Vice
335
+
336
+ This General Public License does not permit incorporating your program into
337
+ proprietary programs. If your program is a subroutine library, you may
338
+ consider it more useful to permit linking proprietary applications with the
339
+ library. If this is what you want to do, use the GNU Library General
340
+ Public License instead of this License.
data/README.EXT ADDED
@@ -0,0 +1,1051 @@
1
+ .\" README.EXT - -*- Text -*- created at: Mon Aug 7 16:45:54 JST 1995
2
+
3
+ This document explains how to make extension libraries for Ruby.
4
+
5
+ 1. Basic knowledge
6
+
7
+ In C, variables have types and data do not have types. In contrast,
8
+ Ruby variables do not have a static type, and data themselves have
9
+ types, so data will need to be converted between the languages.
10
+
11
+ Data in Ruby are represented by C type `VALUE'. Each VALUE data has
12
+ its data-type.
13
+
14
+ To retrieve C data from a VALUE, you need to:
15
+
16
+ (1) Identify the VALUE's data type
17
+ (2) Convert the VALUE into C data
18
+
19
+ Converting to the wrong data type may cause serious problems.
20
+
21
+
22
+ 1.1 Data-types
23
+
24
+ The Ruby interpreter has the following data types:
25
+
26
+ T_NIL nil
27
+ T_OBJECT ordinary object
28
+ T_CLASS class
29
+ T_MODULE module
30
+ T_FLOAT floating point number
31
+ T_STRING string
32
+ T_REGEXP regular expression
33
+ T_ARRAY array
34
+ T_FIXNUM Fixnum(31bit integer)
35
+ T_HASH associative array
36
+ T_STRUCT (Ruby) structure
37
+ T_BIGNUM multi precision integer
38
+ T_FILE IO
39
+ T_TRUE true
40
+ T_FALSE false
41
+ T_DATA data
42
+ T_SYMBOL symbol
43
+
44
+ In addition, there are several other types used internally:
45
+
46
+ T_ICLASS
47
+ T_MATCH
48
+ T_UNDEF
49
+ T_VARMAP
50
+ T_SCOPE
51
+ T_NODE
52
+
53
+ Most of the types are represented by C structures.
54
+
55
+ 1.2 Check Data Type of the VALUE
56
+
57
+ The macro TYPE() defined in ruby.h shows the data type of the VALUE.
58
+ TYPE() returns the constant number T_XXXX described above. To handle
59
+ data types, your code will look something like this:
60
+
61
+ switch (TYPE(obj)) {
62
+ case T_FIXNUM:
63
+ /* process Fixnum */
64
+ break;
65
+ case T_STRING:
66
+ /* process String */
67
+ break;
68
+ case T_ARRAY:
69
+ /* process Array */
70
+ break;
71
+ default:
72
+ /* raise exception */
73
+ rb_raise(rb_eTypeError, "not valid value");
74
+ break;
75
+ }
76
+
77
+ There is the data-type check function
78
+
79
+ void Check_Type(VALUE value, int type)
80
+
81
+ which raises an exception if the VALUE does not have the type specified.
82
+
83
+ There are also faster check macros for fixnums and nil.
84
+
85
+ FIXNUM_P(obj)
86
+ NIL_P(obj)
87
+
88
+ 1.3 Convert VALUE into C data
89
+
90
+ The data for type T_NIL, T_FALSE, T_TRUE are nil, true, false
91
+ respectively. They are singletons for the data type.
92
+
93
+ The T_FIXNUM data is a 31bit length fixed integer (63bit length on
94
+ some machines), which can be convert to a C integer by using the
95
+ FIX2INT() macro. There is also NUM2INT() which converts any Ruby
96
+ numbers into C integers. The NUM2INT() macro includes a type check, so
97
+ an exception will be raised if the conversion failed. NUM2DBL() can
98
+ be used to retrieve the double float value in same way.
99
+
100
+ To get char* from a VALUE, version 1.7 recommend to use new macros
101
+ StringValue() and StringValuePtr(). StringValue(var) replaces var's
102
+ value to the result of "var.to_str()". StringValuePtr(var) does same
103
+ replacement and returns char* representation of var. These macros
104
+ will skip the replacement if var is a String. Notice that the macros
105
+ requires to take only lvalue as their argument, to change the value
106
+ of var in the replacement.
107
+
108
+ In version 1.6 or earlier, STR2CSTR() was used to do same thing
109
+ but now it is obsoleted in version 1.7 because of STR2CSTR() has
110
+ a risk of dangling pointer problem in to_str() impliclit conversion.
111
+
112
+ Other data types have corresponding C structures, e.g. struct RArray
113
+ for T_ARRAY etc. The VALUE of the type which has corresponding structure
114
+ can be cast to retrieve the pointer to the struct. The casting macro
115
+ will be of the form RXXXX for each data type; for instance, RARRAY(obj).
116
+ See "ruby.h".
117
+
118
+ For example, `RSTRING(str)->len' is the way to get the size of the
119
+ Ruby String object. The allocated region can be accessed by
120
+ `RSTRING(str)->ptr'. For arrays, use `RARRAY(ary)->len' and
121
+ `RARRAY(ary)->ptr' respectively.
122
+
123
+ Notice: Do not change the value of the structure directly, unless you
124
+ are responsible for the result. This ends up being the cause of interesting
125
+ bugs.
126
+
127
+ 1.4 Convert C data into VALUE
128
+
129
+ To convert C data to Ruby values:
130
+
131
+ * FIXNUM
132
+
133
+ left shift 1 bit, and turn on LSB.
134
+
135
+ * Other pointer values
136
+
137
+ cast to VALUE.
138
+
139
+ You can determine whether a VALUE is pointer or not by checking its LSB.
140
+
141
+ Notice Ruby does not allow arbitrary pointer values to be a VALUE. They
142
+ should be pointers to the structures which Ruby knows about. The known
143
+ structures are defined in <ruby.h>.
144
+
145
+ To convert C numbers to Ruby values, use these macros.
146
+
147
+ INT2FIX() for integers within 31bits.
148
+ INT2NUM() for arbitrary sized integer.
149
+
150
+ INT2NUM() converts an integer into a Bignum if it is out of the FIXNUM
151
+ range, but is a bit slower.
152
+
153
+ 1.5 Manipulating Ruby data
154
+
155
+ As I already mentioned, it is not recommended to modify an object's internal
156
+ structure. To manipulate objects, use the functions supplied by the Ruby
157
+ interpreter. Some (not all) of the useful functions are listed below:
158
+
159
+ String functions
160
+
161
+ rb_str_new(const char *ptr, long len)
162
+
163
+ Creates a new Ruby string.
164
+
165
+ rb_str_new2(const char *ptr)
166
+
167
+ Creates a new Ruby string from a C string. This is equivalent to
168
+ rb_str_new(ptr, strlen(ptr)).
169
+
170
+ rb_tainted_str_new(const char *ptr, long len)
171
+
172
+ Creates a new tainted Ruby string. Strings from external data
173
+ sources should be tainted.
174
+
175
+ rb_tainted_str_new2(const char *ptr)
176
+
177
+ Creates a new tainted Ruby string from a C string.
178
+
179
+ rb_str_cat(VALUE str, const char *ptr, long len)
180
+
181
+ Appends len bytes of data from ptr to the Ruby string.
182
+
183
+ Array functions
184
+
185
+ rb_ary_new()
186
+
187
+ Creates an array with no elements.
188
+
189
+ rb_ary_new2(long len)
190
+
191
+ Creates an array with no elements, allocating internal buffer
192
+ for len elements.
193
+
194
+ rb_ary_new3(long n, ...)
195
+
196
+ Creates an n-element array from the arguments.
197
+
198
+ rb_ary_new4(long n, VALUE *elts)
199
+
200
+ Creates an n-element array from a C array.
201
+
202
+ rb_ary_push(VALUE ary, VALUE val)
203
+ rb_ary_pop(VALUE ary)
204
+ rb_ary_shift(VALUE ary)
205
+ rb_ary_unshift(VALUE ary, VALUE val)
206
+
207
+ Array operations. The first argument to each functions must be an
208
+ array. They may dump core if other types given.
209
+
210
+ 2. Extending Ruby with C
211
+
212
+ 2.1 Addding new features to Ruby
213
+
214
+ You can add new features (classes, methods, etc.) to the Ruby
215
+ interpreter. Ruby provides APIs for defining the following things:
216
+
217
+ * Classes, Modules
218
+ * Methods, Singleton Methods
219
+ * Constants
220
+
221
+ 2.1.1 Class/module definition
222
+
223
+ To define a class or module, use the functions below:
224
+
225
+ VALUE rb_define_class(const char *name, VALUE super)
226
+ VALUE rb_define_module(const char *name)
227
+
228
+ These functions return the newly created class or module. You may
229
+ want to save this reference into a variable to use later.
230
+
231
+ To define nested classes or modules, use the functions below:
232
+
233
+ VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
234
+ VALUE rb_define_module_under(VALUE outer, const char *name)
235
+
236
+ 2.1.2 Method/singleton method definition
237
+
238
+ To define methods or singleton methods, use these functions:
239
+
240
+ void rb_define_method(VALUE klass, const char *name,
241
+ VALUE (*func)(), int argc)
242
+
243
+ void rb_define_singleton_method(VALUE object, const char *name,
244
+ VALUE (*func)(), int argc)
245
+
246
+ The `argc' represents the number of the arguments to the C function,
247
+ which must be less than 17. But I believe you don't need that much. :-)
248
+
249
+ If `argc' is negative, it specifies the calling sequence, not number of
250
+ the arguments.
251
+
252
+ If argc is -1, the function will be called as:
253
+
254
+ VALUE func(int argc, VALUE *argv, VALUE obj)
255
+
256
+ where argc is the actual number of arguments, argv is the C array of
257
+ the arguments, and obj is the receiver.
258
+
259
+ If argc is -2, the arguments are passed in a Ruby array. The function
260
+ will be called like:
261
+
262
+ VALUE func(VALUE obj, VALUE args)
263
+
264
+ where obj is the receiver, and args is the Ruby array containing
265
+ actual arguments.
266
+
267
+ There are two more functions to define methods. One is to define
268
+ private methods:
269
+
270
+ void rb_define_private_method(VALUE klass, const char *name,
271
+ VALUE (*func)(), int argc)
272
+
273
+ The other is to define module functions, which are private AND singleton
274
+ methods of the module. For example, sqrt is the module function
275
+ defined in Math module. It can be call in the form like:
276
+
277
+ Math.sqrt(4)
278
+
279
+ or
280
+
281
+ include Math
282
+ sqrt(4)
283
+
284
+ To define module functions, use:
285
+
286
+ void rb_define_module_function(VALUE module, const char *name,
287
+ VALUE (*func)(), int argc)
288
+
289
+ Oh, in addition, function-like methods, which are private methods defined
290
+ in the Kernel module, can be defined using:
291
+
292
+ void rb_define_global_function(const char *name, VALUE (*func)(), int argc)
293
+
294
+ To define alias to the method,
295
+
296
+ void rb_define_alias(VALUE module, const char* new, const char* old);
297
+
298
+ 2.1.3 Constant definition
299
+
300
+ We have 2 functions to define constants:
301
+
302
+ void rb_define_const(VALUE klass, const char *name, VALUE val)
303
+ void rb_define_global_const(const char *name, VALUE val)
304
+
305
+ The former is to define a constant under specified class/module. The
306
+ latter is to define a global constant.
307
+
308
+ 2.2 Use Ruby features from C
309
+
310
+ There are several ways to invoke Ruby's features from C code.
311
+
312
+ 2.2.1 Evaluate Ruby Programs in a String
313
+
314
+ The easiest way to use Ruby's functionality from a C program is to
315
+ evaluate the string as Ruby program. This function will do the job.
316
+
317
+ VALUE rb_eval_string(const char *str)
318
+
319
+ Evaluation is done under the current context, thus current local variables
320
+ of the innermost method (which is defined by Ruby) can be accessed.
321
+
322
+ 2.2.2 ID or Symbol
323
+
324
+ You can invoke methods directly, without parsing the string. First I
325
+ need to explain about symbols (whose data type is ID). ID is the
326
+ integer number to represent Ruby's identifiers such as variable names.
327
+ It can be accessed from Ruby in the form:
328
+
329
+ :Identifier
330
+
331
+ You can get the symbol value from a string within C code by using
332
+
333
+ rb_intern(const char *name)
334
+
335
+ 2.2.3 Invoke Ruby method from C
336
+
337
+ To invoke methods directly, you can use the function below
338
+
339
+ VALUE rb_funcall(VALUE recv, ID mid, int argc, ...)
340
+
341
+ This function invokes a method on the recv, with the method name
342
+ specified by the symbol mid.
343
+
344
+ 2.2.4 Accessing the variables and constants
345
+
346
+ You can access class variables and instance variables using access
347
+ functions. Also, global variables can be shared between both environments.
348
+ There's no way to access Ruby's local variables.
349
+
350
+ The functions to access/modify instance variables are below:
351
+
352
+ VALUE rb_ivar_get(VALUE obj, ID id)
353
+ VALUE rb_ivar_set(VALUE obj, ID id, VALUE val)
354
+
355
+ id must be the symbol, which can be retrieved by rb_intern().
356
+
357
+ To access the constants of the class/module:
358
+
359
+ VALUE rb_const_get(VALUE obj, ID id)
360
+
361
+ See 2.1.3 for defining new constant.
362
+
363
+ 3. Information sharing between Ruby and C
364
+
365
+ 3.1 Ruby constants that C can be accessed from C
366
+
367
+ The following Ruby constants can be referred from C.
368
+
369
+ Qtrue
370
+ Qfalse
371
+
372
+ Boolean values. Qfalse is false in C also (i.e. 0).
373
+
374
+ Qnil
375
+
376
+ Ruby nil in C scope.
377
+
378
+ 3.2 Global variables shared between C and Ruby
379
+
380
+ Information can be shared between the two environments using shared global
381
+ variables. To define them, you can use functions listed below:
382
+
383
+ void rb_define_variable(const char *name, VALUE *var)
384
+
385
+ This function defines the variable which is shared by both environments.
386
+ The value of the global variable pointed to by `var' can be accessed
387
+ through Ruby's global variable named `name'.
388
+
389
+ You can define read-only (from Ruby, of course) variables using the
390
+ function below.
391
+
392
+ void rb_define_readonly_variable(const char *name, VALUE *var)
393
+
394
+ You can defined hooked variables. The accessor functions (getter and
395
+ setter) are called on access to the hooked variables.
396
+
397
+ void rb_define_hooked_variable(constchar *name, VALUE *var,
398
+ VALUE (*getter)(), void (*setter)())
399
+
400
+ If you need to supply either setter or getter, just supply 0 for the
401
+ hook you don't need. If both hooks are 0, rb_define_hooked_variable()
402
+ works just like rb_define_variable().
403
+
404
+ void rb_define_virtual_variable(const char *name,
405
+ VALUE (*getter)(), void (*setter)())
406
+
407
+ This function defines a Ruby global variable without a corresponding C
408
+ variable. The value of the variable will be set/get only by hooks.
409
+
410
+ The prototypes of the getter and setter functions are as follows:
411
+
412
+ (*getter)(ID id, void *data, struct global_entry* entry);
413
+ (*setter)(VALUE val, ID id, void *data, struct global_entry* entry);
414
+
415
+ 3.3 Encapsulate C data into Ruby object
416
+
417
+ To wrap and objectify a C pointer as a Ruby object (so called
418
+ DATA), use Data_Wrap_Struct().
419
+
420
+ Data_Wrap_Struct(klass, mark, free, ptr)
421
+
422
+ Data_Wrap_Struct() returns a created DATA object. The klass argument
423
+ is the class for the DATA object. The mark argument is the function
424
+ to mark Ruby objects pointed by this data. The free argument is the
425
+ function to free the pointer allocation. If this is -1, the pointer
426
+ will be just freed. The functions mark and free will be called from
427
+ garbage collector.
428
+
429
+ You can allocate and wrap the structure in one step.
430
+
431
+ Data_Make_Struct(klass, type, mark, free, sval)
432
+
433
+ This macro returns an allocated Data object, wrapping the pointer to
434
+ the structure, which is also allocated. This macro works like:
435
+
436
+ (sval = ALLOC(type), Data_Wrap_Struct(klass, mark, free, sval))
437
+
438
+ Arguments klass, mark, and free work like their counterparts in
439
+ Data_Wrap_Struct(). A pointer to the allocated structure will be
440
+ assigned to sval, which should be a pointer of the type specified.
441
+
442
+ To retrieve the C pointer from the Data object, use the macro
443
+ Data_Get_Struct().
444
+
445
+ Data_Get_Struct(obj, type, sval)
446
+
447
+ A pointer to the structure will be assigned to the variable sval.
448
+
449
+ See the example below for details.
450
+
451
+ 4. Example - Creating dbm extension
452
+
453
+ OK, here's the example of making an extension library. This is the
454
+ extension to access DBMs. The full source is included in the ext/
455
+ directory in the Ruby's source tree.
456
+
457
+ (1) make the directory
458
+
459
+ % mkdir ext/dbm
460
+
461
+ Make a directory for the extension library under ext directory.
462
+
463
+ (2) design the library
464
+
465
+ You need to design the library features, before making it.
466
+
467
+ (3) write C code.
468
+
469
+ You need to write C code for your extension library. If your library
470
+ has only one source file, choosing ``LIBRARY.c'' as a file name is
471
+ preferred. On the other hand, in case your library has multiple source
472
+ files, avoid choosing ``LIBRARY.c'' for a file name. It may conflict
473
+ with an intermediate file ``LIBRARY.o'' on some platforms.
474
+
475
+ Ruby will execute the initializing function named ``Init_LIBRARY'' in
476
+ the library. For example, ``Init_dbm()'' will be executed when loading
477
+ the library.
478
+
479
+ Here's the example of an initializing function.
480
+
481
+ --
482
+ Init_dbm()
483
+ {
484
+ /* define DBM class */
485
+ cDBM = rb_define_class("DBM", rb_cObject);
486
+ /* DBM includes Enumerate module */
487
+ rb_include_module(cDBM, rb_mEnumerable);
488
+
489
+ /* DBM has class method open(): arguments are received as C array */
490
+ rb_define_singleton_method(cDBM, "open", fdbm_s_open, -1);
491
+
492
+ /* DBM instance method close(): no args */
493
+ rb_define_method(cDBM, "close", fdbm_close, 0);
494
+ /* DBM instance method []: 1 argument */
495
+ rb_define_method(cDBM, "[]", fdbm_fetch, 1);
496
+ :
497
+
498
+ /* ID for a instance variable to store DBM data */
499
+ id_dbm = rb_intern("dbm");
500
+ }
501
+ --
502
+
503
+ The dbm extension wraps the dbm struct in the C environment using
504
+ Data_Make_Struct.
505
+
506
+ --
507
+ struct dbmdata {
508
+ int di_size;
509
+ DBM *di_dbm;
510
+ };
511
+
512
+
513
+ obj = Data_Make_Struct(klass, struct dbmdata, 0, free_dbm, dbmp);
514
+ --
515
+
516
+ This code wraps the dbmdata structure into a Ruby object. We avoid wrapping
517
+ DBM* directly, because we want to cache size information.
518
+
519
+ To retrieve the dbmdata structure from a Ruby object, we define the
520
+ following macro:
521
+
522
+ --
523
+ #define GetDBM(obj, dbmp) {\
524
+ Data_Get_Struct(obj, struct dbmdata, dbmp);\
525
+ if (dbmp->di_dbm == 0) closed_dbm();\
526
+ }
527
+ --
528
+
529
+ This sort of complicated macro does the retrieving and close checking for
530
+ the DBM.
531
+
532
+ There are three kinds of way to receive method arguments. First,
533
+ methods with a fixed number of arguments receive arguments like this:
534
+
535
+ --
536
+ static VALUE
537
+ fdbm_delete(obj, keystr)
538
+ VALUE obj, keystr;
539
+ {
540
+ :
541
+ }
542
+ --
543
+
544
+ The first argument of the C function is the self, the rest are the
545
+ arguments to the method.
546
+
547
+ Second, methods with an arbitrary number of arguments receive
548
+ arguments like this:
549
+
550
+ --
551
+ static VALUE
552
+ fdbm_s_open(argc, argv, klass)
553
+ int argc;
554
+ VALUE *argv;
555
+ VALUE klass;
556
+ {
557
+ :
558
+ if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
559
+ mode = 0666; /* default value */
560
+ }
561
+ :
562
+ }
563
+ --
564
+
565
+ The first argument is the number of method arguments, the second
566
+ argument is the C array of the method arguments, and the third
567
+ argument is the receiver of the method.
568
+
569
+ You can use the function rb_scan_args() to check and retrieve the
570
+ arguments. For example, "11" means that the method requires at least one
571
+ argument, and at most receives two arguments.
572
+
573
+ Methods with an arbitrary number of arguments can receive arguments
574
+ by Ruby's array, like this:
575
+
576
+ --
577
+ static VALUE
578
+ fdbm_indexes(obj, args)
579
+ VALUE obj, args;
580
+ {
581
+ :
582
+ }
583
+ --
584
+
585
+ The first argument is the receiver, the second one is the Ruby array
586
+ which contains the arguments to the method.
587
+
588
+ ** Notice
589
+
590
+ GC should know about global variables which refer to Ruby's objects, but
591
+ are not exported to the Ruby world. You need to protect them by
592
+
593
+ void rb_global_variable(VALUE *var)
594
+
595
+ (4) prepare extconf.rb
596
+
597
+ If the file named extconf.rb exists, it will be executed to generate
598
+ Makefile.
599
+
600
+ extconf.rb is the file for check compilation conditions etc. You
601
+ need to put
602
+
603
+ require 'mkmf'
604
+
605
+ at the top of the file. You can use the functions below to check
606
+ various conditions.
607
+
608
+ have_library(lib, func): check whether library containing function exists.
609
+ have_func(func, header): check whether function exists
610
+ have_header(header): check whether header file exists
611
+ create_makefile(target): generate Makefile
612
+
613
+ The value of the variables below will affect the Makefile.
614
+
615
+ $CFLAGS: included in CFLAGS make variable (such as -I)
616
+ $LDFLAGS: included in LDFLAGS make variable (such as -L)
617
+
618
+ If a compilation condition is not fulfilled, you should not call
619
+ ``create_makefile''. The Makefile will not generated, compilation will
620
+ not be done.
621
+
622
+ (5) prepare depend (optional)
623
+
624
+ If the file named depend exists, Makefile will include that file to
625
+ check dependencies. You can make this file by invoking
626
+
627
+ % gcc -MM *.c > depend
628
+
629
+ It's no harm. Prepare it.
630
+
631
+ (6) generate Makefile
632
+
633
+ Try generating the Makefile by:
634
+
635
+ ruby extconf.rb
636
+
637
+ You don't need this step if you put the extension library under the ext
638
+ directory of the ruby source tree. In that case, compilation of the
639
+ interpreter will do this step for you.
640
+
641
+ (7) make
642
+
643
+ Type
644
+
645
+ make
646
+
647
+ to compile your extension. You don't need this step either if you have
648
+ put extension library under the ext directory of the ruby source tree.
649
+
650
+ (8) debug
651
+
652
+ You may need to rb_debug the extension. Extensions can be linked
653
+ statically by the adding directory name in the ext/Setup file so that
654
+ you can inspect the extension with the debugger.
655
+
656
+ (9) done, now you have the extension library
657
+
658
+ You can do anything you want with your library. The author of Ruby
659
+ will not claim any restrictions on your code depending on the Ruby API.
660
+ Feel free to use, modify, distribute or sell your program.
661
+
662
+ Appendix A. Ruby source files overview
663
+
664
+ ruby language core
665
+
666
+ class.c
667
+ error.c
668
+ eval.c
669
+ gc.c
670
+ object.c
671
+ parse.y
672
+ variable.c
673
+
674
+ utility functions
675
+
676
+ dln.c
677
+ regex.c
678
+ st.c
679
+ util.c
680
+
681
+ ruby interpreter implementation
682
+
683
+ dmyext.c
684
+ inits.c
685
+ main.c
686
+ ruby.c
687
+ version.c
688
+
689
+ class library
690
+
691
+ array.c
692
+ bignum.c
693
+ compar.c
694
+ dir.c
695
+ enum.c
696
+ file.c
697
+ hash.c
698
+ io.c
699
+ marshal.c
700
+ math.c
701
+ numeric.c
702
+ pack.c
703
+ prec.c
704
+ process.c
705
+ random.c
706
+ range.c
707
+ re.c
708
+ signal.c
709
+ sprintf.c
710
+ string.c
711
+ struct.c
712
+ time.c
713
+
714
+ Appendix B. Ruby extension API reference
715
+
716
+ ** Types
717
+
718
+ VALUE
719
+
720
+ The type for the Ruby object. Actual structures are defined in ruby.h,
721
+ such as struct RString, etc. To refer the values in structures, use
722
+ casting macros like RSTRING(obj).
723
+
724
+ ** Variables and constants
725
+
726
+ Qnil
727
+
728
+ const: nil object
729
+
730
+ Qtrue
731
+
732
+ const: true object(default true value)
733
+
734
+ Qfalse
735
+
736
+ const: false object
737
+
738
+ ** C pointer wrapping
739
+
740
+ Data_Wrap_Struct(VALUE klass, void (*mark)(), void (*free)(), void *sval)
741
+
742
+ Wrap a C pointer into a Ruby object. If object has references to other
743
+ Ruby objects, they should be marked by using the mark function during
744
+ the GC process. Otherwise, mark should be 0. When this object is no
745
+ longer referred by anywhere, the pointer will be discarded by free
746
+ function.
747
+
748
+ Data_Make_Struct(klass, type, mark, free, sval)
749
+
750
+ This macro allocates memory using malloc(), assigns it to the variable
751
+ sval, and returns the DATA encapsulating the pointer to memory region.
752
+
753
+ Data_Get_Struct(data, type, sval)
754
+
755
+ This macro retrieves the pointer value from DATA, and assigns it to
756
+ the variable sval.
757
+
758
+ ** Checking data types
759
+
760
+ TYPE(value)
761
+ FIXNUM_P(value)
762
+ NIL_P(value)
763
+ void Check_Type(VALUE value, int type)
764
+ void Check_SafeStr(VALUE value)
765
+
766
+ ** Data type conversion
767
+
768
+ FIX2INT(value)
769
+ INT2FIX(i)
770
+ NUM2INT(value)
771
+ INT2NUM(i)
772
+ NUM2DBL(value)
773
+ rb_float_new(f)
774
+ STR2CSTR(value)
775
+ rb_str_new2(s)
776
+
777
+ ** defining class/module
778
+
779
+ VALUE rb_define_class(const char *name, VALUE super)
780
+
781
+ Defines a new Ruby class as a subclass of super.
782
+
783
+ VALUE rb_define_class_under(VALUE module, const char *name, VALUE super)
784
+
785
+ Creates a new Ruby class as a subclass of super, under the module's
786
+ namespace.
787
+
788
+ VALUE rb_define_module(const char *name)
789
+
790
+ Defines a new Ruby module.
791
+
792
+ VALUE rb_define_module_under(VALUE module, const char *name)
793
+
794
+ Defines a new Ruby module under the module's namespace.
795
+
796
+ void rb_include_module(VALUE klass, VALUE module)
797
+
798
+ Includes module into class. If class already includes it, just
799
+ ignored.
800
+
801
+ void rb_extend_object(VALUE object, VALUE module)
802
+
803
+ Extend the object with the module's attributes.
804
+
805
+ ** Defining Global Variables
806
+
807
+ void rb_define_variable(const char *name, VALUE *var)
808
+
809
+ Defines a global variable which is shared between C and Ruby. If name
810
+ contains a character which is not allowed to be part of the symbol,
811
+ it can't be seen from Ruby programs.
812
+
813
+ void rb_define_readonly_variable(const char *name, VALUE *var)
814
+
815
+ Defines a read-only global variable. Works just like
816
+ rb_define_variable(), except defined variable is read-only.
817
+
818
+ void rb_define_virtual_variable(const char *name,
819
+ VALUE (*getter)(), VALUE (*setter)())
820
+
821
+ Defines a virtual variable, whose behavior is defined by a pair of C
822
+ functions. The getter function is called when the variable is
823
+ referred. The setter function is called when the value is set to the
824
+ variable. The prototype for getter/setter functions are:
825
+
826
+ VALUE getter(ID id)
827
+ void setter(VALUE val, ID id)
828
+
829
+ The getter function must return the value for the access.
830
+
831
+ void rb_define_hooked_variable(const char *name, VALUE *var,
832
+ VALUE (*getter)(), VALUE (*setter)())
833
+
834
+ Defines hooked variable. It's a virtual variable with a C variable.
835
+ The getter is called as
836
+
837
+ VALUE getter(ID id, VALUE *var)
838
+
839
+ returning a new value. The setter is called as
840
+
841
+ void setter(VALUE val, ID id, VALUE *var)
842
+
843
+ GC requires C global variables which hold Ruby values to be marked.
844
+
845
+ void rb_global_variable(VALUE *var)
846
+
847
+ Tells GC to protect these variables.
848
+
849
+ ** Constant Definition
850
+
851
+ void rb_define_const(VALUE klass, const char *name, VALUE val)
852
+
853
+ Defines a new constant under the class/module.
854
+
855
+ void rb_define_global_const(const char *name, VALUE val)
856
+
857
+ Defines a global constant. This is just the same as
858
+
859
+ rb_define_const(cKernal, name, val)
860
+
861
+ ** Method Definition
862
+
863
+ rb_define_method(VALUE klass, const char *name, VALUE (*func)(), int argc)
864
+
865
+ Defines a method for the class. func is the function pointer. argc
866
+ is the number of arguments. if argc is -1, the function will receive
867
+ 3 arguments: argc, argv, and self. if argc is -2, the function will
868
+ receive 2 arguments, self and args, where args is a Ruby array of
869
+ the method arguments.
870
+
871
+ rb_define_private_method(VALUE klass, const char *name, VALUE (*func)(), int argc)
872
+
873
+ Defines a private method for the class. Arguments are same as
874
+ rb_define_method().
875
+
876
+ rb_define_singleton_method(VALUE klass, const char *name, VALUE (*func)(), int argc)
877
+
878
+ Defines a singleton method. Arguments are same as rb_define_method().
879
+
880
+ rb_scan_args(int argc, VALUE *argv, const char *fmt, ...)
881
+
882
+ Retrieve argument from argc, argv. The fmt is the format string for
883
+ the arguments, such as "12" for 1 non-optional argument, 2 optional
884
+ arguments. If `*' appears at the end of fmt, it means the rest of
885
+ the arguments are assigned to the corresponding variable, packed in
886
+ an array.
887
+
888
+ ** Invoking Ruby method
889
+
890
+ VALUE rb_funcall(VALUE recv, ID mid, int narg, ...)
891
+
892
+ Invokes a method. To retrieve mid from a method name, use rb_intern().
893
+
894
+ VALUE rb_funcall2(VALUE recv, ID mid, int argc, VALUE *argv)
895
+
896
+ Invokes a method, passing arguments by an array of values.
897
+
898
+ VALUE rb_eval_string(const char *str)
899
+
900
+ Compiles and executes the string as a Ruby program.
901
+
902
+ ID rb_intern(const char *name)
903
+
904
+ Returns ID corresponding to the name.
905
+
906
+ char *rb_id2name(ID id)
907
+
908
+ Returns the name corresponding ID.
909
+
910
+ char *rb_class2name(VALUE klass)
911
+
912
+ Returns the name of the class.
913
+
914
+ int rb_respond_to(VALUE object, ID id)
915
+
916
+ Returns true if the object responds to the message specified by id.
917
+
918
+ ** Instance Variables
919
+
920
+ VALUE rb_iv_get(VALUE obj, const char *name)
921
+
922
+ Retrieve the value of the instance variable. If the name is not
923
+ prefixed by `@', that variable shall be inaccessible from Ruby.
924
+
925
+ VALUE rb_iv_set(VALUE obj, const char *name, VALUE val)
926
+
927
+ Sets the value of the instance variable.
928
+
929
+ ** Control Structure
930
+
931
+ VALUE rb_iterate(VALUE (*func1)(), void *arg1, VALUE (*func2)(), void *arg2)
932
+
933
+ Calls the function func1, supplying func2 as the block. func1 will be
934
+ called with the argument arg1. func2 receives the value from yield as
935
+ the first argument, arg2 as the second argument.
936
+
937
+ VALUE rb_yield(VALUE val)
938
+
939
+ Evaluates the block with value val.
940
+
941
+ VALUE rb_rescue(VALUE (*func1)(), void *arg1, VALUE (*func2)(), void *arg2)
942
+
943
+ Calls the function func1, with arg1 as the argument. If an exception
944
+ occurs during func1, it calls func2 with arg2 as the argument. The
945
+ return value of rb_rescue() is the return value from func1 if no
946
+ exception occurs, from func2 otherwise.
947
+
948
+ VALUE rb_ensure(VALUE (*func1)(), void *arg1, void (*func2)(), void *arg2)
949
+
950
+ Calls the function func1 with arg1 as the argument, then calls func2
951
+ with arg2 if execution terminated. The return value from
952
+ rb_ensure() is that of func1.
953
+
954
+ ** Exceptions and Errors
955
+
956
+ void rb_warn(const char *fmt, ...)
957
+
958
+ Prints a warning message according to a printf-like format.
959
+
960
+ void rb_warning(const char *fmt, ...)
961
+
962
+ Prints a warning message according to a printf-like format, if
963
+ $VERBOSE is true.
964
+
965
+ void rb_raise(rb_eRuntimeError, const char *fmt, ...)
966
+
967
+ Raises RuntimeError. The fmt is a format string just like printf().
968
+
969
+ void rb_raise(VALUE exception, const char *fmt, ...)
970
+
971
+ Raises a class exception. The fmt is a format string just like printf().
972
+
973
+ void rb_fatal(const char *fmt, ...)
974
+
975
+ Raises a fatal error, terminates the interpreter. No exception handling
976
+ will be done for fatal errors, but ensure blocks will be executed.
977
+
978
+ void rb_bug(const char *fmt, ...)
979
+
980
+ Terminates the interpreter immediately. This function should be
981
+ called under the situation caused by the bug in the interpreter. No
982
+ exception handling nor ensure execution will be done.
983
+
984
+ ** Initialize and Starts the Interpreter
985
+
986
+ The embedding API functions are below (not needed for extension libraries):
987
+
988
+ void ruby_init()
989
+
990
+ Initializes the interpreter.
991
+
992
+ void ruby_options(int argc, char **argv)
993
+
994
+ Process command line arguments for the interpreter.
995
+
996
+ void ruby_run()
997
+
998
+ Starts execution of the interpreter.
999
+
1000
+ void ruby_script(char *name)
1001
+
1002
+ Specifies the name of the script ($0).
1003
+
1004
+ Appendix C. Functions Available in extconf.rb
1005
+
1006
+ These functions are available in extconf.rb:
1007
+
1008
+ have_library(lib, func)
1009
+
1010
+ Checks whether the library exists, containing the specified function.
1011
+ Returns true if the library exists.
1012
+
1013
+ find_library(lib, func, path...)
1014
+
1015
+ Checks whether a library which contains the specified function exists in
1016
+ path. Returns true if the library exists.
1017
+
1018
+ have_func(func, header)
1019
+
1020
+ Checks whether func exists with header. Returns true if the function
1021
+ exists. To check functions in an additional library, you need to
1022
+ check that library first using have_library().
1023
+
1024
+ have_header(header)
1025
+
1026
+ Checks whether header exists. Returns true if the header file exists.
1027
+
1028
+ create_makefile(target)
1029
+
1030
+ Generates the Makefile for the extension library. If you don't invoke
1031
+ this method, the compilation will not be done.
1032
+
1033
+ with_config(withval[, default=nil])
1034
+
1035
+ Parses the command line options and returns the value specified by
1036
+ --with-<withval>.
1037
+
1038
+ dir_config(target[, default_dir])
1039
+ dir_config(target[, default_include, default_lib])
1040
+
1041
+ Parses the command line options and adds the directories specified by
1042
+ --with-<target>-dir, --with-<target>-include, and/or --with-<target>-lib
1043
+ to $CFLAGS and/or $LDFLAGS. --with-<target>-dir=/path is equivalent to
1044
+ --with-<target>-include=/path/include --with-<target>-lib=/path/lib.
1045
+ Returns an array of the added directories ([include_dir, lib_dir]).
1046
+
1047
+ /*
1048
+ * Local variables:
1049
+ * fill-column: 70
1050
+ * end:
1051
+ */