2012-12-04 03:34:17 +04:00
|
|
|
# README.EXT - -*- RDoc -*- created at: Mon Aug 7 16:45:54 JST 1995
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
This document explains how to make extension libraries for Ruby.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
= Basic Knowledge
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
In C, variables have types and data do not have types. In contrast,
|
2002-10-23 12:20:35 +04:00
|
|
|
Ruby variables do not have a static type, and data themselves have
|
|
|
|
types, so data will need to be converted between the languages.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2006-09-13 13:49:58 +04:00
|
|
|
Data in Ruby are represented by the C type `VALUE'. Each VALUE data
|
|
|
|
has its data-type.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To retrieve C data from a VALUE, you need to:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
1. Identify the VALUE's data type
|
|
|
|
2. Convert the VALUE into C data
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Converting to the wrong data type may cause serious problems.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Data-Types
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The Ruby interpreter has the following data types:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
T_NIL :: nil
|
|
|
|
T_OBJECT :: ordinary object
|
|
|
|
T_CLASS :: class
|
|
|
|
T_MODULE :: module
|
|
|
|
T_FLOAT :: floating point number
|
|
|
|
T_STRING :: string
|
|
|
|
T_REGEXP :: regular expression
|
|
|
|
T_ARRAY :: array
|
|
|
|
T_HASH :: associative array
|
|
|
|
T_STRUCT :: (Ruby) structure
|
|
|
|
T_BIGNUM :: multi precision integer
|
|
|
|
T_FIXNUM :: Fixnum(31bit or 63bit integer)
|
|
|
|
T_COMPLEX :: complex number
|
|
|
|
T_RATIONAL :: rational number
|
|
|
|
T_FILE :: IO
|
|
|
|
T_TRUE :: true
|
|
|
|
T_FALSE :: false
|
|
|
|
T_DATA :: data
|
|
|
|
T_SYMBOL :: symbol
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
In addition, there are several other types used internally:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
T_ICLASS :: included module
|
|
|
|
T_MATCH :: MatchData object
|
|
|
|
T_UNDEF :: undefined
|
|
|
|
T_NODE :: syntax tree node
|
|
|
|
T_ZOMBIE :: object awaiting finalization
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
Most of the types are represented by C structures.
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Check Data Type of the VALUE
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The macro TYPE() defined in ruby.h shows the data type of the VALUE.
|
1998-01-16 15:13:05 +03:00
|
|
|
TYPE() returns the constant number T_XXXX described above. To handle
|
2002-10-23 12:20:35 +04:00
|
|
|
data types, your code will look something like this:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
switch (TYPE(obj)) {
|
|
|
|
case T_FIXNUM:
|
|
|
|
/* process Fixnum */
|
|
|
|
break;
|
|
|
|
case T_STRING:
|
|
|
|
/* process String */
|
|
|
|
break;
|
|
|
|
case T_ARRAY:
|
|
|
|
/* process Array */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* raise exception */
|
2000-03-06 07:15:42 +03:00
|
|
|
rb_raise(rb_eTypeError, "not valid value");
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
There is the data-type check function
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
void Check_Type(VALUE value, int type)
|
|
|
|
|
2007-12-24 00:01:25 +03:00
|
|
|
which raises an exception if the VALUE does not have the type
|
|
|
|
specified.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
There are also faster check macros for fixnums and nil.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
FIXNUM_P(obj)
|
|
|
|
NIL_P(obj)
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Convert VALUE into C Data
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2009-09-15 19:42:41 +04:00
|
|
|
The data for type T_NIL, T_FALSE, T_TRUE are nil, false, true
|
1999-01-20 07:59:39 +03:00
|
|
|
respectively. They are singletons for the data type.
|
2009-09-15 19:42:41 +04:00
|
|
|
The equivalent C constants are: Qnil, Qfalse, Qtrue.
|
|
|
|
Note that Qfalse is false in C also (i.e. 0), but not Qnil.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2009-12-30 14:45:32 +03:00
|
|
|
The T_FIXNUM data is a 31bit or 63bit length fixed integer.
|
|
|
|
This size is depend on the size of long: if long is 32bit then
|
|
|
|
T_FIXNUM is 31bit, if long is 64bit then T_FIXNUM is 63bit.
|
|
|
|
T_FIXNUM can be converted to a C integer by using the
|
2008-07-22 13:09:41 +04:00
|
|
|
FIX2INT() macro or FIX2LONG(). Though you have to check that the
|
|
|
|
data is really FIXNUM before using them, they are faster. FIX2LONG()
|
|
|
|
never raises exceptions, but FIX2INT() raises RangeError if the
|
|
|
|
result is bigger or smaller than the size of int.
|
|
|
|
There are also NUM2INT() and NUM2LONG() which converts any Ruby
|
|
|
|
numbers into C integers. These macros includes a type check,
|
2007-12-24 00:01:25 +03:00
|
|
|
so an exception will be raised if the conversion failed. NUM2DBL()
|
|
|
|
can be used to retrieve the double float value in the same way.
|
2003-03-26 10:01:14 +03:00
|
|
|
|
2009-01-31 16:30:17 +03:00
|
|
|
You can use the macros
|
2006-09-13 18:45:21 +04:00
|
|
|
StringValue() and StringValuePtr() to get a char* from a VALUE.
|
|
|
|
StringValue(var) replaces var's value with the result of "var.to_str()".
|
|
|
|
StringValuePtr(var) does same replacement and returns char*
|
2007-12-24 00:01:25 +03:00
|
|
|
representation of var. These macros will skip the replacement if var
|
|
|
|
is a String. Notice that the macros take only the lvalue as their
|
2006-09-13 18:45:21 +04:00
|
|
|
argument, to change the value of var in place.
|
2003-03-26 10:01:14 +03:00
|
|
|
|
2008-06-13 09:56:51 +04:00
|
|
|
You can also use the macro named StringValueCStr(). This is just
|
|
|
|
like StringValuePtr(), but always add nul character at the end of
|
|
|
|
the result. If the result contains nul character, this macro causes
|
|
|
|
the ArgumentError exception.
|
2009-09-15 19:42:41 +04:00
|
|
|
StringValuePtr() doesn't guarantee the existence of a nul at the end
|
|
|
|
of the result, and the result may contain nul.
|
2008-06-13 09:56:51 +04:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Other data types have corresponding C structures, e.g. struct RArray
|
2007-12-24 00:01:25 +03:00
|
|
|
for T_ARRAY etc. The VALUE of the type which has the corresponding
|
|
|
|
structure can be cast to retrieve the pointer to the struct. The
|
|
|
|
casting macro will be of the form RXXXX for each data type; for
|
2013-09-25 12:44:09 +04:00
|
|
|
instance, RARRAY(obj). See "ruby.h". However, we do not recommend
|
|
|
|
to access RXXXX data directly because these data structure is complex.
|
|
|
|
Use corresponding rb_xxx() functions to access internal struct.
|
|
|
|
For example, to access an entry of array, use rb_ary_entry(ary, offset)
|
|
|
|
and rb_ary_store(ary, offset, obj).
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2006-09-16 14:51:35 +04:00
|
|
|
There are some accessing macros for structure members, for example
|
2009-06-04 04:53:19 +04:00
|
|
|
`RSTRING_LEN(str)' to get the size of the Ruby String object. The
|
2013-09-25 12:44:09 +04:00
|
|
|
allocated region can be accessed by `RSTRING_PTR(str)'.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Notice: Do not change the value of the structure directly, unless you
|
2007-12-24 00:01:25 +03:00
|
|
|
are responsible for the result. This ends up being the cause of
|
|
|
|
interesting bugs.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Convert C Data into VALUE
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To convert C data to Ruby values:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
FIXNUM ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
left shift 1 bit, and turn on LSB.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Other pointer values::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
cast to VALUE.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2011-08-26 01:00:03 +04:00
|
|
|
You can determine whether a VALUE is pointer or not by checking its LSB.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Notice Ruby does not allow arbitrary pointer values to be a VALUE. They
|
|
|
|
should be pointers to the structures which Ruby knows about. The known
|
1999-08-13 09:45:20 +04:00
|
|
|
structures are defined in <ruby.h>.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To convert C numbers to Ruby values, use these macros.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
INT2FIX() :: for integers within 31bits.
|
|
|
|
INT2NUM() :: for arbitrary sized integer.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
INT2NUM() converts an integer into a Bignum if it is out of the FIXNUM
|
|
|
|
range, but is a bit slower.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Manipulating Ruby Data
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-12-24 00:01:25 +03:00
|
|
|
As I already mentioned, it is not recommended to modify an object's
|
|
|
|
internal structure. To manipulate objects, use the functions supplied
|
|
|
|
by the Ruby interpreter. Some (not all) of the useful functions are
|
|
|
|
listed below:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
=== String Functions
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_str_new(const char *ptr, long len) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Creates a new Ruby string.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_str_new2(const char *ptr) ::
|
|
|
|
rb_str_new_cstr(const char *ptr) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Creates a new Ruby string from a C string. This is equivalent to
|
|
|
|
rb_str_new(ptr, strlen(ptr)).
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2014-09-19 09:53:05 +04:00
|
|
|
rb_str_new_literal(const char *ptr) ::
|
|
|
|
|
|
|
|
Creates a new Ruby string from a C string literal.
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_tainted_str_new(const char *ptr, long len) ::
|
2000-07-10 08:49:24 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Creates a new tainted Ruby string. Strings from external data
|
|
|
|
sources should be tainted.
|
2000-07-10 08:49:24 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_tainted_str_new2(const char *ptr) ::
|
|
|
|
rb_tainted_str_new_cstr(const char *ptr) ::
|
2000-07-10 08:49:24 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Creates a new tainted Ruby string from a C string.
|
2000-07-10 08:49:24 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_sprintf(const char *format, ...) ::
|
|
|
|
rb_vsprintf(const char *format, va_list ap) ::
|
2008-07-21 08:55:40 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Creates a new Ruby string with printf(3) format.
|
2008-07-21 08:55:40 +04:00
|
|
|
|
2014-11-03 10:12:37 +03:00
|
|
|
Note: In the format string, "%"PRIsVALUE can be used for Object#to_s
|
|
|
|
(or Object#inspect if '+' flag is set) output (and related argument
|
|
|
|
must be a VALUE). Since it conflicts with "%i", for integers in
|
|
|
|
format strings, use "%d".
|
2013-04-28 04:42:10 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_str_cat(VALUE str, const char *ptr, long len) ::
|
2008-07-22 11:48:00 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Appends len bytes of data from ptr to the Ruby string.
|
2008-07-22 11:48:00 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_str_cat2(VALUE str, const char* ptr) ::
|
2014-04-17 09:22:57 +04:00
|
|
|
rb_str_cat_cstr(VALUE str, const char* ptr) ::
|
2008-07-21 21:50:52 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Appends C string ptr to Ruby string str. This function is
|
|
|
|
equivalent to rb_str_cat(str, ptr, strlen(ptr)).
|
2008-07-21 21:50:52 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_str_catf(VALUE str, const char* format, ...) ::
|
|
|
|
rb_str_vcatf(VALUE str, const char* format, va_list ap) ::
|
2008-07-22 11:48:00 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Appends C string format and successive arguments to Ruby string
|
|
|
|
str according to a printf-like format. These functions are
|
|
|
|
equivalent to rb_str_cat2(str, rb_sprintf(format, ...)) and
|
|
|
|
rb_str_cat2(str, rb_vsprintf(format, ap)), respectively.
|
2008-07-22 11:48:00 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_enc_str_new(const char *ptr, long len, rb_encoding *enc) ::
|
2013-09-03 17:03:54 +04:00
|
|
|
rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc) ::
|
2011-08-26 01:00:03 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Creates a new Ruby string with the specified encoding.
|
2011-08-26 01:00:03 +04:00
|
|
|
|
2014-09-19 09:53:05 +04:00
|
|
|
rb_enc_str_new_literal(const char *ptr) ::
|
|
|
|
|
|
|
|
Creates a new Ruby string from a C string literal with the specified
|
|
|
|
encoding.
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_usascii_str_new(const char *ptr, long len) ::
|
|
|
|
rb_usascii_str_new_cstr(const char *ptr) ::
|
2008-09-01 09:08:44 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Creates a new Ruby string with encoding US-ASCII.
|
2008-09-01 09:08:44 +04:00
|
|
|
|
2014-09-19 09:53:05 +04:00
|
|
|
rb_usascii_str_new_literal(const char *ptr) ::
|
|
|
|
|
|
|
|
Creates a new Ruby string from a C string literal with encoding
|
|
|
|
US-ASCII.
|
|
|
|
|
2014-09-19 08:55:21 +04:00
|
|
|
rb_utf8_str_new(const char *ptr, long len) ::
|
|
|
|
rb_utf8_str_new_cstr(const char *ptr) ::
|
|
|
|
|
|
|
|
Creates a new Ruby string with encoding UTF-8.
|
|
|
|
|
2014-09-19 09:53:05 +04:00
|
|
|
rb_utf8_str_new_literal(const char *ptr) ::
|
|
|
|
|
|
|
|
Creates a new Ruby string from a C string literal with encoding
|
|
|
|
UTF-8.
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_str_resize(VALUE str, long len) ::
|
2010-08-05 15:14:05 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Resizes Ruby string to len bytes. If str is not modifiable, this
|
|
|
|
function raises an exception. The length of str must be set in
|
|
|
|
advance. If len is less than the old length the content beyond
|
|
|
|
len bytes is discarded, else if len is greater than the old length
|
|
|
|
the content beyond the old length bytes will not be preserved but
|
|
|
|
will be garbage. Note that RSTRING_PTR(str) may change by calling
|
|
|
|
this function.
|
2010-08-05 15:14:05 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_str_set_len(VALUE str, long len) ::
|
2010-08-05 15:14:05 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Sets the length of Ruby string. If str is not modifiable, this
|
|
|
|
function raises an exception. This function preserves the content
|
|
|
|
upto len bytes, regardless RSTRING_LEN(str). len must not exceed
|
|
|
|
the capacity of str.
|
2010-08-05 15:14:05 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
=== Array Functions
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_ary_new() ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Creates an array with no elements.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_ary_new2(long len) ::
|
2013-05-31 12:04:56 +04:00
|
|
|
rb_ary_new_capa(long len) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Creates an array with no elements, allocating internal buffer
|
|
|
|
for len elements.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_ary_new3(long n, ...) ::
|
2013-05-31 12:04:56 +04:00
|
|
|
rb_ary_new_from_args(long n, ...) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Creates an n-element array from the arguments.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_ary_new4(long n, VALUE *elts) ::
|
2013-05-31 12:04:56 +04:00
|
|
|
rb_ary_new_from_values(long n, VALUE *elts) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Creates an n-element array from a C array.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_ary_to_ary(VALUE obj) ::
|
2008-09-01 09:08:44 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Converts the object into an array.
|
|
|
|
Equivalent to Object#to_ary.
|
2008-09-01 09:08:44 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
There are many functions to operate an array. They may dump core if other
|
|
|
|
types are given.
|
2008-09-01 09:08:44 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_ary_aref(argc, VALUE *argv, VALUE ary) ::
|
2008-09-01 09:08:44 +04:00
|
|
|
|
2013-05-31 10:18:08 +04:00
|
|
|
Equivalent to Array#[].
|
2008-09-01 09:08:44 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_ary_entry(VALUE ary, long offset) ::
|
2008-09-01 09:08:44 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
ary[offset]
|
2008-09-01 09:08:44 +04:00
|
|
|
|
2013-09-25 12:44:09 +04:00
|
|
|
rb_ary_store(VALUE ary, long offset, VALUE obj) ::
|
|
|
|
|
|
|
|
ary[offset] = obj
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_ary_subseq(VALUE ary, long beg, long len) ::
|
2008-09-01 09:08:44 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
ary[beg, len]
|
2008-09-01 09:08:44 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_ary_push(VALUE ary, VALUE val) ::
|
|
|
|
rb_ary_pop(VALUE ary) ::
|
|
|
|
rb_ary_shift(VALUE ary) ::
|
|
|
|
rb_ary_unshift(VALUE ary, VALUE val) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_ary_cat(VALUE ary, const VALUE *ptr, long len) ::
|
2012-03-08 19:25:04 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Appends len elements of objects from ptr to the array.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
= Extending Ruby with C
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Adding New Features to Ruby
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
You can add new features (classes, methods, etc.) to the Ruby
|
2002-10-23 12:20:35 +04:00
|
|
|
interpreter. Ruby provides APIs for defining the following things:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
* Classes, Modules
|
|
|
|
* Methods, Singleton Methods
|
|
|
|
* Constants
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
=== Class and Module Definition
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To define a class or module, use the functions below:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
VALUE rb_define_class(const char *name, VALUE super)
|
|
|
|
VALUE rb_define_module(const char *name)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
These functions return the newly created class or module. You may
|
2002-10-23 12:20:35 +04:00
|
|
|
want to save this reference into a variable to use later.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To define nested classes or modules, use the functions below:
|
2000-03-06 07:15:42 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
|
|
|
|
VALUE rb_define_module_under(VALUE outer, const char *name)
|
2000-03-06 07:15:42 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
=== Method and Singleton Method Definition
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To define methods or singleton methods, use these functions:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2011-08-26 01:00:03 +04:00
|
|
|
void rb_define_method(VALUE klass, const char *name,
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE (*func)(), int argc)
|
|
|
|
|
2011-08-26 01:00:03 +04:00
|
|
|
void rb_define_singleton_method(VALUE object, const char *name,
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE (*func)(), int argc)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
The `argc' represents the number of the arguments to the C function,
|
2006-09-13 13:49:58 +04:00
|
|
|
which must be less than 17. But I doubt you'll need that many.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
If `argc' is negative, it specifies the calling sequence, not number of
|
2011-08-26 01:00:03 +04:00
|
|
|
the arguments.
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
If argc is -1, the function will be called as:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE func(int argc, VALUE *argv, VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
where argc is the actual number of arguments, argv is the C array of
|
|
|
|
the arguments, and obj is the receiver.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
If argc is -2, the arguments are passed in a Ruby array. The function
|
1999-01-20 07:59:39 +03:00
|
|
|
will be called like:
|
|
|
|
|
|
|
|
VALUE func(VALUE obj, VALUE args)
|
|
|
|
|
|
|
|
where obj is the receiver, and args is the Ruby array containing
|
|
|
|
actual arguments.
|
|
|
|
|
2008-09-01 09:08:44 +04:00
|
|
|
There are some more functions to define methods. One takes an ID
|
2012-12-04 03:34:17 +04:00
|
|
|
as the name of method to be defined. See also ID or Symbol below.
|
2008-09-01 09:08:44 +04:00
|
|
|
|
2011-08-26 01:00:03 +04:00
|
|
|
void rb_define_method_id(VALUE klass, ID name,
|
2008-09-01 09:08:44 +04:00
|
|
|
VALUE (*func)(ANYARGS), int argc)
|
|
|
|
|
|
|
|
There are two functions to define private/protected methods:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2011-08-26 01:00:03 +04:00
|
|
|
void rb_define_private_method(VALUE klass, const char *name,
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE (*func)(), int argc)
|
2011-08-26 01:00:03 +04:00
|
|
|
void rb_define_protected_method(VALUE klass, const char *name,
|
2008-09-01 09:08:44 +04:00
|
|
|
VALUE (*func)(), int argc)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2009-09-15 19:42:41 +04:00
|
|
|
At last, rb_define_module_function defines a module functions,
|
2008-09-01 09:08:44 +04:00
|
|
|
which are private AND singleton methods of the module.
|
|
|
|
For example, sqrt is the module function defined in Math module.
|
|
|
|
It can be called in the following way:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
Math.sqrt(4)
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
or
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
include Math
|
|
|
|
sqrt(4)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To define module functions, use:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2011-08-26 01:00:03 +04:00
|
|
|
void rb_define_module_function(VALUE module, const char *name,
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE (*func)(), int argc)
|
|
|
|
|
2009-09-15 19:42:41 +04:00
|
|
|
In addition, function-like methods, which are private methods defined
|
2002-10-23 12:20:35 +04:00
|
|
|
in the Kernel module, can be defined using:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_global_function(const char *name, VALUE (*func)(), int argc)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2006-09-13 13:49:58 +04:00
|
|
|
To define an alias for the method,
|
2000-07-10 08:49:24 +04:00
|
|
|
|
|
|
|
void rb_define_alias(VALUE module, const char* new, const char* old);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2009-09-15 19:42:41 +04:00
|
|
|
To define a reader/writer for an attribute,
|
2008-09-01 09:08:44 +04:00
|
|
|
|
|
|
|
void rb_define_attr(VALUE klass, const char *name, int read, int write)
|
|
|
|
|
2005-09-21 03:20:58 +04:00
|
|
|
To define and undefine the `allocate' class method,
|
|
|
|
|
|
|
|
void rb_define_alloc_func(VALUE klass, VALUE (*func)(VALUE klass));
|
|
|
|
void rb_undef_alloc_func(VALUE klass);
|
|
|
|
|
2009-09-15 19:42:41 +04:00
|
|
|
func has to take the klass as the argument and return a newly
|
|
|
|
allocated instance. This instance should be as empty as possible,
|
2005-09-21 03:20:58 +04:00
|
|
|
without any expensive (including external) resources.
|
|
|
|
|
2014-06-02 20:38:31 +04:00
|
|
|
If you are overriding an existing method of any ancestor of your class,
|
|
|
|
you may rely on:
|
|
|
|
|
|
|
|
VALUE rb_call_super(int argc, const VALUE *argv)
|
|
|
|
|
2014-11-16 13:38:15 +03:00
|
|
|
To achieve the receiver of the current scope (if no other way is
|
|
|
|
available), you can use:
|
|
|
|
|
|
|
|
VALUE rb_current_receiver(void)
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
=== Constant Definition
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
We have 2 functions to define constants:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_const(VALUE klass, const char *name, VALUE val)
|
|
|
|
void rb_define_global_const(const char *name, VALUE val)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The former is to define a constant under specified class/module. The
|
|
|
|
latter is to define a global constant.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Use Ruby Features from C
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
There are several ways to invoke Ruby's features from C code.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
=== Evaluate Ruby Programs in a String
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The easiest way to use Ruby's functionality from a C program is to
|
2006-09-13 13:49:58 +04:00
|
|
|
evaluate the string as Ruby program. This function will do the job:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
VALUE rb_eval_string(const char *str)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Evaluation is done under the current context, thus current local variables
|
1999-01-20 07:59:39 +03:00
|
|
|
of the innermost method (which is defined by Ruby) can be accessed.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2011-08-26 01:00:03 +04:00
|
|
|
Note that the evaluation can raise an exception. There is a safer
|
2008-09-01 09:08:44 +04:00
|
|
|
function:
|
|
|
|
|
|
|
|
VALUE rb_eval_string_protect(const char *str, int *state)
|
|
|
|
|
2009-09-15 19:42:41 +04:00
|
|
|
It returns nil when an error occur. Moreover, *state is zero if str was
|
2008-09-01 09:08:44 +04:00
|
|
|
successfully evaluated, or nonzero otherwise.
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
=== ID or Symbol
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-12-24 00:01:25 +03:00
|
|
|
You can invoke methods directly, without parsing the string. First I
|
|
|
|
need to explain about ID. ID is the integer number to represent
|
|
|
|
Ruby's identifiers such as variable names. The Ruby data type
|
|
|
|
corresponding to ID is Symbol. It can be accessed from Ruby in the
|
|
|
|
form:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
:Identifier
|
|
|
|
|
2008-09-01 09:08:44 +04:00
|
|
|
or
|
2012-12-04 03:34:17 +04:00
|
|
|
|
|
|
|
:"any kind of string"
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
You can get the ID value from a string within C code by using
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
rb_intern(const char *name)
|
2011-09-12 08:38:15 +04:00
|
|
|
rb_intern_str(VALUE name)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
You can retrieve ID from Ruby object (Symbol or String) given as an
|
|
|
|
argument by using
|
|
|
|
|
|
|
|
rb_to_id(VALUE symbol)
|
2011-09-12 08:38:15 +04:00
|
|
|
rb_check_id(volatile VALUE *name)
|
2012-04-11 17:31:23 +04:00
|
|
|
rb_check_id_cstr(const char *name, long len, rb_encoding *enc)
|
2011-09-12 08:38:15 +04:00
|
|
|
|
|
|
|
These functions try to convert the argument to a String if it was not
|
2012-04-11 17:31:23 +04:00
|
|
|
a Symbol nor a String. The second function stores the converted
|
2011-09-12 08:38:15 +04:00
|
|
|
result into *name, and returns 0 if the string is not a known symbol.
|
|
|
|
After this function returned a non-zero value, *name is always a
|
|
|
|
Symbol or a String, otherwise it is a String if the result is 0.
|
2012-04-11 17:31:23 +04:00
|
|
|
The third function takes NUL-terminated C string, not Ruby VALUE.
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
|
2014-08-03 05:55:10 +04:00
|
|
|
You can retrieve Symbol from Ruby object (Symbol or String) given as
|
|
|
|
an argument by using
|
|
|
|
|
|
|
|
rb_to_symbol(VALUE name)
|
|
|
|
rb_check_symbol(volatile VALUE *namep)
|
|
|
|
rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc)
|
|
|
|
|
|
|
|
These functions are similar to above functions except that these
|
|
|
|
return a Symbol instead of an ID.
|
|
|
|
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
You can convert C ID to Ruby Symbol by using
|
|
|
|
|
|
|
|
VALUE ID2SYM(ID id)
|
|
|
|
|
|
|
|
and to convert Ruby Symbol object to ID, use
|
|
|
|
|
|
|
|
ID SYM2ID(VALUE symbol)
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
=== Invoke Ruby Method from C
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
To invoke methods directly, you can use the function below
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
VALUE rb_funcall(VALUE recv, ID mid, int argc, ...)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
This function invokes a method on the recv, with the method name
|
|
|
|
specified by the symbol mid.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
=== Accessing the Variables and Constants
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
You can access class variables and instance variables using access
|
2007-12-24 00:01:25 +03:00
|
|
|
functions. Also, global variables can be shared between both
|
|
|
|
environments. There's no way to access Ruby's local variables.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
The functions to access/modify instance variables are below:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
VALUE rb_ivar_get(VALUE obj, ID id)
|
|
|
|
VALUE rb_ivar_set(VALUE obj, ID id, VALUE val)
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
id must be the symbol, which can be retrieved by rb_intern().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
To access the constants of the class/module:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
VALUE rb_const_get(VALUE obj, ID id)
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
See also Constant Definition above.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
= Information Sharing Between Ruby and C
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
=== Ruby Constants That C Can Be Accessed From C
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2009-09-15 19:42:41 +04:00
|
|
|
As stated in section 1.3,
|
|
|
|
the following Ruby constants can be referred from C.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Qtrue
|
|
|
|
Qfalse
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Boolean values. Qfalse is false in C also (i.e. 0).
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
Qnil
|
|
|
|
|
|
|
|
Ruby nil in C scope.
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Global Variables Shared Between C and Ruby
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Information can be shared between the two environments using shared global
|
1999-08-13 09:45:20 +04:00
|
|
|
variables. To define them, you can use functions listed below:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_variable(const char *name, VALUE *var)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
This function defines the variable which is shared by both environments.
|
|
|
|
The value of the global variable pointed to by `var' can be accessed
|
1999-08-13 09:45:20 +04:00
|
|
|
through Ruby's global variable named `name'.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
You can define read-only (from Ruby, of course) variables using the
|
1999-08-13 09:45:20 +04:00
|
|
|
function below.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-10-05 13:57:04 +04:00
|
|
|
void rb_define_readonly_variable(const char *name, VALUE *var)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
You can defined hooked variables. The accessor functions (getter and
|
|
|
|
setter) are called on access to the hooked variables.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-09-01 09:08:44 +04:00
|
|
|
void rb_define_hooked_variable(const char *name, VALUE *var,
|
2000-10-05 13:57:04 +04:00
|
|
|
VALUE (*getter)(), void (*setter)())
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
If you need to supply either setter or getter, just supply 0 for the
|
|
|
|
hook you don't need. If both hooks are 0, rb_define_hooked_variable()
|
|
|
|
works just like rb_define_variable().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-09-01 09:08:44 +04:00
|
|
|
The prototypes of the getter and setter functions are as follows:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-09-01 09:08:44 +04:00
|
|
|
VALUE (*getter)(ID id, VALUE *var);
|
|
|
|
void (*setter)(VALUE val, ID id, VALUE *var);
|
|
|
|
|
|
|
|
|
|
|
|
Also you can define a Ruby global variable without a corresponding C
|
1999-08-13 09:45:20 +04:00
|
|
|
variable. The value of the variable will be set/get only by hooks.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-09-01 09:08:44 +04:00
|
|
|
void rb_define_virtual_variable(const char *name,
|
|
|
|
VALUE (*getter)(), void (*setter)())
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The prototypes of the getter and setter functions are as follows:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-09-01 09:08:44 +04:00
|
|
|
VALUE (*getter)(ID id);
|
|
|
|
void (*setter)(VALUE val, ID id);
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Encapsulate C Data into a Ruby Object
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To wrap and objectify a C pointer as a Ruby object (so called
|
1999-08-13 09:45:20 +04:00
|
|
|
DATA), use Data_Wrap_Struct().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-06-22 13:52:32 +04:00
|
|
|
Data_Wrap_Struct(klass, mark, free, sval)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-03-06 07:15:42 +03:00
|
|
|
Data_Wrap_Struct() returns a created DATA object. The klass argument
|
1999-08-13 09:45:20 +04:00
|
|
|
is the class for the DATA object. The mark argument is the function
|
|
|
|
to mark Ruby objects pointed by this data. The free argument is the
|
2003-04-02 10:11:28 +04:00
|
|
|
function to free the pointer allocation. If this is -1, the pointer
|
|
|
|
will be just freed. The functions mark and free will be called from
|
|
|
|
garbage collector.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-06-22 04:24:45 +04:00
|
|
|
These mark / free functions are invoked during GC execution. No
|
|
|
|
object allocations are allowed during it, so do not allocate ruby
|
|
|
|
objects inside them.
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
You can allocate and wrap the structure in one step.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
Data_Make_Struct(klass, type, mark, free, sval)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
This macro returns an allocated Data object, wrapping the pointer to
|
|
|
|
the structure, which is also allocated. This macro works like:
|
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
(sval = ALLOC(type), Data_Wrap_Struct(klass, mark, free, sval))
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Arguments klass, mark, and free work like their counterparts in
|
|
|
|
Data_Wrap_Struct(). A pointer to the allocated structure will be
|
|
|
|
assigned to sval, which should be a pointer of the type specified.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
To retrieve the C pointer from the Data object, use the macro
|
|
|
|
Data_Get_Struct().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
Data_Get_Struct(obj, type, sval)
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
A pointer to the structure will be assigned to the variable sval.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2011-08-26 01:00:03 +04:00
|
|
|
See the example below for details.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
= Example - Creating dbm Extension
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
OK, here's the example of making an extension library. This is the
|
|
|
|
extension to access DBMs. The full source is included in the ext/
|
1999-08-13 09:45:20 +04:00
|
|
|
directory in the Ruby's source tree.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Make the Directory
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
% mkdir ext/dbm
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
Make a directory for the extension library under ext directory.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Design the Library
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
You need to design the library features, before making it.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Write the C Code
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
You need to write C code for your extension library. If your library
|
|
|
|
has only one source file, choosing ``LIBRARY.c'' as a file name is
|
2002-10-23 12:20:35 +04:00
|
|
|
preferred. On the other hand, in case your library has multiple source
|
1999-08-24 12:21:56 +04:00
|
|
|
files, avoid choosing ``LIBRARY.c'' for a file name. It may conflict
|
2002-10-23 12:20:35 +04:00
|
|
|
with an intermediate file ``LIBRARY.o'' on some platforms.
|
2011-01-20 10:13:58 +03:00
|
|
|
Note that some functions in mkmf library described below generate
|
|
|
|
a file ``conftest.c'' for checking with compilation. You shouldn't
|
|
|
|
choose ``conftest.c'' as a name of a source file.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Ruby will execute the initializing function named ``Init_LIBRARY'' in
|
1999-08-24 12:21:56 +04:00
|
|
|
the library. For example, ``Init_dbm()'' will be executed when loading
|
1999-08-13 09:45:20 +04:00
|
|
|
the library.
|
|
|
|
|
|
|
|
Here's the example of an initializing function.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void
|
|
|
|
Init_dbm(void)
|
|
|
|
{
|
|
|
|
/* define DBM class */
|
2014-10-13 03:45:48 +04:00
|
|
|
VALUE cDBM = rb_define_class("DBM", rb_cObject);
|
2014-04-01 12:58:59 +04:00
|
|
|
/* DBM includes Enumerable module */
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_include_module(cDBM, rb_mEnumerable);
|
|
|
|
|
|
|
|
/* DBM has class method open(): arguments are received as C array */
|
|
|
|
rb_define_singleton_method(cDBM, "open", fdbm_s_open, -1);
|
|
|
|
|
|
|
|
/* DBM instance method close(): no args */
|
|
|
|
rb_define_method(cDBM, "close", fdbm_close, 0);
|
|
|
|
/* DBM instance method []: 1 argument */
|
|
|
|
rb_define_method(cDBM, "[]", fdbm_fetch, 1);
|
|
|
|
|
|
|
|
/* ... */
|
|
|
|
|
|
|
|
/* ID for a instance variable to store DBM data */
|
|
|
|
id_dbm = rb_intern("dbm");
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2011-08-26 01:00:03 +04:00
|
|
|
The dbm extension wraps the dbm struct in the C environment using
|
2002-10-23 12:20:35 +04:00
|
|
|
Data_Make_Struct.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
struct dbmdata {
|
|
|
|
int di_size;
|
|
|
|
DBM *di_dbm;
|
|
|
|
};
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
obj = Data_Make_Struct(klass, struct dbmdata, 0, free_dbm, dbmp);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-12-24 00:01:25 +03:00
|
|
|
This code wraps the dbmdata structure into a Ruby object. We avoid
|
|
|
|
wrapping DBM* directly, because we want to cache size information.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
To retrieve the dbmdata structure from a Ruby object, we define the
|
|
|
|
following macro:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2014-03-03 02:50:31 +04:00
|
|
|
#define GetDBM(obj, dbmp) do {\
|
2014-03-02 07:33:55 +04:00
|
|
|
Data_Get_Struct(obj, struct dbmdata, dbmp);\
|
|
|
|
if (dbmp->di_dbm == 0) closed_dbm();\
|
2014-03-03 02:50:31 +04:00
|
|
|
} while (0)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
This sort of complicated macro does the retrieving and close checking for
|
1999-08-13 09:45:20 +04:00
|
|
|
the DBM.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
There are three kinds of way to receive method arguments. First,
|
|
|
|
methods with a fixed number of arguments receive arguments like this:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
static VALUE
|
|
|
|
fdbm_delete(VALUE obj, VALUE keystr)
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
The first argument of the C function is the self, the rest are the
|
|
|
|
arguments to the method.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Second, methods with an arbitrary number of arguments receive
|
1999-08-13 09:45:20 +04:00
|
|
|
arguments like this:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
static VALUE
|
|
|
|
fdbm_s_open(int argc, VALUE *argv, VALUE klass)
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
|
|
|
|
mode = 0666; /* default value */
|
|
|
|
}
|
|
|
|
/* ... */
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The first argument is the number of method arguments, the second
|
|
|
|
argument is the C array of the method arguments, and the third
|
1999-08-13 09:45:20 +04:00
|
|
|
argument is the receiver of the method.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
You can use the function rb_scan_args() to check and retrieve the
|
2009-02-16 08:54:17 +03:00
|
|
|
arguments. The third argument is a string that specifies how to
|
2009-02-18 21:34:38 +03:00
|
|
|
capture method arguments and assign them to the following VALUE
|
|
|
|
references.
|
2009-02-16 08:54:17 +03:00
|
|
|
|
|
|
|
|
2009-02-18 21:34:38 +03:00
|
|
|
The following is an example of a method that takes arguments by Ruby's
|
|
|
|
array:
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
static VALUE
|
|
|
|
thread_initialize(VALUE thread, VALUE args)
|
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
The first argument is the receiver, the second one is the Ruby array
|
|
|
|
which contains the arguments to the method.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
*Notice*: GC should know about global variables which refer to Ruby's objects,
|
|
|
|
but are not exported to the Ruby world. You need to protect them by
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
void rb_global_variable(VALUE *var)
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Prepare extconf.rb
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
If the file named extconf.rb exists, it will be executed to generate
|
2004-11-10 06:31:55 +03:00
|
|
|
Makefile.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2006-09-13 13:49:58 +04:00
|
|
|
extconf.rb is the file for checking compilation conditions etc. You
|
1999-08-13 09:45:20 +04:00
|
|
|
need to put
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
require 'mkmf'
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
at the top of the file. You can use the functions below to check
|
|
|
|
various conditions.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2011-11-13 18:46:01 +04:00
|
|
|
have_macro(macro[, headers[, opt]]): check whether macro is defined
|
|
|
|
have_library(lib[, func[, headers[, opt]]]): check whether library containing function exists
|
|
|
|
find_library(lib[, func, *paths]): find library from paths
|
|
|
|
have_func(func[, headers[, opt]): check whether function exists
|
|
|
|
have_var(var[, headers[, opt]]): check whether variable exists
|
|
|
|
have_header(header[, preheaders[, opt]]): check whether header file exists
|
|
|
|
find_header(header, *paths): find header from paths
|
|
|
|
have_framework(fw): check whether framework exists (for MacOS X)
|
2012-06-09 03:21:50 +04:00
|
|
|
have_struct_member(type, member[, headers[, opt]]): check whether struct has member
|
2011-11-13 18:46:01 +04:00
|
|
|
have_type(type[, headers[, opt]]): check whether type exists
|
|
|
|
find_type(type, opt, *headers): check whether type exists in headers
|
|
|
|
have_const(const[, headers[, opt]]): check whether constant is defined
|
|
|
|
check_sizeof(type[, headers[, opts]]): check size of type
|
|
|
|
check_signedness(type[, headers[, opts]]): check signedness of type
|
|
|
|
convertible_int(type[, headers[, opts]]): find convertible integer type
|
2013-05-19 07:10:21 +04:00
|
|
|
find_executable(bin[, path]): find executable file path
|
2011-11-13 18:46:01 +04:00
|
|
|
create_header(header): generate configured header
|
2012-06-09 03:21:50 +04:00
|
|
|
create_makefile(target[, target_prefix]): generate Makefile
|
|
|
|
|
|
|
|
See MakeMakefile for full documentation of these functions.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The value of the variables below will affect the Makefile.
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2005-09-21 03:20:58 +04:00
|
|
|
$CFLAGS: included in CFLAGS make variable (such as -O)
|
|
|
|
$CPPFLAGS: included in CPPFLAGS make variable (such as -I, -D)
|
1999-08-13 09:45:20 +04:00
|
|
|
$LDFLAGS: included in LDFLAGS make variable (such as -L)
|
2005-09-21 03:20:58 +04:00
|
|
|
$objs: list of object file names
|
|
|
|
|
2006-09-13 13:49:58 +04:00
|
|
|
Normally, the object files list is automatically generated by searching
|
|
|
|
source files, but you must define them explicitly if any sources will
|
2005-09-21 03:20:58 +04:00
|
|
|
be generated while building.
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
If a compilation condition is not fulfilled, you should not call
|
2006-09-13 13:49:58 +04:00
|
|
|
``create_makefile''. The Makefile will not be generated, compilation will
|
1999-08-13 09:45:20 +04:00
|
|
|
not be done.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Prepare Depend (Optional)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
If the file named depend exists, Makefile will include that file to
|
2002-10-23 12:20:35 +04:00
|
|
|
check dependencies. You can make this file by invoking
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-03-06 07:15:42 +03:00
|
|
|
% gcc -MM *.c > depend
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2006-09-13 13:49:58 +04:00
|
|
|
It's harmless. Prepare it.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Generate Makefile
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
Try generating the Makefile by:
|
1999-08-13 09:45:20 +04:00
|
|
|
|
|
|
|
ruby extconf.rb
|
|
|
|
|
2007-11-03 16:41:52 +03:00
|
|
|
If the library should be installed under vendor_ruby directory
|
|
|
|
instead of site_ruby directory, use --vendor option as follows.
|
|
|
|
|
|
|
|
ruby extconf.rb --vendor
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
You don't need this step if you put the extension library under the ext
|
1999-08-13 09:45:20 +04:00
|
|
|
directory of the ruby source tree. In that case, compilation of the
|
|
|
|
interpreter will do this step for you.
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Run make
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
Type
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
make
|
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
to compile your extension. You don't need this step either if you have
|
2006-09-13 13:49:58 +04:00
|
|
|
put the extension library under the ext directory of the ruby source tree.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Debug
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
You may need to rb_debug the extension. Extensions can be linked
|
2006-09-13 13:49:58 +04:00
|
|
|
statically by adding the directory name in the ext/Setup file so that
|
2002-10-23 12:20:35 +04:00
|
|
|
you can inspect the extension with the debugger.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Done! Now You Have the Extension Library
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
You can do anything you want with your library. The author of Ruby
|
2002-10-23 12:20:35 +04:00
|
|
|
will not claim any restrictions on your code depending on the Ruby API.
|
1999-08-13 09:45:20 +04:00
|
|
|
Feel free to use, modify, distribute or sell your program.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
= Appendix A. Ruby Source Files Overview
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Ruby Language Core
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
class.c :: classes and modules
|
|
|
|
error.c :: exception classes and exception mechanism
|
|
|
|
gc.c :: memory management
|
|
|
|
load.c :: library loading
|
|
|
|
object.c :: objects
|
|
|
|
variable.c :: variables and constants
|
2008-09-01 09:08:44 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Ruby Syntax Parser
|
|
|
|
|
|
|
|
parse.y :: grammar definition
|
|
|
|
parse.c :: automatically generated from parse.y
|
|
|
|
keywords :: reserved keywords
|
|
|
|
lex.c :: automatically generated from keywords
|
|
|
|
|
|
|
|
== Ruby Evaluator (a.k.a. YARV)
|
2008-09-01 09:08:44 +04:00
|
|
|
|
|
|
|
compile.c
|
|
|
|
eval.c
|
|
|
|
eval_error.c
|
|
|
|
eval_jump.c
|
|
|
|
eval_safe.c
|
|
|
|
insns.def : definition of VM instructions
|
|
|
|
iseq.c : implementation of VM::ISeq
|
2013-05-19 07:10:21 +04:00
|
|
|
thread.c : thread management and context switching
|
2008-09-01 09:08:44 +04:00
|
|
|
thread_win32.c : thread implementation
|
|
|
|
thread_pthread.c : ditto
|
|
|
|
vm.c
|
|
|
|
vm_dump.c
|
|
|
|
vm_eval.c
|
2008-11-14 14:31:10 +03:00
|
|
|
vm_exec.c
|
2008-09-01 09:08:44 +04:00
|
|
|
vm_insnhelper.c
|
|
|
|
vm_method.c
|
|
|
|
|
|
|
|
opt_insns_unif.def : instruction unification
|
|
|
|
opt_operand.def : definitions for optimization
|
|
|
|
|
|
|
|
-> insn*.inc : automatically generated
|
|
|
|
-> opt*.inc : automatically generated
|
|
|
|
-> vm.inc : automatically generated
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Regular Expression Engine (Oniguruma)
|
|
|
|
|
2008-09-01 09:08:44 +04:00
|
|
|
regex.c
|
|
|
|
regcomp.c
|
|
|
|
regenc.c
|
|
|
|
regerror.c
|
|
|
|
regexec.c
|
|
|
|
regparse.c
|
|
|
|
regsyntax.c
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Utility Functions
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2013-05-19 07:10:21 +04:00
|
|
|
debug.c :: debug symbols for C debugger
|
2012-12-04 03:34:17 +04:00
|
|
|
dln.c :: dynamic loading
|
|
|
|
st.c :: general purpose hash table
|
|
|
|
strftime.c :: formatting times
|
|
|
|
util.c :: misc utilities
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Ruby Interpreter Implementation
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
dmyext.c
|
2011-08-26 01:00:03 +04:00
|
|
|
dmydln.c
|
2008-09-01 09:08:44 +04:00
|
|
|
dmyencoding.c
|
|
|
|
id.c
|
1998-01-16 15:13:05 +03:00
|
|
|
inits.c
|
|
|
|
main.c
|
|
|
|
ruby.c
|
|
|
|
version.c
|
|
|
|
|
2008-09-01 09:08:44 +04:00
|
|
|
gem_prelude.rb
|
|
|
|
prelude.rb
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Class Library
|
|
|
|
|
|
|
|
array.c :: Array
|
|
|
|
bignum.c :: Bignum
|
|
|
|
compar.c :: Comparable
|
|
|
|
complex.c :: Complex
|
|
|
|
cont.c :: Fiber, Continuation
|
|
|
|
dir.c :: Dir
|
|
|
|
enum.c :: Enumerable
|
|
|
|
enumerator.c :: Enumerator
|
|
|
|
file.c :: File
|
|
|
|
hash.c :: Hash
|
|
|
|
io.c :: IO
|
|
|
|
marshal.c :: Marshal
|
|
|
|
math.c :: Math
|
|
|
|
numeric.c :: Numeric, Integer, Fixnum, Float
|
|
|
|
pack.c :: Array#pack, String#unpack
|
|
|
|
proc.c :: Binding, Proc
|
|
|
|
process.c :: Process
|
|
|
|
random.c :: random number
|
|
|
|
range.c :: Range
|
|
|
|
rational.c :: Rational
|
|
|
|
re.c :: Regexp, MatchData
|
|
|
|
signal.c :: Signal
|
|
|
|
sprintf.c :: String#sprintf
|
|
|
|
string.c :: String
|
|
|
|
struct.c :: Struct
|
|
|
|
time.c :: Time
|
|
|
|
|
|
|
|
defs/known_errors.def :: Errno::* exception classes
|
|
|
|
-> known_errors.inc :: automatically generated
|
|
|
|
|
|
|
|
== Multilingualization
|
|
|
|
|
|
|
|
encoding.c :: Encoding
|
|
|
|
transcode.c :: Encoding::Converter
|
|
|
|
enc/*.c :: encoding classes
|
|
|
|
enc/trans/* :: codepoint mapping tables
|
|
|
|
|
|
|
|
== goruby Interpreter Implementation
|
2011-08-26 01:00:03 +04:00
|
|
|
|
2008-09-01 09:08:44 +04:00
|
|
|
goruby.c
|
2008-09-26 12:34:35 +04:00
|
|
|
golf_prelude.rb : goruby specific libraries.
|
|
|
|
-> golf_prelude.c : automatically generated
|
2008-09-01 09:08:44 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
= Appendix B. Ruby Extension API Reference
|
|
|
|
|
|
|
|
== Types
|
|
|
|
|
|
|
|
VALUE ::
|
|
|
|
|
|
|
|
The type for the Ruby object. Actual structures are defined in ruby.h,
|
|
|
|
such as struct RString, etc. To refer the values in structures, use
|
|
|
|
casting macros like RSTRING(obj).
|
|
|
|
|
|
|
|
== Variables and Constants
|
|
|
|
|
|
|
|
Qnil::
|
|
|
|
nil object
|
|
|
|
|
|
|
|
Qtrue::
|
|
|
|
true object (default true value)
|
|
|
|
|
|
|
|
Qfalse::
|
|
|
|
false object
|
|
|
|
|
|
|
|
== C Pointer Wrapping
|
|
|
|
|
|
|
|
Data_Wrap_Struct(VALUE klass, void (*mark)(), void (*free)(), void *sval) ::
|
|
|
|
|
|
|
|
Wrap a C pointer into a Ruby object. If object has references to other
|
|
|
|
Ruby objects, they should be marked by using the mark function during
|
|
|
|
the GC process. Otherwise, mark should be 0. When this object is no
|
|
|
|
longer referred by anywhere, the pointer will be discarded by free
|
|
|
|
function.
|
|
|
|
|
|
|
|
Data_Make_Struct(klass, type, mark, free, sval) ::
|
|
|
|
|
|
|
|
This macro allocates memory using malloc(), assigns it to the variable
|
|
|
|
sval, and returns the DATA encapsulating the pointer to memory region.
|
|
|
|
|
|
|
|
Data_Get_Struct(data, type, sval) ::
|
|
|
|
|
|
|
|
This macro retrieves the pointer value from DATA, and assigns it to
|
|
|
|
the variable sval.
|
|
|
|
|
|
|
|
== Checking Data Types
|
|
|
|
|
|
|
|
TYPE(value) ::
|
|
|
|
|
|
|
|
Internal type (T_NIL, T_FIXNUM, etc.)
|
|
|
|
|
|
|
|
FIXNUM_P(value) ::
|
|
|
|
|
|
|
|
Is +value+ a Fixnum?
|
|
|
|
|
|
|
|
NIL_P(value) ::
|
|
|
|
|
|
|
|
Is +value+ nil?
|
|
|
|
|
|
|
|
void Check_Type(VALUE value, int type) ::
|
|
|
|
|
|
|
|
Ensures +value+ is of the given internal +type+ or raises a TypeError
|
|
|
|
|
|
|
|
SaveStringValue(value) ::
|
|
|
|
|
|
|
|
Checks that +value+ is a String and is not tainted
|
|
|
|
|
|
|
|
== Data Type Conversion
|
|
|
|
|
|
|
|
FIX2INT(value), INT2FIX(i) ::
|
|
|
|
|
|
|
|
Fixnum <-> integer
|
|
|
|
|
|
|
|
FIX2LONG(value), LONG2FIX(l) ::
|
|
|
|
|
|
|
|
Fixnum <-> long
|
|
|
|
|
|
|
|
NUM2INT(value), INT2NUM(i) ::
|
|
|
|
|
|
|
|
Numeric <-> integer
|
|
|
|
|
|
|
|
NUM2UINT(value), UINT2NUM(ui) ::
|
|
|
|
|
|
|
|
Numeric <-> unsigned integer
|
|
|
|
|
|
|
|
NUM2LONG(value), LONG2NUM(l) ::
|
|
|
|
|
|
|
|
Numeric <-> long
|
|
|
|
|
|
|
|
NUM2ULONG(value), ULONG2NUM(ul) ::
|
|
|
|
|
|
|
|
Numeric <-> unsigned long
|
|
|
|
|
|
|
|
NUM2LL(value), LL2NUM(ll) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Numeric <-> long long
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
NUM2ULL(value), ULL2NUM(ull) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Numeric <-> unsigned long long
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
NUM2OFFT(value), OFFT2NUM(off) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Numeric <-> off_t
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
NUM2SIZET(value), SIZET2NUM(size) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Numeric <-> size_t
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
NUM2SSIZET(value), SSIZET2NUM(ssize) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Numeric <-> ssize_t
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2013-08-04 02:15:26 +04:00
|
|
|
rb_integer_pack(value, words, numwords, wordsize, nails, flags), rb_integer_unpack(words, numwords, wordsize, nails, flags) ::
|
|
|
|
|
|
|
|
Numeric <-> Arbitrary size integer buffer
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
NUM2DBL(value) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Numeric -> double
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_float_new(f) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
double -> Float
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2014-04-18 16:42:04 +04:00
|
|
|
RSTRING_LEN(str) ::
|
|
|
|
|
|
|
|
String -> length of String data in bytes
|
|
|
|
|
|
|
|
RSTRING_PTR(str) ::
|
|
|
|
|
|
|
|
String -> pointer to String data
|
2014-04-18 19:11:35 +04:00
|
|
|
Note that the result pointer may not be NUL-terminated
|
2014-04-18 16:42:04 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
StringValue(value) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Object with #to_str -> String
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
StringValuePtr(value) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Object with #to_str -> pointer to String data
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
StringValueCStr(value) ::
|
2003-03-20 09:27:22 +03:00
|
|
|
|
2014-04-18 19:11:35 +04:00
|
|
|
Object with #to_str -> pointer to String data without NUL bytes
|
|
|
|
It is guaranteed that the result data is NUL-terminated
|
2003-03-20 09:27:22 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_str_new2(s) ::
|
2003-03-20 09:27:22 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
char * -> String
|
2003-03-20 09:27:22 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Defining Class and Module
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
VALUE rb_define_class(const char *name, VALUE super) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Defines a new Ruby class as a subclass of super.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
VALUE rb_define_class_under(VALUE module, const char *name, VALUE super) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Creates a new Ruby class as a subclass of super, under the module's
|
|
|
|
namespace.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
VALUE rb_define_module(const char *name) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Defines a new Ruby module.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
VALUE rb_define_module_under(VALUE module, const char *name) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Defines a new Ruby module under the module's namespace.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_include_module(VALUE klass, VALUE module) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Includes module into class. If class already includes it, just ignored.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_extend_object(VALUE object, VALUE module) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Extend the object with the module's attributes.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Defining Global Variables
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_define_variable(const char *name, VALUE *var) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Defines a global variable which is shared between C and Ruby. If name
|
|
|
|
contains a character which is not allowed to be part of the symbol,
|
|
|
|
it can't be seen from Ruby programs.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_define_readonly_variable(const char *name, VALUE *var) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Defines a read-only global variable. Works just like
|
|
|
|
rb_define_variable(), except the defined variable is read-only.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_define_virtual_variable(const char *name, VALUE (*getter)(), VALUE (*setter)()) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Defines a virtual variable, whose behavior is defined by a pair of C
|
|
|
|
functions. The getter function is called when the variable is
|
|
|
|
referenced. The setter function is called when the variable is set to a
|
|
|
|
value. The prototype for getter/setter functions are:
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
VALUE getter(ID id)
|
|
|
|
void setter(VALUE val, ID id)
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
The getter function must return the value for the access.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_define_hooked_variable(const char *name, VALUE *var, VALUE (*getter)(), VALUE (*setter)()) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Defines hooked variable. It's a virtual variable with a C variable.
|
|
|
|
The getter is called as
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
VALUE getter(ID id, VALUE *var)
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
returning a new value. The setter is called as
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void setter(VALUE val, ID id, VALUE *var)
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
GC requires C global variables which hold Ruby values to be marked.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_global_variable(VALUE *var)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Tells GC to protect these variables.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Constant Definition
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_define_const(VALUE klass, const char *name, VALUE val) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Defines a new constant under the class/module.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_define_global_const(const char *name, VALUE val) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Defines a global constant. This is just the same as
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_define_const(cKernal, name, val)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Method Definition
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_define_method(VALUE klass, const char *name, VALUE (*func)(), int argc) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Defines a method for the class. func is the function pointer. argc
|
|
|
|
is the number of arguments. if argc is -1, the function will receive
|
|
|
|
3 arguments: argc, argv, and self. if argc is -2, the function will
|
|
|
|
receive 2 arguments, self and args, where args is a Ruby array of
|
|
|
|
the method arguments.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_define_private_method(VALUE klass, const char *name, VALUE (*func)(), int argc) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Defines a private method for the class. Arguments are same as
|
|
|
|
rb_define_method().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_define_singleton_method(VALUE klass, const char *name, VALUE (*func)(), int argc) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Defines a singleton method. Arguments are same as rb_define_method().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
rb_scan_args(int argc, VALUE *argv, const char *fmt, ...) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Retrieve argument from argc and argv to given VALUE references
|
|
|
|
according to the format string. The format can be described in ABNF
|
|
|
|
as follows:
|
2009-02-18 21:34:38 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
scan-arg-spec := param-arg-spec [option-hash-arg-spec] [block-arg-spec]
|
2009-02-18 21:34:38 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
param-arg-spec := pre-arg-spec [post-arg-spec] / post-arg-spec /
|
|
|
|
pre-opt-post-arg-spec
|
|
|
|
pre-arg-spec := num-of-leading-mandatory-args [num-of-optional-args]
|
|
|
|
post-arg-spec := sym-for-variable-length-args
|
|
|
|
[num-of-trailing-mandatory-args]
|
|
|
|
pre-opt-post-arg-spec := num-of-leading-mandatory-args num-of-optional-args
|
|
|
|
num-of-trailing-mandatory-args
|
|
|
|
option-hash-arg-spec := sym-for-option-hash-arg
|
|
|
|
block-arg-spec := sym-for-block-arg
|
2009-02-18 21:34:38 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
num-of-leading-mandatory-args := DIGIT ; The number of leading
|
|
|
|
; mandatory arguments
|
|
|
|
num-of-optional-args := DIGIT ; The number of optional
|
|
|
|
; arguments
|
|
|
|
sym-for-variable-length-args := "*" ; Indicates that variable
|
|
|
|
; length arguments are
|
|
|
|
; captured as a ruby array
|
|
|
|
num-of-trailing-mandatory-args := DIGIT ; The number of trailing
|
|
|
|
; mandatory arguments
|
|
|
|
sym-for-option-hash-arg := ":" ; Indicates that an option
|
|
|
|
; hash is captured if the last
|
|
|
|
; argument is a hash or can be
|
|
|
|
; converted to a hash with
|
|
|
|
; #to_hash. When the last
|
|
|
|
; argument is nil, it is
|
|
|
|
; captured if it is not
|
|
|
|
; ambiguous to take it as
|
|
|
|
; empty option hash; i.e. '*'
|
|
|
|
; is not specified and
|
|
|
|
; arguments are given more
|
|
|
|
; than sufficient.
|
|
|
|
sym-for-block-arg := "&" ; Indicates that an iterator
|
|
|
|
; block should be captured if
|
|
|
|
; given
|
2009-02-18 21:34:38 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
For example, "12" means that the method requires at least one
|
|
|
|
argument, and at most receives three (1+2) arguments. So, the format
|
|
|
|
string must be followed by three variable references, which are to be
|
|
|
|
assigned to captured arguments. For omitted arguments, variables are
|
|
|
|
set to Qnil. NULL can be put in place of a variable reference, which
|
|
|
|
means the corresponding captured argument(s) should be just dropped.
|
2009-02-18 21:34:38 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
The number of given arguments, excluding an option hash or iterator
|
|
|
|
block, is returned.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2014-11-26 16:28:15 +03:00
|
|
|
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
|
|
|
|
|
|
|
|
Retrieves argument VALUEs bound to keywords, which directed by +table+
|
|
|
|
into +values+. First +required+ number of IDs referred by +table+ are
|
2014-11-26 16:28:32 +03:00
|
|
|
mandatory, and succeeding +optional+ (- +optional+ - 1 if
|
2014-11-26 16:28:15 +03:00
|
|
|
+optional+ is negative) number of IDs are optional. If a
|
|
|
|
mandatory key is not contained in +keyword_hash+, raises "missing
|
|
|
|
keyword" +ArgumentError+. If an optional key is not present in
|
|
|
|
+keyword_hash+, the corresponding element in +values+ is not changed.
|
|
|
|
If +optional+ is negative, rest of +keyword_hash+ are stored in the
|
|
|
|
next to optional +values+ as a new Hash, otherwise raises "unknown
|
|
|
|
keyword" +ArgumentError+.
|
|
|
|
|
|
|
|
VALUE rb_extract_keywords(VALUE *original_hash)
|
|
|
|
|
2014-11-27 23:38:51 +03:00
|
|
|
Extracts pairs whose key is a symbol into a new hash from a hash
|
2014-11-26 16:28:15 +03:00
|
|
|
object referred by +original_hash+. If the original hash contains
|
|
|
|
non-symbol keys, then they are copied to another hash and the new hash
|
|
|
|
is stored through +original_hash+, else 0 is stored.
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Invoking Ruby method
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
VALUE rb_funcall(VALUE recv, ID mid, int narg, ...) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Invokes a method. To retrieve mid from a method name, use rb_intern().
|
2013-05-31 12:27:06 +04:00
|
|
|
Able to call even private/protected methods.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
VALUE rb_funcall2(VALUE recv, ID mid, int argc, VALUE *argv) ::
|
2013-05-31 12:27:06 +04:00
|
|
|
VALUE rb_funcallv(VALUE recv, ID mid, int argc, VALUE *argv) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2013-05-31 12:27:01 +04:00
|
|
|
Invokes a method, passing arguments as an array of values.
|
2013-05-31 12:27:06 +04:00
|
|
|
Able to call even private/protected methods.
|
|
|
|
|
|
|
|
VALUE rb_funcallv_public(VALUE recv, ID mid, int argc, VALUE *argv) ::
|
|
|
|
|
|
|
|
Invokes a method, passing arguments as an array of values.
|
|
|
|
Able to call only public methods.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
VALUE rb_eval_string(const char *str) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Compiles and executes the string as a Ruby program.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
ID rb_intern(const char *name) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Returns ID corresponding to the name.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
char *rb_id2name(ID id) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Returns the name corresponding ID.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
char *rb_class2name(VALUE klass) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Returns the name of the class.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
int rb_respond_to(VALUE object, ID id) ::
|
1999-10-12 08:53:36 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Returns true if the object responds to the message specified by id.
|
1999-10-12 08:53:36 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Instance Variables
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
VALUE rb_iv_get(VALUE obj, const char *name) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Retrieve the value of the instance variable. If the name is not
|
|
|
|
prefixed by `@', that variable shall be inaccessible from Ruby.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
VALUE rb_iv_set(VALUE obj, const char *name, VALUE val) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Sets the value of the instance variable.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Control Structure
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
VALUE rb_block_call(VALUE recv, ID mid, int argc, VALUE * argv, VALUE (*func) (ANYARGS), VALUE data2) ::
|
2009-07-13 20:07:43 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Calls a method on the recv, with the method name specified by the
|
|
|
|
symbol mid, with argc arguments in argv, supplying func as the
|
|
|
|
block. When func is called as the block, it will receive the value
|
|
|
|
from yield as the first argument, and data2 as the second argument.
|
|
|
|
When yielded with multiple values (in C, rb_yield_values(),
|
|
|
|
rb_yield_values2() and rb_yield_splat()), data2 is packed as an Array,
|
|
|
|
whereas yielded values can be gotten via argc/argv of the third/fourth
|
|
|
|
arguments.
|
2009-07-13 20:07:43 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
[OBSOLETE] VALUE rb_iterate(VALUE (*func1)(), void *arg1, VALUE (*func2)(), void *arg2) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Calls the function func1, supplying func2 as the block. func1 will be
|
|
|
|
called with the argument arg1. func2 receives the value from yield as
|
|
|
|
the first argument, arg2 as the second argument.
|
2011-08-26 01:00:03 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
When rb_iterate is used in 1.9, func1 has to call some Ruby-level method.
|
|
|
|
This function is obsolete since 1.9; use rb_block_call instead.
|
2009-07-13 20:07:43 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
VALUE rb_yield(VALUE val) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Evaluates the block with value val.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
VALUE rb_rescue(VALUE (*func1)(), VALUE arg1, VALUE (*func2)(), VALUE arg2) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Calls the function func1, with arg1 as the argument. If an exception
|
|
|
|
occurs during func1, it calls func2 with arg2 as the argument. The
|
|
|
|
return value of rb_rescue() is the return value from func1 if no
|
|
|
|
exception occurs, from func2 otherwise.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
VALUE rb_ensure(VALUE (*func1)(), VALUE arg1, VALUE (*func2)(), VALUE arg2) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Calls the function func1 with arg1 as the argument, then calls func2
|
|
|
|
with arg2 if execution terminated. The return value from
|
2013-05-19 07:10:21 +04:00
|
|
|
rb_ensure() is that of func1 when no exception occurred.
|
2009-09-16 05:14:56 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
VALUE rb_protect(VALUE (*func) (VALUE), VALUE arg, int *state) ::
|
2009-09-16 05:14:56 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Calls the function func with arg as the argument. If no exception
|
2013-05-19 07:10:21 +04:00
|
|
|
occurred during func, it returns the result of func and *state is zero.
|
2012-12-04 03:34:17 +04:00
|
|
|
Otherwise, it returns Qnil and sets *state to nonzero. If state is
|
|
|
|
NULL, it is not set in both cases.
|
|
|
|
You have to clear the error info with rb_set_errinfo(Qnil) when
|
|
|
|
ignoring the caught exception.
|
2009-09-16 05:14:56 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_jump_tag(int state) ::
|
2009-09-16 05:14:56 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Continues the exception caught by rb_protect() and rb_eval_string_protect().
|
|
|
|
state must be the returned value from those functions. This function
|
|
|
|
never return to the caller.
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_iter_break() ::
|
2012-01-24 10:28:26 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Exits from the current innermost block. This function never return to
|
|
|
|
the caller.
|
2012-01-24 10:28:26 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_iter_break_value(VALUE value) ::
|
2012-01-24 10:28:26 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Exits from the current innermost block with the value. The block will
|
|
|
|
return the given argument value. This function never return to the
|
|
|
|
caller.
|
2012-01-24 10:28:26 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Exceptions and Errors
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_warn(const char *fmt, ...) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Prints a warning message according to a printf-like format.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_warning(const char *fmt, ...) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Prints a warning message according to a printf-like format, if
|
|
|
|
$VERBOSE is true.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_raise(rb_eRuntimeError, const char *fmt, ...) ::
|
2003-03-20 09:27:22 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Raises RuntimeError. The fmt is a format string just like printf().
|
2003-03-20 09:27:22 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_raise(VALUE exception, const char *fmt, ...) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Raises a class exception. The fmt is a format string just like printf().
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_fatal(const char *fmt, ...) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Raises a fatal error, terminates the interpreter. No exception handling
|
|
|
|
will be done for fatal errors, but ensure blocks will be executed.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_bug(const char *fmt, ...) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Terminates the interpreter immediately. This function should be
|
|
|
|
called under the situation caused by the bug in the interpreter. No
|
|
|
|
exception handling nor ensure execution will be done.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2014-11-03 10:12:37 +03:00
|
|
|
Note: In the format string, "%"PRIsVALUE can be used for Object#to_s
|
|
|
|
(or Object#inspect if '+' flag is set) output (and related argument
|
|
|
|
must be a VALUE). Since it conflicts with "%i", for integers in
|
|
|
|
format strings, use "%d".
|
2013-04-28 03:04:12 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Initialize and Start the Interpreter
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-10-23 12:20:35 +04:00
|
|
|
The embedding API functions are below (not needed for extension libraries):
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void ruby_init() ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Initializes the interpreter.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2014-03-11 05:55:15 +04:00
|
|
|
void *ruby_options(int argc, char **argv) ::
|
1999-10-04 08:51:08 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Process command line arguments for the interpreter.
|
2014-03-11 05:55:15 +04:00
|
|
|
And compiles the Ruby source to execute.
|
|
|
|
It returns an opaque pointer to the compiled source
|
|
|
|
or an internal special value.
|
1999-10-04 08:51:08 +04:00
|
|
|
|
2014-03-11 05:55:15 +04:00
|
|
|
int ruby_run_node(void *n) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2014-03-11 05:55:15 +04:00
|
|
|
Runs the given compiled source and exits this process.
|
|
|
|
It returns EXIT_SUCCESS if successfully runs the source.
|
|
|
|
Otherwise, it returns other value.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void ruby_script(char *name) ::
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Specifies the name of the script ($0).
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Hooks for the Interpreter Events
|
2005-03-16 16:05:46 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
void rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events,
|
|
|
|
VALUE data)
|
2005-03-16 16:05:46 +03:00
|
|
|
|
|
|
|
Adds a hook function for the specified interpreter events.
|
2012-12-04 03:34:17 +04:00
|
|
|
events should be OR'ed value of:
|
|
|
|
|
|
|
|
RUBY_EVENT_LINE
|
|
|
|
RUBY_EVENT_CLASS
|
|
|
|
RUBY_EVENT_END
|
|
|
|
RUBY_EVENT_CALL
|
|
|
|
RUBY_EVENT_RETURN
|
|
|
|
RUBY_EVENT_C_CALL
|
|
|
|
RUBY_EVENT_C_RETURN
|
|
|
|
RUBY_EVENT_RAISE
|
|
|
|
RUBY_EVENT_ALL
|
2005-03-16 16:05:46 +03:00
|
|
|
|
|
|
|
The definition of rb_event_hook_func_t is below:
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
typedef void (*rb_event_hook_func_t)(rb_event_t event, VALUE data,
|
|
|
|
VALUE self, ID id, VALUE klass)
|
2005-03-16 16:05:46 +03:00
|
|
|
|
2009-05-21 07:07:45 +04:00
|
|
|
The third argument `data' to rb_add_event_hook() is passed to the hook
|
|
|
|
function as the second argument, which was the pointer to the current
|
|
|
|
NODE in 1.8. See RB_EVENT_HOOKS_HAVE_CALLBACK_DATA below.
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
int rb_remove_event_hook(rb_event_hook_func_t func)
|
2005-03-16 16:05:46 +03:00
|
|
|
|
|
|
|
Removes the specified hook function.
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
== Macros for Compatibility
|
2009-02-23 04:15:37 +03:00
|
|
|
|
|
|
|
Some macros to check API compatibilities are available by default.
|
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
NORETURN_STYLE_NEW ::
|
2009-02-23 04:15:37 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Means that NORETURN macro is functional style instead of prefix.
|
2009-02-23 04:15:37 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
HAVE_RB_DEFINE_ALLOC_FUNC ::
|
2009-02-23 04:15:37 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Means that function rb_define_alloc_func() is provided, that means the
|
|
|
|
allocation framework is used. This is same as the result of
|
|
|
|
have_func("rb_define_alloc_func", "ruby.h").
|
2009-02-23 04:15:37 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
HAVE_RB_REG_NEW_STR ::
|
2009-02-23 04:15:37 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Means that function rb_reg_new_str() is provided, that creates Regexp
|
|
|
|
object from String object. This is same as the result of
|
|
|
|
have_func("rb_reg_new_str", "ruby.h").
|
2009-02-23 04:15:37 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
HAVE_RB_IO_T ::
|
2009-02-23 04:15:37 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Means that type rb_io_t is provided.
|
2009-02-23 04:15:37 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
USE_SYMBOL_AS_METHOD_NAME ::
|
2009-02-23 04:19:43 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Means that Symbols will be returned as method names, e.g.,
|
|
|
|
Module#methods, #singleton_methods and so on.
|
2009-02-23 04:19:43 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
HAVE_RUBY_*_H ::
|
2009-03-02 10:40:13 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Defined in ruby.h and means corresponding header is available. For
|
|
|
|
instance, when HAVE_RUBY_ST_H is defined you should use ruby/st.h not
|
|
|
|
mere st.h.
|
2009-02-23 04:15:37 +03:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
RB_EVENT_HOOKS_HAVE_CALLBACK_DATA ::
|
2009-05-21 07:07:45 +04:00
|
|
|
|
2012-12-04 03:34:17 +04:00
|
|
|
Means that rb_add_event_hook() takes the third argument `data', to be
|
|
|
|
passed to the given event hook function.
|
2009-05-21 07:07:45 +04:00
|
|
|
|
2013-06-12 12:48:01 +04:00
|
|
|
= Appendix C. Functions available for use in extconf.rb
|
|
|
|
|
|
|
|
See documentation for {mkmf}[rdoc-ref:MakeMakefile].
|
2013-12-24 09:13:43 +04:00
|
|
|
|
2013-12-24 09:00:37 +04:00
|
|
|
= Appendix D. Generational GC
|
|
|
|
|
2013-12-24 09:01:05 +04:00
|
|
|
Ruby 2.1 introduced a generational garbage collector (called RGenGC).
|
2013-12-24 09:00:37 +04:00
|
|
|
RGenGC (mostly) keeps compatibility.
|
|
|
|
|
2013-12-24 09:01:05 +04:00
|
|
|
Generally, the use of the technique called write barriers is required in
|
|
|
|
extension libraries for generational GC
|
|
|
|
(http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29).
|
2013-12-24 09:00:37 +04:00
|
|
|
RGenGC works fine without write barriers in extension libraries.
|
2013-12-24 09:01:05 +04:00
|
|
|
|
2013-12-24 09:00:37 +04:00
|
|
|
If your library adheres to the following tips, performance can
|
|
|
|
be further improved. Especially, the "Don't touch pointers directly" section is
|
|
|
|
important.
|
|
|
|
|
|
|
|
== Incompatibility
|
2013-12-24 09:01:05 +04:00
|
|
|
|
|
|
|
You can't write RBASIC(obj)->klass field directly because it is const
|
2013-12-24 09:00:37 +04:00
|
|
|
value now.
|
|
|
|
|
2013-12-24 09:01:05 +04:00
|
|
|
Basically you should not write this field because MRI expects it to be
|
|
|
|
an immutable field, but if you want to do it in your extension you can
|
2013-12-24 09:00:37 +04:00
|
|
|
use the following functions:
|
|
|
|
|
|
|
|
VALUE rb_obj_hide(VALUE obj) ::
|
|
|
|
|
|
|
|
Clear RBasic::klass field. The object will be an internal object.
|
|
|
|
ObjectSpace::each_object can't find this object.
|
|
|
|
|
|
|
|
VALUE rb_obj_reveal(VALUE obj, VALUE klass) ::
|
|
|
|
|
|
|
|
Reset RBasic::klass to be klass.
|
|
|
|
We expect the `klass' is hidden class by rb_obj_hide().
|
|
|
|
|
|
|
|
== Write barriers
|
|
|
|
|
2013-12-24 09:01:05 +04:00
|
|
|
RGenGC doesn't require write barriers to support generational GC.
|
|
|
|
However, caring about write barrier can improve the performance of
|
2013-12-24 09:00:37 +04:00
|
|
|
RGenGC. Please check the following tips.
|
2013-12-24 09:01:05 +04:00
|
|
|
|
2013-12-24 09:00:37 +04:00
|
|
|
=== Don't touch pointers directly
|
2013-12-24 09:01:05 +04:00
|
|
|
|
|
|
|
In MRI (include/ruby/ruby.h), some macros to acquire pointers to the
|
|
|
|
internal data structures are supported such as RARRAY_PTR(),
|
2013-12-24 09:00:37 +04:00
|
|
|
RSTRUCT_PTR() and so on.
|
|
|
|
|
2013-12-24 09:01:05 +04:00
|
|
|
DO NOT USE THESE MACROS and instead use the corresponding C-APIs such as
|
2013-12-24 09:00:37 +04:00
|
|
|
rb_ary_aref(), rb_ary_store() and so on.
|
|
|
|
|
|
|
|
=== Consider whether to insert write barriers
|
|
|
|
|
2013-12-24 09:01:05 +04:00
|
|
|
You don't need to care about write barriers if you only use built-in
|
2013-12-24 09:00:37 +04:00
|
|
|
types.
|
|
|
|
|
|
|
|
If you support T_DATA objects, you may consider using write barriers.
|
|
|
|
|
2013-12-24 09:01:05 +04:00
|
|
|
Inserting write barriers into T_DATA objects only works with the
|
|
|
|
following type objects: (a) long-lived objects, (b) when a huge number
|
|
|
|
of objects are generated and (c) container-type objects that have
|
|
|
|
references to other objects. If your extension provides such a type of
|
2013-12-24 09:00:37 +04:00
|
|
|
T_DATA objects, consider inserting write barriers.
|
|
|
|
|
|
|
|
(a): short-lived objects don't become old generation objects.
|
|
|
|
(b): only a few oldgen objects don't have performance impact.
|
|
|
|
(c): only a few references don't have performance impact.
|
2013-12-24 09:01:05 +04:00
|
|
|
|
|
|
|
Inserting write barriers is a very difficult hack, it is easy to
|
|
|
|
introduce critical bugs. And inserting write barriers has several areas
|
|
|
|
of overhead. Basically we don't recommend you insert write barriers.
|
2013-12-24 09:00:37 +04:00
|
|
|
Please carefully consider the risks.
|
|
|
|
|
|
|
|
=== Combine with built-in types
|
|
|
|
|
2013-12-24 09:01:05 +04:00
|
|
|
Please consider utilizing built-in types. Most built-in types support
|
|
|
|
write barrier, so you can use them to avoid manually inserting write
|
2013-12-24 09:00:37 +04:00
|
|
|
barriers.
|
|
|
|
|
2013-12-24 09:01:05 +04:00
|
|
|
For example, if your T_DATA has references to other objects, then you
|
|
|
|
can move these references to Array. A T_DATA object only has a reference
|
|
|
|
to an array object. Or you can also use a Struct object to gather a
|
|
|
|
T_DATA object (without any references) and an that Array contains
|
2013-12-24 09:00:37 +04:00
|
|
|
references.
|
|
|
|
|
2013-12-24 09:01:05 +04:00
|
|
|
With use of such techniques, you don't need to insert write barriers
|
2013-12-24 09:00:37 +04:00
|
|
|
anymore.
|
|
|
|
|
|
|
|
=== Insert write barriers
|
|
|
|
|
2013-12-24 09:01:05 +04:00
|
|
|
[AGAIN] Inserting write barriers is a very difficult hack, and it is
|
|
|
|
easy to introduce critical bugs. And inserting write barriers has
|
|
|
|
several areas of overhead. Basically we don't recommend you insert write
|
2013-12-24 09:00:37 +04:00
|
|
|
barriers. Please carefully consider the risks.
|
|
|
|
|
2013-12-24 09:01:05 +04:00
|
|
|
Before inserting write barriers, you need to know about RGenGC algorithm
|
|
|
|
(gc.c will help you). Macros and functions to insert write barriers are
|
2013-12-24 09:00:37 +04:00
|
|
|
available in in include/ruby/ruby.h. An example is available in iseq.c.
|
|
|
|
|
2013-12-24 09:13:43 +04:00
|
|
|
For a complete guide for RGenGC and write barriers, please refer to
|
|
|
|
<https://bugs.ruby-lang.org/projects/ruby-trunk/wiki/RGenGC>.
|
2013-06-12 12:48:01 +04:00
|
|
|
|
2014-08-15 00:55:27 +04:00
|
|
|
= Appendix E. RB_GC_GUARD to protect from premature GC
|
|
|
|
|
|
|
|
C Ruby currently uses conservative garbage collection, thus VALUE
|
|
|
|
variables must remain visible on the stack or registers to ensure any
|
|
|
|
associated data remains usable. Optimizing C compilers are not designed
|
|
|
|
with conservative garbage collection in mind, so they may optimize away
|
|
|
|
the original VALUE even if the code depends on data associated with that
|
|
|
|
VALUE.
|
|
|
|
|
|
|
|
The following example illustrates the use of RB_GC_GUARD to ensure
|
|
|
|
the contents of sptr remain valid while the second invocation of
|
|
|
|
rb_str_new_cstr is running.
|
|
|
|
|
|
|
|
VALUE s, w;
|
|
|
|
const char *sptr;
|
|
|
|
|
|
|
|
s = rb_str_new_cstr("hello world!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
|
|
|
sptr = RSTRING_PTR(s);
|
|
|
|
w = rb_str_new_cstr(sptr + 6); /* Possible GC invocation */
|
|
|
|
|
|
|
|
RB_GC_GUARD(s); /* ensure s (and thus sptr) do not get GC-ed */
|
|
|
|
|
|
|
|
In the above example, RB_GC_GUARD must be placed _after_ the last use of
|
|
|
|
sptr. Placing RB_GC_GUARD before dereferencing sptr would be of no use.
|
|
|
|
RB_GC_GUARD is only effective on the VALUE data type, not converted C
|
|
|
|
data types.
|
|
|
|
|
|
|
|
RB_GC_GUARD would not be necessary at all in the above example if
|
|
|
|
non-inlined function calls are made on the `s' VALUE after sptr is
|
|
|
|
dereferenced. Thus, in the above example, calling any un-inlined
|
|
|
|
function on `s' such as:
|
|
|
|
|
|
|
|
rb_str_modify(s);
|
|
|
|
|
|
|
|
Will ensure `s' stays on the stack or register to prevent a
|
|
|
|
GC invocation from prematurely freeing it.
|
|
|
|
|
|
|
|
Using the RB_GC_GUARD macro is preferable to using the "volatile"
|
|
|
|
keyword in C. RB_GC_GUARD has the following advantages:
|
|
|
|
|
|
|
|
1) the intent of the macro use is clear
|
|
|
|
|
|
|
|
2) RB_GC_GUARD only affects its call site, "volatile" generates some
|
|
|
|
extra code every time the variable is used, hurting optimization.
|
|
|
|
|
|
|
|
3) "volatile" implementations may be buggy/inconsistent in some
|
|
|
|
compilers and architectures. RB_GC_GUARD is customizable for broken
|
|
|
|
systems/compilers without those without negatively affecting other
|
|
|
|
systems.
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
/*
|
|
|
|
* Local variables:
|
1999-08-13 09:45:20 +04:00
|
|
|
* fill-column: 70
|
1998-01-16 15:13:05 +03:00
|
|
|
* end:
|
|
|
|
*/
|