2000-05-01 13:42:38 +04:00
|
|
|
/**********************************************************************
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
object.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Thu Jul 15 12:01:24 JST 1993
|
|
|
|
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-25 07:29:39 +04:00
|
|
|
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
2000-05-01 13:42:38 +04:00
|
|
|
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
2000-05-09 08:53:16 +04:00
|
|
|
Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-05-01 13:42:38 +04:00
|
|
|
**********************************************************************/
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-06-10 07:06:15 +04:00
|
|
|
#include "ruby/ruby.h"
|
|
|
|
#include "ruby/st.h"
|
|
|
|
#include "ruby/util.h"
|
2012-01-06 11:06:22 +04:00
|
|
|
#include "ruby/encoding.h"
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <stdio.h>
|
2000-12-25 09:29:27 +03:00
|
|
|
#include <errno.h>
|
2001-05-16 13:05:54 +04:00
|
|
|
#include <ctype.h>
|
2002-06-28 18:42:46 +04:00
|
|
|
#include <math.h>
|
2008-01-16 09:26:33 +03:00
|
|
|
#include <float.h>
|
2010-10-26 21:27:32 +04:00
|
|
|
#include "constant.h"
|
2011-05-18 17:41:54 +04:00
|
|
|
#include "internal.h"
|
2013-05-02 11:54:17 +04:00
|
|
|
#include "id.h"
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
#include "probes.h"
|
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
|
|
|
VALUE rb_cBasicObject;
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE rb_mKernel;
|
|
|
|
VALUE rb_cObject;
|
|
|
|
VALUE rb_cModule;
|
|
|
|
VALUE rb_cClass;
|
|
|
|
VALUE rb_cData;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE rb_cNilClass;
|
|
|
|
VALUE rb_cTrueClass;
|
|
|
|
VALUE rb_cFalseClass;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2013-05-02 11:54:17 +04:00
|
|
|
#define id_eq idEq
|
|
|
|
#define id_eql idEqlP
|
|
|
|
#define id_match idEqTilde
|
|
|
|
#define id_inspect idInspect
|
|
|
|
#define id_init_copy idInitialize_copy
|
|
|
|
#define id_init_clone idInitialize_clone
|
|
|
|
#define id_init_dup idInitialize_dup
|
|
|
|
#define id_const_missing idConst_missing
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2013-01-15 18:07:24 +04:00
|
|
|
#define CLASS_OR_MODULE_P(obj) \
|
|
|
|
(!SPECIAL_CONST_P(obj) && \
|
|
|
|
(BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE))
|
|
|
|
|
2013-04-03 11:35:35 +04:00
|
|
|
VALUE
|
|
|
|
rb_obj_hide(VALUE obj)
|
|
|
|
{
|
|
|
|
if (!SPECIAL_CONST_P(obj)) {
|
* include/ruby/ruby.h: constify RBasic::klass and add
RBASIC_CLASS(obj) macro which returns a class of `obj'.
This change is a part of RGENGC branch [ruby-trunk - Feature #8339].
* object.c: add new function rb_obj_reveal().
This function reveal interal (hidden) object by rb_obj_hide().
Note that do not change class before and after hiding.
Only permitted example is:
klass = RBASIC_CLASS(obj);
rb_obj_hide(obj);
....
rb_obj_reveal(obj, klass);
TODO: API design. rb_obj_reveal() should be replaced with others.
TODO: modify constified variables using cast may be harmful for
compiler's analysis and optimizaton.
Any idea to prohibt inserting RBasic::klass directly?
If rename RBasic::klass and force to use RBASIC_CLASS(obj),
then all codes such as `RBASIC(obj)->klass' will be
compilation error. Is it acceptable? (We have similar
experience at Ruby 1.9,
for example "RARRAY(ary)->ptr" to "RARRAY_PTR(ary)".
* internal.h: add some macros.
* RBASIC_CLEAR_CLASS(obj) clear RBasic::klass to make it internal
object.
* RBASIC_SET_CLASS(obj, cls) set RBasic::klass.
* RBASIC_SET_CLASS_RAW(obj, cls) same as RBASIC_SET_CLASS
without write barrier (planned).
* RCLASS_SET_SUPER(a, b) set super class of a.
* array.c, class.c, compile.c, encoding.c, enum.c, error.c, eval.c,
file.c, gc.c, hash.c, io.c, iseq.c, marshal.c, object.c,
parse.y, proc.c, process.c, random.c, ruby.c, sprintf.c,
string.c, thread.c, transcode.c, vm.c, vm_eval.c, win32/file.c:
Use above macros and functions to access RBasic::klass.
* ext/coverage/coverage.c, ext/readline/readline.c,
ext/socket/ancdata.c, ext/socket/init.c,
* ext/zlib/zlib.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 14:49:11 +04:00
|
|
|
RBASIC_CLEAR_CLASS(obj);
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_obj_reveal(VALUE obj, VALUE klass)
|
|
|
|
{
|
|
|
|
if (!SPECIAL_CONST_P(obj)) {
|
|
|
|
RBASIC_SET_CLASS(obj, klass);
|
2013-04-03 11:35:35 +04:00
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2013-05-13 10:33:48 +04:00
|
|
|
VALUE
|
|
|
|
rb_obj_setup(VALUE obj, VALUE klass, VALUE type)
|
|
|
|
{
|
|
|
|
RBASIC(obj)->flags = type;
|
* include/ruby/ruby.h: constify RBasic::klass and add
RBASIC_CLASS(obj) macro which returns a class of `obj'.
This change is a part of RGENGC branch [ruby-trunk - Feature #8339].
* object.c: add new function rb_obj_reveal().
This function reveal interal (hidden) object by rb_obj_hide().
Note that do not change class before and after hiding.
Only permitted example is:
klass = RBASIC_CLASS(obj);
rb_obj_hide(obj);
....
rb_obj_reveal(obj, klass);
TODO: API design. rb_obj_reveal() should be replaced with others.
TODO: modify constified variables using cast may be harmful for
compiler's analysis and optimizaton.
Any idea to prohibt inserting RBasic::klass directly?
If rename RBasic::klass and force to use RBASIC_CLASS(obj),
then all codes such as `RBASIC(obj)->klass' will be
compilation error. Is it acceptable? (We have similar
experience at Ruby 1.9,
for example "RARRAY(ary)->ptr" to "RARRAY_PTR(ary)".
* internal.h: add some macros.
* RBASIC_CLEAR_CLASS(obj) clear RBasic::klass to make it internal
object.
* RBASIC_SET_CLASS(obj, cls) set RBasic::klass.
* RBASIC_SET_CLASS_RAW(obj, cls) same as RBASIC_SET_CLASS
without write barrier (planned).
* RCLASS_SET_SUPER(a, b) set super class of a.
* array.c, class.c, compile.c, encoding.c, enum.c, error.c, eval.c,
file.c, gc.c, hash.c, io.c, iseq.c, marshal.c, object.c,
parse.y, proc.c, process.c, random.c, ruby.c, sprintf.c,
string.c, thread.c, transcode.c, vm.c, vm_eval.c, win32/file.c:
Use above macros and functions to access RBasic::klass.
* ext/coverage/coverage.c, ext/readline/readline.c,
ext/socket/ancdata.c, ext/socket/init.c,
* ext/zlib/zlib.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 14:49:11 +04:00
|
|
|
RBASIC_SET_CLASS(obj, klass);
|
* safe.c (rb_set_safe_level, safe_setter): raise an ArgumentError
when $SAFE is set to 4. $SAFE=4 is now obsolete.
[ruby-core:55222] [Feature #8468]
* object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust):
Kernel#untrusted?, untrust, and trust are now deprecated.
Their behavior is same as tainted?, taint, and untaint,
respectively.
* include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED()
and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(),
respectively.
* array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c,
ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c,
ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c,
ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c,
ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c,
ext/socket/socket.c, ext/socket/udpsocket.c,
ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c,
ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c,
load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c,
safe.c, string.c, thread.c, transcode.c, variable.c,
vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for
$SAFE=4.
* test/dl/test_dl2.rb, test/erb/test_erb.rb,
test/readline/test_readline.rb,
test/readline/test_readline_history.rb, test/ruby/test_alias.rb,
test/ruby/test_array.rb, test/ruby/test_dir.rb,
test/ruby/test_encoding.rb, test/ruby/test_env.rb,
test/ruby/test_eval.rb, test/ruby/test_exception.rb,
test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb,
test/ruby/test_io.rb, test/ruby/test_method.rb,
test/ruby/test_module.rb, test/ruby/test_object.rb,
test/ruby/test_pack.rb, test/ruby/test_rand.rb,
test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb,
test/ruby/test_struct.rb, test/ruby/test_thread.rb,
test/ruby/test_time.rb: remove tests for $SAFE=4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-12 18:20:51 +04:00
|
|
|
if (rb_safe_level() >= 3) FL_SET((obj), FL_TAINT);
|
2013-05-13 10:33:48 +04:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj === other -> true or false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2012-06-01 01:30:18 +04:00
|
|
|
* Case Equality -- For class Object, effectively the same as calling
|
|
|
|
* <code>#==</code>, but typically overridden by descendants to provide
|
|
|
|
* meaningful semantics in +case+ statements.
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_equal(VALUE obj1, VALUE obj2)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE result;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (obj1 == obj2) return Qtrue;
|
2003-05-19 09:41:08 +04:00
|
|
|
result = rb_funcall(obj1, id_eq, 1, obj2);
|
2000-07-17 13:38:10 +04:00
|
|
|
if (RTEST(result)) return Qtrue;
|
2003-07-21 22:48:58 +04:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_eql(VALUE obj1, VALUE obj2)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2003-05-19 09:41:08 +04:00
|
|
|
return RTEST(rb_funcall(obj1, id_eql, 1, obj2));
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj == other -> true or false
|
|
|
|
* obj.equal?(other) -> true or false
|
|
|
|
* obj.eql?(other) -> true or false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2012-02-24 02:36:40 +04:00
|
|
|
* Equality --- At the <code>Object</code> level, <code>==</code> returns
|
|
|
|
* <code>true</code> only if +obj+ and +other+ are the same object.
|
|
|
|
* Typically, this method is overridden in descendant classes to provide
|
|
|
|
* class-specific meaning.
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* Unlike <code>==</code>, the <code>equal?</code> method should never be
|
2012-02-24 02:36:40 +04:00
|
|
|
* overridden by subclasses as it is used to determine object identity
|
|
|
|
* (that is, <code>a.equal?(b)</code> if and only if <code>a</code> is the
|
|
|
|
* same object as <code>b</code>):
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
2012-02-24 02:36:40 +04:00
|
|
|
* obj = "a"
|
|
|
|
* other = obj.dup
|
|
|
|
*
|
|
|
|
* a == other #=> true
|
|
|
|
* a.equal? other #=> false
|
|
|
|
* a.equal? a #=> true
|
|
|
|
*
|
|
|
|
* The <code>eql?</code> method returns <code>true</code> if +obj+ and
|
|
|
|
* +other+ refer to the same hash key. This is used by Hash to test members
|
|
|
|
* for equality. For objects of class <code>Object</code>, <code>eql?</code>
|
|
|
|
* is synonymous with <code>==</code>. Subclasses normally continue this
|
|
|
|
* tradition by aliasing <code>eql?</code> to their overridden <code>==</code>
|
|
|
|
* method, but there are exceptions. <code>Numeric</code> types, for
|
|
|
|
* example, perform type conversion across <code>==</code>, but not across
|
2006-09-22 12:36:02 +04:00
|
|
|
* <code>eql?</code>, so:
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* 1 == 1.0 #=> true
|
|
|
|
* 1.eql? 1.0 #=> false
|
|
|
|
*/
|
|
|
|
|
2007-12-18 15:07:51 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_equal(VALUE obj1, VALUE obj2)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
if (obj1 == obj2) return Qtrue;
|
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2011-05-12 16:18:47 +04:00
|
|
|
/*
|
2012-02-24 02:23:58 +04:00
|
|
|
* Generates a Fixnum hash value for this object. This function must have the
|
2013-01-17 15:28:52 +04:00
|
|
|
* property that <code>a.eql?(b)</code> implies <code>a.hash == b.hash</code>.
|
2011-05-12 02:56:13 +04:00
|
|
|
*
|
2012-02-24 02:23:58 +04:00
|
|
|
* The hash value is used along with #eql? by the Hash class to determine if
|
|
|
|
* two objects reference the same hash key. Any hash value that exceeds the
|
|
|
|
* capacity of a Fixnum will be truncated before being used.
|
|
|
|
*
|
|
|
|
* The hash value for an object may not be identical across invocations or
|
|
|
|
* implementations of ruby. If you need a stable identifier across ruby
|
|
|
|
* invocations and implementations you will need to generate one with a custom
|
|
|
|
* method.
|
2011-05-12 02:56:13 +04:00
|
|
|
*/
|
* string.c (rb_hash_uint32, rb_hash_uint, rb_hash_start, rb_hash_end),
include/ruby/intern.h: add Murmurhash API. [ruby-dev:37784]
* complex.c (nucomp_hash), array.c (rb_ary_hash), time.c (time_hash),
string.c (rb_str_hsah), object.c (rb_obj_hash), range.c
(range_hash), struct.c (rb_struct_hash), hash.c (rb_any_hash),
rational.c (nurat_hash): use Murmurhash. [ruby-dev:37784]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22317 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-14 22:55:34 +03:00
|
|
|
VALUE
|
|
|
|
rb_obj_hash(VALUE obj)
|
|
|
|
{
|
|
|
|
VALUE oid = rb_obj_id(obj);
|
2012-12-21 19:30:44 +04:00
|
|
|
#if SIZEOF_LONG == SIZEOF_VOIDP
|
|
|
|
st_index_t index = NUM2LONG(oid);
|
|
|
|
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
|
|
|
|
st_index_t index = NUM2LL(oid);
|
|
|
|
#else
|
|
|
|
# error not supported
|
|
|
|
#endif
|
|
|
|
st_index_t h = rb_hash_end(rb_hash_start(index));
|
2010-03-21 03:24:44 +03:00
|
|
|
return LONG2FIX(h);
|
* string.c (rb_hash_uint32, rb_hash_uint, rb_hash_start, rb_hash_end),
include/ruby/intern.h: add Murmurhash API. [ruby-dev:37784]
* complex.c (nucomp_hash), array.c (rb_ary_hash), time.c (time_hash),
string.c (rb_str_hsah), object.c (rb_obj_hash), range.c
(range_hash), struct.c (rb_struct_hash), hash.c (rb_any_hash),
rational.c (nurat_hash): use Murmurhash. [ruby-dev:37784]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22317 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-14 22:55:34 +03:00
|
|
|
}
|
|
|
|
|
2007-12-09 19:39:49 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* !obj -> true or false
|
2007-12-09 19:39:49 +03:00
|
|
|
*
|
|
|
|
* Boolean negate.
|
|
|
|
*/
|
|
|
|
|
2007-12-18 15:07:51 +03:00
|
|
|
VALUE
|
2007-12-09 19:39:49 +03:00
|
|
|
rb_obj_not(VALUE obj)
|
|
|
|
{
|
|
|
|
return RTEST(obj) ? Qfalse : Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj != other -> true or false
|
2007-12-09 19:39:49 +03:00
|
|
|
*
|
|
|
|
* Returns true if two objects are not-equal, otherwise false.
|
|
|
|
*/
|
|
|
|
|
2007-12-18 15:07:51 +03:00
|
|
|
VALUE
|
2007-12-09 19:39:49 +03:00
|
|
|
rb_obj_not_equal(VALUE obj1, VALUE obj2)
|
|
|
|
{
|
|
|
|
VALUE result = rb_funcall(obj1, id_eq, 1, obj2);
|
|
|
|
return RTEST(result) ? Qfalse : Qtrue;
|
|
|
|
}
|
|
|
|
|
2001-07-14 19:17:19 +04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_class_real(VALUE cl)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2007-09-29 05:21:15 +04:00
|
|
|
if (cl == 0)
|
|
|
|
return 0;
|
2007-09-29 04:13:58 +04:00
|
|
|
while ((RBASIC(cl)->flags & FL_SINGLETON) || BUILTIN_TYPE(cl) == T_ICLASS) {
|
2007-09-28 10:21:46 +04:00
|
|
|
cl = RCLASS_SUPER(cl);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
return cl;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.class -> class
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2010-08-27 07:27:50 +04:00
|
|
|
* Returns the class of <i>obj</i>. This method must always be
|
2003-12-28 09:33:07 +03:00
|
|
|
* called with an explicit receiver, as <code>class</code> is also a
|
|
|
|
* reserved word in Ruby.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* 1.class #=> Fixnum
|
|
|
|
* self.class #=> Object
|
|
|
|
*/
|
|
|
|
|
2001-07-14 19:17:19 +04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_class(VALUE obj)
|
2001-07-14 19:17:19 +04:00
|
|
|
{
|
|
|
|
return rb_class_real(CLASS_OF(obj));
|
|
|
|
}
|
|
|
|
|
2010-03-23 12:38:54 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.singleton_class -> class
|
2010-03-23 12:38:54 +03:00
|
|
|
*
|
|
|
|
* Returns the singleton class of <i>obj</i>. This method creates
|
|
|
|
* a new singleton class if <i>obj</i> does not have it.
|
|
|
|
*
|
|
|
|
* If <i>obj</i> is <code>nil</code>, <code>true</code>, or
|
|
|
|
* <code>false</code>, it returns NilClass, TrueClass, or FalseClass,
|
|
|
|
* respectively.
|
|
|
|
* If <i>obj</i> is a Fixnum or a Symbol, it raises a TypeError.
|
|
|
|
*
|
|
|
|
* Object.new.singleton_class #=> #<Class:#<Object:0xb7ce1e24>>
|
|
|
|
* String.singleton_class #=> #<Class:String>
|
|
|
|
* nil.singleton_class #=> NilClass
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_obj_singleton_class(VALUE obj)
|
|
|
|
{
|
|
|
|
return rb_singleton_class(obj);
|
|
|
|
}
|
|
|
|
|
2002-09-03 09:20:14 +04:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
init_copy(VALUE dest, VALUE obj)
|
2002-09-03 09:20:14 +04:00
|
|
|
{
|
2002-09-04 10:37:39 +04:00
|
|
|
if (OBJ_FROZEN(dest)) {
|
2003-01-31 07:00:17 +03:00
|
|
|
rb_raise(rb_eTypeError, "[bug] frozen object (%s) allocated", rb_obj_classname(dest));
|
2002-09-04 10:37:39 +04:00
|
|
|
}
|
|
|
|
RBASIC(dest)->flags &= ~(T_MASK|FL_EXIVAR);
|
* safe.c (rb_set_safe_level, safe_setter): raise an ArgumentError
when $SAFE is set to 4. $SAFE=4 is now obsolete.
[ruby-core:55222] [Feature #8468]
* object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust):
Kernel#untrusted?, untrust, and trust are now deprecated.
Their behavior is same as tainted?, taint, and untaint,
respectively.
* include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED()
and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(),
respectively.
* array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c,
ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c,
ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c,
ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c,
ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c,
ext/socket/socket.c, ext/socket/udpsocket.c,
ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c,
ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c,
load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c,
safe.c, string.c, thread.c, transcode.c, variable.c,
vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for
$SAFE=4.
* test/dl/test_dl2.rb, test/erb/test_erb.rb,
test/readline/test_readline.rb,
test/readline/test_readline_history.rb, test/ruby/test_alias.rb,
test/ruby/test_array.rb, test/ruby/test_dir.rb,
test/ruby/test_encoding.rb, test/ruby/test_env.rb,
test/ruby/test_eval.rb, test/ruby/test_exception.rb,
test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb,
test/ruby/test_io.rb, test/ruby/test_method.rb,
test/ruby/test_module.rb, test/ruby/test_object.rb,
test/ruby/test_pack.rb, test/ruby/test_rand.rb,
test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb,
test/ruby/test_struct.rb, test/ruby/test_thread.rb,
test/ruby/test_time.rb: remove tests for $SAFE=4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-12 18:20:51 +04:00
|
|
|
RBASIC(dest)->flags |= RBASIC(obj)->flags & (T_MASK|FL_EXIVAR|FL_TAINT);
|
2004-05-14 20:39:15 +04:00
|
|
|
rb_copy_generic_ivar(dest, obj);
|
2002-12-04 10:39:32 +03:00
|
|
|
rb_gc_copy_finalizer(dest, obj);
|
2002-09-03 09:20:14 +04:00
|
|
|
switch (TYPE(obj)) {
|
|
|
|
case T_OBJECT:
|
2008-02-25 19:18:18 +03:00
|
|
|
if (!(RBASIC(dest)->flags & ROBJECT_EMBED) && ROBJECT_IVPTR(dest)) {
|
|
|
|
xfree(ROBJECT_IVPTR(dest));
|
|
|
|
ROBJECT(dest)->as.heap.ivptr = 0;
|
|
|
|
ROBJECT(dest)->as.heap.numiv = 0;
|
2008-02-13 14:52:46 +03:00
|
|
|
ROBJECT(dest)->as.heap.iv_index_tbl = 0;
|
2007-09-28 10:21:46 +04:00
|
|
|
}
|
|
|
|
if (RBASIC(obj)->flags & ROBJECT_EMBED) {
|
|
|
|
MEMCPY(ROBJECT(dest)->as.ary, ROBJECT(obj)->as.ary, VALUE, ROBJECT_EMBED_LEN_MAX);
|
|
|
|
RBASIC(dest)->flags |= ROBJECT_EMBED;
|
|
|
|
}
|
|
|
|
else {
|
2008-02-25 19:18:18 +03:00
|
|
|
long len = ROBJECT(obj)->as.heap.numiv;
|
2007-09-28 10:21:46 +04:00
|
|
|
VALUE *ptr = ALLOC_N(VALUE, len);
|
2008-02-25 19:18:18 +03:00
|
|
|
MEMCPY(ptr, ROBJECT(obj)->as.heap.ivptr, VALUE, len);
|
|
|
|
ROBJECT(dest)->as.heap.ivptr = ptr;
|
|
|
|
ROBJECT(dest)->as.heap.numiv = len;
|
2008-02-13 14:52:46 +03:00
|
|
|
ROBJECT(dest)->as.heap.iv_index_tbl = ROBJECT(obj)->as.heap.iv_index_tbl;
|
2007-09-28 10:21:46 +04:00
|
|
|
RBASIC(dest)->flags &= ~ROBJECT_EMBED;
|
|
|
|
}
|
|
|
|
break;
|
2002-09-03 09:20:14 +04:00
|
|
|
case T_CLASS:
|
|
|
|
case T_MODULE:
|
2007-09-28 10:21:46 +04:00
|
|
|
if (RCLASS_IV_TBL(dest)) {
|
|
|
|
st_free_table(RCLASS_IV_TBL(dest));
|
|
|
|
RCLASS_IV_TBL(dest) = 0;
|
2002-09-03 09:20:14 +04:00
|
|
|
}
|
2010-10-26 21:27:21 +04:00
|
|
|
if (RCLASS_CONST_TBL(dest)) {
|
2010-10-26 21:27:32 +04:00
|
|
|
rb_free_const_table(RCLASS_CONST_TBL(dest));
|
2010-10-26 21:27:21 +04:00
|
|
|
RCLASS_CONST_TBL(dest) = 0;
|
|
|
|
}
|
2007-09-28 10:21:46 +04:00
|
|
|
if (RCLASS_IV_TBL(obj)) {
|
2013-06-14 13:23:54 +04:00
|
|
|
RCLASS_IV_TBL(dest) = rb_st_copy(dest, RCLASS_IV_TBL(obj));
|
2002-09-03 09:20:14 +04:00
|
|
|
}
|
2007-09-28 10:21:46 +04:00
|
|
|
break;
|
2002-09-03 09:20:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* obj.clone -> an_object
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Produces a shallow copy of <i>obj</i>---the instance variables of
|
|
|
|
* <i>obj</i> are copied, but not the objects they reference. Copies
|
|
|
|
* the frozen and tainted state of <i>obj</i>. See also the discussion
|
|
|
|
* under <code>Object#dup</code>.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* class Klass
|
|
|
|
* attr_accessor :str
|
|
|
|
* end
|
|
|
|
* s1 = Klass.new #=> #<Klass:0x401b3a38>
|
|
|
|
* s1.str = "Hello" #=> "Hello"
|
|
|
|
* s2 = s1.clone #=> #<Klass:0x401b3998 @str="Hello">
|
|
|
|
* s2.str[1,4] = "i" #=> "i"
|
|
|
|
* s1.inspect #=> "#<Klass:0x401b3a38 @str=\"Hi\">"
|
|
|
|
* s2.inspect #=> "#<Klass:0x401b3998 @str=\"Hi\">"
|
2004-02-10 11:12:04 +03:00
|
|
|
*
|
|
|
|
* This method may have class-specific behavior. If so, that
|
|
|
|
* behavior will be documented under the #+initialize_copy+ method of
|
|
|
|
* the class.
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_clone(VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE clone;
|
2011-09-19 02:54:25 +04:00
|
|
|
VALUE singleton;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-10-10 12:21:13 +04:00
|
|
|
if (rb_special_const_p(obj)) {
|
2003-01-31 07:00:17 +03:00
|
|
|
rb_raise(rb_eTypeError, "can't clone %s", rb_obj_classname(obj));
|
2001-10-10 12:21:13 +04:00
|
|
|
}
|
2002-09-03 09:20:14 +04:00
|
|
|
clone = rb_obj_alloc(rb_obj_class(obj));
|
* safe.c (rb_set_safe_level, safe_setter): raise an ArgumentError
when $SAFE is set to 4. $SAFE=4 is now obsolete.
[ruby-core:55222] [Feature #8468]
* object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust):
Kernel#untrusted?, untrust, and trust are now deprecated.
Their behavior is same as tainted?, taint, and untaint,
respectively.
* include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED()
and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(),
respectively.
* array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c,
ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c,
ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c,
ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c,
ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c,
ext/socket/socket.c, ext/socket/udpsocket.c,
ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c,
ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c,
load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c,
safe.c, string.c, thread.c, transcode.c, variable.c,
vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for
$SAFE=4.
* test/dl/test_dl2.rb, test/erb/test_erb.rb,
test/readline/test_readline.rb,
test/readline/test_readline_history.rb, test/ruby/test_alias.rb,
test/ruby/test_array.rb, test/ruby/test_dir.rb,
test/ruby/test_encoding.rb, test/ruby/test_env.rb,
test/ruby/test_eval.rb, test/ruby/test_exception.rb,
test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb,
test/ruby/test_io.rb, test/ruby/test_method.rb,
test/ruby/test_module.rb, test/ruby/test_object.rb,
test/ruby/test_pack.rb, test/ruby/test_rand.rb,
test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb,
test/ruby/test_struct.rb, test/ruby/test_thread.rb,
test/ruby/test_time.rb: remove tests for $SAFE=4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-12 18:20:51 +04:00
|
|
|
RBASIC(clone)->flags &= FL_TAINT;
|
2013-05-23 22:01:46 +04:00
|
|
|
RBASIC(clone)->flags |= RBASIC(obj)->flags & ~(FL_OLDGEN|FL_FREEZE|FL_FINALIZE);
|
|
|
|
|
2012-12-29 06:37:47 +04:00
|
|
|
singleton = rb_singleton_class_clone_and_attach(obj, clone);
|
* include/ruby/ruby.h: constify RBasic::klass and add
RBASIC_CLASS(obj) macro which returns a class of `obj'.
This change is a part of RGENGC branch [ruby-trunk - Feature #8339].
* object.c: add new function rb_obj_reveal().
This function reveal interal (hidden) object by rb_obj_hide().
Note that do not change class before and after hiding.
Only permitted example is:
klass = RBASIC_CLASS(obj);
rb_obj_hide(obj);
....
rb_obj_reveal(obj, klass);
TODO: API design. rb_obj_reveal() should be replaced with others.
TODO: modify constified variables using cast may be harmful for
compiler's analysis and optimizaton.
Any idea to prohibt inserting RBasic::klass directly?
If rename RBasic::klass and force to use RBASIC_CLASS(obj),
then all codes such as `RBASIC(obj)->klass' will be
compilation error. Is it acceptable? (We have similar
experience at Ruby 1.9,
for example "RARRAY(ary)->ptr" to "RARRAY_PTR(ary)".
* internal.h: add some macros.
* RBASIC_CLEAR_CLASS(obj) clear RBasic::klass to make it internal
object.
* RBASIC_SET_CLASS(obj, cls) set RBasic::klass.
* RBASIC_SET_CLASS_RAW(obj, cls) same as RBASIC_SET_CLASS
without write barrier (planned).
* RCLASS_SET_SUPER(a, b) set super class of a.
* array.c, class.c, compile.c, encoding.c, enum.c, error.c, eval.c,
file.c, gc.c, hash.c, io.c, iseq.c, marshal.c, object.c,
parse.y, proc.c, process.c, random.c, ruby.c, sprintf.c,
string.c, thread.c, transcode.c, vm.c, vm_eval.c, win32/file.c:
Use above macros and functions to access RBasic::klass.
* ext/coverage/coverage.c, ext/readline/readline.c,
ext/socket/ancdata.c, ext/socket/init.c,
* ext/zlib/zlib.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 14:49:11 +04:00
|
|
|
RBASIC_SET_CLASS(clone, singleton);
|
2011-09-19 02:54:25 +04:00
|
|
|
if (FL_TEST(singleton, FL_SINGLETON)) {
|
|
|
|
rb_singleton_class_attached(singleton, clone);
|
|
|
|
}
|
2013-05-23 22:01:46 +04:00
|
|
|
|
2003-05-20 12:40:50 +04:00
|
|
|
init_copy(clone, obj);
|
2010-02-08 10:43:54 +03:00
|
|
|
rb_funcall(clone, id_init_clone, 1, obj);
|
2003-05-22 20:37:22 +04:00
|
|
|
RBASIC(clone)->flags |= RBASIC(obj)->flags & FL_FREEZE;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* obj.dup -> an_object
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Produces a shallow copy of <i>obj</i>---the instance variables of
|
|
|
|
* <i>obj</i> are copied, but not the objects they reference.
|
|
|
|
* <code>dup</code> copies the tainted state of <i>obj</i>. See also
|
|
|
|
* the discussion under <code>Object#clone</code>. In general,
|
|
|
|
* <code>clone</code> and <code>dup</code> may have different semantics
|
2009-11-03 20:46:28 +03:00
|
|
|
* in descendant classes. While <code>clone</code> is used to duplicate
|
2003-12-28 09:33:07 +03:00
|
|
|
* an object, including its internal state, <code>dup</code> typically
|
2009-11-03 20:46:28 +03:00
|
|
|
* uses the class of the descendant object to create the new instance.
|
2004-02-10 11:12:04 +03:00
|
|
|
*
|
|
|
|
* This method may have class-specific behavior. If so, that
|
|
|
|
* behavior will be documented under the #+initialize_copy+ method of
|
|
|
|
* the class.
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
2000-07-17 13:38:10 +04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_dup(VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-07-17 13:38:10 +04:00
|
|
|
VALUE dup;
|
2000-06-22 12:29:58 +04:00
|
|
|
|
2002-02-01 09:03:03 +03:00
|
|
|
if (rb_special_const_p(obj)) {
|
2003-01-31 07:00:17 +03:00
|
|
|
rb_raise(rb_eTypeError, "can't dup %s", rb_obj_classname(obj));
|
2002-02-01 09:03:03 +03:00
|
|
|
}
|
2002-09-03 09:20:14 +04:00
|
|
|
dup = rb_obj_alloc(rb_obj_class(obj));
|
2003-05-19 09:41:08 +04:00
|
|
|
init_copy(dup, obj);
|
2010-02-08 10:43:54 +03:00
|
|
|
rb_funcall(dup, id_init_dup, 1, obj);
|
2002-08-27 12:31:08 +04:00
|
|
|
|
|
|
|
return dup;
|
|
|
|
}
|
|
|
|
|
2004-01-18 17:16:47 +03:00
|
|
|
/* :nodoc: */
|
2002-08-27 12:31:08 +04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_init_copy(VALUE obj, VALUE orig)
|
2002-08-27 12:31:08 +04:00
|
|
|
{
|
2002-09-03 09:20:14 +04:00
|
|
|
if (obj == orig) return obj;
|
|
|
|
rb_check_frozen(obj);
|
2012-06-05 15:13:18 +04:00
|
|
|
rb_check_trusted(obj);
|
2002-09-03 09:20:14 +04:00
|
|
|
if (TYPE(obj) != TYPE(orig) || rb_obj_class(obj) != rb_obj_class(orig)) {
|
2003-05-19 09:41:08 +04:00
|
|
|
rb_raise(rb_eTypeError, "initialize_copy should take same class object");
|
2000-07-17 13:38:10 +04:00
|
|
|
}
|
2002-08-27 12:31:08 +04:00
|
|
|
return obj;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2010-02-08 10:43:54 +03:00
|
|
|
/* :nodoc: */
|
|
|
|
VALUE
|
|
|
|
rb_obj_init_dup_clone(VALUE obj, VALUE orig)
|
|
|
|
{
|
|
|
|
rb_funcall(obj, id_init_copy, 1, orig);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.to_s -> string
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Returns a string representing <i>obj</i>. The default
|
|
|
|
* <code>to_s</code> prints the object's class and an encoding of the
|
|
|
|
* object id. As a special case, the top-level object that is the
|
|
|
|
* initial execution context of Ruby programs returns ``main.''
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_any_to_s(VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE str;
|
2012-08-17 18:29:00 +04:00
|
|
|
VALUE cname = rb_class_name(CLASS_OF(obj));
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2012-08-17 18:29:00 +04:00
|
|
|
str = rb_sprintf("#<%"PRIsVALUE":%p>", cname, (void*)obj);
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
OBJ_INFECT(str, obj);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
return str;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2012-01-15 11:28:50 +04:00
|
|
|
/*
|
|
|
|
* If the default external encoding is ASCII compatible, the encoding of
|
|
|
|
* inspected result must be compatible with it.
|
2013-05-19 01:23:15 +04:00
|
|
|
* If the default external encoding is ASCII incompatible,
|
2012-01-15 11:28:50 +04:00
|
|
|
* the result must be ASCII only.
|
|
|
|
*/
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_inspect(VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-01-15 11:28:50 +04:00
|
|
|
VALUE str = rb_obj_as_string(rb_funcall(obj, id_inspect, 0, 0));
|
|
|
|
rb_encoding *ext = rb_default_external_encoding();
|
|
|
|
if (!rb_enc_asciicompat(ext)) {
|
|
|
|
if (!rb_enc_str_asciionly_p(str))
|
|
|
|
rb_raise(rb_eEncCompatError, "inspected result must be ASCII only if default external encoding is ASCII incompatible");
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
if (rb_enc_get(str) != ext && !rb_enc_str_asciionly_p(str))
|
2013-05-19 01:23:15 +04:00
|
|
|
rb_raise(rb_eEncCompatError, "inspected result must be ASCII only or use the default external encoding");
|
2012-01-15 11:28:50 +04:00
|
|
|
return str;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-03-31 02:40:54 +04:00
|
|
|
inspect_i(st_data_t k, st_data_t v, st_data_t a)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-03-31 02:40:54 +04:00
|
|
|
ID id = (ID)k;
|
|
|
|
VALUE value = (VALUE)v;
|
|
|
|
VALUE str = (VALUE)a;
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE str2;
|
* 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
|
|
|
const char *ivname;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
/* need not to show internal data */
|
|
|
|
if (CLASS_OF(value) == 0) return ST_CONTINUE;
|
1999-01-20 07:59:39 +03:00
|
|
|
if (!rb_is_instance_id(id)) return ST_CONTINUE;
|
2006-08-31 14:47:44 +04:00
|
|
|
if (RSTRING_PTR(str)[0] == '-') { /* first element */
|
|
|
|
RSTRING_PTR(str)[0] = '#';
|
2001-01-15 10:01:00 +03:00
|
|
|
rb_str_cat2(str, " ");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
2000-04-10 09:48:43 +04:00
|
|
|
rb_str_cat2(str, ", ");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
ivname = rb_id2name(id);
|
2000-04-10 09:48:43 +04:00
|
|
|
rb_str_cat2(str, ivname);
|
|
|
|
rb_str_cat2(str, "=");
|
1999-01-20 07:59:39 +03:00
|
|
|
str2 = rb_inspect(value);
|
2000-04-10 09:48:43 +04:00
|
|
|
rb_str_append(str, str2);
|
2000-02-23 08:23:12 +03:00
|
|
|
OBJ_INFECT(str, str2);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
inspect_obj(VALUE obj, VALUE str, int recur)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
if (recur) {
|
2005-03-07 05:05:08 +03:00
|
|
|
rb_str_cat2(str, " ...");
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
}
|
|
|
|
else {
|
2007-09-28 10:21:46 +04:00
|
|
|
rb_ivar_foreach(obj, inspect_i, str);
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
}
|
2000-04-10 09:48:43 +04:00
|
|
|
rb_str_cat2(str, ">");
|
2006-08-31 14:47:44 +04:00
|
|
|
RSTRING_PTR(str)[0] = '#';
|
2000-02-23 08:23:12 +03:00
|
|
|
OBJ_INFECT(str, obj);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.inspect -> string
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2012-01-06 11:06:22 +04:00
|
|
|
* Returns a string containing a human-readable representation of <i>obj</i>.
|
2012-08-15 15:50:01 +04:00
|
|
|
* By default, show the class name and the list of the instance variables and
|
|
|
|
* their values (by calling #inspect on each of them).
|
2012-01-06 11:06:22 +04:00
|
|
|
* User defined classes should override this method to make better
|
|
|
|
* representation of <i>obj</i>. When overriding this method, it should
|
|
|
|
* return a string whose encoding is compatible with the default external
|
|
|
|
* encoding.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* [ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]"
|
2008-03-09 04:04:46 +03:00
|
|
|
* Time.new.inspect #=> "2008-03-08 19:43:39 +0900"
|
2012-01-06 11:06:22 +04:00
|
|
|
*
|
|
|
|
* class Foo
|
|
|
|
* end
|
|
|
|
* Foo.new.inspect #=> "#<Foo:0x0300c868>"
|
|
|
|
*
|
|
|
|
* class Bar
|
|
|
|
* def initialize
|
|
|
|
* @bar = 1
|
|
|
|
* end
|
|
|
|
* end
|
|
|
|
* Bar.new.inspect #=> "#<Bar:0x0300c868 @bar=1>"
|
|
|
|
*
|
|
|
|
* class Baz
|
|
|
|
* def to_s
|
|
|
|
* "baz"
|
|
|
|
* end
|
|
|
|
* end
|
2012-08-15 15:50:01 +04:00
|
|
|
* Baz.new.inspect #=> "#<Baz:0x0300c868>"
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_inspect(VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-08-15 15:50:01 +04:00
|
|
|
if (rb_ivar_count(obj) > 0) {
|
|
|
|
VALUE str;
|
2012-08-17 18:29:00 +04:00
|
|
|
VALUE c = rb_class_name(CLASS_OF(obj));
|
2007-09-28 10:21:46 +04:00
|
|
|
|
2012-08-17 18:29:00 +04:00
|
|
|
str = rb_sprintf("-<%"PRIsVALUE":%p", c, (void*)obj);
|
2012-08-15 15:50:01 +04:00
|
|
|
return rb_exec_recursive(inspect_obj, obj, str);
|
2012-08-17 18:29:00 +04:00
|
|
|
}
|
|
|
|
else {
|
2009-10-22 00:17:27 +04:00
|
|
|
return rb_any_to_s(obj);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 04:31:00 +04:00
|
|
|
static VALUE
|
|
|
|
class_or_module_required(VALUE c)
|
|
|
|
{
|
|
|
|
if (SPECIAL_CONST_P(c)) goto not_class;
|
|
|
|
switch (BUILTIN_TYPE(c)) {
|
|
|
|
case T_MODULE:
|
|
|
|
case T_CLASS:
|
|
|
|
case T_ICLASS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
not_class:
|
|
|
|
rb_raise(rb_eTypeError, "class or module required");
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
2003-12-28 09:33:07 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.instance_of?(class) -> true or false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Returns <code>true</code> if <i>obj</i> is an instance of the given
|
|
|
|
* class. See also <code>Object#kind_of?</code>.
|
2012-01-11 21:19:54 +04:00
|
|
|
*
|
|
|
|
* class A; end
|
|
|
|
* class B < A; end
|
|
|
|
* class C < B; end
|
|
|
|
*
|
|
|
|
* b = B.new
|
|
|
|
* b.instance_of? A #=> false
|
|
|
|
* b.instance_of? B #=> true
|
|
|
|
* b.instance_of? C #=> false
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_is_instance_of(VALUE obj, VALUE c)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2012-06-01 04:31:00 +04:00
|
|
|
c = class_or_module_required(c);
|
2001-08-20 08:29:58 +04:00
|
|
|
if (rb_obj_class(obj) == c) return Qtrue;
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.is_a?(class) -> true or false
|
|
|
|
* obj.kind_of?(class) -> true or false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Returns <code>true</code> if <i>class</i> is the class of
|
|
|
|
* <i>obj</i>, or if <i>class</i> is one of the superclasses of
|
|
|
|
* <i>obj</i> or modules included in <i>obj</i>.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* module M; end
|
|
|
|
* class A
|
|
|
|
* include M
|
|
|
|
* end
|
|
|
|
* class B < A; end
|
|
|
|
* class C < B; end
|
2012-01-11 21:19:54 +04:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* b = B.new
|
2012-01-11 21:19:54 +04:00
|
|
|
* b.is_a? A #=> true
|
|
|
|
* b.is_a? B #=> true
|
|
|
|
* b.is_a? C #=> false
|
|
|
|
* b.is_a? M #=> true
|
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* b.kind_of? A #=> true
|
|
|
|
* b.kind_of? B #=> true
|
|
|
|
* b.kind_of? C #=> false
|
|
|
|
* b.kind_of? M #=> true
|
|
|
|
*/
|
2007-06-10 07:06:15 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_is_kind_of(VALUE obj, VALUE c)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE cl = CLASS_OF(obj);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2012-06-01 04:31:00 +04:00
|
|
|
c = class_or_module_required(c);
|
2013-05-02 18:23:56 +04:00
|
|
|
c = RCLASS_ORIGIN(c);
|
1998-01-16 15:19:22 +03:00
|
|
|
while (cl) {
|
2007-09-28 10:21:46 +04:00
|
|
|
if (cl == c || RCLASS_M_TBL(cl) == RCLASS_M_TBL(c))
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qtrue;
|
2007-09-28 10:21:46 +04:00
|
|
|
cl = RCLASS_SUPER(cl);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
|
2006-11-22 11:37:12 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.tap{|x|...} -> obj
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2007-11-08 11:12:59 +03:00
|
|
|
* Yields <code>x</code> to the block, and then returns <code>x</code>.
|
|
|
|
* The primary purpose of this method is to "tap into" a method chain,
|
|
|
|
* in order to perform operations on intermediate results within the chain.
|
|
|
|
*
|
|
|
|
* (1..10) .tap {|x| puts "original: #{x.inspect}"}
|
|
|
|
* .to_a .tap {|x| puts "array: #{x.inspect}"}
|
|
|
|
* .select {|x| x%2==0} .tap {|x| puts "evens: #{x.inspect}"}
|
|
|
|
* .map { |x| x*x } .tap {|x| puts "squares: #{x.inspect}"}
|
|
|
|
*
|
2006-11-22 11:37:12 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_obj_tap(VALUE obj)
|
|
|
|
{
|
|
|
|
rb_yield(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-13 13:25:15 +04:00
|
|
|
/*
|
|
|
|
* Document-method: inherited
|
|
|
|
*
|
|
|
|
* call-seq:
|
|
|
|
* inherited(subclass)
|
|
|
|
*
|
|
|
|
* Callback invoked whenever a subclass of the current class is created.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
|
|
|
* class Foo
|
2012-03-17 01:57:24 +04:00
|
|
|
* def self.inherited(subclass)
|
|
|
|
* puts "New subclass: #{subclass}"
|
|
|
|
* end
|
2006-10-13 13:25:15 +04:00
|
|
|
* end
|
|
|
|
*
|
|
|
|
* class Bar < Foo
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* class Baz < Bar
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* produces:
|
|
|
|
*
|
|
|
|
* New subclass: Bar
|
|
|
|
* New subclass: Baz
|
|
|
|
*/
|
|
|
|
|
2011-06-17 04:11:20 +04:00
|
|
|
/* Document-method: method_added
|
|
|
|
*
|
|
|
|
* call-seq:
|
|
|
|
* method_added(method_name)
|
|
|
|
*
|
|
|
|
* Invoked as a callback whenever an instance method is added to the
|
|
|
|
* receiver.
|
|
|
|
*
|
|
|
|
* module Chatty
|
|
|
|
* def self.method_added(method_name)
|
|
|
|
* puts "Adding #{method_name.inspect}"
|
|
|
|
* end
|
|
|
|
* def self.some_class_method() end
|
|
|
|
* def some_instance_method() end
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* produces:
|
|
|
|
*
|
|
|
|
* Adding :some_instance_method
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Document-method: method_removed
|
|
|
|
*
|
|
|
|
* call-seq:
|
|
|
|
* method_removed(method_name)
|
|
|
|
*
|
|
|
|
* Invoked as a callback whenever an instance method is removed from the
|
|
|
|
* receiver.
|
|
|
|
*
|
|
|
|
* module Chatty
|
|
|
|
* def self.method_removed(method_name)
|
|
|
|
* puts "Removing #{method_name.inspect}"
|
|
|
|
* end
|
|
|
|
* def self.some_class_method() end
|
|
|
|
* def some_instance_method() end
|
|
|
|
* class << self
|
|
|
|
* remove_method :some_class_method
|
|
|
|
* end
|
|
|
|
* remove_method :some_instance_method
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* produces:
|
|
|
|
*
|
|
|
|
* Removing :some_instance_method
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
2004-08-30 18:23:19 +04:00
|
|
|
* Document-method: singleton_method_added
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* call-seq:
|
|
|
|
* singleton_method_added(symbol)
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Invoked as a callback whenever a singleton method is added to the
|
|
|
|
* receiver.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* module Chatty
|
|
|
|
* def Chatty.singleton_method_added(id)
|
|
|
|
* puts "Adding #{id.id2name}"
|
|
|
|
* end
|
|
|
|
* def self.one() end
|
|
|
|
* def two() end
|
|
|
|
* def Chatty.three() end
|
|
|
|
* end
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* <em>produces:</em>
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Adding singleton_method_added
|
|
|
|
* Adding one
|
|
|
|
* Adding three
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2004-08-30 18:23:19 +04:00
|
|
|
* Document-method: singleton_method_removed
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* call-seq:
|
|
|
|
* singleton_method_removed(symbol)
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Invoked as a callback whenever a singleton method is removed from
|
|
|
|
* the receiver.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* module Chatty
|
|
|
|
* def Chatty.singleton_method_removed(id)
|
|
|
|
* puts "Removing #{id.id2name}"
|
|
|
|
* end
|
|
|
|
* def self.one() end
|
|
|
|
* def two() end
|
|
|
|
* def Chatty.three() end
|
2010-05-23 12:48:44 +04:00
|
|
|
* class << self
|
2003-12-28 09:33:07 +03:00
|
|
|
* remove_method :three
|
|
|
|
* remove_method :one
|
|
|
|
* end
|
|
|
|
* end
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* <em>produces:</em>
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Removing three
|
|
|
|
* Removing one
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2004-08-30 18:23:19 +04:00
|
|
|
* Document-method: singleton_method_undefined
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* call-seq:
|
|
|
|
* singleton_method_undefined(symbol)
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Invoked as a callback whenever a singleton method is undefined in
|
|
|
|
* the receiver.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* module Chatty
|
|
|
|
* def Chatty.singleton_method_undefined(id)
|
|
|
|
* puts "Undefining #{id.id2name}"
|
|
|
|
* end
|
|
|
|
* def Chatty.one() end
|
|
|
|
* class << self
|
|
|
|
* undef_method(:one)
|
|
|
|
* end
|
|
|
|
* end
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* <em>produces:</em>
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Undefining one
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2004-08-30 18:23:19 +04:00
|
|
|
/*
|
|
|
|
* Document-method: included
|
|
|
|
*
|
|
|
|
* call-seq:
|
|
|
|
* included( othermod )
|
|
|
|
*
|
|
|
|
* Callback invoked whenever the receiver is included in another
|
|
|
|
* module or class. This should be used in preference to
|
|
|
|
* <tt>Module.append_features</tt> if your code wants to perform some
|
|
|
|
* action when a module is included in another.
|
|
|
|
*
|
|
|
|
* module A
|
|
|
|
* def A.included(mod)
|
|
|
|
* puts "#{self} included in #{mod}"
|
|
|
|
* end
|
|
|
|
* end
|
|
|
|
* module Enumerable
|
|
|
|
* include A
|
|
|
|
* end
|
2013-02-23 03:18:33 +04:00
|
|
|
* # => prints "A included in Enumerable"
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-method: prepended
|
|
|
|
*
|
|
|
|
* call-seq:
|
|
|
|
* prepended( othermod )
|
|
|
|
*
|
|
|
|
* The equivalent of <tt>included</tt>, but for prepended modules.
|
|
|
|
*
|
|
|
|
* module A
|
|
|
|
* def self.prepended(mod)
|
|
|
|
* puts "#{self} prepended to #{mod}"
|
|
|
|
* end
|
|
|
|
* end
|
|
|
|
* module Enumerable
|
|
|
|
* prepend A
|
|
|
|
* end
|
|
|
|
* # => prints "A prepended to Enumerable"
|
2004-08-30 18:23:19 +04:00
|
|
|
*/
|
|
|
|
|
2009-12-21 02:05:07 +03:00
|
|
|
/*
|
|
|
|
* Document-method: initialize
|
|
|
|
*
|
|
|
|
* call-seq:
|
2010-10-30 05:25:41 +04:00
|
|
|
* BasicObject.new
|
2009-12-21 02:05:07 +03:00
|
|
|
*
|
2010-10-30 05:25:41 +04:00
|
|
|
* Returns a new BasicObject.
|
2009-12-21 02:05:07 +03:00
|
|
|
*/
|
2004-08-30 18:23:19 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Not documented
|
|
|
|
*/
|
2003-12-28 09:33:07 +03:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_dummy(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.tainted? -> true or false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2013-04-28 05:35:56 +04:00
|
|
|
* Returns true if the object is tainted.
|
2013-04-28 04:51:46 +04:00
|
|
|
*
|
|
|
|
* See #taint for more information.
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_tainted(VALUE obj)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
|
|
|
if (OBJ_TAINTED(obj))
|
|
|
|
return Qtrue;
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* obj.taint -> obj
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2013-04-28 04:51:46 +04:00
|
|
|
* Mark the object as tainted.
|
|
|
|
*
|
|
|
|
* Objects that are marked as tainted will be restricted from various built-in
|
|
|
|
* methods. This is to prevent insecure data, such as command-line arguments
|
|
|
|
* or strings read from Kernel#gets, from inadvertently compromising the users
|
|
|
|
* system.
|
|
|
|
*
|
2013-04-28 05:35:56 +04:00
|
|
|
* To check whether an object is tainted, use #tainted?
|
|
|
|
*
|
2013-04-28 04:51:46 +04:00
|
|
|
* You should only untaint a tainted object if your code has inspected it and
|
|
|
|
* determined that it is safe. To do so use #untaint
|
|
|
|
*
|
2013-04-28 05:35:56 +04:00
|
|
|
* In $SAFE level 3 and 4, all objects are tainted and untrusted, any use of
|
|
|
|
* trust or taint methods will raise a SecurityError exception.
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_taint(VALUE obj)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
2001-01-18 11:43:14 +03:00
|
|
|
if (!OBJ_TAINTED(obj)) {
|
* array.c, gc.c, hash.c, object.c, string.c, struct.c,
transcode.c, variable.c, vm.c, vm_insnhelper.c, vm_method.c:
replace calls to rb_error_frozen() with rb_check_frozen(). a
patch from Run Paint Run Run at [ruby-core:32014]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-24 12:14:05 +04:00
|
|
|
rb_check_frozen(obj);
|
2001-01-15 10:01:00 +03:00
|
|
|
OBJ_TAINT(obj);
|
2001-01-09 19:55:50 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.untaint -> obj
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2013-04-28 04:51:46 +04:00
|
|
|
* Removes the tainted mark from the object.
|
|
|
|
*
|
|
|
|
* See #taint for more information.
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_untaint(VALUE obj)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
|
|
|
rb_secure(3);
|
2001-01-18 11:43:14 +03:00
|
|
|
if (OBJ_TAINTED(obj)) {
|
* array.c, gc.c, hash.c, object.c, string.c, struct.c,
transcode.c, variable.c, vm.c, vm_insnhelper.c, vm_method.c:
replace calls to rb_error_frozen() with rb_check_frozen(). a
patch from Run Paint Run Run at [ruby-core:32014]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-24 12:14:05 +04:00
|
|
|
rb_check_frozen(obj);
|
2001-01-15 10:01:00 +03:00
|
|
|
FL_UNSET(obj, FL_TAINT);
|
2001-01-09 19:55:50 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.untrusted? -> true or false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
* safe.c (rb_set_safe_level, safe_setter): raise an ArgumentError
when $SAFE is set to 4. $SAFE=4 is now obsolete.
[ruby-core:55222] [Feature #8468]
* object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust):
Kernel#untrusted?, untrust, and trust are now deprecated.
Their behavior is same as tainted?, taint, and untaint,
respectively.
* include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED()
and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(),
respectively.
* array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c,
ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c,
ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c,
ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c,
ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c,
ext/socket/socket.c, ext/socket/udpsocket.c,
ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c,
ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c,
load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c,
safe.c, string.c, thread.c, transcode.c, variable.c,
vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for
$SAFE=4.
* test/dl/test_dl2.rb, test/erb/test_erb.rb,
test/readline/test_readline.rb,
test/readline/test_readline_history.rb, test/ruby/test_alias.rb,
test/ruby/test_array.rb, test/ruby/test_dir.rb,
test/ruby/test_encoding.rb, test/ruby/test_env.rb,
test/ruby/test_eval.rb, test/ruby/test_exception.rb,
test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb,
test/ruby/test_io.rb, test/ruby/test_method.rb,
test/ruby/test_module.rb, test/ruby/test_object.rb,
test/ruby/test_pack.rb, test/ruby/test_rand.rb,
test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb,
test/ruby/test_struct.rb, test/ruby/test_thread.rb,
test/ruby/test_time.rb: remove tests for $SAFE=4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-12 18:20:51 +04:00
|
|
|
* Deprecated method that is equivalent to #tainted?.
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_obj_untrusted(VALUE obj)
|
|
|
|
{
|
* safe.c (rb_set_safe_level, safe_setter): raise an ArgumentError
when $SAFE is set to 4. $SAFE=4 is now obsolete.
[ruby-core:55222] [Feature #8468]
* object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust):
Kernel#untrusted?, untrust, and trust are now deprecated.
Their behavior is same as tainted?, taint, and untaint,
respectively.
* include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED()
and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(),
respectively.
* array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c,
ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c,
ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c,
ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c,
ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c,
ext/socket/socket.c, ext/socket/udpsocket.c,
ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c,
ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c,
load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c,
safe.c, string.c, thread.c, transcode.c, variable.c,
vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for
$SAFE=4.
* test/dl/test_dl2.rb, test/erb/test_erb.rb,
test/readline/test_readline.rb,
test/readline/test_readline_history.rb, test/ruby/test_alias.rb,
test/ruby/test_array.rb, test/ruby/test_dir.rb,
test/ruby/test_encoding.rb, test/ruby/test_env.rb,
test/ruby/test_eval.rb, test/ruby/test_exception.rb,
test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb,
test/ruby/test_io.rb, test/ruby/test_method.rb,
test/ruby/test_module.rb, test/ruby/test_object.rb,
test/ruby/test_pack.rb, test/ruby/test_rand.rb,
test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb,
test/ruby/test_struct.rb, test/ruby/test_thread.rb,
test/ruby/test_time.rb: remove tests for $SAFE=4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-12 18:20:51 +04:00
|
|
|
rb_warning("untrusted? is deprecated and its behavior is same as tainted?");
|
|
|
|
return rb_obj_tainted(obj);
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* obj.untrust -> obj
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
* safe.c (rb_set_safe_level, safe_setter): raise an ArgumentError
when $SAFE is set to 4. $SAFE=4 is now obsolete.
[ruby-core:55222] [Feature #8468]
* object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust):
Kernel#untrusted?, untrust, and trust are now deprecated.
Their behavior is same as tainted?, taint, and untaint,
respectively.
* include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED()
and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(),
respectively.
* array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c,
ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c,
ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c,
ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c,
ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c,
ext/socket/socket.c, ext/socket/udpsocket.c,
ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c,
ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c,
load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c,
safe.c, string.c, thread.c, transcode.c, variable.c,
vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for
$SAFE=4.
* test/dl/test_dl2.rb, test/erb/test_erb.rb,
test/readline/test_readline.rb,
test/readline/test_readline_history.rb, test/ruby/test_alias.rb,
test/ruby/test_array.rb, test/ruby/test_dir.rb,
test/ruby/test_encoding.rb, test/ruby/test_env.rb,
test/ruby/test_eval.rb, test/ruby/test_exception.rb,
test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb,
test/ruby/test_io.rb, test/ruby/test_method.rb,
test/ruby/test_module.rb, test/ruby/test_object.rb,
test/ruby/test_pack.rb, test/ruby/test_rand.rb,
test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb,
test/ruby/test_struct.rb, test/ruby/test_thread.rb,
test/ruby/test_time.rb: remove tests for $SAFE=4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-12 18:20:51 +04:00
|
|
|
* Deprecated method that is equivalent to #taint.
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_obj_untrust(VALUE obj)
|
|
|
|
{
|
* safe.c (rb_set_safe_level, safe_setter): raise an ArgumentError
when $SAFE is set to 4. $SAFE=4 is now obsolete.
[ruby-core:55222] [Feature #8468]
* object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust):
Kernel#untrusted?, untrust, and trust are now deprecated.
Their behavior is same as tainted?, taint, and untaint,
respectively.
* include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED()
and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(),
respectively.
* array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c,
ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c,
ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c,
ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c,
ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c,
ext/socket/socket.c, ext/socket/udpsocket.c,
ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c,
ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c,
load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c,
safe.c, string.c, thread.c, transcode.c, variable.c,
vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for
$SAFE=4.
* test/dl/test_dl2.rb, test/erb/test_erb.rb,
test/readline/test_readline.rb,
test/readline/test_readline_history.rb, test/ruby/test_alias.rb,
test/ruby/test_array.rb, test/ruby/test_dir.rb,
test/ruby/test_encoding.rb, test/ruby/test_env.rb,
test/ruby/test_eval.rb, test/ruby/test_exception.rb,
test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb,
test/ruby/test_io.rb, test/ruby/test_method.rb,
test/ruby/test_module.rb, test/ruby/test_object.rb,
test/ruby/test_pack.rb, test/ruby/test_rand.rb,
test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb,
test/ruby/test_struct.rb, test/ruby/test_thread.rb,
test/ruby/test_time.rb: remove tests for $SAFE=4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-12 18:20:51 +04:00
|
|
|
rb_warning("untrust is deprecated and its behavior is same as taint");
|
|
|
|
return rb_obj_taint(obj);
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.trust -> obj
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
* safe.c (rb_set_safe_level, safe_setter): raise an ArgumentError
when $SAFE is set to 4. $SAFE=4 is now obsolete.
[ruby-core:55222] [Feature #8468]
* object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust):
Kernel#untrusted?, untrust, and trust are now deprecated.
Their behavior is same as tainted?, taint, and untaint,
respectively.
* include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED()
and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(),
respectively.
* array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c,
ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c,
ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c,
ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c,
ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c,
ext/socket/socket.c, ext/socket/udpsocket.c,
ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c,
ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c,
load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c,
safe.c, string.c, thread.c, transcode.c, variable.c,
vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for
$SAFE=4.
* test/dl/test_dl2.rb, test/erb/test_erb.rb,
test/readline/test_readline.rb,
test/readline/test_readline_history.rb, test/ruby/test_alias.rb,
test/ruby/test_array.rb, test/ruby/test_dir.rb,
test/ruby/test_encoding.rb, test/ruby/test_env.rb,
test/ruby/test_eval.rb, test/ruby/test_exception.rb,
test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb,
test/ruby/test_io.rb, test/ruby/test_method.rb,
test/ruby/test_module.rb, test/ruby/test_object.rb,
test/ruby/test_pack.rb, test/ruby/test_rand.rb,
test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb,
test/ruby/test_struct.rb, test/ruby/test_thread.rb,
test/ruby/test_time.rb: remove tests for $SAFE=4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-12 18:20:51 +04:00
|
|
|
* Deprecated method that is equivalent to #untaint.
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_obj_trust(VALUE obj)
|
|
|
|
{
|
* safe.c (rb_set_safe_level, safe_setter): raise an ArgumentError
when $SAFE is set to 4. $SAFE=4 is now obsolete.
[ruby-core:55222] [Feature #8468]
* object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust):
Kernel#untrusted?, untrust, and trust are now deprecated.
Their behavior is same as tainted?, taint, and untaint,
respectively.
* include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED()
and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(),
respectively.
* array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c,
ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c,
ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c,
ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c,
ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c,
ext/socket/socket.c, ext/socket/udpsocket.c,
ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c,
ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c,
load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c,
safe.c, string.c, thread.c, transcode.c, variable.c,
vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for
$SAFE=4.
* test/dl/test_dl2.rb, test/erb/test_erb.rb,
test/readline/test_readline.rb,
test/readline/test_readline_history.rb, test/ruby/test_alias.rb,
test/ruby/test_array.rb, test/ruby/test_dir.rb,
test/ruby/test_encoding.rb, test/ruby/test_env.rb,
test/ruby/test_eval.rb, test/ruby/test_exception.rb,
test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb,
test/ruby/test_io.rb, test/ruby/test_method.rb,
test/ruby/test_module.rb, test/ruby/test_object.rb,
test/ruby/test_pack.rb, test/ruby/test_rand.rb,
test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb,
test/ruby/test_struct.rb, test/ruby/test_thread.rb,
test/ruby/test_time.rb: remove tests for $SAFE=4.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-12 18:20:51 +04:00
|
|
|
rb_warning("trust is deprecated and its behavior is same as untaint");
|
|
|
|
return rb_obj_untaint(obj);
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
}
|
|
|
|
|
2003-03-25 06:11:27 +03:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_infect(VALUE obj1, VALUE obj2)
|
2003-03-25 06:11:27 +03:00
|
|
|
{
|
|
|
|
OBJ_INFECT(obj1, obj2);
|
|
|
|
}
|
|
|
|
|
2007-12-18 11:28:39 +03:00
|
|
|
static st_table *immediate_frozen_tbl = 0;
|
2003-12-28 09:33:07 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.freeze -> obj
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Prevents further modifications to <i>obj</i>. A
|
2008-08-29 21:49:18 +04:00
|
|
|
* <code>RuntimeError</code> will be raised if modification is attempted.
|
2003-12-28 09:33:07 +03:00
|
|
|
* There is no way to unfreeze a frozen object. See also
|
|
|
|
* <code>Object#frozen?</code>.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2009-05-24 17:37:43 +04:00
|
|
|
* This method returns self.
|
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* a = [ "a", "b", "c" ]
|
|
|
|
* a.freeze
|
|
|
|
* a << "z"
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* <em>produces:</em>
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2008-08-29 21:49:18 +04:00
|
|
|
* prog.rb:3:in `<<': can't modify frozen array (RuntimeError)
|
2003-12-28 09:33:07 +03:00
|
|
|
* from prog.rb:3
|
|
|
|
*/
|
|
|
|
|
2000-02-01 06:12:21 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_freeze(VALUE obj)
|
2000-02-01 06:12:21 +03:00
|
|
|
{
|
2001-01-18 11:43:14 +03:00
|
|
|
if (!OBJ_FROZEN(obj)) {
|
2001-01-15 10:01:00 +03:00
|
|
|
OBJ_FREEZE(obj);
|
2007-12-18 11:28:39 +03:00
|
|
|
if (SPECIAL_CONST_P(obj)) {
|
|
|
|
if (!immediate_frozen_tbl) {
|
|
|
|
immediate_frozen_tbl = st_init_numtable();
|
|
|
|
}
|
|
|
|
st_insert(immediate_frozen_tbl, obj, (st_data_t)Qtrue);
|
|
|
|
}
|
2001-01-15 10:01:00 +03:00
|
|
|
}
|
2000-02-01 06:12:21 +03:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.frozen? -> true or false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Returns the freeze status of <i>obj</i>.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* a = [ "a", "b", "c" ]
|
|
|
|
* a.freeze #=> ["a", "b", "c"]
|
|
|
|
* a.frozen? #=> true
|
|
|
|
*/
|
|
|
|
|
2007-12-18 11:28:39 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_frozen_p(VALUE obj)
|
2000-02-01 06:12:21 +03:00
|
|
|
{
|
|
|
|
if (OBJ_FROZEN(obj)) return Qtrue;
|
2007-12-18 11:28:39 +03:00
|
|
|
if (SPECIAL_CONST_P(obj)) {
|
|
|
|
if (!immediate_frozen_tbl) return Qfalse;
|
|
|
|
if (st_lookup(immediate_frozen_tbl, obj, 0)) return Qtrue;
|
|
|
|
}
|
2000-02-01 06:12:21 +03:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
|
|
|
|
/*
|
2003-12-28 23:47:56 +03:00
|
|
|
* Document-class: NilClass
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* The class of the singleton object <code>nil</code>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* nil.to_i -> 0
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Always returns zero.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* nil.to_i #=> 0
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
nil_to_i(VALUE obj)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
|
|
|
return INT2FIX(0);
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* nil.to_f -> 0.0
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Always returns zero.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* nil.to_f #=> 0.0
|
|
|
|
*/
|
|
|
|
|
2002-06-28 18:42:46 +04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
nil_to_f(VALUE obj)
|
2002-06-28 18:42:46 +04:00
|
|
|
{
|
2008-09-05 22:24:21 +04:00
|
|
|
return DBL2NUM(0.0);
|
2002-06-28 18:42:46 +04:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* nil.to_s -> ""
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2006-09-07 20:11:28 +04:00
|
|
|
* Always returns the empty string.
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
nil_to_s(VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-02-28 21:13:45 +03:00
|
|
|
return rb_usascii_str_new(0, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2005-10-21 13:00:02 +04:00
|
|
|
/*
|
2006-11-06 13:27:59 +03:00
|
|
|
* Document-method: to_a
|
|
|
|
*
|
2005-10-21 13:00:02 +04:00
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* nil.to_a -> []
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2005-10-21 13:00:02 +04:00
|
|
|
* Always returns an empty array.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2005-10-21 13:00:02 +04:00
|
|
|
* nil.to_a #=> []
|
|
|
|
*/
|
|
|
|
|
|
|
|
static 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
|
|
|
nil_to_a(VALUE obj)
|
2005-10-21 13:00:02 +04:00
|
|
|
{
|
|
|
|
return rb_ary_new2(0);
|
|
|
|
}
|
|
|
|
|
2012-04-24 07:46:55 +04:00
|
|
|
/*
|
|
|
|
* Document-method: to_h
|
|
|
|
*
|
|
|
|
* call-seq:
|
|
|
|
* nil.to_h -> {}
|
|
|
|
*
|
|
|
|
* Always returns an empty hash.
|
|
|
|
*
|
|
|
|
* nil.to_h #=> {}
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
nil_to_h(VALUE obj)
|
|
|
|
{
|
|
|
|
return rb_hash_new();
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* nil.inspect -> "nil"
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* Always returns the string "nil".
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
nil_inspect(VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
* string.c (rb_str_usascii_new{,2}: defined.
(rb_str_new): set US-ASCII and ENC_CODERANGE_7BIT when empty
string.
* encoding.c (rb_usascii_encoding, rb_usascii_encindex): defined.
(rb_enc_inspect, enc_name, rb_locale_charmap, rb_enc_name_list_i):
use rb_str_ascii_new.
* array.c (recursive_join, inspect_ary): ditto.
* object.c (nil_to_s, nil_inspect, true_to_s, false_to_s,
rb_mod_to_s): ditto.
* hash.c (inspect_hash, rb_hash_inspect, rb_f_getenv, env_fetch,
env_clear, env_to_s, env_inspect): ditto.
* numeric.c (flo_to_s, int_chr, rb_fix2str): ditto.
* bignum.c (rb_big2str): ditto.
* file.c (rb_file_ftype, rb_file_s_dirname, rb_file_s_extname,
file_inspect_join, Init_file): ditto.
* test/ruby/test_ruby_m17n.rb: add checks for encoding of string.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-01-25 19:40:02 +03:00
|
|
|
return rb_usascii_str_new2("nil");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 09:09:08 +03:00
|
|
|
/***********************************************************************
|
2004-01-12 06:11:25 +03:00
|
|
|
* Document-class: TrueClass
|
2003-12-27 09:09:08 +03:00
|
|
|
*
|
|
|
|
* The global value <code>true</code> is the only instance of class
|
|
|
|
* <code>TrueClass</code> and represents a logically true value in
|
|
|
|
* boolean expressions. The class provides operators allowing
|
|
|
|
* <code>true</code> to be used in logical expressions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* true.to_s -> "true"
|
2003-12-27 09:09:08 +03:00
|
|
|
*
|
|
|
|
* The string representation of <code>true</code> is "true".
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
true_to_s(VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
* string.c (rb_str_usascii_new{,2}: defined.
(rb_str_new): set US-ASCII and ENC_CODERANGE_7BIT when empty
string.
* encoding.c (rb_usascii_encoding, rb_usascii_encindex): defined.
(rb_enc_inspect, enc_name, rb_locale_charmap, rb_enc_name_list_i):
use rb_str_ascii_new.
* array.c (recursive_join, inspect_ary): ditto.
* object.c (nil_to_s, nil_inspect, true_to_s, false_to_s,
rb_mod_to_s): ditto.
* hash.c (inspect_hash, rb_hash_inspect, rb_f_getenv, env_fetch,
env_clear, env_to_s, env_inspect): ditto.
* numeric.c (flo_to_s, int_chr, rb_fix2str): ditto.
* bignum.c (rb_big2str): ditto.
* file.c (rb_file_ftype, rb_file_s_dirname, rb_file_s_extname,
file_inspect_join, Init_file): ditto.
* test/ruby/test_ruby_m17n.rb: add checks for encoding of string.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-01-25 19:40:02 +03:00
|
|
|
return rb_usascii_str_new2("true");
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 09:09:08 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* true & obj -> true or false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-27 09:09:08 +03:00
|
|
|
* And---Returns <code>false</code> if <i>obj</i> is
|
|
|
|
* <code>nil</code> or <code>false</code>, <code>true</code> otherwise.
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
true_and(VALUE obj, VALUE obj2)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
|
|
|
return RTEST(obj2)?Qtrue:Qfalse;
|
|
|
|
}
|
|
|
|
|
2003-12-27 09:09:08 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* true | obj -> true
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-27 09:09:08 +03:00
|
|
|
* Or---Returns <code>true</code>. As <i>anObject</i> is an argument to
|
|
|
|
* a method call, it is always evaluated; there is no short-circuit
|
|
|
|
* evaluation in this case.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-27 09:09:08 +03:00
|
|
|
* true | puts("or")
|
|
|
|
* true || puts("logical or")
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-27 09:09:08 +03:00
|
|
|
* <em>produces:</em>
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-27 09:09:08 +03:00
|
|
|
* or
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
true_or(VALUE obj, VALUE obj2)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
2003-12-27 09:09:08 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* true ^ obj -> !obj
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-27 09:09:08 +03:00
|
|
|
* Exclusive Or---Returns <code>true</code> if <i>obj</i> is
|
|
|
|
* <code>nil</code> or <code>false</code>, <code>false</code>
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
true_xor(VALUE obj, VALUE obj2)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
|
|
|
return RTEST(obj2)?Qfalse:Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-21 10:28:54 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-class: FalseClass
|
|
|
|
*
|
|
|
|
* The global value <code>false</code> is the only instance of class
|
|
|
|
* <code>FalseClass</code> and represents a logically false value in
|
|
|
|
* boolean expressions. The class provides operators allowing
|
|
|
|
* <code>false</code> to participate correctly in logical expressions.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-21 10:28:54 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* false.to_s -> "false"
|
2003-12-21 10:28:54 +03:00
|
|
|
*
|
|
|
|
* 'nuf said...
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
false_to_s(VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
* string.c (rb_str_usascii_new{,2}: defined.
(rb_str_new): set US-ASCII and ENC_CODERANGE_7BIT when empty
string.
* encoding.c (rb_usascii_encoding, rb_usascii_encindex): defined.
(rb_enc_inspect, enc_name, rb_locale_charmap, rb_enc_name_list_i):
use rb_str_ascii_new.
* array.c (recursive_join, inspect_ary): ditto.
* object.c (nil_to_s, nil_inspect, true_to_s, false_to_s,
rb_mod_to_s): ditto.
* hash.c (inspect_hash, rb_hash_inspect, rb_f_getenv, env_fetch,
env_clear, env_to_s, env_inspect): ditto.
* numeric.c (flo_to_s, int_chr, rb_fix2str): ditto.
* bignum.c (rb_big2str): ditto.
* file.c (rb_file_ftype, rb_file_s_dirname, rb_file_s_extname,
file_inspect_join, Init_file): ditto.
* test/ruby/test_ruby_m17n.rb: add checks for encoding of string.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-01-25 19:40:02 +03:00
|
|
|
return rb_usascii_str_new2("false");
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
2003-12-21 10:28:54 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* false & obj -> false
|
|
|
|
* nil & obj -> false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-21 10:28:54 +03:00
|
|
|
* And---Returns <code>false</code>. <i>obj</i> is always
|
|
|
|
* evaluated as it is the argument to a method call---there is no
|
|
|
|
* short-circuit evaluation in this case.
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
false_and(VALUE obj, VALUE obj2)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
2003-12-21 10:28:54 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* false | obj -> true or false
|
|
|
|
* nil | obj -> true or false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-21 10:28:54 +03:00
|
|
|
* Or---Returns <code>false</code> if <i>obj</i> is
|
|
|
|
* <code>nil</code> or <code>false</code>; <code>true</code> otherwise.
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
false_or(VALUE obj, VALUE obj2)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
|
|
|
return RTEST(obj2)?Qtrue:Qfalse;
|
|
|
|
}
|
|
|
|
|
2003-12-21 10:28:54 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* false ^ obj -> true or false
|
|
|
|
* nil ^ obj -> true or false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-21 10:28:54 +03:00
|
|
|
* Exclusive Or---If <i>obj</i> is <code>nil</code> or
|
|
|
|
* <code>false</code>, returns <code>false</code>; otherwise, returns
|
|
|
|
* <code>true</code>.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-21 10:28:54 +03:00
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
false_xor(VALUE obj, VALUE obj2)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
|
|
|
return RTEST(obj2)?Qtrue:Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
2013-05-31 11:04:33 +04:00
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* nil.nil? -> true
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* Only the object <i>nil</i> responds <code>true</code> to <code>nil?</code>.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_true(VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
2013-05-31 11:04:33 +04:00
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* nil.nil? -> true
|
|
|
|
* <anything_else>.nil? -> false
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* Only the object <i>nil</i> responds <code>true</code> to <code>nil?</code>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_false(VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 09:09:08 +03:00
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj =~ other -> nil
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2009-11-03 20:46:28 +03:00
|
|
|
* Pattern Match---Overridden by descendants (notably
|
2003-12-28 09:33:07 +03:00
|
|
|
* <code>Regexp</code> and <code>String</code>) to provide meaningful
|
|
|
|
* pattern-match semantics.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
2007-12-09 19:39:49 +03:00
|
|
|
rb_obj_match(VALUE obj1, VALUE obj2)
|
2003-12-28 09:33:07 +03:00
|
|
|
{
|
2005-07-06 13:47:08 +04:00
|
|
|
return Qnil;
|
2003-12-28 09:33:07 +03:00
|
|
|
}
|
|
|
|
|
2007-12-09 19:39:49 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj !~ other -> true or false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2009-01-13 15:29:54 +03:00
|
|
|
* Returns true if two objects do not match (using the <i>=~</i>
|
|
|
|
* method), otherwise false.
|
2007-12-09 19:39:49 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_obj_not_match(VALUE obj1, VALUE obj2)
|
|
|
|
{
|
2007-12-10 02:25:20 +03:00
|
|
|
VALUE result = rb_funcall(obj1, id_match, 1, obj2);
|
|
|
|
return RTEST(result) ? Qfalse : Qtrue;
|
2007-12-09 19:39:49 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
|
2010-08-20 09:13:39 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* obj <=> other -> 0 or nil
|
|
|
|
*
|
|
|
|
* Returns 0 if obj === other, otherwise nil.
|
2013-02-23 06:11:53 +04:00
|
|
|
*
|
|
|
|
* The <=> is used by various methods to compare objects, for example
|
|
|
|
* Enumerable#sort, Enumerable#max etc.
|
|
|
|
*
|
|
|
|
* Your implementation of <=> should return one of the following values: -1, 0,
|
|
|
|
* 1 or nil. -1 means self is smaller than other. 0 means self is equal to other.
|
|
|
|
* 1 means self is bigger than other. Nil means the two values could not be
|
|
|
|
* compared.
|
|
|
|
*
|
|
|
|
* When you defined <=>, you can include Comparable to gain the methods <=, <,
|
|
|
|
* ==, >=, > and between?.
|
2010-08-20 09:13:39 +04:00
|
|
|
*/
|
2009-10-24 20:48:05 +04:00
|
|
|
static VALUE
|
|
|
|
rb_obj_cmp(VALUE obj1, VALUE obj2)
|
|
|
|
{
|
2009-12-24 04:32:01 +03:00
|
|
|
if (obj1 == obj2 || rb_equal(obj1, obj2))
|
2009-10-24 20:48:05 +04:00
|
|
|
return INT2FIX(0);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
2004-01-02 09:01:12 +03:00
|
|
|
* Document-class: Module
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* A <code>Module</code> is a collection of methods and constants. The
|
|
|
|
* methods in a module may be instance methods or module methods.
|
|
|
|
* Instance methods appear as methods in a class when the module is
|
|
|
|
* included, module methods do not. Conversely, module methods may be
|
|
|
|
* called without creating an encapsulating object, while instance
|
|
|
|
* methods may not. (See <code>Module#module_function</code>)
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2009-11-03 20:46:28 +03:00
|
|
|
* In the descriptions that follow, the parameter <i>sym</i> refers
|
2003-12-28 09:33:07 +03:00
|
|
|
* to a symbol, which is either a quoted string or a
|
|
|
|
* <code>Symbol</code> (such as <code>:name</code>).
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* module Mod
|
|
|
|
* include Math
|
|
|
|
* CONST = 1
|
|
|
|
* def meth
|
|
|
|
* # ...
|
|
|
|
* end
|
|
|
|
* end
|
|
|
|
* Mod.class #=> Module
|
2008-03-09 04:04:46 +03:00
|
|
|
* Mod.constants #=> [:CONST, :PI, :E]
|
|
|
|
* Mod.instance_methods #=> [:meth]
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
2004-01-02 09:01:12 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* mod.to_s -> string
|
2004-01-02 09:01:12 +03:00
|
|
|
*
|
|
|
|
* Return a string representing this module or class. For basic
|
|
|
|
* classes and modules, this is the name. For singletons, we
|
|
|
|
* show information on the thing we're attached to as well.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_to_s(VALUE klass)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
* revised r37993 to avoid SEGV/ILL in tests. In r37993, a method
entry with VM_METHOD_TYPE_REFINED holds only the original method
definition, so ci->me is set to a method entry allocated in the
stack, and it causes SEGV/ILL. In this commit, a method entry
with VM_METHOD_TYPE_REFINED holds the whole original method entry.
Furthermore, rb_thread_mark() is changed to mark cfp->klass to
avoid GC for iclasses created by copy_refinement_iclass().
* vm_method.c (rb_method_entry_make): add a method entry with
VM_METHOD_TYPE_REFINED to the class refined by the refinement if
the target module is a refinement. When a method entry with
VM_METHOD_TYPE_UNDEF is invoked by vm_call_method(), a method with
the same name is searched in refinements. If such a method is
found, the method is invoked. Otherwise, the original method in
the refined class (rb_method_definition_t::body.orig_me) is
invoked. This change is made to simplify the normal method lookup
and to improve the performance of normal method calls.
* vm_method.c (EXPR1, search_method, rb_method_entry),
vm_eval.c (rb_call0, rb_search_method_entry): do not use
refinements for method lookup.
* vm_insnhelper.c (vm_call_method): search methods in refinements if
ci->me is VM_METHOD_TYPE_REFINED. If the method is called by
super (i.e., ci->call == vm_call_super_method), skip the same
method entry as the current method to avoid infinite call of the
same method.
* class.c (include_modules_at): add a refined method entry for each
method defined in a module included in a refinement.
* class.c (rb_prepend_module): set an empty table to
RCLASS_M_TBL(klass) to add refined method entries, because
refinements should have priority over prepended modules.
* proc.c (mnew): use rb_method_entry_with_refinements() to get
a refined method.
* vm.c (rb_thread_mark): mark cfp->klass for iclasses created by
copy_refinement_iclass().
* vm.c (Init_VM), cont.c (fiber_init): initialize th->cfp->klass.
* test/ruby/test_refinement.rb (test_inline_method_cache): do not skip
the test because it should pass successfully.
* test/ruby/test_refinement.rb (test_redefine_refined_method): new
test for the case a refined method is redefined.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-06 17:08:41 +04:00
|
|
|
ID id_defined_at;
|
2012-11-02 12:53:06 +04:00
|
|
|
VALUE refined_class, defined_at;
|
|
|
|
|
2001-05-11 09:24:59 +04:00
|
|
|
if (FL_TEST(klass, FL_SINGLETON)) {
|
2013-01-15 18:07:22 +04:00
|
|
|
VALUE s = rb_usascii_str_new2("#<Class:");
|
2013-05-02 11:54:17 +04:00
|
|
|
VALUE v = rb_ivar_get(klass, id__attached__);
|
2001-05-11 09:24:59 +04:00
|
|
|
|
2013-01-15 18:07:24 +04:00
|
|
|
if (CLASS_OR_MODULE_P(v)) {
|
2002-02-25 12:16:25 +03:00
|
|
|
rb_str_append(s, rb_inspect(v));
|
2013-01-15 18:07:24 +04:00
|
|
|
}
|
|
|
|
else {
|
2002-02-25 12:16:25 +03:00
|
|
|
rb_str_append(s, rb_any_to_s(v));
|
|
|
|
}
|
2001-05-11 09:24:59 +04:00
|
|
|
rb_str_cat2(s, ">");
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
* revised r37993 to avoid SEGV/ILL in tests. In r37993, a method
entry with VM_METHOD_TYPE_REFINED holds only the original method
definition, so ci->me is set to a method entry allocated in the
stack, and it causes SEGV/ILL. In this commit, a method entry
with VM_METHOD_TYPE_REFINED holds the whole original method entry.
Furthermore, rb_thread_mark() is changed to mark cfp->klass to
avoid GC for iclasses created by copy_refinement_iclass().
* vm_method.c (rb_method_entry_make): add a method entry with
VM_METHOD_TYPE_REFINED to the class refined by the refinement if
the target module is a refinement. When a method entry with
VM_METHOD_TYPE_UNDEF is invoked by vm_call_method(), a method with
the same name is searched in refinements. If such a method is
found, the method is invoked. Otherwise, the original method in
the refined class (rb_method_definition_t::body.orig_me) is
invoked. This change is made to simplify the normal method lookup
and to improve the performance of normal method calls.
* vm_method.c (EXPR1, search_method, rb_method_entry),
vm_eval.c (rb_call0, rb_search_method_entry): do not use
refinements for method lookup.
* vm_insnhelper.c (vm_call_method): search methods in refinements if
ci->me is VM_METHOD_TYPE_REFINED. If the method is called by
super (i.e., ci->call == vm_call_super_method), skip the same
method entry as the current method to avoid infinite call of the
same method.
* class.c (include_modules_at): add a refined method entry for each
method defined in a module included in a refinement.
* class.c (rb_prepend_module): set an empty table to
RCLASS_M_TBL(klass) to add refined method entries, because
refinements should have priority over prepended modules.
* proc.c (mnew): use rb_method_entry_with_refinements() to get
a refined method.
* vm.c (rb_thread_mark): mark cfp->klass for iclasses created by
copy_refinement_iclass().
* vm.c (Init_VM), cont.c (fiber_init): initialize th->cfp->klass.
* test/ruby/test_refinement.rb (test_inline_method_cache): do not skip
the test because it should pass successfully.
* test/ruby/test_refinement.rb (test_redefine_refined_method): new
test for the case a refined method is redefined.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-06 17:08:41 +04:00
|
|
|
refined_class = rb_refinement_module_get_refined_class(klass);
|
2012-11-02 12:53:06 +04:00
|
|
|
if (!NIL_P(refined_class)) {
|
|
|
|
VALUE s = rb_usascii_str_new2("#<refinement:");
|
|
|
|
|
|
|
|
rb_str_concat(s, rb_inspect(refined_class));
|
|
|
|
rb_str_cat2(s, "@");
|
|
|
|
CONST_ID(id_defined_at, "__defined_at__");
|
|
|
|
defined_at = rb_attr_get(klass, id_defined_at);
|
|
|
|
rb_str_concat(s, rb_inspect(defined_at));
|
|
|
|
rb_str_cat2(s, ">");
|
|
|
|
return s;
|
|
|
|
}
|
2004-01-19 12:19:31 +03:00
|
|
|
return rb_str_dup(rb_class_name(klass));
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2004-06-16 18:21:34 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* mod.freeze -> mod
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2004-06-16 18:21:34 +04:00
|
|
|
* Prevents further modifications to <i>mod</i>.
|
2009-05-24 17:37:43 +04:00
|
|
|
*
|
|
|
|
* This method returns self.
|
2004-06-16 18:21:34 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_freeze(VALUE mod)
|
2004-06-16 18:21:34 +04:00
|
|
|
{
|
2008-03-06 04:33:56 +03:00
|
|
|
rb_class_name(mod);
|
2004-06-16 18:21:34 +04:00
|
|
|
return rb_obj_freeze(mod);
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* mod === obj -> true or false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Case Equality---Returns <code>true</code> if <i>anObject</i> is an
|
2009-11-03 20:46:28 +03:00
|
|
|
* instance of <i>mod</i> or one of <i>mod</i>'s descendants. Of
|
2003-12-28 09:33:07 +03:00
|
|
|
* limited use for modules, but can be used in <code>case</code>
|
|
|
|
* statements to classify objects by class.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_eqq(VALUE mod, VALUE arg)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_obj_is_kind_of(arg, mod);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* mod <= other -> true, false, or nil
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* Returns true if <i>mod</i> is a subclass of <i>other</i> or
|
2009-02-22 17:23:33 +03:00
|
|
|
* is the same as <i>other</i>. Returns
|
|
|
|
* <code>nil</code> if there's no relationship between the two.
|
|
|
|
* (Think of the relationship in terms of the class definition:
|
2003-12-28 09:33:07 +03:00
|
|
|
* "class A<B" implies "A<B").
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-02-10 14:49:14 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_class_inherited_p(VALUE mod, VALUE arg)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2003-05-15 11:57:07 +04:00
|
|
|
VALUE start = mod;
|
|
|
|
|
2002-01-23 10:30:43 +03:00
|
|
|
if (mod == arg) return Qtrue;
|
2013-01-15 18:07:24 +04:00
|
|
|
if (!CLASS_OR_MODULE_P(arg)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_raise(rb_eTypeError, "compared with non class/module");
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
2013-05-02 18:23:56 +04:00
|
|
|
arg = RCLASS_ORIGIN(arg);
|
1998-01-16 15:19:22 +03:00
|
|
|
while (mod) {
|
2007-09-28 10:21:46 +04:00
|
|
|
if (RCLASS_M_TBL(mod) == RCLASS_M_TBL(arg))
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qtrue;
|
2007-09-28 10:21:46 +04:00
|
|
|
mod = RCLASS_SUPER(mod);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
2003-05-15 11:57:07 +04:00
|
|
|
/* not mod < arg; check if mod > arg */
|
|
|
|
while (arg) {
|
2007-09-28 10:21:46 +04:00
|
|
|
if (RCLASS_M_TBL(arg) == RCLASS_M_TBL(start))
|
2003-05-15 11:57:07 +04:00
|
|
|
return Qfalse;
|
2007-09-28 10:21:46 +04:00
|
|
|
arg = RCLASS_SUPER(arg);
|
2003-05-15 11:57:07 +04:00
|
|
|
}
|
|
|
|
return Qnil;
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* mod < other -> true, false, or nil
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
2009-02-22 17:23:33 +03:00
|
|
|
* Returns true if <i>mod</i> is a subclass of <i>other</i>. Returns
|
|
|
|
* <code>nil</code> if there's no relationship between the two.
|
|
|
|
* (Think of the relationship in terms of the class definition:
|
2003-12-28 09:33:07 +03:00
|
|
|
* "class A<B" implies "A<B").
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_lt(VALUE mod, VALUE arg)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
if (mod == arg) return Qfalse;
|
2004-02-10 14:49:14 +03:00
|
|
|
return rb_class_inherited_p(mod, arg);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* mod >= other -> true, false, or nil
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* Returns true if <i>mod</i> is an ancestor of <i>other</i>, or the
|
2009-02-22 17:23:33 +03:00
|
|
|
* two modules are the same. Returns
|
|
|
|
* <code>nil</code> if there's no relationship between the two.
|
|
|
|
* (Think of the relationship in terms of the class definition:
|
2003-12-28 09:33:07 +03:00
|
|
|
* "class A<B" implies "B>A").
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_ge(VALUE mod, VALUE arg)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2013-01-15 18:07:24 +04:00
|
|
|
if (!CLASS_OR_MODULE_P(arg)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_raise(rb_eTypeError, "compared with non class/module");
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2004-02-10 14:49:14 +03:00
|
|
|
return rb_class_inherited_p(arg, mod);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* mod > other -> true, false, or nil
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
2009-02-22 17:23:33 +03:00
|
|
|
* Returns true if <i>mod</i> is an ancestor of <i>other</i>. Returns
|
|
|
|
* <code>nil</code> if there's no relationship between the two.
|
|
|
|
* (Think of the relationship in terms of the class definition:
|
2003-12-28 09:33:07 +03:00
|
|
|
* "class A<B" implies "B>A").
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_gt(VALUE mod, VALUE arg)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
if (mod == arg) return Qfalse;
|
|
|
|
return rb_mod_ge(mod, arg);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2013-02-23 07:35:38 +04:00
|
|
|
* module <=> other_module -> -1, 0, +1, or nil
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2013-02-23 07:35:38 +04:00
|
|
|
* Comparison---Returns -1, 0, +1 or nil depending on whether +module+
|
|
|
|
* includes +other_module+, they are the same, or if +module+ is included by
|
|
|
|
* +other_module+. This is the basis for the tests in Comparable.
|
|
|
|
*
|
|
|
|
* Returns +nil+ if +module+ has no relationship with +other_module+, if
|
|
|
|
* +other_module+ is not a module, or if the two values are incomparable.
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_cmp(VALUE mod, VALUE arg)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2003-05-15 11:57:07 +04:00
|
|
|
VALUE cmp;
|
1998-01-16 15:19:22 +03:00
|
|
|
|
2002-01-23 10:30:43 +03:00
|
|
|
if (mod == arg) return INT2FIX(0);
|
2013-01-15 18:07:24 +04:00
|
|
|
if (!CLASS_OR_MODULE_P(arg)) {
|
2002-12-19 12:20:20 +03:00
|
|
|
return Qnil;
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2004-02-10 14:49:14 +03:00
|
|
|
cmp = rb_class_inherited_p(mod, arg);
|
2003-05-19 10:27:06 +04:00
|
|
|
if (NIL_P(cmp)) return Qnil;
|
2003-05-15 11:57:07 +04:00
|
|
|
if (cmp) {
|
|
|
|
return INT2FIX(-1);
|
2002-01-23 10:30:43 +03:00
|
|
|
}
|
2003-05-15 11:57:07 +04:00
|
|
|
return INT2FIX(1);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2000-05-25 09:55:12 +04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_module_s_alloc(VALUE klass)
|
2000-05-25 09:55:12 +04:00
|
|
|
{
|
2003-08-07 01:50:06 +04:00
|
|
|
VALUE mod = rb_module_new();
|
|
|
|
|
* include/ruby/ruby.h: constify RBasic::klass and add
RBASIC_CLASS(obj) macro which returns a class of `obj'.
This change is a part of RGENGC branch [ruby-trunk - Feature #8339].
* object.c: add new function rb_obj_reveal().
This function reveal interal (hidden) object by rb_obj_hide().
Note that do not change class before and after hiding.
Only permitted example is:
klass = RBASIC_CLASS(obj);
rb_obj_hide(obj);
....
rb_obj_reveal(obj, klass);
TODO: API design. rb_obj_reveal() should be replaced with others.
TODO: modify constified variables using cast may be harmful for
compiler's analysis and optimizaton.
Any idea to prohibt inserting RBasic::klass directly?
If rename RBasic::klass and force to use RBASIC_CLASS(obj),
then all codes such as `RBASIC(obj)->klass' will be
compilation error. Is it acceptable? (We have similar
experience at Ruby 1.9,
for example "RARRAY(ary)->ptr" to "RARRAY_PTR(ary)".
* internal.h: add some macros.
* RBASIC_CLEAR_CLASS(obj) clear RBasic::klass to make it internal
object.
* RBASIC_SET_CLASS(obj, cls) set RBasic::klass.
* RBASIC_SET_CLASS_RAW(obj, cls) same as RBASIC_SET_CLASS
without write barrier (planned).
* RCLASS_SET_SUPER(a, b) set super class of a.
* array.c, class.c, compile.c, encoding.c, enum.c, error.c, eval.c,
file.c, gc.c, hash.c, io.c, iseq.c, marshal.c, object.c,
parse.y, proc.c, process.c, random.c, ruby.c, sprintf.c,
string.c, thread.c, transcode.c, vm.c, vm_eval.c, win32/file.c:
Use above macros and functions to access RBasic::klass.
* ext/coverage/coverage.c, ext/readline/readline.c,
ext/socket/ancdata.c, ext/socket/init.c,
* ext/zlib/zlib.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 14:49:11 +04:00
|
|
|
RBASIC_SET_CLASS(mod, klass);
|
2003-08-07 01:50:06 +04:00
|
|
|
return mod;
|
2000-05-25 09:55:12 +04:00
|
|
|
}
|
|
|
|
|
2002-01-23 10:30:43 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_class_s_alloc(VALUE klass)
|
2002-01-23 10:30:43 +03:00
|
|
|
{
|
2003-08-07 01:50:06 +04:00
|
|
|
return rb_class_boot(0);
|
2002-01-23 10:30:43 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* Module.new -> mod
|
|
|
|
* Module.new {|mod| block } -> mod
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Creates a new anonymous module. If a block is given, it is passed
|
|
|
|
* the module object, and the block is evaluated in the context of this
|
|
|
|
* module using <code>module_eval</code>.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2010-09-18 10:56:41 +04:00
|
|
|
* fred = Module.new do
|
2003-12-28 09:33:07 +03:00
|
|
|
* def meth1
|
|
|
|
* "hello"
|
|
|
|
* end
|
|
|
|
* def meth2
|
|
|
|
* "bye"
|
|
|
|
* end
|
|
|
|
* end
|
|
|
|
* a = "my string"
|
2010-09-18 10:56:41 +04:00
|
|
|
* a.extend(fred) #=> "my string"
|
2003-12-28 09:33:07 +03:00
|
|
|
* a.meth1 #=> "hello"
|
|
|
|
* a.meth2 #=> "bye"
|
2010-09-18 10:56:41 +04:00
|
|
|
*
|
|
|
|
* Assign the module to a constant (name starting uppercase) if you
|
|
|
|
* want to treat it like a regular module.
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_initialize(VALUE module)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
2003-08-07 01:50:06 +04:00
|
|
|
if (rb_block_given_p()) {
|
2006-10-07 06:53:24 +04:00
|
|
|
rb_mod_module_exec(1, &module, module);
|
2003-08-07 01:50:06 +04:00
|
|
|
}
|
|
|
|
return Qnil;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
2003-12-19 18:18:09 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-09-18 10:56:41 +04:00
|
|
|
* Class.new(super_class=Object) -> a_class
|
|
|
|
* Class.new(super_class=Object) { |mod| ... } -> a_class
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-19 18:18:09 +03:00
|
|
|
* Creates a new anonymous (unnamed) class with the given superclass
|
|
|
|
* (or <code>Object</code> if no parameter is given). You can give a
|
|
|
|
* class a name by assigning the class object to a constant.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2010-09-18 10:56:41 +04:00
|
|
|
* If a block is given, it is passed the class object, and the block
|
|
|
|
* is evaluated in the context of this class using
|
|
|
|
* <code>class_eval</code>.
|
|
|
|
*
|
|
|
|
* fred = Class.new do
|
|
|
|
* def meth1
|
|
|
|
* "hello"
|
|
|
|
* end
|
|
|
|
* def meth2
|
|
|
|
* "bye"
|
|
|
|
* end
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* a = fred.new #=> #<#<Class:0x100381890>:0x100376b98>
|
|
|
|
* a.meth1 #=> "hello"
|
|
|
|
* a.meth2 #=> "bye"
|
|
|
|
*
|
|
|
|
* Assign the class to a constant (name starting uppercase) if you
|
|
|
|
* want to treat it like a regular class.
|
2003-12-19 18:18:09 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_class_initialize(int argc, VALUE *argv, VALUE klass)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2003-08-07 01:50:06 +04:00
|
|
|
VALUE super;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2010-01-13 05:57:48 +03:00
|
|
|
if (RCLASS_SUPER(klass) != 0 || klass == rb_cBasicObject) {
|
2003-08-07 01:50:06 +04:00
|
|
|
rb_raise(rb_eTypeError, "already initialized class");
|
|
|
|
}
|
2008-03-05 08:22:17 +03:00
|
|
|
if (argc == 0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
super = rb_cObject;
|
|
|
|
}
|
2003-12-21 11:29:06 +03:00
|
|
|
else {
|
2008-03-05 08:22:17 +03:00
|
|
|
rb_scan_args(argc, argv, "01", &super);
|
2003-12-21 11:29:06 +03:00
|
|
|
rb_check_inheritable(super);
|
2012-08-16 14:15:28 +04:00
|
|
|
if (super != rb_cBasicObject && !RCLASS_SUPER(super)) {
|
|
|
|
rb_raise(rb_eTypeError, "can't inherit uninitialized class");
|
|
|
|
}
|
2003-12-21 11:29:06 +03:00
|
|
|
}
|
* include/ruby/ruby.h: constify RBasic::klass and add
RBASIC_CLASS(obj) macro which returns a class of `obj'.
This change is a part of RGENGC branch [ruby-trunk - Feature #8339].
* object.c: add new function rb_obj_reveal().
This function reveal interal (hidden) object by rb_obj_hide().
Note that do not change class before and after hiding.
Only permitted example is:
klass = RBASIC_CLASS(obj);
rb_obj_hide(obj);
....
rb_obj_reveal(obj, klass);
TODO: API design. rb_obj_reveal() should be replaced with others.
TODO: modify constified variables using cast may be harmful for
compiler's analysis and optimizaton.
Any idea to prohibt inserting RBasic::klass directly?
If rename RBasic::klass and force to use RBASIC_CLASS(obj),
then all codes such as `RBASIC(obj)->klass' will be
compilation error. Is it acceptable? (We have similar
experience at Ruby 1.9,
for example "RARRAY(ary)->ptr" to "RARRAY_PTR(ary)".
* internal.h: add some macros.
* RBASIC_CLEAR_CLASS(obj) clear RBasic::klass to make it internal
object.
* RBASIC_SET_CLASS(obj, cls) set RBasic::klass.
* RBASIC_SET_CLASS_RAW(obj, cls) same as RBASIC_SET_CLASS
without write barrier (planned).
* RCLASS_SET_SUPER(a, b) set super class of a.
* array.c, class.c, compile.c, encoding.c, enum.c, error.c, eval.c,
file.c, gc.c, hash.c, io.c, iseq.c, marshal.c, object.c,
parse.y, proc.c, process.c, random.c, ruby.c, sprintf.c,
string.c, thread.c, transcode.c, vm.c, vm_eval.c, win32/file.c:
Use above macros and functions to access RBasic::klass.
* ext/coverage/coverage.c, ext/readline/readline.c,
ext/socket/ancdata.c, ext/socket/init.c,
* ext/zlib/zlib.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 14:49:11 +04:00
|
|
|
RCLASS_SET_SUPER(klass, super);
|
2002-01-10 23:18:39 +03:00
|
|
|
rb_make_metaclass(klass, RBASIC(super)->klass);
|
|
|
|
rb_class_inherited(super, klass);
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
rb_mod_initialize(klass);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
return klass;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-19 18:18:09 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* class.allocate() -> obj
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2008-06-04 13:55:14 +04:00
|
|
|
* Allocates space for a new object of <i>class</i>'s class and does not
|
|
|
|
* call initialize on the new instance. The returned object must be an
|
|
|
|
* instance of <i>class</i>.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2008-06-04 13:55:14 +04:00
|
|
|
* klass = Class.new do
|
|
|
|
* def initialize(*args)
|
|
|
|
* @initialized = true
|
|
|
|
* end
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2008-06-04 13:55:14 +04:00
|
|
|
* def initialized?
|
|
|
|
* @initialized || false
|
|
|
|
* end
|
|
|
|
* end
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2008-06-04 13:55:14 +04:00
|
|
|
* klass.allocate.initialized? #=> false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-19 18:18:09 +03:00
|
|
|
*/
|
|
|
|
|
2001-10-03 11:19:19 +04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_alloc(VALUE klass)
|
2001-10-03 11:19:19 +04:00
|
|
|
{
|
2003-05-17 03:28:31 +04:00
|
|
|
VALUE obj;
|
2012-09-08 13:52:26 +04:00
|
|
|
rb_alloc_func_t allocator;
|
2001-10-03 11:19:19 +04:00
|
|
|
|
2007-09-28 10:21:46 +04:00
|
|
|
if (RCLASS_SUPER(klass) == 0 && klass != rb_cBasicObject) {
|
2003-08-07 01:50:06 +04:00
|
|
|
rb_raise(rb_eTypeError, "can't instantiate uninitialized class");
|
|
|
|
}
|
2003-05-17 03:28:31 +04:00
|
|
|
if (FL_TEST(klass, FL_SINGLETON)) {
|
2004-11-16 07:55:14 +03:00
|
|
|
rb_raise(rb_eTypeError, "can't create instance of singleton class");
|
2003-05-17 03:28:31 +04:00
|
|
|
}
|
2012-09-08 13:52:26 +04:00
|
|
|
allocator = rb_get_alloc_func(klass);
|
|
|
|
if (!allocator) {
|
|
|
|
rb_raise(rb_eTypeError, "allocator undefined for %"PRIsVALUE,
|
|
|
|
klass);
|
|
|
|
}
|
|
|
|
|
2012-11-16 21:02:39 +04:00
|
|
|
#if !defined(DTRACE_PROBES_DISABLED) || !DTRACE_PROBES_DISABLED
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
if (RUBY_DTRACE_OBJECT_CREATE_ENABLED()) {
|
|
|
|
const char * file = rb_sourcefile();
|
|
|
|
RUBY_DTRACE_OBJECT_CREATE(rb_class2name(klass),
|
2012-11-16 21:02:35 +04:00
|
|
|
file ? file : "",
|
|
|
|
rb_sourceline());
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
}
|
2012-11-16 21:02:39 +04:00
|
|
|
#endif
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
|
2012-09-08 13:52:26 +04:00
|
|
|
obj = (*allocator)(klass);
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
|
2001-10-03 11:19:19 +04:00
|
|
|
if (rb_obj_class(obj) != rb_class_real(klass)) {
|
|
|
|
rb_raise(rb_eTypeError, "wrong instance allocation");
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_class_allocate_instance(VALUE klass)
|
2001-10-03 11:19:19 +04:00
|
|
|
{
|
* gc.c: support RGENGC. [ruby-trunk - Feature #8339]
See this ticet about RGENGC.
* gc.c: Add several flags:
* RGENGC_DEBUG: if >0, then prints debug information.
* RGENGC_CHECK_MODE: if >0, add assertions.
* RGENGC_PROFILE: if >0, add profiling features.
check GC.stat and GC::Profiler.
* include/ruby/ruby.h: disable RGENGC by default (USE_RGENGC == 0).
* array.c: add write barriers for T_ARRAY and generate sunny objects.
* include/ruby/ruby.h (RARRAY_PTR_USE): added. Use this macro if
you want to access raw pointers. If you modify the contents which
pointer pointed, then you need to care write barrier.
* bignum.c, marshal.c, random.c: generate T_BIGNUM sunny objects.
* complex.c, include/ruby/ruby.h: add write barriers for T_COMPLEX
and generate sunny objects.
* rational.c (nurat_s_new_internal), include/ruby/ruby.h: add write
barriers for T_RATIONAL and generate sunny objects.
* internal.h: add write barriers for RBasic::klass.
* numeric.c (rb_float_new_in_heap): generate sunny T_FLOAT objects.
* object.c (rb_class_allocate_instance), range.c:
generate sunny T_OBJECT objects.
* string.c: add write barriers for T_STRING and generate sunny objects.
* variable.c: add write barriers for ivars.
* vm_insnhelper.c (vm_setivar): ditto.
* include/ruby/ruby.h, debug.c: use two flags
FL_WB_PROTECTED and FL_OLDGEN.
* node.h (NODE_FL_CREF_PUSHED_BY_EVAL, NODE_FL_CREF_OMOD_SHARED):
move flag bits.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 22:07:47 +04:00
|
|
|
NEWOBJ_OF(obj, struct RObject, klass, T_OBJECT | (RGENGC_WB_PROTECTED_OBJECT ? FL_WB_PROTECTED : 0));
|
2003-05-17 03:28:31 +04:00
|
|
|
return (VALUE)obj;
|
2001-10-03 11:19:19 +04:00
|
|
|
}
|
|
|
|
|
2003-12-19 18:18:09 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* class.new(args, ...) -> obj
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-19 18:18:09 +03:00
|
|
|
* Calls <code>allocate</code> to create a new object of
|
|
|
|
* <i>class</i>'s class, then invokes that object's
|
|
|
|
* <code>initialize</code> method, passing it <i>args</i>.
|
|
|
|
* This is the method that ends up getting called whenever
|
|
|
|
* an object is constructed using .new.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-19 18:18:09 +03:00
|
|
|
*/
|
|
|
|
|
2001-10-03 11:19:19 +04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_class_new_instance(int argc, VALUE *argv, VALUE klass)
|
2001-10-03 11:19:19 +04:00
|
|
|
{
|
|
|
|
VALUE obj;
|
|
|
|
|
|
|
|
obj = rb_obj_alloc(klass);
|
|
|
|
rb_obj_call_init(obj, argc, argv);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2003-12-19 18:18:09 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* class.superclass -> a_super_class or nil
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-19 18:18:09 +03:00
|
|
|
* Returns the superclass of <i>class</i>, or <code>nil</code>.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2008-03-09 04:04:46 +03:00
|
|
|
* File.superclass #=> IO
|
|
|
|
* IO.superclass #=> Object
|
|
|
|
* Object.superclass #=> BasicObject
|
2008-06-22 04:51:17 +04:00
|
|
|
* class Foo; end
|
|
|
|
* class Bar < Foo; end
|
|
|
|
* Bar.superclass #=> Foo
|
|
|
|
*
|
|
|
|
* returns nil when the given class hasn't a parent class:
|
|
|
|
*
|
2008-03-09 04:04:46 +03:00
|
|
|
* BasicObject.superclass #=> nil
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-19 18:18:09 +03:00
|
|
|
*/
|
|
|
|
|
2011-05-18 17:41:54 +04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_class_superclass(VALUE klass)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2007-09-28 10:21:46 +04:00
|
|
|
VALUE super = RCLASS_SUPER(klass);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2003-08-07 01:50:06 +04:00
|
|
|
if (!super) {
|
2007-11-19 11:49:42 +03:00
|
|
|
if (klass == rb_cBasicObject) return Qnil;
|
2003-08-07 01:50:06 +04:00
|
|
|
rb_raise(rb_eTypeError, "uninitialized class");
|
|
|
|
}
|
2011-09-29 15:07:45 +04:00
|
|
|
while (RB_TYPE_P(super, T_ICLASS)) {
|
2007-09-28 10:21:46 +04:00
|
|
|
super = RCLASS_SUPER(super);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
if (!super) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
return super;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2011-06-18 07:05:11 +04:00
|
|
|
VALUE
|
|
|
|
rb_class_get_superclass(VALUE klass)
|
|
|
|
{
|
* include/ruby/ruby.h: constify RBasic::klass and add
RBASIC_CLASS(obj) macro which returns a class of `obj'.
This change is a part of RGENGC branch [ruby-trunk - Feature #8339].
* object.c: add new function rb_obj_reveal().
This function reveal interal (hidden) object by rb_obj_hide().
Note that do not change class before and after hiding.
Only permitted example is:
klass = RBASIC_CLASS(obj);
rb_obj_hide(obj);
....
rb_obj_reveal(obj, klass);
TODO: API design. rb_obj_reveal() should be replaced with others.
TODO: modify constified variables using cast may be harmful for
compiler's analysis and optimizaton.
Any idea to prohibt inserting RBasic::klass directly?
If rename RBasic::klass and force to use RBASIC_CLASS(obj),
then all codes such as `RBASIC(obj)->klass' will be
compilation error. Is it acceptable? (We have similar
experience at Ruby 1.9,
for example "RARRAY(ary)->ptr" to "RARRAY_PTR(ary)".
* internal.h: add some macros.
* RBASIC_CLEAR_CLASS(obj) clear RBasic::klass to make it internal
object.
* RBASIC_SET_CLASS(obj, cls) set RBasic::klass.
* RBASIC_SET_CLASS_RAW(obj, cls) same as RBASIC_SET_CLASS
without write barrier (planned).
* RCLASS_SET_SUPER(a, b) set super class of a.
* array.c, class.c, compile.c, encoding.c, enum.c, error.c, eval.c,
file.c, gc.c, hash.c, io.c, iseq.c, marshal.c, object.c,
parse.y, proc.c, process.c, random.c, ruby.c, sprintf.c,
string.c, thread.c, transcode.c, vm.c, vm_eval.c, win32/file.c:
Use above macros and functions to access RBasic::klass.
* ext/coverage/coverage.c, ext/readline/readline.c,
ext/socket/ancdata.c, ext/socket/init.c,
* ext/zlib/zlib.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 14:49:11 +04:00
|
|
|
return RCLASS_EXT(klass)->super;
|
2011-06-18 07:05:11 +04:00
|
|
|
}
|
|
|
|
|
2013-04-08 18:57:29 +04:00
|
|
|
#define id_for_setter(name, type, message) \
|
|
|
|
check_setter_id(name, rb_is_##type##_id, rb_is_##type##_name, message)
|
|
|
|
static ID
|
|
|
|
check_setter_id(VALUE name, int (*valid_id_p)(ID), int (*valid_name_p)(VALUE),
|
|
|
|
const char *message)
|
|
|
|
{
|
|
|
|
ID id;
|
|
|
|
if (SYMBOL_P(name)) {
|
|
|
|
id = SYM2ID(name);
|
|
|
|
if (!valid_id_p(id)) {
|
|
|
|
rb_name_error(id, message, QUOTE_ID(id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
VALUE str = rb_check_string_type(name);
|
|
|
|
if (NIL_P(str)) {
|
|
|
|
rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol or string",
|
|
|
|
str);
|
|
|
|
}
|
|
|
|
if (!valid_name_p(str)) {
|
|
|
|
rb_name_error_str(str, message, QUOTE(str));
|
|
|
|
}
|
|
|
|
id = rb_to_id(str);
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2013-02-24 08:24:52 +04:00
|
|
|
* attr_reader(symbol, ...) -> nil
|
|
|
|
* attr(symbol, ...) -> nil
|
|
|
|
* attr_reader(string, ...) -> nil
|
|
|
|
* attr(string, ...) -> nil
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Creates instance variables and corresponding methods that return the
|
|
|
|
* value of each instance variable. Equivalent to calling
|
|
|
|
* ``<code>attr</code><i>:name</i>'' on each name in turn.
|
2013-02-24 08:24:52 +04:00
|
|
|
* String arguments are converted to symbols.
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_attr_reader(int argc, VALUE *argv, VALUE klass)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<argc; i++) {
|
2009-07-18 12:05:32 +04:00
|
|
|
rb_attr(klass, rb_to_id(argv[i]), TRUE, FALSE, TRUE);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2006-07-20 21:30:01 +04:00
|
|
|
VALUE
|
|
|
|
rb_mod_attr(int argc, VALUE *argv, VALUE klass)
|
|
|
|
{
|
|
|
|
if (argc == 2 && (argv[1] == Qtrue || argv[1] == Qfalse)) {
|
|
|
|
rb_warning("optional boolean argument is obsoleted");
|
2009-07-18 12:05:32 +04:00
|
|
|
rb_attr(klass, rb_to_id(argv[0]), 1, RTEST(argv[1]), TRUE);
|
2006-07-20 21:30:01 +04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
return rb_mod_attr_reader(argc, argv, klass);
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* attr_writer(symbol, ...) -> nil
|
2013-02-24 08:24:52 +04:00
|
|
|
* attr_writer(string, ...) -> nil
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Creates an accessor method to allow assignment to the attribute
|
2013-01-29 22:58:37 +04:00
|
|
|
* <i>symbol</i><code>.id2name</code>.
|
2013-02-24 08:24:52 +04:00
|
|
|
* String arguments are converted to symbols.
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_attr_writer(int argc, VALUE *argv, VALUE klass)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<argc; i++) {
|
2009-07-18 12:05:32 +04:00
|
|
|
rb_attr(klass, rb_to_id(argv[i]), FALSE, TRUE, TRUE);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* attr_accessor(symbol, ...) -> nil
|
2013-02-24 08:24:52 +04:00
|
|
|
* attr_accessor(string, ...) -> nil
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2006-07-20 21:30:01 +04:00
|
|
|
* Defines a named attribute for this module, where the name is
|
|
|
|
* <i>symbol.</i><code>id2name</code>, creating an instance variable
|
|
|
|
* (<code>@name</code>) and a corresponding access method to read it.
|
|
|
|
* Also creates a method called <code>name=</code> to set the attribute.
|
2013-02-24 08:24:52 +04:00
|
|
|
* String arguments are converted to symbols.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* module Mod
|
|
|
|
* attr_accessor(:one, :two)
|
|
|
|
* end
|
2008-03-09 04:04:46 +03:00
|
|
|
* Mod.instance_methods.sort #=> [:one, :one=, :two, :two=]
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_attr_accessor(int argc, VALUE *argv, VALUE klass)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<argc; i++) {
|
2009-07-18 12:05:32 +04:00
|
|
|
rb_attr(klass, rb_to_id(argv[i]), TRUE, TRUE, TRUE);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* mod.const_get(sym, inherit=true) -> obj
|
2012-10-27 01:31:23 +04:00
|
|
|
* mod.const_get(str, inherit=true) -> obj
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2011-05-27 17:55:21 +04:00
|
|
|
* Checks for a constant with the given name in <i>mod</i>
|
|
|
|
* If +inherit+ is set, the lookup will also search
|
|
|
|
* the ancestors (and +Object+ if <i>mod</i> is a +Module+.)
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2011-05-27 17:55:21 +04:00
|
|
|
* The value of the constant is returned if a definition is found,
|
|
|
|
* otherwise a +NameError+ is raised.
|
2006-01-17 17:05:49 +03:00
|
|
|
*
|
2011-05-27 17:55:21 +04:00
|
|
|
* Math.const_get(:PI) #=> 3.14159265358979
|
2012-10-27 01:31:23 +04:00
|
|
|
*
|
|
|
|
* This method will recursively look up constant names if a namespaced
|
|
|
|
* class name is provided. For example:
|
|
|
|
*
|
|
|
|
* module Foo; class Bar; end end
|
|
|
|
* Object.const_get 'Foo::Bar'
|
|
|
|
*
|
|
|
|
* The +inherit+ flag is respected on each lookup. For example:
|
|
|
|
*
|
|
|
|
* module Foo
|
|
|
|
* class Bar
|
|
|
|
* VAL = 10
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* class Baz < Bar; end
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* Object.const_get 'Foo::Baz::VAL' # => 10
|
|
|
|
* Object.const_get 'Foo::Baz::VAL', false # => NameError
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static VALUE
|
2006-01-17 17:05:49 +03:00
|
|
|
rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2006-01-17 17:05:49 +03:00
|
|
|
VALUE name, recur;
|
2012-10-27 01:31:23 +04:00
|
|
|
rb_encoding *enc;
|
2012-12-19 14:34:13 +04:00
|
|
|
const char *pbeg, *p, *path, *pend;
|
2006-01-17 17:05:49 +03:00
|
|
|
ID id;
|
2012-12-22 15:31:13 +04:00
|
|
|
int nestable = 1;
|
2001-05-02 08:22:21 +04:00
|
|
|
|
2006-01-17 17:05:49 +03:00
|
|
|
if (argc == 1) {
|
|
|
|
name = argv[0];
|
|
|
|
recur = Qtrue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_scan_args(argc, argv, "11", &name, &recur);
|
|
|
|
}
|
2012-10-27 01:31:23 +04:00
|
|
|
|
|
|
|
if (SYMBOL_P(name)) {
|
2012-10-27 05:51:58 +04:00
|
|
|
name = rb_sym_to_s(name);
|
2012-12-22 15:31:13 +04:00
|
|
|
nestable = 0;
|
2012-10-27 01:31:23 +04:00
|
|
|
}
|
|
|
|
|
2012-10-27 05:51:58 +04:00
|
|
|
name = rb_check_string_type(name);
|
|
|
|
Check_Type(name, T_STRING);
|
|
|
|
|
2012-10-27 01:31:23 +04:00
|
|
|
enc = rb_enc_get(name);
|
|
|
|
path = RSTRING_PTR(name);
|
|
|
|
|
|
|
|
if (!rb_enc_asciicompat(enc)) {
|
|
|
|
rb_raise(rb_eArgError, "invalid class path encoding (non ASCII)");
|
|
|
|
}
|
|
|
|
|
|
|
|
pbeg = p = path;
|
2012-12-19 14:34:13 +04:00
|
|
|
pend = path + RSTRING_LEN(name);
|
2012-11-06 15:42:24 +04:00
|
|
|
|
2012-12-22 14:40:03 +04:00
|
|
|
if (p >= pend || !*p) {
|
|
|
|
wrong_name:
|
2012-12-22 19:04:57 +04:00
|
|
|
rb_raise(rb_eNameError, "wrong constant name %"PRIsVALUE,
|
|
|
|
QUOTE(name));
|
2012-11-06 15:42:24 +04:00
|
|
|
}
|
|
|
|
|
2012-12-22 14:26:40 +04:00
|
|
|
if (p + 2 < pend && p[0] == ':' && p[1] == ':') {
|
2012-12-22 15:31:13 +04:00
|
|
|
if (!nestable) goto wrong_name;
|
2012-11-06 15:42:24 +04:00
|
|
|
mod = rb_cObject;
|
|
|
|
p += 2;
|
|
|
|
pbeg = p;
|
|
|
|
}
|
|
|
|
|
2012-12-19 14:34:13 +04:00
|
|
|
while (p < pend) {
|
2012-11-07 04:16:03 +04:00
|
|
|
VALUE part;
|
2012-12-22 19:04:57 +04:00
|
|
|
long len, beglen;
|
2012-11-07 04:16:03 +04:00
|
|
|
|
2012-12-19 14:34:13 +04:00
|
|
|
while (p < pend && *p != ':') p++;
|
2012-11-06 15:42:24 +04:00
|
|
|
|
2012-12-22 14:40:03 +04:00
|
|
|
if (pbeg == p) goto wrong_name;
|
|
|
|
|
|
|
|
id = rb_check_id_cstr(pbeg, len = p-pbeg, enc);
|
2012-12-22 19:04:57 +04:00
|
|
|
beglen = pbeg-path;
|
2012-11-06 15:42:24 +04:00
|
|
|
|
2012-12-22 14:26:40 +04:00
|
|
|
if (p < pend && p[0] == ':') {
|
2012-12-22 15:31:13 +04:00
|
|
|
if (!nestable) goto wrong_name;
|
2012-12-22 14:40:03 +04:00
|
|
|
if (p + 2 >= pend || p[1] != ':') goto wrong_name;
|
2012-10-27 01:31:23 +04:00
|
|
|
p += 2;
|
|
|
|
pbeg = p;
|
2011-07-26 20:05:35 +04:00
|
|
|
}
|
2012-10-27 01:31:23 +04:00
|
|
|
|
|
|
|
if (!RB_TYPE_P(mod, T_MODULE) && !RB_TYPE_P(mod, T_CLASS)) {
|
2012-12-22 19:04:57 +04:00
|
|
|
rb_raise(rb_eTypeError, "%"PRIsVALUE" does not refer to class/module",
|
|
|
|
QUOTE(name));
|
2011-07-26 20:05:35 +04:00
|
|
|
}
|
2012-10-27 01:31:23 +04:00
|
|
|
|
2012-12-22 14:40:03 +04:00
|
|
|
if (!id) {
|
|
|
|
if (!ISUPPER(*pbeg) || !rb_enc_symname2_p(pbeg, len, enc)) {
|
2012-12-22 19:04:57 +04:00
|
|
|
part = rb_str_subseq(name, beglen, len);
|
|
|
|
rb_name_error_str(part, "wrong constant name %"PRIsVALUE,
|
|
|
|
QUOTE(part));
|
2012-12-22 14:40:03 +04:00
|
|
|
}
|
|
|
|
else if (!rb_method_basic_definition_p(CLASS_OF(mod), id_const_missing)) {
|
|
|
|
id = rb_intern3(pbeg, len, enc);
|
|
|
|
}
|
|
|
|
else {
|
2012-12-22 19:04:57 +04:00
|
|
|
part = rb_str_subseq(name, beglen, len);
|
|
|
|
rb_name_error_str(part, "uninitialized constant %"PRIsVALUE"%"PRIsVALUE,
|
|
|
|
rb_str_subseq(name, 0, beglen),
|
|
|
|
QUOTE(part));
|
2012-12-22 14:40:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!rb_is_const_id(id)) {
|
2012-12-22 19:04:57 +04:00
|
|
|
rb_name_error(id, "wrong constant name %"PRIsVALUE,
|
|
|
|
QUOTE_ID(id));
|
2012-12-22 14:40:03 +04:00
|
|
|
}
|
|
|
|
mod = RTEST(recur) ? rb_const_get(mod, id) : rb_const_get_at(mod, id);
|
2011-07-26 20:05:35 +04:00
|
|
|
}
|
2012-10-27 01:31:23 +04:00
|
|
|
|
|
|
|
return mod;
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* mod.const_set(sym, obj) -> obj
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Sets the named constant to the given object, returning that object.
|
|
|
|
* Creates a new constant if no constant with the given name previously
|
|
|
|
* existed.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Math.const_set("HIGH_SCHOOL_PI", 22.0/7.0) #=> 3.14285714285714
|
|
|
|
* Math::HIGH_SCHOOL_PI - Math::PI #=> 0.00126448926734968
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_const_set(VALUE mod, VALUE name, VALUE value)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2013-04-08 18:57:29 +04:00
|
|
|
ID id = id_for_setter(name, const, "wrong constant name %"PRIsVALUE);
|
2013-04-04 12:18:54 +04:00
|
|
|
rb_const_set(mod, id, value);
|
1998-01-16 15:19:22 +03:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* mod.const_defined?(sym, inherit=true) -> true or false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2011-05-27 17:55:21 +04:00
|
|
|
* Checks for a constant with the given name in <i>mod</i>
|
|
|
|
* If +inherit+ is set, the lookup will also search
|
|
|
|
* the ancestors (and +Object+ if <i>mod</i> is a +Module+.)
|
|
|
|
*
|
|
|
|
* Returns whether or not a definition is found:
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Math.const_defined? "PI" #=> true
|
2011-05-27 17:55:21 +04:00
|
|
|
* IO.const_defined? :SYNC #=> true
|
|
|
|
* IO.const_defined? :SYNC, false #=> false
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static VALUE
|
2006-01-17 17:05:49 +03:00
|
|
|
rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2006-01-17 17:05:49 +03:00
|
|
|
VALUE name, recur;
|
|
|
|
ID id;
|
2001-05-02 08:22:21 +04:00
|
|
|
|
2006-01-17 17:05:49 +03:00
|
|
|
if (argc == 1) {
|
|
|
|
name = argv[0];
|
|
|
|
recur = Qtrue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_scan_args(argc, argv, "11", &name, &recur);
|
|
|
|
}
|
2011-07-26 20:05:27 +04:00
|
|
|
if (!(id = rb_check_id(&name))) {
|
2011-07-23 19:05:03 +04:00
|
|
|
if (rb_is_const_name(name)) {
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
else {
|
2012-12-22 19:04:57 +04:00
|
|
|
rb_name_error_str(name, "wrong constant name %"PRIsVALUE,
|
|
|
|
QUOTE(name));
|
2011-07-23 19:05:03 +04:00
|
|
|
}
|
|
|
|
}
|
2001-05-02 08:22:21 +04:00
|
|
|
if (!rb_is_const_id(id)) {
|
2012-12-22 19:04:57 +04:00
|
|
|
rb_name_error(id, "wrong constant name %"PRIsVALUE,
|
|
|
|
QUOTE_ID(id));
|
2001-05-02 08:22:21 +04:00
|
|
|
}
|
2006-01-17 17:05:49 +03:00
|
|
|
return RTEST(recur) ? rb_const_defined(mod, id) : rb_const_defined_at(mod, id);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.instance_variable_get(symbol) -> obj
|
2013-02-24 08:24:52 +04:00
|
|
|
* obj.instance_variable_get(string) -> obj
|
2007-03-02 01:59:12 +03:00
|
|
|
*
|
|
|
|
* Returns the value of the given instance variable, or nil if the
|
2007-03-03 09:53:38 +03:00
|
|
|
* instance variable is not set. The <code>@</code> part of the
|
|
|
|
* variable name should be included for regular instance
|
|
|
|
* variables. Throws a <code>NameError</code> exception if the
|
|
|
|
* supplied symbol is not valid as an instance variable name.
|
2013-02-24 08:24:52 +04:00
|
|
|
* String arguments are converted to symbols.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* class Fred
|
|
|
|
* def initialize(p1, p2)
|
|
|
|
* @a, @b = p1, p2
|
|
|
|
* end
|
|
|
|
* end
|
|
|
|
* fred = Fred.new('cat', 99)
|
|
|
|
* fred.instance_variable_get(:@a) #=> "cat"
|
|
|
|
* fred.instance_variable_get("@b") #=> 99
|
|
|
|
*/
|
2007-06-10 07:06:15 +04:00
|
|
|
|
2003-02-10 12:40:13 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_ivar_get(VALUE obj, VALUE iv)
|
2003-02-10 12:40:13 +03:00
|
|
|
{
|
2011-07-26 20:05:27 +04:00
|
|
|
ID id = rb_check_id(&iv);
|
2003-02-10 12:40:13 +03:00
|
|
|
|
2011-07-23 19:05:03 +04:00
|
|
|
if (!id) {
|
|
|
|
if (rb_is_instance_name(iv)) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
else {
|
2012-12-22 19:04:57 +04:00
|
|
|
rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as an instance variable name",
|
|
|
|
QUOTE(iv));
|
2011-07-23 19:05:03 +04:00
|
|
|
}
|
|
|
|
}
|
* parse.y, compile.c, gc.c, insns.def, intern.h, iseq.c, node.h,
object.c, string.c, variable.c, vm_macro.def: revert private
instance variable feature, which is postponed until next major
release.
* marshal.c: TYPE_SYMBOL2 removed; MARSHAL_MINOR reverted back to
8th version.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-23 05:49:41 +03:00
|
|
|
if (!rb_is_instance_id(id)) {
|
2012-12-22 19:04:57 +04:00
|
|
|
rb_name_error(id, "`%"PRIsVALUE"' is not allowed as an instance variable name",
|
|
|
|
QUOTE_ID(id));
|
2003-02-10 12:40:13 +03:00
|
|
|
}
|
|
|
|
return rb_ivar_get(obj, id);
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.instance_variable_set(symbol, obj) -> obj
|
2013-02-24 08:24:52 +04:00
|
|
|
* obj.instance_variable_set(string, obj) -> obj
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Sets the instance variable names by <i>symbol</i> to
|
|
|
|
* <i>object</i>, thereby frustrating the efforts of the class's
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
* author to attempt to provide proper encapsulation. The variable
|
|
|
|
* did not have to exist prior to this call.
|
2013-02-24 08:24:52 +04:00
|
|
|
* If the instance variable name is passed as a string, that string
|
|
|
|
* is converted to a symbol.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* class Fred
|
|
|
|
* def initialize(p1, p2)
|
|
|
|
* @a, @b = p1, p2
|
|
|
|
* end
|
|
|
|
* end
|
|
|
|
* fred = Fred.new('cat', 99)
|
|
|
|
* fred.instance_variable_set(:@a, 'dog') #=> "dog"
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
* fred.instance_variable_set(:@c, 'cat') #=> "cat"
|
|
|
|
* fred.inspect #=> "#<Fred:0x401b3da8 @a=\"dog\", @b=99, @c=\"cat\">"
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
2003-02-10 12:40:13 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_ivar_set(VALUE obj, VALUE iv, VALUE val)
|
2003-02-10 12:40:13 +03:00
|
|
|
{
|
2013-04-08 18:57:29 +04:00
|
|
|
ID id = id_for_setter(iv, instance, "`%"PRIsVALUE"' is not allowed as an instance variable name");
|
2013-04-04 12:18:54 +04:00
|
|
|
return rb_ivar_set(obj, id, val);
|
2003-02-10 12:40:13 +03:00
|
|
|
}
|
|
|
|
|
2006-09-18 19:43:06 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.instance_variable_defined?(symbol) -> true or false
|
2013-02-24 08:24:52 +04:00
|
|
|
* obj.instance_variable_defined?(string) -> true or false
|
2006-09-18 19:43:06 +04:00
|
|
|
*
|
|
|
|
* Returns <code>true</code> if the given instance variable is
|
|
|
|
* defined in <i>obj</i>.
|
2013-02-24 08:24:52 +04:00
|
|
|
* String arguments are converted to symbols.
|
2006-09-18 19:43:06 +04:00
|
|
|
*
|
|
|
|
* class Fred
|
|
|
|
* def initialize(p1, p2)
|
|
|
|
* @a, @b = p1, p2
|
|
|
|
* end
|
|
|
|
* end
|
|
|
|
* fred = Fred.new('cat', 99)
|
|
|
|
* fred.instance_variable_defined?(:@a) #=> true
|
|
|
|
* fred.instance_variable_defined?("@b") #=> true
|
|
|
|
* fred.instance_variable_defined?("@c") #=> false
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_obj_ivar_defined(VALUE obj, VALUE iv)
|
|
|
|
{
|
2011-07-26 20:05:27 +04:00
|
|
|
ID id = rb_check_id(&iv);
|
2006-09-18 19:43:06 +04:00
|
|
|
|
2011-07-23 19:05:03 +04:00
|
|
|
if (!id) {
|
|
|
|
if (rb_is_instance_name(iv)) {
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
else {
|
2012-12-22 19:04:57 +04:00
|
|
|
rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as an instance variable name",
|
|
|
|
QUOTE(iv));
|
2011-07-23 19:05:03 +04:00
|
|
|
}
|
|
|
|
}
|
* parse.y, compile.c, gc.c, insns.def, intern.h, iseq.c, node.h,
object.c, string.c, variable.c, vm_macro.def: revert private
instance variable feature, which is postponed until next major
release.
* marshal.c: TYPE_SYMBOL2 removed; MARSHAL_MINOR reverted back to
8th version.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-23 05:49:41 +03:00
|
|
|
if (!rb_is_instance_id(id)) {
|
2012-12-22 19:04:57 +04:00
|
|
|
rb_name_error(id, "`%"PRIsVALUE"' is not allowed as an instance variable name",
|
|
|
|
QUOTE_ID(id));
|
2006-09-18 19:43:06 +04:00
|
|
|
}
|
|
|
|
return rb_ivar_defined(obj, id);
|
|
|
|
}
|
|
|
|
|
2004-03-23 22:14:16 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* mod.class_variable_get(symbol) -> obj
|
2013-02-24 08:24:52 +04:00
|
|
|
* mod.class_variable_get(string) -> obj
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2004-03-23 22:14:16 +03:00
|
|
|
* Returns the value of the given class variable (or throws a
|
|
|
|
* <code>NameError</code> exception). The <code>@@</code> part of the
|
|
|
|
* variable name should be included for regular class variables
|
2013-02-24 08:24:52 +04:00
|
|
|
* String arguments are converted to symbols.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2004-03-23 22:14:16 +03:00
|
|
|
* class Fred
|
|
|
|
* @@foo = 99
|
|
|
|
* end
|
2006-09-18 19:43:06 +04:00
|
|
|
* Fred.class_variable_get(:@@foo) #=> 99
|
2004-03-23 22:14:16 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_cvar_get(VALUE obj, VALUE iv)
|
2004-03-23 22:14:16 +03:00
|
|
|
{
|
2011-07-26 20:05:27 +04:00
|
|
|
ID id = rb_check_id(&iv);
|
2004-03-23 22:14:16 +03:00
|
|
|
|
2011-07-23 19:05:03 +04:00
|
|
|
if (!id) {
|
|
|
|
if (rb_is_class_name(iv)) {
|
2012-12-22 19:04:57 +04:00
|
|
|
rb_name_error_str(iv, "uninitialized class variable %"PRIsVALUE" in %"PRIsVALUE"",
|
|
|
|
iv, rb_class_name(obj));
|
2011-07-23 19:05:03 +04:00
|
|
|
}
|
|
|
|
else {
|
2012-12-22 19:04:57 +04:00
|
|
|
rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as a class variable name",
|
|
|
|
QUOTE(iv));
|
2011-07-23 19:05:03 +04:00
|
|
|
}
|
|
|
|
}
|
2004-03-23 22:14:16 +03:00
|
|
|
if (!rb_is_class_id(id)) {
|
2012-12-22 19:04:57 +04:00
|
|
|
rb_name_error(id, "`%"PRIsVALUE"' is not allowed as a class variable name",
|
|
|
|
QUOTE_ID(id));
|
2004-03-23 22:14:16 +03:00
|
|
|
}
|
|
|
|
return rb_cvar_get(obj, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.class_variable_set(symbol, obj) -> obj
|
2013-02-24 08:24:52 +04:00
|
|
|
* obj.class_variable_set(string, obj) -> obj
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2004-03-23 22:14:16 +03:00
|
|
|
* Sets the class variable names by <i>symbol</i> to
|
|
|
|
* <i>object</i>.
|
2013-02-24 08:24:52 +04:00
|
|
|
* If the class variable name is passed as a string, that string
|
|
|
|
* is converted to a symbol.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2004-03-23 22:14:16 +03:00
|
|
|
* class Fred
|
|
|
|
* @@foo = 99
|
|
|
|
* def foo
|
|
|
|
* @@foo
|
|
|
|
* end
|
|
|
|
* end
|
2006-09-18 19:43:06 +04:00
|
|
|
* Fred.class_variable_set(:@@foo, 101) #=> 101
|
2004-03-23 22:14:16 +03:00
|
|
|
* Fred.new.foo #=> 101
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_cvar_set(VALUE obj, VALUE iv, VALUE val)
|
2004-03-23 22:14:16 +03:00
|
|
|
{
|
2013-04-08 18:57:29 +04:00
|
|
|
ID id = id_for_setter(iv, class, "`%"PRIsVALUE"' is not allowed as a class variable name");
|
2013-04-04 12:18:54 +04:00
|
|
|
rb_cvar_set(obj, id, val);
|
2004-03-23 22:14:16 +03:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2006-09-18 19:43:06 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* obj.class_variable_defined?(symbol) -> true or false
|
2013-02-24 08:24:52 +04:00
|
|
|
* obj.class_variable_defined?(string) -> true or false
|
2006-09-18 19:43:06 +04:00
|
|
|
*
|
|
|
|
* Returns <code>true</code> if the given class variable is defined
|
|
|
|
* in <i>obj</i>.
|
2013-02-24 08:24:52 +04:00
|
|
|
* String arguments are converted to symbols.
|
2006-09-18 19:43:06 +04:00
|
|
|
*
|
|
|
|
* class Fred
|
|
|
|
* @@foo = 99
|
|
|
|
* end
|
|
|
|
* Fred.class_variable_defined?(:@@foo) #=> true
|
|
|
|
* Fred.class_variable_defined?(:@@bar) #=> false
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_mod_cvar_defined(VALUE obj, VALUE iv)
|
|
|
|
{
|
2011-07-26 20:05:27 +04:00
|
|
|
ID id = rb_check_id(&iv);
|
2006-09-18 19:43:06 +04:00
|
|
|
|
2011-07-23 19:05:03 +04:00
|
|
|
if (!id) {
|
|
|
|
if (rb_is_class_name(iv)) {
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
else {
|
2012-12-22 19:04:57 +04:00
|
|
|
rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as a class variable name",
|
|
|
|
QUOTE(iv));
|
2011-07-23 19:05:03 +04:00
|
|
|
}
|
|
|
|
}
|
2006-10-12 19:39:19 +04:00
|
|
|
if (!rb_is_class_id(id)) {
|
2012-12-22 19:04:57 +04:00
|
|
|
rb_name_error(id, "`%"PRIsVALUE"' is not allowed as a class variable name",
|
|
|
|
QUOTE_ID(id));
|
2006-09-18 19:43:06 +04:00
|
|
|
}
|
|
|
|
return rb_cvar_defined(obj, id);
|
|
|
|
}
|
|
|
|
|
2008-08-28 15:50:31 +04:00
|
|
|
static struct conv_method_tbl {
|
|
|
|
const char *method;
|
|
|
|
ID id;
|
|
|
|
} conv_method_names[] = {
|
|
|
|
{"to_int", 0},
|
|
|
|
{"to_ary", 0},
|
|
|
|
{"to_str", 0},
|
|
|
|
{"to_sym", 0},
|
|
|
|
{"to_hash", 0},
|
|
|
|
{"to_proc", 0},
|
|
|
|
{"to_io", 0},
|
|
|
|
{"to_a", 0},
|
|
|
|
{"to_s", 0},
|
|
|
|
{NULL, 0}
|
|
|
|
};
|
2013-01-30 02:00:58 +04:00
|
|
|
#define IMPLICIT_CONVERSIONS 7
|
2008-08-28 15:50:31 +04:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
convert_type(VALUE val, const char *tname, const char *method, int raise)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
2008-08-28 15:50:31 +04:00
|
|
|
ID m = 0;
|
|
|
|
int i;
|
2009-10-29 07:55:10 +03:00
|
|
|
VALUE r;
|
2002-01-04 17:15:33 +03:00
|
|
|
|
2008-08-28 15:50:31 +04:00
|
|
|
for (i=0; conv_method_names[i].method; i++) {
|
|
|
|
if (conv_method_names[i].method[0] == method[0] &&
|
|
|
|
strcmp(conv_method_names[i].method, method) == 0) {
|
|
|
|
m = conv_method_names[i].id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!m) m = rb_intern(method);
|
2009-10-29 07:55:10 +03:00
|
|
|
r = rb_check_funcall(val, m, 0, 0);
|
|
|
|
if (r == Qundef) {
|
2002-01-04 17:15:33 +03:00
|
|
|
if (raise) {
|
2013-01-30 02:00:58 +04:00
|
|
|
rb_raise(rb_eTypeError, i < IMPLICIT_CONVERSIONS
|
|
|
|
? "no implicit conversion of %s into %s"
|
|
|
|
: "can't convert %s into %s",
|
2002-01-04 17:15:33 +03:00
|
|
|
NIL_P(val) ? "nil" :
|
|
|
|
val == Qtrue ? "true" :
|
|
|
|
val == Qfalse ? "false" :
|
2009-02-22 17:23:33 +03:00
|
|
|
rb_obj_classname(val),
|
2002-01-04 17:15:33 +03:00
|
|
|
tname);
|
|
|
|
}
|
2009-10-29 07:55:10 +03:00
|
|
|
return Qnil;
|
2002-01-04 17:15:33 +03:00
|
|
|
}
|
2009-10-29 07:55:10 +03:00
|
|
|
return r;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_convert_type(VALUE val, int type, const char *tname, const char *method)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2002-01-04 17:15:33 +03:00
|
|
|
VALUE v;
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
if (TYPE(val) == type) return val;
|
2009-07-18 12:05:32 +04:00
|
|
|
v = convert_type(val, tname, method, TRUE);
|
2002-01-04 17:15:33 +03:00
|
|
|
if (TYPE(v) != type) {
|
2008-05-31 13:28:20 +04:00
|
|
|
const char *cname = rb_obj_classname(val);
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
rb_raise(rb_eTypeError, "can't convert %s to %s (%s#%s gives %s)",
|
2004-01-22 21:06:38 +03:00
|
|
|
cname, tname, cname, method, rb_obj_classname(v));
|
2000-08-31 09:29:54 +04:00
|
|
|
}
|
2002-01-04 17:15:33 +03:00
|
|
|
return v;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2001-11-29 18:57:25 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_check_convert_type(VALUE val, int type, const char *tname, const char *method)
|
2001-11-29 18:57:25 +03:00
|
|
|
{
|
2002-01-04 17:15:33 +03:00
|
|
|
VALUE v;
|
2001-11-29 18:57:25 +03:00
|
|
|
|
2002-04-24 08:54:16 +04:00
|
|
|
/* always convert T_DATA */
|
|
|
|
if (TYPE(val) == type && type != T_DATA) return val;
|
2009-07-18 12:05:32 +04:00
|
|
|
v = convert_type(val, tname, method, FALSE);
|
2002-01-04 17:15:33 +03:00
|
|
|
if (NIL_P(v)) return Qnil;
|
|
|
|
if (TYPE(v) != type) {
|
2008-05-31 13:28:20 +04:00
|
|
|
const char *cname = rb_obj_classname(val);
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
rb_raise(rb_eTypeError, "can't convert %s to %s (%s#%s gives %s)",
|
2004-01-22 21:06:38 +03:00
|
|
|
cname, tname, cname, method, rb_obj_classname(v));
|
2001-11-29 18:57:25 +03:00
|
|
|
}
|
2002-01-04 17:15:33 +03:00
|
|
|
return v;
|
2001-11-29 18:57:25 +03:00
|
|
|
}
|
|
|
|
|
2002-06-28 18:42:46 +04:00
|
|
|
|
2000-11-13 08:39:35 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_to_integer(VALUE val, const char *method)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2008-02-11 20:46:52 +03:00
|
|
|
VALUE v;
|
|
|
|
|
|
|
|
if (FIXNUM_P(val)) return val;
|
2011-09-29 15:07:45 +04:00
|
|
|
if (RB_TYPE_P(val, T_BIGNUM)) return val;
|
2009-07-18 12:05:32 +04:00
|
|
|
v = convert_type(val, "Integer", method, TRUE);
|
2002-01-04 17:15:33 +03:00
|
|
|
if (!rb_obj_is_kind_of(v, rb_cInteger)) {
|
2008-05-31 13:28:20 +04:00
|
|
|
const char *cname = rb_obj_classname(val);
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
rb_raise(rb_eTypeError, "can't convert %s to Integer (%s#%s gives %s)",
|
2004-01-22 21:06:38 +03:00
|
|
|
cname, cname, method, rb_obj_classname(v));
|
2000-11-13 08:39:35 +03:00
|
|
|
}
|
2002-01-04 17:15:33 +03:00
|
|
|
return v;
|
2000-11-13 08:39:35 +03:00
|
|
|
}
|
|
|
|
|
2005-08-04 08:31:33 +04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_check_to_integer(VALUE val, const char *method)
|
2005-08-04 08:31:33 +04:00
|
|
|
{
|
2008-02-11 20:46:52 +03:00
|
|
|
VALUE v;
|
|
|
|
|
|
|
|
if (FIXNUM_P(val)) return val;
|
2011-09-29 15:07:45 +04:00
|
|
|
if (RB_TYPE_P(val, T_BIGNUM)) return val;
|
2009-07-18 12:05:32 +04:00
|
|
|
v = convert_type(val, "Integer", method, FALSE);
|
2005-08-04 08:31:33 +04:00
|
|
|
if (!rb_obj_is_kind_of(v, rb_cInteger)) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2000-11-13 08:39:35 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_to_int(VALUE val)
|
2000-11-13 08:39:35 +03:00
|
|
|
{
|
|
|
|
return rb_to_integer(val, "to_int");
|
|
|
|
}
|
|
|
|
|
2011-12-11 05:37:50 +04:00
|
|
|
VALUE
|
|
|
|
rb_check_to_int(VALUE val)
|
|
|
|
{
|
|
|
|
return rb_check_to_integer(val, "to_int");
|
|
|
|
}
|
|
|
|
|
2009-10-03 14:18:14 +04:00
|
|
|
static VALUE
|
|
|
|
rb_convert_to_integer(VALUE val, int base)
|
2000-11-13 08:39:35 +03:00
|
|
|
{
|
2004-11-29 09:09:40 +03:00
|
|
|
VALUE tmp;
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
switch (TYPE(val)) {
|
|
|
|
case T_FLOAT:
|
2009-10-03 14:18:14 +04:00
|
|
|
if (base != 0) goto arg_error;
|
* include/ruby/ruby.h: introduce 2 macros:
RFLOAT_VALUE(v), DOUBLE2NUM(dbl).
Rename RFloat#value -> RFloat#double_value.
Do not touch RFloat#double_value directly.
* bignum.c, insns.def, marshal.c, math.c, numeric.c, object.c,
pack.c, parse.y, process.c, random.c, sprintf.c, string.c,
time.c: apply above changes.
* ext/dl/mkcallback.rb, ext/json/ext/generator/generator.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-13 19:00:53 +03:00
|
|
|
if (RFLOAT_VALUE(val) <= (double)FIXNUM_MAX
|
|
|
|
&& RFLOAT_VALUE(val) >= (double)FIXNUM_MIN) {
|
1999-08-13 09:45:20 +04:00
|
|
|
break;
|
|
|
|
}
|
* include/ruby/ruby.h: introduce 2 macros:
RFLOAT_VALUE(v), DOUBLE2NUM(dbl).
Rename RFloat#value -> RFloat#double_value.
Do not touch RFloat#double_value directly.
* bignum.c, insns.def, marshal.c, math.c, numeric.c, object.c,
pack.c, parse.y, process.c, random.c, sprintf.c, string.c,
time.c: apply above changes.
* ext/dl/mkcallback.rb, ext/json/ext/generator/generator.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-13 19:00:53 +03:00
|
|
|
return rb_dbl2big(RFLOAT_VALUE(val));
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-07-02 13:58:13 +04:00
|
|
|
case T_FIXNUM:
|
1999-08-13 09:45:20 +04:00
|
|
|
case T_BIGNUM:
|
2009-10-03 14:18:14 +04:00
|
|
|
if (base != 0) goto arg_error;
|
1999-08-13 09:45:20 +04:00
|
|
|
return val;
|
|
|
|
|
|
|
|
case T_STRING:
|
2009-10-03 14:18:14 +04:00
|
|
|
string_conv:
|
|
|
|
return rb_str_to_inum(val, base, TRUE);
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2006-08-30 13:46:57 +04:00
|
|
|
case T_NIL:
|
2009-10-03 14:18:14 +04:00
|
|
|
if (base != 0) goto arg_error;
|
2006-08-30 13:46:57 +04:00
|
|
|
rb_raise(rb_eTypeError, "can't convert nil into Integer");
|
|
|
|
break;
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-10-03 14:18:14 +04:00
|
|
|
if (base != 0) {
|
|
|
|
tmp = rb_check_string_type(val);
|
|
|
|
if (!NIL_P(tmp)) goto string_conv;
|
|
|
|
arg_error:
|
|
|
|
rb_raise(rb_eArgError, "base specified for non string value");
|
|
|
|
}
|
2009-07-18 12:05:32 +04:00
|
|
|
tmp = convert_type(val, "Integer", "to_int", FALSE);
|
2004-11-29 09:09:40 +03:00
|
|
|
if (NIL_P(tmp)) {
|
|
|
|
return rb_to_integer(val, "to_i");
|
2002-06-28 18:42:46 +04:00
|
|
|
}
|
2004-11-29 09:09:40 +03:00
|
|
|
return tmp;
|
2009-10-03 14:18:14 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_Integer(VALUE val)
|
|
|
|
{
|
|
|
|
return rb_convert_to_integer(val, 0);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* Integer(arg,base=0) -> integer
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Converts <i>arg</i> to a <code>Fixnum</code> or <code>Bignum</code>.
|
|
|
|
* Numeric types are converted directly (with floating point numbers
|
2009-10-03 14:18:14 +04:00
|
|
|
* being truncated). <i>base</i> (0, or between 2 and 36) is a base for
|
|
|
|
* integer string representation. If <i>arg</i> is a <code>String</code>,
|
|
|
|
* when <i>base</i> is omitted or equals to zero, radix indicators
|
|
|
|
* (<code>0</code>, <code>0b</code>, and <code>0x</code>) are honored.
|
|
|
|
* In any case, strings should be strictly conformed to numeric
|
2010-05-29 22:51:39 +04:00
|
|
|
* representation. This behavior is different from that of
|
2009-11-03 20:46:28 +03:00
|
|
|
* <code>String#to_i</code>. Non string values will be converted using
|
2009-10-03 14:18:14 +04:00
|
|
|
* <code>to_int</code>, and <code>to_i</code>.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Integer(123.999) #=> 123
|
|
|
|
* Integer("0x1a") #=> 26
|
2008-03-09 04:04:46 +03:00
|
|
|
* Integer(Time.new) #=> 1204973019
|
2010-07-07 02:02:25 +04:00
|
|
|
* Integer("0930", 10) #=> 930
|
|
|
|
* Integer("111", 2) #=> 7
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static VALUE
|
2009-10-03 14:18:14 +04:00
|
|
|
rb_f_integer(int argc, VALUE *argv, VALUE obj)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2009-10-03 14:18:14 +04:00
|
|
|
VALUE arg = Qnil;
|
|
|
|
int base = 0;
|
|
|
|
|
|
|
|
switch (argc) {
|
|
|
|
case 2:
|
|
|
|
base = NUM2INT(argv[1]);
|
|
|
|
case 1:
|
|
|
|
arg = argv[0];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* should cause ArgumentError */
|
|
|
|
rb_scan_args(argc, argv, "11", NULL, NULL);
|
|
|
|
}
|
|
|
|
return rb_convert_to_integer(arg, base);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
2002-02-01 13:23:22 +03:00
|
|
|
double
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_cstr_to_dbl(const char *p, int badcheck)
|
2002-02-01 13:23:22 +03:00
|
|
|
{
|
|
|
|
const char *q;
|
|
|
|
char *end;
|
|
|
|
double d;
|
2006-07-18 05:55:15 +04:00
|
|
|
const char *ellipsis = "";
|
|
|
|
int w;
|
2009-07-18 12:05:32 +04:00
|
|
|
enum {max_width = 20};
|
|
|
|
#define OutOfRange() ((end - p > max_width) ? \
|
|
|
|
(w = max_width, ellipsis = "...") : \
|
|
|
|
(w = (int)(end - p), ellipsis = ""))
|
2002-02-01 13:23:22 +03:00
|
|
|
|
2002-10-17 11:27:00 +04:00
|
|
|
if (!p) return 0.0;
|
2002-02-01 13:23:22 +03:00
|
|
|
q = p;
|
2008-03-01 18:08:13 +03:00
|
|
|
while (ISSPACE(*p)) p++;
|
2010-04-01 08:32:43 +04:00
|
|
|
|
|
|
|
if (!badcheck && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2002-02-01 13:23:22 +03:00
|
|
|
d = strtod(p, &end);
|
2003-07-10 02:28:42 +04:00
|
|
|
if (errno == ERANGE) {
|
2006-07-18 05:55:15 +04:00
|
|
|
OutOfRange();
|
2008-05-15 14:48:10 +04:00
|
|
|
rb_warning("Float %.*s%s out of range", w, p, ellipsis);
|
2003-07-10 02:28:42 +04:00
|
|
|
errno = 0;
|
|
|
|
}
|
2002-02-01 13:23:22 +03:00
|
|
|
if (p == end) {
|
|
|
|
if (badcheck) {
|
2008-03-01 18:08:13 +03:00
|
|
|
bad:
|
2002-02-01 13:23:22 +03:00
|
|
|
rb_invalid_str(q, "Float()");
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
if (*end) {
|
2008-01-16 09:26:33 +03:00
|
|
|
char buf[DBL_DIG * 4 + 10];
|
2002-02-01 13:23:22 +03:00
|
|
|
char *n = buf;
|
2008-01-16 09:26:33 +03:00
|
|
|
char *e = buf + sizeof(buf) - 1;
|
2008-03-01 18:08:13 +03:00
|
|
|
char prev = 0;
|
2002-02-01 13:23:22 +03:00
|
|
|
|
2008-03-12 11:33:37 +03:00
|
|
|
while (p < end && n < e) prev = *n++ = *p++;
|
2008-03-01 18:08:13 +03:00
|
|
|
while (*p) {
|
2002-02-01 13:23:22 +03:00
|
|
|
if (*p == '_') {
|
|
|
|
/* remove underscores between digits */
|
2008-03-01 18:08:13 +03:00
|
|
|
if (badcheck) {
|
|
|
|
if (n == buf || !ISDIGIT(prev)) goto bad;
|
|
|
|
++p;
|
|
|
|
if (!ISDIGIT(*p)) goto bad;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (*++p == '_');
|
|
|
|
continue;
|
2002-02-01 13:23:22 +03:00
|
|
|
}
|
|
|
|
}
|
2008-03-01 18:08:13 +03:00
|
|
|
prev = *p++;
|
|
|
|
if (n < e) *n++ = prev;
|
2002-02-01 13:23:22 +03:00
|
|
|
}
|
|
|
|
*n = '\0';
|
|
|
|
p = buf;
|
2010-04-01 08:32:43 +04:00
|
|
|
|
|
|
|
if (!badcheck && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
2002-02-01 13:23:22 +03:00
|
|
|
d = strtod(p, &end);
|
2003-07-10 02:28:42 +04:00
|
|
|
if (errno == ERANGE) {
|
2006-07-18 05:55:15 +04:00
|
|
|
OutOfRange();
|
2008-05-15 14:48:10 +04:00
|
|
|
rb_warning("Float %.*s%s out of range", w, p, ellipsis);
|
2003-07-10 02:28:42 +04:00
|
|
|
errno = 0;
|
|
|
|
}
|
2002-02-01 13:23:22 +03:00
|
|
|
if (badcheck) {
|
2006-07-18 05:55:15 +04:00
|
|
|
if (!end || p == end) goto bad;
|
2002-02-01 13:23:22 +03:00
|
|
|
while (*end && ISSPACE(*end)) end++;
|
|
|
|
if (*end) goto bad;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (errno == ERANGE) {
|
|
|
|
errno = 0;
|
2006-07-18 05:55:15 +04:00
|
|
|
OutOfRange();
|
|
|
|
rb_raise(rb_eArgError, "Float %.*s%s out of range", w, q, ellipsis);
|
2002-02-01 13:23:22 +03:00
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_str_to_dbl(VALUE str, int badcheck)
|
2002-02-01 13:23:22 +03:00
|
|
|
{
|
|
|
|
char *s;
|
2002-08-21 19:47:54 +04:00
|
|
|
long len;
|
2011-01-24 15:30:02 +03:00
|
|
|
double ret;
|
2011-01-27 15:46:30 +03:00
|
|
|
VALUE v = 0;
|
2002-02-01 13:23:22 +03:00
|
|
|
|
|
|
|
StringValue(str);
|
2006-08-31 14:47:44 +04:00
|
|
|
s = RSTRING_PTR(str);
|
|
|
|
len = RSTRING_LEN(str);
|
2002-10-17 11:27:00 +04:00
|
|
|
if (s) {
|
2009-07-18 12:05:32 +04:00
|
|
|
if (badcheck && memchr(s, '\0', len)) {
|
|
|
|
rb_raise(rb_eArgError, "string for Float contains null byte");
|
|
|
|
}
|
2002-10-17 11:27:00 +04:00
|
|
|
if (s[len]) { /* no sentinel somehow */
|
2011-01-27 15:46:30 +03:00
|
|
|
char *p = ALLOCV(v, len);
|
2002-10-17 11:27:00 +04:00
|
|
|
MEMCPY(p, s, char, len);
|
|
|
|
p[len] = '\0';
|
|
|
|
s = p;
|
|
|
|
}
|
2002-02-01 13:23:22 +03:00
|
|
|
}
|
2011-01-24 15:30:02 +03:00
|
|
|
ret = rb_cstr_to_dbl(s, badcheck);
|
2011-01-27 15:46:30 +03:00
|
|
|
if (v)
|
|
|
|
ALLOCV_END(v);
|
2011-01-24 15:30:02 +03:00
|
|
|
return ret;
|
2002-02-01 13:23:22 +03:00
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_Float(VALUE val)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
switch (TYPE(val)) {
|
1998-01-16 15:19:22 +03:00
|
|
|
case T_FIXNUM:
|
2008-09-05 22:24:21 +04:00
|
|
|
return DBL2NUM((double)FIX2LONG(val));
|
1998-01-16 15:19:22 +03:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
case T_FLOAT:
|
1999-01-20 07:59:39 +03:00
|
|
|
return val;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
case T_BIGNUM:
|
2008-09-05 22:24:21 +04:00
|
|
|
return DBL2NUM(rb_big2dbl(val));
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-12-25 09:29:27 +03:00
|
|
|
case T_STRING:
|
2009-07-18 12:05:32 +04:00
|
|
|
return DBL2NUM(rb_str_to_dbl(val, TRUE));
|
2000-12-25 09:29:27 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
case T_NIL:
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
rb_raise(rb_eTypeError, "can't convert nil into Float");
|
2002-06-28 18:42:46 +04:00
|
|
|
break;
|
1999-08-13 09:45:20 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
default:
|
2008-05-16 08:17:45 +04:00
|
|
|
return rb_convert_type(val, T_FLOAT, "Float", "to_f");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2012-04-14 03:45:37 +04:00
|
|
|
|
|
|
|
UNREACHABLE;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* Float(arg) -> float
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Returns <i>arg</i> converted to a float. Numeric types are converted
|
|
|
|
* directly, the rest are converted using <i>arg</i>.to_f. As of Ruby
|
|
|
|
* 1.8, converting <code>nil</code> generates a <code>TypeError</code>.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Float(1) #=> 1.0
|
|
|
|
* Float("123.456") #=> 123.456
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_f_float(VALUE obj, VALUE arg)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_Float(arg);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2008-12-29 16:40:33 +03:00
|
|
|
VALUE
|
|
|
|
rb_to_float(VALUE val)
|
|
|
|
{
|
2011-09-29 15:07:45 +04:00
|
|
|
if (RB_TYPE_P(val, T_FLOAT)) return val;
|
2008-12-31 17:30:50 +03:00
|
|
|
if (!rb_obj_is_kind_of(val, rb_cNumeric)) {
|
|
|
|
rb_raise(rb_eTypeError, "can't convert %s into Float",
|
|
|
|
NIL_P(val) ? "nil" :
|
|
|
|
val == Qtrue ? "true" :
|
|
|
|
val == Qfalse ? "false" :
|
|
|
|
rb_obj_classname(val));
|
|
|
|
}
|
|
|
|
return rb_convert_type(val, T_FLOAT, "Float", "to_f");
|
2008-12-29 16:40:33 +03:00
|
|
|
}
|
|
|
|
|
2009-08-26 14:20:30 +04:00
|
|
|
VALUE
|
|
|
|
rb_check_to_float(VALUE val)
|
|
|
|
{
|
2011-09-29 15:07:45 +04:00
|
|
|
if (RB_TYPE_P(val, T_FLOAT)) return val;
|
2009-08-26 14:20:30 +04:00
|
|
|
if (!rb_obj_is_kind_of(val, rb_cNumeric)) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
return rb_check_convert_type(val, T_FLOAT, "Float", "to_f");
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
double
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_num2dbl(VALUE val)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
switch (TYPE(val)) {
|
|
|
|
case T_FLOAT:
|
* include/ruby/ruby.h: introduce 2 macros:
RFLOAT_VALUE(v), DOUBLE2NUM(dbl).
Rename RFloat#value -> RFloat#double_value.
Do not touch RFloat#double_value directly.
* bignum.c, insns.def, marshal.c, math.c, numeric.c, object.c,
pack.c, parse.y, process.c, random.c, sprintf.c, string.c,
time.c: apply above changes.
* ext/dl/mkcallback.rb, ext/json/ext/generator/generator.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-13 19:00:53 +03:00
|
|
|
return RFLOAT_VALUE(val);
|
1999-08-13 09:45:20 +04:00
|
|
|
|
|
|
|
case T_STRING:
|
2001-10-02 08:31:23 +04:00
|
|
|
rb_raise(rb_eTypeError, "no implicit conversion to float from string");
|
1999-08-13 09:45:20 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_NIL:
|
2001-10-02 08:31:23 +04:00
|
|
|
rb_raise(rb_eTypeError, "no implicit conversion to float from nil");
|
1999-08-13 09:45:20 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
* include/ruby/ruby.h: introduce 2 macros:
RFLOAT_VALUE(v), DOUBLE2NUM(dbl).
Rename RFloat#value -> RFloat#double_value.
Do not touch RFloat#double_value directly.
* bignum.c, insns.def, marshal.c, math.c, numeric.c, object.c,
pack.c, parse.y, process.c, random.c, sprintf.c, string.c,
time.c: apply above changes.
* ext/dl/mkcallback.rb, ext/json/ext/generator/generator.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-13 19:00:53 +03:00
|
|
|
return RFLOAT_VALUE(rb_Float(val));
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_String(VALUE val)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2011-03-29 16:56:40 +04:00
|
|
|
VALUE tmp = rb_check_string_type(val);
|
|
|
|
if (NIL_P(tmp))
|
|
|
|
tmp = rb_convert_type(val, T_STRING, "String", "to_s");
|
|
|
|
return tmp;
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* String(arg) -> string
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Converts <i>arg</i> to a <code>String</code> by calling its
|
|
|
|
* <code>to_s</code> method.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* String(self) #=> "main"
|
2006-12-28 09:34:02 +03:00
|
|
|
* String(self.class) #=> "Object"
|
2003-12-28 09:33:07 +03:00
|
|
|
* String(123456) #=> "123456"
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_f_string(VALUE obj, VALUE arg)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_String(arg);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_Array(VALUE val)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2003-05-26 12:22:33 +04:00
|
|
|
VALUE tmp = rb_check_array_type(val);
|
2000-09-12 09:37:38 +04:00
|
|
|
|
2003-05-26 12:22:33 +04:00
|
|
|
if (NIL_P(tmp)) {
|
2006-12-28 09:34:02 +03:00
|
|
|
tmp = rb_check_convert_type(val, T_ARRAY, "Array", "to_a");
|
|
|
|
if (NIL_P(tmp)) {
|
|
|
|
return rb_ary_new3(1, val);
|
|
|
|
}
|
2000-09-12 09:37:38 +04:00
|
|
|
}
|
2003-05-26 12:22:33 +04:00
|
|
|
return tmp;
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:07:33 +04:00
|
|
|
* Array(arg) -> array
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2013-02-19 07:32:11 +04:00
|
|
|
* Returns +arg+ as an Array.
|
|
|
|
*
|
|
|
|
* First tries to call Array#to_ary on +arg+, then Array#to_a.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* Array(1..5) #=> [1, 2, 3, 4, 5]
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_f_array(VALUE obj, VALUE arg)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_Array(arg);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2012-01-24 08:02:30 +04:00
|
|
|
VALUE
|
|
|
|
rb_Hash(VALUE val)
|
|
|
|
{
|
2012-01-24 11:21:33 +04:00
|
|
|
VALUE tmp;
|
|
|
|
|
2012-01-24 08:02:30 +04:00
|
|
|
if (NIL_P(val)) return rb_hash_new();
|
2012-01-24 11:21:33 +04:00
|
|
|
tmp = rb_check_hash_type(val);
|
2012-01-24 08:02:30 +04:00
|
|
|
if (NIL_P(tmp)) {
|
2012-01-24 08:29:07 +04:00
|
|
|
if (RB_TYPE_P(val, T_ARRAY) && RARRAY_LEN(val) == 0)
|
2012-01-24 08:02:30 +04:00
|
|
|
return rb_hash_new();
|
|
|
|
rb_raise(rb_eTypeError, "can't convert %s into Hash", rb_obj_classname(val));
|
|
|
|
}
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* Hash(arg) -> hash
|
|
|
|
*
|
|
|
|
* Converts <i>arg</i> to a <code>Hash</code> by calling
|
|
|
|
* <i>arg</i><code>.to_hash</code>. Returns an empty <code>Hash</code> when
|
|
|
|
* <i>arg</i> is <tt>nil</tt> or <tt>[]</tt>.
|
|
|
|
*
|
|
|
|
* Hash([]) #=> {}
|
2013-06-04 18:47:33 +04:00
|
|
|
* Hash(nil) #=> {}
|
2012-01-24 08:02:30 +04:00
|
|
|
* Hash(key: :value) #=> {:key => :value}
|
|
|
|
* Hash([1, 2, 3]) #=> TypeError
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_f_hash(VALUE obj, VALUE arg)
|
|
|
|
{
|
|
|
|
return rb_Hash(arg);
|
|
|
|
}
|
|
|
|
|
2003-12-19 18:18:09 +03:00
|
|
|
/*
|
|
|
|
* Document-class: Class
|
|
|
|
*
|
|
|
|
* Classes in Ruby are first-class objects---each is an instance of
|
|
|
|
* class <code>Class</code>.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2011-10-11 00:54:45 +04:00
|
|
|
* Typically, you create a new class by using:
|
|
|
|
*
|
|
|
|
* class Name
|
|
|
|
* # some class describing the class behavior
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* When a new class is created, an object of type Class is initialized and
|
|
|
|
* assigned to a global constant (<code>Name</code> in this case).
|
|
|
|
*
|
|
|
|
* When <code>Name.new</code> is called to create a new object, the
|
2003-12-19 18:18:09 +03:00
|
|
|
* <code>new</code> method in <code>Class</code> is run by default.
|
|
|
|
* This can be demonstrated by overriding <code>new</code> in
|
|
|
|
* <code>Class</code>:
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-19 18:18:09 +03:00
|
|
|
* class Class
|
|
|
|
* alias oldNew new
|
|
|
|
* def new(*args)
|
|
|
|
* print "Creating a new ", self.name, "\n"
|
|
|
|
* oldNew(*args)
|
|
|
|
* end
|
|
|
|
* end
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
|
|
|
*
|
2003-12-19 18:18:09 +03:00
|
|
|
* class Name
|
|
|
|
* end
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
|
|
|
*
|
2003-12-19 18:18:09 +03:00
|
|
|
* n = Name.new
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-19 18:18:09 +03:00
|
|
|
* <em>produces:</em>
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2003-12-19 18:18:09 +03:00
|
|
|
* Creating a new Name
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2004-01-02 09:01:12 +03:00
|
|
|
* Classes, modules, and objects are interrelated. In the diagram
|
2005-05-11 11:00:32 +04:00
|
|
|
* that follows, the vertical arrows represent inheritance, and the
|
2009-02-22 17:23:33 +03:00
|
|
|
* parentheses meta-classes. All metaclasses are instances
|
2004-01-02 09:01:12 +03:00
|
|
|
* of the class `Class'.
|
2009-06-29 19:34:30 +04:00
|
|
|
* +---------+ +-...
|
|
|
|
* | | |
|
|
|
|
* BasicObject-----|-->(BasicObject)-------|-...
|
|
|
|
* ^ | ^ |
|
|
|
|
* | | | |
|
|
|
|
* Object---------|----->(Object)---------|-...
|
|
|
|
* ^ | ^ |
|
|
|
|
* | | | |
|
|
|
|
* +-------+ | +--------+ |
|
|
|
|
* | | | | | |
|
|
|
|
* | Module-|---------|--->(Module)-|-...
|
|
|
|
* | ^ | | ^ |
|
|
|
|
* | | | | | |
|
|
|
|
* | Class-|---------|---->(Class)-|-...
|
|
|
|
* | ^ | | ^ |
|
|
|
|
* | +---+ | +----+
|
|
|
|
* | |
|
|
|
|
* obj--->OtherClass---------->(OtherClass)-----------...
|
2006-12-31 18:02:22 +03:00
|
|
|
*
|
2003-12-19 18:18:09 +03:00
|
|
|
*/
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
|
2009-06-29 20:39:28 +04:00
|
|
|
/*!
|
|
|
|
* Initializes the world of objects and classes.
|
|
|
|
*
|
|
|
|
* At first, the function bootstraps the class hierarchy.
|
|
|
|
* It initializes the most fundamental classes and their metaclasses.
|
|
|
|
* - \c BasicObject
|
|
|
|
* - \c Object
|
|
|
|
* - \c Module
|
|
|
|
* - \c Class
|
|
|
|
* After the bootstrap step, the class hierarchy becomes as the following
|
|
|
|
* diagram.
|
|
|
|
*
|
|
|
|
* \image html boottime-classes.png
|
|
|
|
*
|
|
|
|
* Then, the function defines classes, modules and methods as usual.
|
|
|
|
* \ingroup class
|
2009-06-29 20:52:57 +04:00
|
|
|
*/
|
|
|
|
|
2011-06-28 02:51:42 +04:00
|
|
|
/* Document-class: BasicObject
|
|
|
|
*
|
|
|
|
* BasicObject is the parent class of all classes in Ruby. It's an explicit
|
|
|
|
* blank class.
|
2011-07-27 10:44:39 +04:00
|
|
|
*
|
|
|
|
* BasicObject can be used for creating object hierarchies independent of
|
|
|
|
* Ruby's object hierarchy, proxy objects like the Delegator class, or other
|
|
|
|
* uses where namespace pollution from Ruby's methods and classes must be
|
|
|
|
* avoided.
|
|
|
|
*
|
|
|
|
* To avoid polluting BasicObject for other users an appropriately named
|
|
|
|
* subclass of BasicObject should be created instead of directly modifying
|
|
|
|
* BasicObject:
|
|
|
|
*
|
|
|
|
* class MyObjectSystem < BasicObject
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* BasicObject does not include Kernel (for methods like +puts+) and
|
|
|
|
* BasicObject is outside of the namespace of the standard library so common
|
|
|
|
* classes will not be found without a using a full class path.
|
|
|
|
*
|
|
|
|
* A variety of strategies can be used to provide useful portions of the
|
|
|
|
* standard library to subclasses of BasicObject. A subclass could
|
|
|
|
* <code>include Kernel</code> to obtain +puts+, +exit+, etc. A custom
|
|
|
|
* Kernel-like module could be created and included or delegation can be used
|
|
|
|
* via #method_missing:
|
|
|
|
*
|
|
|
|
* class MyObjectSystem < BasicObject
|
|
|
|
* DELEGATE = [:puts, :p]
|
|
|
|
*
|
|
|
|
* def method_missing(name, *args, &block)
|
|
|
|
* super unless DELEGATE.include? name
|
|
|
|
* ::Kernel.send(name, *args, &block)
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* def respond_to_missing?(name, include_private = false)
|
2012-06-19 17:58:30 +04:00
|
|
|
* DELEGATE.include?(name) or super
|
2011-07-27 10:44:39 +04:00
|
|
|
* end
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* Access to classes and modules from the Ruby standard library can be
|
|
|
|
* obtained in a BasicObject subclass by referencing the desired constant
|
|
|
|
* from the root like <code>::File</code> or <code>::Enumerator</code>.
|
|
|
|
* Like #method_missing, #const_missing can be used to delegate constant
|
|
|
|
* lookup to +Object+:
|
|
|
|
*
|
|
|
|
* class MyObjectSystem < BasicObject
|
|
|
|
* def self.const_missing(name)
|
|
|
|
* ::Object.const_get(name)
|
|
|
|
* end
|
|
|
|
* end
|
2011-06-28 02:51:42 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Document-class: Object
|
2009-06-29 20:52:57 +04:00
|
|
|
*
|
2011-10-11 00:54:45 +04:00
|
|
|
* Object is the default root of all Ruby objects. Object inherits from
|
|
|
|
* BasicObject which allows creating alternate object hierarchies. Methods
|
|
|
|
* on object are available to all classes unless explicitly overridden.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2011-06-28 02:51:42 +04:00
|
|
|
* Object mixes in the Kernel module, making the built-in kernel functions
|
2011-10-11 00:54:45 +04:00
|
|
|
* globally accessible. Although the instance methods of Object are defined
|
2011-06-28 02:51:42 +04:00
|
|
|
* by the Kernel module, we have chosen to document them here for clarity.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2011-10-11 00:54:45 +04:00
|
|
|
* When referencing constants in classes inheriting from Object you do not
|
|
|
|
* need to use the full namespace. For example, referencing +File+ inside
|
|
|
|
* +YourClass+ will find the top-level File class.
|
|
|
|
*
|
2003-12-28 09:33:07 +03:00
|
|
|
* In the descriptions of Object's methods, the parameter <i>symbol</i> refers
|
2011-06-28 02:51:42 +04:00
|
|
|
* to a symbol, which is either a quoted string or a Symbol (such as
|
|
|
|
* <code>:name</code>).
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
Init_Object(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-08-28 15:50:31 +04:00
|
|
|
int i;
|
|
|
|
|
2009-08-31 09:55:57 +04:00
|
|
|
Init_class_hierarchy();
|
|
|
|
|
2011-06-28 02:51:42 +04:00
|
|
|
#if 0
|
|
|
|
// teach RDoc about these classes
|
|
|
|
rb_cBasicObject = rb_define_class("BasicObject", Qnil);
|
|
|
|
rb_cObject = rb_define_class("Object", rb_cBasicObject);
|
|
|
|
rb_cModule = rb_define_class("Module", rb_cObject);
|
|
|
|
rb_cClass = rb_define_class("Class", rb_cModule);
|
|
|
|
#endif
|
|
|
|
|
2008-06-09 13:25:32 +04:00
|
|
|
#undef rb_intern
|
2008-08-16 04:20:31 +04:00
|
|
|
#define rb_intern(str) rb_intern_const(str)
|
2008-06-09 13:25:32 +04:00
|
|
|
|
2010-10-30 05:25:41 +04:00
|
|
|
rb_define_private_method(rb_cBasicObject, "initialize", rb_obj_dummy, 0);
|
* 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
|
|
|
rb_define_alloc_func(rb_cBasicObject, rb_class_allocate_instance);
|
|
|
|
rb_define_method(rb_cBasicObject, "==", rb_obj_equal, 1);
|
|
|
|
rb_define_method(rb_cBasicObject, "equal?", rb_obj_equal, 1);
|
2007-12-18 08:50:37 +03:00
|
|
|
rb_define_method(rb_cBasicObject, "!", rb_obj_not, 0);
|
2007-12-09 19:39:49 +03:00
|
|
|
rb_define_method(rb_cBasicObject, "!=", rb_obj_not_equal, 1);
|
* 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
|
|
|
|
2007-12-11 09:23:21 +03:00
|
|
|
rb_define_private_method(rb_cBasicObject, "singleton_method_added", rb_obj_dummy, 1);
|
|
|
|
rb_define_private_method(rb_cBasicObject, "singleton_method_removed", rb_obj_dummy, 1);
|
|
|
|
rb_define_private_method(rb_cBasicObject, "singleton_method_undefined", rb_obj_dummy, 1);
|
|
|
|
|
2012-06-01 01:41:21 +04:00
|
|
|
/* Document-module: Kernel
|
|
|
|
*
|
|
|
|
* The Kernel module is included by class Object, so its methods are
|
|
|
|
* available in every Ruby object.
|
|
|
|
*
|
|
|
|
* The Kernel instance methods are documented in class Object while the
|
|
|
|
* module methods are documented here. These methods are called without a
|
|
|
|
* receiver and thus can be called in functional form:
|
|
|
|
*
|
|
|
|
* sprintf "%.1f", 1.234 #=> "1.2"
|
|
|
|
*
|
|
|
|
*/
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_mKernel = rb_define_module("Kernel");
|
|
|
|
rb_include_module(rb_cObject, rb_mKernel);
|
|
|
|
rb_define_private_method(rb_cClass, "inherited", rb_obj_dummy, 1);
|
2001-05-11 09:24:59 +04:00
|
|
|
rb_define_private_method(rb_cModule, "included", rb_obj_dummy, 1);
|
2003-12-05 08:54:00 +03:00
|
|
|
rb_define_private_method(rb_cModule, "extended", rb_obj_dummy, 1);
|
2012-06-27 11:48:50 +04:00
|
|
|
rb_define_private_method(rb_cModule, "prepended", rb_obj_dummy, 1);
|
2001-05-11 09:24:59 +04:00
|
|
|
rb_define_private_method(rb_cModule, "method_added", rb_obj_dummy, 1);
|
|
|
|
rb_define_private_method(rb_cModule, "method_removed", rb_obj_dummy, 1);
|
|
|
|
rb_define_private_method(rb_cModule, "method_undefined", rb_obj_dummy, 1);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_mKernel, "nil?", rb_false, 0);
|
2009-02-22 17:23:33 +03:00
|
|
|
rb_define_method(rb_mKernel, "===", rb_equal, 1);
|
2007-12-09 19:39:49 +03:00
|
|
|
rb_define_method(rb_mKernel, "=~", rb_obj_match, 1);
|
|
|
|
rb_define_method(rb_mKernel, "!~", rb_obj_not_match, 1);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1);
|
* string.c (rb_hash_uint32, rb_hash_uint, rb_hash_start, rb_hash_end),
include/ruby/intern.h: add Murmurhash API. [ruby-dev:37784]
* complex.c (nucomp_hash), array.c (rb_ary_hash), time.c (time_hash),
string.c (rb_str_hsah), object.c (rb_obj_hash), range.c
(range_hash), struct.c (rb_struct_hash), hash.c (rb_any_hash),
rational.c (nurat_hash): use Murmurhash. [ruby-dev:37784]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22317 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-14 22:55:34 +03:00
|
|
|
rb_define_method(rb_mKernel, "hash", rb_obj_hash, 0);
|
2009-10-24 20:48:05 +04:00
|
|
|
rb_define_method(rb_mKernel, "<=>", rb_obj_cmp, 1);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2001-08-20 08:29:58 +04:00
|
|
|
rb_define_method(rb_mKernel, "class", rb_obj_class, 0);
|
2010-03-23 12:38:54 +03:00
|
|
|
rb_define_method(rb_mKernel, "singleton_class", rb_obj_singleton_class, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_mKernel, "clone", rb_obj_clone, 0);
|
|
|
|
rb_define_method(rb_mKernel, "dup", rb_obj_dup, 0);
|
2003-05-19 09:41:08 +04:00
|
|
|
rb_define_method(rb_mKernel, "initialize_copy", rb_obj_init_copy, 1);
|
2010-02-08 10:43:54 +03:00
|
|
|
rb_define_method(rb_mKernel, "initialize_dup", rb_obj_init_dup_clone, 1);
|
|
|
|
rb_define_method(rb_mKernel, "initialize_clone", rb_obj_init_dup_clone, 1);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
rb_define_method(rb_mKernel, "taint", rb_obj_taint, 0);
|
|
|
|
rb_define_method(rb_mKernel, "tainted?", rb_obj_tainted, 0);
|
|
|
|
rb_define_method(rb_mKernel, "untaint", rb_obj_untaint, 0);
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
rb_define_method(rb_mKernel, "untrust", rb_obj_untrust, 0);
|
|
|
|
rb_define_method(rb_mKernel, "untrusted?", rb_obj_untrusted, 0);
|
|
|
|
rb_define_method(rb_mKernel, "trust", rb_obj_trust, 0);
|
2000-02-01 06:12:21 +03:00
|
|
|
rb_define_method(rb_mKernel, "freeze", rb_obj_freeze, 0);
|
|
|
|
rb_define_method(rb_mKernel, "frozen?", rb_obj_frozen_p, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
rb_define_method(rb_mKernel, "to_s", rb_any_to_s, 0);
|
|
|
|
rb_define_method(rb_mKernel, "inspect", rb_obj_inspect, 0);
|
2012-07-03 01:12:48 +04:00
|
|
|
rb_define_method(rb_mKernel, "methods", rb_obj_methods, -1); /* in class.c */
|
2004-01-10 20:39:07 +03:00
|
|
|
rb_define_method(rb_mKernel, "singleton_methods", rb_obj_singleton_methods, -1); /* in class.c */
|
2012-07-03 01:12:48 +04:00
|
|
|
rb_define_method(rb_mKernel, "protected_methods", rb_obj_protected_methods, -1); /* in class.c */
|
|
|
|
rb_define_method(rb_mKernel, "private_methods", rb_obj_private_methods, -1); /* in class.c */
|
|
|
|
rb_define_method(rb_mKernel, "public_methods", rb_obj_public_methods, -1); /* in class.c */
|
2004-01-10 20:39:07 +03:00
|
|
|
rb_define_method(rb_mKernel, "instance_variables", rb_obj_instance_variables, 0); /* in variable.c */
|
2003-02-10 12:40:13 +03:00
|
|
|
rb_define_method(rb_mKernel, "instance_variable_get", rb_obj_ivar_get, 1);
|
|
|
|
rb_define_method(rb_mKernel, "instance_variable_set", rb_obj_ivar_set, 2);
|
2006-09-18 19:43:06 +04:00
|
|
|
rb_define_method(rb_mKernel, "instance_variable_defined?", rb_obj_ivar_defined, 1);
|
2012-12-01 13:16:57 +04:00
|
|
|
rb_define_method(rb_mKernel, "remove_instance_variable",
|
|
|
|
rb_obj_remove_instance_variable, 1); /* in variable.c */
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
rb_define_method(rb_mKernel, "instance_of?", rb_obj_is_instance_of, 1);
|
|
|
|
rb_define_method(rb_mKernel, "kind_of?", rb_obj_is_kind_of, 1);
|
|
|
|
rb_define_method(rb_mKernel, "is_a?", rb_obj_is_kind_of, 1);
|
2006-11-22 11:37:12 +03:00
|
|
|
rb_define_method(rb_mKernel, "tap", rb_obj_tap, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2004-01-08 05:21:28 +03:00
|
|
|
rb_define_global_function("sprintf", rb_f_sprintf, -1); /* in sprintf.c */
|
2004-01-10 20:39:07 +03:00
|
|
|
rb_define_global_function("format", rb_f_sprintf, -1); /* in sprintf.c */
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2009-10-03 14:18:14 +04:00
|
|
|
rb_define_global_function("Integer", rb_f_integer, -1);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_global_function("Float", rb_f_float, 1);
|
|
|
|
|
|
|
|
rb_define_global_function("String", rb_f_string, 1);
|
|
|
|
rb_define_global_function("Array", rb_f_array, 1);
|
2012-01-24 08:02:30 +04:00
|
|
|
rb_define_global_function("Hash", rb_f_hash, 1);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
rb_cNilClass = rb_define_class("NilClass", rb_cObject);
|
|
|
|
rb_define_method(rb_cNilClass, "to_i", nil_to_i, 0);
|
2002-07-02 13:58:13 +04:00
|
|
|
rb_define_method(rb_cNilClass, "to_f", nil_to_f, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_cNilClass, "to_s", nil_to_s, 0);
|
2005-10-21 13:00:02 +04:00
|
|
|
rb_define_method(rb_cNilClass, "to_a", nil_to_a, 0);
|
2012-04-24 07:46:55 +04:00
|
|
|
rb_define_method(rb_cNilClass, "to_h", nil_to_h, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_cNilClass, "inspect", nil_inspect, 0);
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_define_method(rb_cNilClass, "&", false_and, 1);
|
|
|
|
rb_define_method(rb_cNilClass, "|", false_or, 1);
|
|
|
|
rb_define_method(rb_cNilClass, "^", false_xor, 1);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
rb_define_method(rb_cNilClass, "nil?", rb_true, 0);
|
2002-12-20 11:33:17 +03:00
|
|
|
rb_undef_alloc_func(rb_cNilClass);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_undef_method(CLASS_OF(rb_cNilClass), "new");
|
2011-06-29 07:09:34 +04:00
|
|
|
/*
|
|
|
|
* An alias of +nil+
|
|
|
|
*/
|
1998-01-16 15:19:22 +03:00
|
|
|
rb_define_global_const("NIL", Qnil);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-06-16 18:21:34 +04:00
|
|
|
rb_define_method(rb_cModule, "freeze", rb_mod_freeze, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_cModule, "===", rb_mod_eqq, 1);
|
2002-05-21 09:39:19 +04:00
|
|
|
rb_define_method(rb_cModule, "==", rb_obj_equal, 1);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_cModule, "<=>", rb_mod_cmp, 1);
|
|
|
|
rb_define_method(rb_cModule, "<", rb_mod_lt, 1);
|
2004-02-10 14:49:14 +03:00
|
|
|
rb_define_method(rb_cModule, "<=", rb_class_inherited_p, 1);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_cModule, ">", rb_mod_gt, 1);
|
|
|
|
rb_define_method(rb_cModule, ">=", rb_mod_ge, 1);
|
2004-01-18 17:16:47 +03:00
|
|
|
rb_define_method(rb_cModule, "initialize_copy", rb_mod_init_copy, 1); /* in class.c */
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_cModule, "to_s", rb_mod_to_s, 0);
|
2012-08-15 15:50:01 +04:00
|
|
|
rb_define_alias(rb_cModule, "inspect", "to_s");
|
2004-01-10 20:39:07 +03:00
|
|
|
rb_define_method(rb_cModule, "included_modules", rb_mod_included_modules, 0); /* in class.c */
|
2004-01-08 05:21:28 +03:00
|
|
|
rb_define_method(rb_cModule, "include?", rb_mod_include_p, 1); /* in class.c */
|
|
|
|
rb_define_method(rb_cModule, "name", rb_mod_name, 0); /* in variable.c */
|
|
|
|
rb_define_method(rb_cModule, "ancestors", rb_mod_ancestors, 0); /* in class.c */
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
rb_define_private_method(rb_cModule, "attr", rb_mod_attr, -1);
|
|
|
|
rb_define_private_method(rb_cModule, "attr_reader", rb_mod_attr_reader, -1);
|
|
|
|
rb_define_private_method(rb_cModule, "attr_writer", rb_mod_attr_writer, -1);
|
|
|
|
rb_define_private_method(rb_cModule, "attr_accessor", rb_mod_attr_accessor, -1);
|
|
|
|
|
2002-12-20 11:33:17 +03:00
|
|
|
rb_define_alloc_func(rb_cModule, rb_module_s_alloc);
|
2002-01-23 10:30:43 +03:00
|
|
|
rb_define_method(rb_cModule, "initialize", rb_mod_initialize, 0);
|
2004-01-10 20:39:07 +03:00
|
|
|
rb_define_method(rb_cModule, "instance_methods", rb_class_instance_methods, -1); /* in class.c */
|
2009-02-22 17:23:33 +03:00
|
|
|
rb_define_method(rb_cModule, "public_instance_methods",
|
2004-01-08 05:21:28 +03:00
|
|
|
rb_class_public_instance_methods, -1); /* in class.c */
|
2009-02-22 17:23:33 +03:00
|
|
|
rb_define_method(rb_cModule, "protected_instance_methods",
|
2004-01-08 05:21:28 +03:00
|
|
|
rb_class_protected_instance_methods, -1); /* in class.c */
|
2009-02-22 17:23:33 +03:00
|
|
|
rb_define_method(rb_cModule, "private_instance_methods",
|
2004-01-08 05:21:28 +03:00
|
|
|
rb_class_private_instance_methods, -1); /* in class.c */
|
2003-12-28 09:33:07 +03:00
|
|
|
|
2006-12-04 18:19:33 +03:00
|
|
|
rb_define_method(rb_cModule, "constants", rb_mod_constants, -1); /* in variable.c */
|
2006-01-17 17:05:49 +03:00
|
|
|
rb_define_method(rb_cModule, "const_get", rb_mod_const_get, -1);
|
1999-12-14 09:50:43 +03:00
|
|
|
rb_define_method(rb_cModule, "const_set", rb_mod_const_set, 2);
|
2006-01-17 17:05:49 +03:00
|
|
|
rb_define_method(rb_cModule, "const_defined?", rb_mod_const_defined, -1);
|
2009-02-22 17:23:33 +03:00
|
|
|
rb_define_private_method(rb_cModule, "remove_const",
|
2004-01-08 05:21:28 +03:00
|
|
|
rb_mod_remove_const, 1); /* in variable.c */
|
2009-02-22 17:23:33 +03:00
|
|
|
rb_define_method(rb_cModule, "const_missing",
|
2004-01-08 05:21:28 +03:00
|
|
|
rb_mod_const_missing, 1); /* in variable.c */
|
2009-02-22 17:23:33 +03:00
|
|
|
rb_define_method(rb_cModule, "class_variables",
|
2012-07-19 10:41:47 +04:00
|
|
|
rb_mod_class_variables, -1); /* in variable.c */
|
2009-02-22 17:23:33 +03:00
|
|
|
rb_define_method(rb_cModule, "remove_class_variable",
|
2005-09-08 08:42:46 +04:00
|
|
|
rb_mod_remove_cvar, 1); /* in variable.c */
|
|
|
|
rb_define_method(rb_cModule, "class_variable_get", rb_mod_cvar_get, 1);
|
|
|
|
rb_define_method(rb_cModule, "class_variable_set", rb_mod_cvar_set, 2);
|
2006-09-18 19:43:06 +04:00
|
|
|
rb_define_method(rb_cModule, "class_variable_defined?", rb_mod_cvar_defined, 1);
|
2012-05-08 00:35:59 +04:00
|
|
|
rb_define_method(rb_cModule, "public_constant", rb_mod_public_constant, -1); /* in variable.c */
|
|
|
|
rb_define_method(rb_cModule, "private_constant", rb_mod_private_constant, -1); /* in variable.c */
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2002-12-20 12:00:10 +03:00
|
|
|
rb_define_method(rb_cClass, "allocate", rb_obj_alloc, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);
|
2002-01-23 10:30:43 +03:00
|
|
|
rb_define_method(rb_cClass, "initialize", rb_class_initialize, -1);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0);
|
2003-08-07 01:50:06 +04:00
|
|
|
rb_define_alloc_func(rb_cClass, rb_class_s_alloc);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_undef_method(rb_cClass, "extend_object");
|
|
|
|
rb_undef_method(rb_cClass, "append_features");
|
|
|
|
|
2013-02-20 07:19:01 +04:00
|
|
|
/*
|
|
|
|
* Document-class: Data
|
|
|
|
*
|
|
|
|
* This is a recommended base class for C extensions using Data_Make_Struct
|
|
|
|
* or Data_Wrap_Struct, see README.EXT for details.
|
|
|
|
*/
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_cData = rb_define_class("Data", rb_cObject);
|
2002-12-20 11:33:17 +03:00
|
|
|
rb_undef_alloc_func(rb_cData);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
rb_cTrueClass = rb_define_class("TrueClass", rb_cObject);
|
|
|
|
rb_define_method(rb_cTrueClass, "to_s", true_to_s, 0);
|
2012-08-15 15:50:01 +04:00
|
|
|
rb_define_alias(rb_cTrueClass, "inspect", "to_s");
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_cTrueClass, "&", true_and, 1);
|
|
|
|
rb_define_method(rb_cTrueClass, "|", true_or, 1);
|
|
|
|
rb_define_method(rb_cTrueClass, "^", true_xor, 1);
|
2002-12-20 11:33:17 +03:00
|
|
|
rb_undef_alloc_func(rb_cTrueClass);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_undef_method(CLASS_OF(rb_cTrueClass), "new");
|
2011-06-29 07:09:34 +04:00
|
|
|
/*
|
|
|
|
* An alias of +true+
|
|
|
|
*/
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_global_const("TRUE", Qtrue);
|
|
|
|
|
|
|
|
rb_cFalseClass = rb_define_class("FalseClass", rb_cObject);
|
|
|
|
rb_define_method(rb_cFalseClass, "to_s", false_to_s, 0);
|
2012-08-15 15:50:01 +04:00
|
|
|
rb_define_alias(rb_cFalseClass, "inspect", "to_s");
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_cFalseClass, "&", false_and, 1);
|
|
|
|
rb_define_method(rb_cFalseClass, "|", false_or, 1);
|
|
|
|
rb_define_method(rb_cFalseClass, "^", false_xor, 1);
|
2002-12-20 11:33:17 +03:00
|
|
|
rb_undef_alloc_func(rb_cFalseClass);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_undef_method(CLASS_OF(rb_cFalseClass), "new");
|
2011-06-29 07:09:34 +04:00
|
|
|
/*
|
|
|
|
* An alias of +false+
|
|
|
|
*/
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_global_const("FALSE", Qfalse);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-08-28 15:50:31 +04:00
|
|
|
for (i=0; conv_method_names[i].method; i++) {
|
|
|
|
conv_method_names[i].id = rb_intern(conv_method_names[i].method);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|