mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* marshal.c (r_object): better allocation type check for
TYPE_UCLASS. usage of allocation framework is disabled for now. * variable.c (rb_class_path): Module may have subclass. * string.c (rb_str_update): should maintain original negative offset. * string.c (rb_str_subpat_set): ditto * string.c (rb_str_aset): ditto. * re.c (rb_reg_nth_match): should check negative nth. * re.c (rb_reg_nth_defined): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d902111a57
commit
1fe40b7cc5
25 changed files with 349 additions and 342 deletions
27
ChangeLog
27
ChangeLog
|
@ -1,7 +1,34 @@
|
|||
Wed Oct 3 13:32:06 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* marshal.c (r_object): better allocation type check for
|
||||
TYPE_UCLASS. usage of allocation framework is disabled for now.
|
||||
|
||||
* variable.c (rb_class_path): Module may have subclass.
|
||||
|
||||
* string.c (rb_str_update): should maintain original negative
|
||||
offset.
|
||||
|
||||
* string.c (rb_str_subpat_set): ditto
|
||||
|
||||
* string.c (rb_str_aset): ditto.
|
||||
|
||||
* re.c (rb_reg_nth_match): should check negative nth.
|
||||
|
||||
* re.c (rb_reg_nth_defined): ditto.
|
||||
|
||||
Tue Oct 2 19:12:47 2001 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||
|
||||
* lib/ftools.rb (catname): allow trailing '/' for the destination.
|
||||
|
||||
Tue Oct 2 18:31:20 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* eval.c (rb_eval): should override existing class.
|
||||
|
||||
Tue Oct 2 17:08:49 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* object.c (rb_obj_alloc): general instance allocation framework.
|
||||
use of NEWOBJ() is deprecated except within 'allocate' method.
|
||||
|
||||
Tue Oct 2 08:04:52 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
|
||||
|
||||
* marshal.c (r_object): TYPE_UCLASS check should be inversed.
|
||||
|
|
59
array.c
59
array.c
|
@ -71,12 +71,25 @@ rb_ary_frozen_p(ary)
|
|||
return Qfalse;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_ary_s_alloc(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
NEWOBJ(ary, struct RArray);
|
||||
OBJSETUP(ary, rb_cArray, T_ARRAY);
|
||||
|
||||
ary->len = 0;
|
||||
ary->capa = 0;
|
||||
ary->ptr = 0;
|
||||
|
||||
return (VALUE)ary;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_ary_new2(len)
|
||||
long len;
|
||||
{
|
||||
NEWOBJ(ary, struct RArray);
|
||||
OBJSETUP(ary, rb_cArray, T_ARRAY);
|
||||
VALUE ary = rb_obj_alloc(rb_cArray);
|
||||
|
||||
if (len < 0) {
|
||||
rb_raise(rb_eArgError, "negative array size (or size too big)");
|
||||
|
@ -84,13 +97,11 @@ rb_ary_new2(len)
|
|||
if (len > 0 && len*sizeof(VALUE) <= 0) {
|
||||
rb_raise(rb_eArgError, "array size too big");
|
||||
}
|
||||
ary->len = 0;
|
||||
ary->capa = len;
|
||||
ary->ptr = 0;
|
||||
if (len == 0) len++;
|
||||
ary->ptr = ALLOC_N(VALUE, len);
|
||||
RARRAY(ary)->ptr = ALLOC_N(VALUE, len);
|
||||
RARRAY(ary)->capa = len;
|
||||
|
||||
return (VALUE)ary;
|
||||
return ary;
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
@ -143,7 +154,7 @@ rb_ary_new4(n, elts)
|
|||
VALUE ary;
|
||||
|
||||
ary = rb_ary_new2(n);
|
||||
if (elts) {
|
||||
if (n > 0 && elts) {
|
||||
MEMCPY(RARRAY(ary)->ptr, elts, VALUE, n);
|
||||
}
|
||||
RARRAY(ary)->len = n;
|
||||
|
@ -165,19 +176,6 @@ rb_assoc_new(car, cdr)
|
|||
return ary;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_ary_s_new(argc, argv, klass)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE klass;
|
||||
{
|
||||
VALUE ary = rb_ary_new();
|
||||
OBJSETUP(ary, klass, T_ARRAY);
|
||||
rb_obj_call_init(ary, argc, argv);
|
||||
|
||||
return ary;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
to_ary(ary)
|
||||
VALUE ary;
|
||||
|
@ -237,20 +235,15 @@ rb_ary_s_create(argc, argv, klass)
|
|||
VALUE *argv;
|
||||
VALUE klass;
|
||||
{
|
||||
NEWOBJ(ary, struct RArray);
|
||||
OBJSETUP(ary, klass, T_ARRAY);
|
||||
VALUE ary = rb_obj_alloc(klass);
|
||||
|
||||
ary->len = ary->capa = 0;
|
||||
if (argc == 0) {
|
||||
ary->ptr = 0;
|
||||
if (argc != 0) {
|
||||
RARRAY(ary)->ptr = ALLOC_N(VALUE, argc);
|
||||
MEMCPY(RARRAY(ary)->ptr, argv, VALUE, argc);
|
||||
}
|
||||
else {
|
||||
ary->ptr = ALLOC_N(VALUE, argc);
|
||||
MEMCPY(ary->ptr, argv, VALUE, argc);
|
||||
}
|
||||
ary->len = ary->capa = argc;
|
||||
RARRAY(ary)->len = RARRAY(ary)->capa = argc;
|
||||
|
||||
return (VALUE)ary;
|
||||
return ary;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1715,7 +1708,7 @@ Init_Array()
|
|||
rb_cArray = rb_define_class("Array", rb_cObject);
|
||||
rb_include_module(rb_cArray, rb_mEnumerable);
|
||||
|
||||
rb_define_singleton_method(rb_cArray, "new", rb_ary_s_new, -1);
|
||||
rb_define_singleton_method(rb_cArray, "allocate", rb_ary_s_alloc, 0);
|
||||
rb_define_singleton_method(rb_cArray, "[]", rb_ary_s_create, -1);
|
||||
rb_define_method(rb_cArray, "initialize", rb_ary_initialize, -1);
|
||||
rb_define_method(rb_cArray, "to_s", rb_ary_to_s, 0);
|
||||
|
|
13
class.c
13
class.c
|
@ -62,19 +62,18 @@ VALUE
|
|||
rb_mod_clone(module)
|
||||
VALUE module;
|
||||
{
|
||||
NEWOBJ(clone, struct RClass);
|
||||
CLONESETUP(clone, module);
|
||||
VALUE clone = rb_obj_clone(module);
|
||||
|
||||
clone->super = RCLASS(module)->super;
|
||||
RCLASS(clone)->super = RCLASS(module)->super;
|
||||
if (RCLASS(module)->iv_tbl) {
|
||||
clone->iv_tbl = st_copy(RCLASS(module)->iv_tbl);
|
||||
RCLASS(clone)->iv_tbl = st_copy(RCLASS(module)->iv_tbl);
|
||||
}
|
||||
if (RCLASS(module)->m_tbl) {
|
||||
clone->m_tbl = st_init_numtable();
|
||||
st_foreach(RCLASS(module)->m_tbl, clone_method, clone->m_tbl);
|
||||
RCLASS(clone)->m_tbl = st_init_numtable();
|
||||
st_foreach(RCLASS(module)->m_tbl, clone_method, RCLASS(clone)->m_tbl);
|
||||
}
|
||||
|
||||
return (VALUE)clone;
|
||||
return clone;
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
|
4
config.guess
vendored
4
config.guess
vendored
|
@ -870,11 +870,11 @@ EOF
|
|||
objdump --private-headers $dummy | \
|
||||
grep ld.so.1 > /dev/null
|
||||
if test "$?" = 0 ; then
|
||||
LIBC="libc1"
|
||||
LIBC="-libc1"
|
||||
fi
|
||||
fi
|
||||
rm -f $dummy.s $dummy
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
echo ${UNAME_MACHINE}-unknown-linux${LIBC}
|
||||
exit 0 ;;
|
||||
parisc:Linux:*:* | hppa:Linux:*:*)
|
||||
# Look for CPU level
|
||||
|
|
7
dir.c
7
dir.c
|
@ -249,9 +249,7 @@ free_dir(dir)
|
|||
static VALUE dir_close _((VALUE));
|
||||
|
||||
static VALUE
|
||||
dir_s_new(argc, argv, klass)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
dir_s_alloc(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
struct dir_data *dirp;
|
||||
|
@ -259,7 +257,6 @@ dir_s_new(argc, argv, klass)
|
|||
|
||||
dirp->dir = NULL;
|
||||
dirp->path = NULL;
|
||||
rb_obj_call_init(obj, argc, argv);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
@ -995,7 +992,7 @@ Init_Dir()
|
|||
|
||||
rb_include_module(rb_cDir, rb_mEnumerable);
|
||||
|
||||
rb_define_singleton_method(rb_cDir, "new", dir_s_new, -1);
|
||||
rb_define_singleton_method(rb_cDir, "allocate", dir_s_alloc, 0);
|
||||
rb_define_singleton_method(rb_cDir, "open", dir_s_open, 1);
|
||||
rb_define_singleton_method(rb_cDir, "foreach", dir_foreach, 1);
|
||||
rb_define_singleton_method(rb_cDir, "entries", dir_entries, 1);
|
||||
|
|
1
enum.c
1
enum.c
|
@ -235,7 +235,6 @@ enum_sort_by(obj)
|
|||
for (i=0; i<RARRAY(ary)->len; i++) {
|
||||
VALUE e = RARRAY(ary)->ptr[i];
|
||||
RARRAY(ary)->ptr[i] = rb_ary_entry(e, 2);
|
||||
rb_gc_force_recycle(e);
|
||||
}
|
||||
|
||||
return ary;
|
||||
|
|
5
error.c
5
error.c
|
@ -278,10 +278,7 @@ rb_exc_new(etype, ptr, len)
|
|||
const char *ptr;
|
||||
long len;
|
||||
{
|
||||
VALUE exc = rb_obj_alloc(etype);
|
||||
|
||||
rb_iv_set(exc, "mesg", rb_str_new(ptr, len));
|
||||
return exc;
|
||||
return rb_funcall(etype, rb_intern("new"), 1, rb_str_new(ptr, len));
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
|
53
eval.c
53
eval.c
|
@ -3195,15 +3195,8 @@ rb_eval(self, n)
|
|||
rb_id2name(node->nd_cname));
|
||||
}
|
||||
if (super) {
|
||||
tmp = RCLASS(klass)->super;
|
||||
if (FL_TEST(tmp, FL_SINGLETON)) {
|
||||
tmp = RCLASS(tmp)->super;
|
||||
}
|
||||
while (TYPE(tmp) == T_ICLASS) {
|
||||
tmp = RCLASS(tmp)->super;
|
||||
}
|
||||
tmp = rb_class_real(RCLASS(klass)->super);
|
||||
if (tmp != super) {
|
||||
super = tmp;
|
||||
goto override_class;
|
||||
}
|
||||
}
|
||||
|
@ -5768,23 +5761,6 @@ rb_obj_call_init(obj, argc, argv)
|
|||
POP_ITER();
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_class_new_instance(argc, argv, klass)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE klass;
|
||||
{
|
||||
VALUE obj;
|
||||
|
||||
if (FL_TEST(klass, FL_SINGLETON)) {
|
||||
rb_raise(rb_eTypeError, "can't create instance of virtual class");
|
||||
}
|
||||
obj = rb_obj_alloc(klass);
|
||||
rb_obj_call_init(obj, argc, argv);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
top_include(argc, argv)
|
||||
int argc;
|
||||
|
@ -6388,18 +6364,6 @@ proc_new(klass)
|
|||
return proc;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
proc_s_new(argc, argv, klass)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE klass;
|
||||
{
|
||||
VALUE proc = proc_new(klass);
|
||||
|
||||
rb_obj_call_init(proc, argc, argv);
|
||||
return proc;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_f_lambda()
|
||||
{
|
||||
|
@ -7005,7 +6969,7 @@ Init_Proc()
|
|||
rb_eSysStackError = rb_define_class("SystemStackError", rb_eStandardError);
|
||||
|
||||
rb_cProc = rb_define_class("Proc", rb_cObject);
|
||||
rb_define_singleton_method(rb_cProc, "new", proc_s_new, -1);
|
||||
rb_define_singleton_method(rb_cProc, "allocate", proc_new, 0);
|
||||
|
||||
rb_define_method(rb_cProc, "call", proc_call, -2);
|
||||
rb_define_method(rb_cProc, "yield", proc_yield, -2);
|
||||
|
@ -7017,10 +6981,12 @@ Init_Proc()
|
|||
rb_define_global_function("lambda", rb_f_lambda, 0);
|
||||
rb_define_global_function("binding", rb_f_binding, 0);
|
||||
rb_cBinding = rb_define_class("Binding", rb_cObject);
|
||||
rb_undef_method(CLASS_OF(rb_cBinding), "allocate");
|
||||
rb_undef_method(CLASS_OF(rb_cBinding), "new");
|
||||
rb_define_method(rb_cBinding, "clone", bind_clone, 0);
|
||||
|
||||
rb_cMethod = rb_define_class("Method", rb_cObject);
|
||||
rb_undef_method(CLASS_OF(rb_cMethod), "allocate");
|
||||
rb_undef_method(CLASS_OF(rb_cMethod), "new");
|
||||
rb_define_method(rb_cMethod, "==", method_eq, 1);
|
||||
rb_define_method(rb_cMethod, "clone", method_clone, 0);
|
||||
|
@ -8913,9 +8879,7 @@ struct thgroup {
|
|||
};
|
||||
|
||||
static VALUE
|
||||
thgroup_s_new(argc, argv, klass)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
thgroup_s_alloc(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
VALUE group;
|
||||
|
@ -8925,7 +8889,6 @@ thgroup_s_new(argc, argv, klass)
|
|||
group = Data_Make_Struct(klass, struct thgroup, 0, free, data);
|
||||
data->gid = serial++;
|
||||
|
||||
rb_obj_call_init(group, argc, argv);
|
||||
return group;
|
||||
}
|
||||
|
||||
|
@ -8972,6 +8935,7 @@ Init_Thread()
|
|||
|
||||
rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError);
|
||||
rb_cThread = rb_define_class("Thread", rb_cObject);
|
||||
rb_undef_method(CLASS_OF(rb_cThread), "allocate");
|
||||
|
||||
rb_define_singleton_method(rb_cThread, "new", rb_thread_s_new, -1);
|
||||
rb_define_method(rb_cThread, "initialize", rb_thread_initialize, -2);
|
||||
|
@ -9022,15 +8986,16 @@ Init_Thread()
|
|||
curr_thread = main_thread->prev = main_thread->next = main_thread;
|
||||
|
||||
rb_cCont = rb_define_class("Continuation", rb_cObject);
|
||||
rb_undef_method(CLASS_OF(rb_cCont), "allocate");
|
||||
rb_undef_method(CLASS_OF(rb_cCont), "new");
|
||||
rb_define_method(rb_cCont, "call", rb_cont_call, -1);
|
||||
rb_define_global_function("callcc", rb_callcc, 0);
|
||||
|
||||
cThGroup = rb_define_class("ThreadGroup", rb_cObject);
|
||||
rb_define_singleton_method(cThGroup, "new", thgroup_s_new, -1);
|
||||
rb_define_singleton_method(cThGroup, "allocate", thgroup_s_alloc, 0);
|
||||
rb_define_method(cThGroup, "list", thgroup_list, 0);
|
||||
rb_define_method(cThGroup, "add", thgroup_add, 1);
|
||||
rb_define_const(cThGroup, "Default", thgroup_s_new(0, 0, cThGroup));
|
||||
rb_define_const(cThGroup, "Default", rb_obj_alloc(cThGroup));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
|
|
@ -159,18 +159,17 @@ rb_gdbm_fetch(dbm, key)
|
|||
datum key;
|
||||
{
|
||||
datum val;
|
||||
NEWOBJ(str, struct RString);
|
||||
OBJSETUP(str, rb_cString, T_STRING);
|
||||
VALUE str = rb_obj_alloc(rb_cString);
|
||||
|
||||
val = gdbm_fetch(dbm, key);
|
||||
if (val.dptr == 0)
|
||||
return Qnil;
|
||||
|
||||
str->ptr = 0;
|
||||
str->len = val.dsize;
|
||||
str->orig = 0;
|
||||
str->ptr = REALLOC_N(val.dptr,char,val.dsize+1);
|
||||
str->ptr[str->len] = '\0';
|
||||
RSTRING(str)->ptr = 0;
|
||||
RSTRING(str)->len = val.dsize;
|
||||
RSTRING(str)->orig = 0;
|
||||
RSTRING(str)->ptr = REALLOC_N(val.dptr,char,val.dsize+1);
|
||||
RSTRING(str)->ptr[str->len] = '\0';
|
||||
|
||||
OBJ_TAINT(str);
|
||||
return (VALUE)str;
|
||||
|
@ -207,18 +206,17 @@ rb_gdbm_firstkey(dbm)
|
|||
GDBM_FILE dbm;
|
||||
{
|
||||
datum key;
|
||||
NEWOBJ(str, struct RString);
|
||||
OBJSETUP(str, rb_cString, T_STRING);
|
||||
VALUE str = rb_obj_alloc(rb_cString);
|
||||
|
||||
key = gdbm_firstkey(dbm);
|
||||
if (key.dptr == 0)
|
||||
return Qnil;
|
||||
|
||||
str->ptr = 0;
|
||||
str->len = key.dsize;
|
||||
str->orig = 0;
|
||||
str->ptr = REALLOC_N(key.dptr,char,key.dsize+1);
|
||||
str->ptr[str->len] = '\0';
|
||||
RSTRING(str)->ptr = 0;
|
||||
RSTRING(str)->len = key.dsize;
|
||||
RSTRING(str)->orig = 0;
|
||||
RSTRING(str)->ptr = REALLOC_N(key.dptr,char,key.dsize+1);
|
||||
RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
|
||||
|
||||
OBJ_TAINT(str);
|
||||
return (VALUE)str;
|
||||
|
@ -230,8 +228,7 @@ rb_gdbm_nextkey(dbm, keystr)
|
|||
VALUE keystr;
|
||||
{
|
||||
datum key, key2;
|
||||
NEWOBJ(str, struct RString);
|
||||
OBJSETUP(str, rb_cString, T_STRING);
|
||||
VALUE str = rb_obj_alloc(rb_cString);
|
||||
|
||||
key.dptr = RSTRING(keystr)->ptr;
|
||||
key.dsize = RSTRING(keystr)->len;
|
||||
|
@ -239,11 +236,11 @@ rb_gdbm_nextkey(dbm, keystr)
|
|||
if (key2.dptr == 0)
|
||||
return Qnil;
|
||||
|
||||
str->ptr = 0;
|
||||
str->len = key2.dsize;
|
||||
str->orig = 0;
|
||||
str->ptr = REALLOC_N(key2.dptr,char,key2.dsize+1);
|
||||
str->ptr[str->len] = '\0';
|
||||
RSTRING(str)->ptr = 0;
|
||||
RSTRING(str)->len = key2.dsize;
|
||||
RSTRING(str)->orig = 0;
|
||||
RSTRING(str)->ptr = REALLOC_N(key2.dptr,char,key2.dsize+1);
|
||||
RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
|
||||
|
||||
OBJ_TAINT(str);
|
||||
return (VALUE)str;
|
||||
|
|
|
@ -367,13 +367,10 @@ pty_getpty(self, shell)
|
|||
VALUE res, th;
|
||||
struct pty_info info;
|
||||
OpenFile *wfptr,*rfptr;
|
||||
NEWOBJ(rport, struct RFile);
|
||||
NEWOBJ(wport, struct RFile);
|
||||
VALUE rport = rb_obj_alloc(rb_cFile);
|
||||
VALUE wport = rb_obj_alloc(rb_cFile);
|
||||
|
||||
OBJSETUP(rport, rb_cFile, T_FILE);
|
||||
MakeOpenFile(rport, rfptr);
|
||||
|
||||
OBJSETUP(wport, rb_cFile, T_FILE);
|
||||
MakeOpenFile(wport, wfptr);
|
||||
|
||||
establishShell(RSTRING(shell)->ptr,&info);
|
||||
|
@ -399,7 +396,7 @@ pty_getpty(self, shell)
|
|||
return res;
|
||||
}
|
||||
else {
|
||||
return (VALUE)res;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -177,8 +177,7 @@ sock_new(class, fd)
|
|||
int fd;
|
||||
{
|
||||
OpenFile *fp;
|
||||
NEWOBJ(sock, struct RFile);
|
||||
OBJSETUP(sock, class, T_FILE);
|
||||
VALUE sock = rb_obj_alloc(class);
|
||||
|
||||
MakeOpenFile(sock, fp);
|
||||
fp->f = rb_fdopen(fd, "r");
|
||||
|
@ -190,7 +189,7 @@ sock_new(class, fd)
|
|||
fp->mode = FMODE_READWRITE;
|
||||
rb_io_synchronized(fp);
|
||||
|
||||
return (VALUE)sock;
|
||||
return sock;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
|
44
file.c
44
file.c
|
@ -113,11 +113,12 @@ stat_new_0(klass, st)
|
|||
VALUE klass;
|
||||
struct stat *st;
|
||||
{
|
||||
struct stat *nst;
|
||||
if (!st) rb_bug("stat_new() called with bad value");
|
||||
struct stat *nst = 0;
|
||||
|
||||
nst = ALLOC(struct stat);
|
||||
*nst = *st;
|
||||
if (st) {
|
||||
nst = ALLOC(struct stat);
|
||||
*nst = *st;
|
||||
}
|
||||
return Data_Wrap_Struct(klass, NULL, free, nst);
|
||||
}
|
||||
|
||||
|
@ -134,7 +135,7 @@ get_stat(self)
|
|||
{
|
||||
struct stat* st;
|
||||
Data_Get_Struct(self, struct stat, st);
|
||||
if (!st) rb_bug("collapsed File::Stat");
|
||||
if (!st) rb_raise(rb_eTypeError, "uninitialized File::Stat");
|
||||
return st;
|
||||
}
|
||||
|
||||
|
@ -1883,26 +1884,27 @@ rb_f_test(argc, argv)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
rb_stat_s_new(klass, fname)
|
||||
VALUE klass, fname;
|
||||
rb_stat_s_alloc(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
VALUE s;
|
||||
struct stat st;
|
||||
|
||||
Check_SafeStr(fname);
|
||||
if (stat(RSTRING(fname)->ptr, &st) == -1) {
|
||||
rb_sys_fail(RSTRING(fname)->ptr);
|
||||
}
|
||||
s = stat_new_0(klass, &st);
|
||||
rb_obj_call_init(s, 1, &fname);
|
||||
return s;
|
||||
return stat_new_0(klass, 0);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_stat_init(klass, fname)
|
||||
VALUE klass, fname;
|
||||
rb_stat_init(obj, fname)
|
||||
VALUE obj, fname;
|
||||
{
|
||||
/* do nothing */
|
||||
struct stat st, *nst;
|
||||
|
||||
Check_SafeStr(fname);
|
||||
|
||||
if (stat(RSTRING(fname)->ptr, &st) == -1) {
|
||||
rb_sys_fail(RSTRING(fname)->ptr);
|
||||
}
|
||||
nst = ALLOC(struct stat);
|
||||
*nst = st;
|
||||
DATA_PTR(obj) = nst;
|
||||
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
|
@ -2505,7 +2507,7 @@ Init_File()
|
|||
rb_define_global_function("test", rb_f_test, -1);
|
||||
|
||||
rb_cStat = rb_define_class_under(rb_cFile, "Stat", rb_cObject);
|
||||
rb_define_singleton_method(rb_cStat, "new", rb_stat_s_new, 1);
|
||||
rb_define_singleton_method(rb_cStat, "allocate", rb_stat_s_alloc, 0);
|
||||
rb_define_method(rb_cStat, "initialize", rb_stat_init, 1);
|
||||
|
||||
rb_include_module(rb_cStat, rb_mComparable);
|
||||
|
|
38
hash.c
38
hash.c
|
@ -172,7 +172,7 @@ rb_hash_foreach(hash, func, farg)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
rb_hash_new2(klass)
|
||||
rb_hash_s_alloc(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
NEWOBJ(hash, struct RHash);
|
||||
|
@ -187,19 +187,7 @@ rb_hash_new2(klass)
|
|||
VALUE
|
||||
rb_hash_new()
|
||||
{
|
||||
return rb_hash_new2(rb_cHash);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_hash_s_new(argc, argv, klass)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE klass;
|
||||
{
|
||||
VALUE hash = rb_hash_new2(klass);
|
||||
|
||||
rb_obj_call_init(hash, argc, argv);
|
||||
return hash;
|
||||
return rb_hash_s_alloc(rb_cHash);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -227,19 +215,18 @@ rb_hash_s_create(argc, argv, klass)
|
|||
int i;
|
||||
|
||||
if (argc == 1 && TYPE(argv[0]) == T_HASH) {
|
||||
NEWOBJ(hash, struct RHash);
|
||||
OBJSETUP(hash, klass, T_HASH);
|
||||
VALUE hash = rb_obj_alloc(klass);
|
||||
|
||||
hash->ifnone = Qnil;
|
||||
hash->tbl = st_copy(RHASH(argv[0])->tbl);
|
||||
RHASH(hash)->ifnone = Qnil;
|
||||
RHASH(hash)->tbl = st_copy(RHASH(argv[0])->tbl);
|
||||
|
||||
return (VALUE)hash;
|
||||
return hash;
|
||||
}
|
||||
|
||||
if (argc % 2 != 0) {
|
||||
rb_raise(rb_eArgError, "odd number args for Hash");
|
||||
}
|
||||
hash = rb_hash_new2(klass);
|
||||
hash = rb_hash_s_alloc(klass);
|
||||
|
||||
for (i=0; i<argc; i+=2) {
|
||||
st_insert(RHASH(hash)->tbl, argv[i], argv[i+1]);
|
||||
|
@ -252,13 +239,12 @@ static VALUE
|
|||
rb_hash_clone(hash)
|
||||
VALUE hash;
|
||||
{
|
||||
NEWOBJ(clone, struct RHash);
|
||||
CLONESETUP(clone, hash);
|
||||
VALUE clone = rb_obj_clone(hash);
|
||||
|
||||
clone->ifnone = RHASH(hash)->ifnone;
|
||||
clone->tbl = (st_table*)st_copy(RHASH(hash)->tbl);
|
||||
RHASH(clone)->ifnone = RHASH(hash)->ifnone;
|
||||
RHASH(clone)->tbl = (st_table*)st_copy(RHASH(hash)->tbl);
|
||||
|
||||
return (VALUE)clone;
|
||||
return clone;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -1454,7 +1440,7 @@ Init_Hash()
|
|||
|
||||
rb_include_module(rb_cHash, rb_mEnumerable);
|
||||
|
||||
rb_define_singleton_method(rb_cHash, "new", rb_hash_s_new, -1);
|
||||
rb_define_singleton_method(rb_cHash, "allocate", rb_hash_s_alloc, 0);
|
||||
rb_define_singleton_method(rb_cHash, "[]", rb_hash_s_create, -1);
|
||||
rb_define_method(rb_cHash,"initialize", rb_hash_initialize, -1);
|
||||
|
||||
|
|
51
io.c
51
io.c
|
@ -1503,9 +1503,9 @@ VALUE
|
|||
rb_file_open(fname, mode)
|
||||
const char *fname, *mode;
|
||||
{
|
||||
NEWOBJ(io, struct RFile);
|
||||
OBJSETUP(io, rb_cFile, T_FILE);
|
||||
return rb_file_open_internal((VALUE)io, fname, mode);
|
||||
VALUE io = rb_obj_alloc(rb_cFile);
|
||||
|
||||
return rb_file_open_internal(io, fname, mode);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -1535,9 +1535,9 @@ rb_file_sysopen(fname, flags, mode)
|
|||
const char *fname;
|
||||
int flags, mode;
|
||||
{
|
||||
NEWOBJ(io, struct RFile);
|
||||
OBJSETUP(io, rb_cFile, T_FILE);
|
||||
return rb_file_sysopen_internal((VALUE)io, fname, flags, mode);
|
||||
VALUE io = rb_obj_alloc(rb_cFile);
|
||||
|
||||
return rb_file_sysopen_internal(io, fname, flags, mode);
|
||||
}
|
||||
|
||||
#if defined (NT) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__)
|
||||
|
@ -1650,8 +1650,8 @@ pipe_open(pname, mode)
|
|||
|
||||
if (!f) rb_sys_fail(pname);
|
||||
else {
|
||||
NEWOBJ(port, struct RFile);
|
||||
OBJSETUP(port, rb_cIO, T_FILE);
|
||||
VALUE port = rb_obj_alloc(rb_cIO);
|
||||
|
||||
MakeOpenFile(port, fptr);
|
||||
fptr->finalize = pipe_finalize;
|
||||
fptr->mode = modef;
|
||||
|
@ -1724,8 +1724,8 @@ pipe_open(pname, mode)
|
|||
default: /* parent */
|
||||
if (pid < 0) rb_sys_fail(pname);
|
||||
else {
|
||||
NEWOBJ(port, struct RFile);
|
||||
OBJSETUP(port, rb_cIO, T_FILE);
|
||||
VALUE port = rb_obj_alloc(rb_cIO);
|
||||
|
||||
MakeOpenFile(port, fptr);
|
||||
fptr->mode = modef;
|
||||
fptr->mode |= FMODE_SYNC;
|
||||
|
@ -1838,10 +1838,9 @@ rb_file_s_open(argc, argv, klass)
|
|||
VALUE *argv;
|
||||
VALUE klass;
|
||||
{
|
||||
NEWOBJ(io, struct RFile);
|
||||
OBJSETUP(io, klass, T_FILE);
|
||||
RFILE(io)->fptr = 0;
|
||||
VALUE io = rb_obj_alloc(klass);
|
||||
|
||||
RFILE(io)->fptr = 0;
|
||||
rb_open_file(argc, argv, (VALUE)io);
|
||||
if (rb_block_given_p()) {
|
||||
return rb_ensure(rb_yield, (VALUE)io, rb_io_close, (VALUE)io);
|
||||
|
@ -2043,9 +2042,7 @@ rb_io_clone(io)
|
|||
OpenFile *fptr, *orig;
|
||||
int fd;
|
||||
char *mode;
|
||||
|
||||
NEWOBJ(clone, struct RFile);
|
||||
CLONESETUP(clone, io);
|
||||
VALUE clone = rb_obj_clone(io);
|
||||
|
||||
GetOpenFile(io, orig);
|
||||
MakeOpenFile(clone, fptr);
|
||||
|
@ -2409,8 +2406,7 @@ prep_stdio(f, mode, klass)
|
|||
VALUE klass;
|
||||
{
|
||||
OpenFile *fp;
|
||||
NEWOBJ(io, struct RFile);
|
||||
OBJSETUP(io, klass, T_FILE);
|
||||
VALUE io = rb_obj_alloc(klass);
|
||||
|
||||
MakeOpenFile(io, fp);
|
||||
fp->f = f;
|
||||
|
@ -2432,16 +2428,13 @@ prep_path(io, path)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
rb_io_s_new(argc, argv, klass)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
rb_io_s_alloc(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
NEWOBJ(io, struct RFile);
|
||||
OBJSETUP(io, klass, T_FILE);
|
||||
|
||||
io->fptr = 0;
|
||||
rb_obj_call_init((VALUE)io, argc, argv);
|
||||
|
||||
return (VALUE)io;
|
||||
}
|
||||
|
@ -2456,11 +2449,6 @@ rb_io_initialize(argc, argv, io)
|
|||
OpenFile *fp;
|
||||
char *m = "r";
|
||||
|
||||
if (RFILE(io)->fptr) {
|
||||
rb_io_close_m(io);
|
||||
free(RFILE(io)->fptr);
|
||||
RFILE(io)->fptr = 0;
|
||||
}
|
||||
if (rb_scan_args(argc, argv, "11", &fnum, &mode) == 2) {
|
||||
SafeStringValue(mode);
|
||||
m = RSTRING(mode)->ptr;
|
||||
|
@ -2500,9 +2488,8 @@ rb_io_s_for_fd(argc, argv, klass)
|
|||
VALUE fnum, mode;
|
||||
OpenFile *fp;
|
||||
char *m = "r";
|
||||
NEWOBJ(io, struct RFile);
|
||||
OBJSETUP(io, klass, T_FILE);
|
||||
|
||||
VALUE io = rb_obj_alloc(klass);
|
||||
|
||||
if (rb_scan_args(argc, argv, "11", &fnum, &mode) == 2) {
|
||||
SafeStringValue(mode);
|
||||
m = RSTRING(mode)->ptr;
|
||||
|
@ -2512,7 +2499,7 @@ rb_io_s_for_fd(argc, argv, klass)
|
|||
fp->f = rb_fdopen(NUM2INT(fnum), m);
|
||||
fp->mode = rb_io_mode_flags(m);
|
||||
|
||||
return (VALUE)io;
|
||||
return io;
|
||||
}
|
||||
|
||||
static int binmode = 0;
|
||||
|
@ -3535,7 +3522,7 @@ Init_IO()
|
|||
rb_cIO = rb_define_class("IO", rb_cObject);
|
||||
rb_include_module(rb_cIO, rb_mEnumerable);
|
||||
|
||||
rb_define_singleton_method(rb_cIO, "new", rb_io_s_new, -1);
|
||||
rb_define_singleton_method(rb_cIO, "allocate", rb_io_s_alloc, 0);
|
||||
rb_define_singleton_method(rb_cIO, "for_fd", rb_io_s_for_fd, -1);
|
||||
rb_define_method(rb_cIO, "initialize", rb_io_initialize, -1);
|
||||
rb_define_singleton_method(rb_cIO, "popen", rb_io_s_popen, -1);
|
||||
|
|
|
@ -86,11 +86,11 @@ class PStore
|
|||
value = nil
|
||||
backup = @filename+"~"
|
||||
begin
|
||||
file = File::open(@filename, "r+")
|
||||
file = File::open(@filename, "rb+")
|
||||
orig = true
|
||||
rescue Errno::ENOENT
|
||||
raise if read_only
|
||||
file = File::open(@filename, "w+")
|
||||
file = File::open(@filename, "wb+")
|
||||
end
|
||||
file.flock(read_only ? File::LOCK_SH : File::LOCK_EX)
|
||||
if read_only
|
||||
|
|
12
marshal.c
12
marshal.c
|
@ -796,11 +796,20 @@ r_object(arg)
|
|||
case TYPE_UCLASS:
|
||||
{
|
||||
VALUE c = rb_path2class(r_unique(arg));
|
||||
VALUE tmp;
|
||||
|
||||
v = r_object(arg);
|
||||
if (rb_special_const_p(v) ||
|
||||
TYPE(v) == T_OBJECT || TYPE(v) == T_CLASS || TYPE(v) == T_MODULE ||
|
||||
!RTEST(rb_funcall(c, '<', 1, RBASIC(v)->klass))) {
|
||||
rb_raise(rb_eArgError, "dump format error (user class)");
|
||||
}
|
||||
#if 0
|
||||
tmp = rb_obj_alloc(c);
|
||||
if (TYPE(v) != TYPE(tmp)) {
|
||||
rb_raise(rb_eArgError, "dump format error (user class)");
|
||||
}
|
||||
#endif
|
||||
RBASIC(v)->klass = c;
|
||||
return v;
|
||||
}
|
||||
|
@ -968,6 +977,9 @@ r_object(arg)
|
|||
|
||||
klass = rb_path2class(r_unique(arg));
|
||||
v = rb_obj_alloc(klass);
|
||||
if (TYPE(v) != T_OBJECT) {
|
||||
rb_raise(rb_eArgError, "dump format error");
|
||||
}
|
||||
r_regist(v, arg);
|
||||
r_ivar(v, arg);
|
||||
return v;
|
||||
|
|
|
@ -1571,6 +1571,7 @@ Init_Numeric()
|
|||
rb_define_method(rb_cNumeric, "truncate", num_truncate, 0);
|
||||
|
||||
rb_cInteger = rb_define_class("Integer", rb_cNumeric);
|
||||
rb_undef_method(CLASS_OF(rb_cInteger), "allocate");
|
||||
rb_undef_method(CLASS_OF(rb_cInteger), "new");
|
||||
|
||||
rb_define_method(rb_cInteger, "integer?", int_int_p, 0);
|
||||
|
@ -1642,6 +1643,7 @@ Init_Numeric()
|
|||
|
||||
rb_cFloat = rb_define_class("Float", rb_cNumeric);
|
||||
|
||||
rb_undef_method(CLASS_OF(rb_cFloat), "allocate");
|
||||
rb_undef_method(CLASS_OF(rb_cFloat), "new");
|
||||
|
||||
rb_define_singleton_method(rb_cFloat, "induced_from", rb_flo_induced_from, 1);
|
||||
|
|
70
object.c
70
object.c
|
@ -32,6 +32,7 @@ VALUE rb_cSymbol;
|
|||
static ID eq, eql;
|
||||
static ID inspect;
|
||||
static ID clone;
|
||||
static ID alloc;
|
||||
|
||||
VALUE
|
||||
rb_equal(obj1, obj2)
|
||||
|
@ -93,12 +94,9 @@ rb_obj_clone(obj)
|
|||
{
|
||||
VALUE clone;
|
||||
|
||||
if (TYPE(obj) != T_OBJECT) {
|
||||
rb_raise(rb_eTypeError, "can't clone %s", rb_class2name(CLASS_OF(obj)));
|
||||
}
|
||||
clone = rb_obj_alloc(RBASIC(obj)->klass);
|
||||
CLONESETUP(clone,obj);
|
||||
if (ROBJECT(obj)->iv_tbl) {
|
||||
if (TYPE(clone) == T_OBJECT && ROBJECT(obj)->iv_tbl) {
|
||||
ROBJECT(clone)->iv_tbl = st_copy(ROBJECT(obj)->iv_tbl);
|
||||
}
|
||||
|
||||
|
@ -453,16 +451,6 @@ rb_false(obj)
|
|||
return Qfalse;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_obj_alloc(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
NEWOBJ(obj, struct RObject);
|
||||
OBJSETUP(obj, klass, T_OBJECT);
|
||||
|
||||
return (VALUE)obj;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
sym_to_i(sym)
|
||||
VALUE sym;
|
||||
|
@ -607,13 +595,12 @@ rb_mod_initialize(argc, argv)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
rb_module_s_new(klass)
|
||||
rb_module_s_alloc(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
VALUE mod = rb_module_new();
|
||||
|
||||
RBASIC(mod)->klass = klass;
|
||||
rb_obj_call_init(klass, 0, 0);
|
||||
return mod;
|
||||
}
|
||||
|
||||
|
@ -637,6 +624,45 @@ rb_class_s_new(argc, argv)
|
|||
return klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_obj_alloc(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
VALUE obj = rb_funcall(klass, alloc, 0, 0);
|
||||
|
||||
if (rb_obj_class(obj) != rb_class_real(klass)) {
|
||||
rb_raise(rb_eTypeError, "wrong instance allocation");
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_class_allocate_instance(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
NEWOBJ(obj, struct RObject);
|
||||
OBJSETUP(obj, klass, T_OBJECT);
|
||||
|
||||
return (VALUE)obj;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_class_new_instance(argc, argv, klass)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE klass;
|
||||
{
|
||||
VALUE obj;
|
||||
|
||||
if (FL_TEST(klass, FL_SINGLETON)) {
|
||||
rb_raise(rb_eTypeError, "can't create instance of virtual class");
|
||||
}
|
||||
obj = rb_obj_alloc(klass);
|
||||
rb_obj_call_init(obj, argc, argv);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_class_superclass(klass)
|
||||
VALUE klass;
|
||||
|
@ -1072,6 +1098,8 @@ Init_Object()
|
|||
{
|
||||
VALUE metaclass;
|
||||
|
||||
alloc = rb_intern("allocate");
|
||||
|
||||
rb_cObject = boot_defclass("Object", 0);
|
||||
rb_cModule = boot_defclass("Module", rb_cObject);
|
||||
rb_cClass = boot_defclass("Class", rb_cModule);
|
||||
|
@ -1178,12 +1206,14 @@ Init_Object()
|
|||
rb_define_method(rb_cNilClass, "^", false_xor, 1);
|
||||
|
||||
rb_define_method(rb_cNilClass, "nil?", rb_true, 0);
|
||||
rb_undef_method(CLASS_OF(rb_cNilClass), "allocate");
|
||||
rb_undef_method(CLASS_OF(rb_cNilClass), "new");
|
||||
rb_define_global_const("NIL", Qnil);
|
||||
|
||||
rb_cSymbol = rb_define_class("Symbol", rb_cObject);
|
||||
rb_undef_method(CLASS_OF(rb_cSymbol), "new");
|
||||
rb_define_singleton_method(rb_cSymbol, "all_symbols", rb_sym_all_symbols, 0);
|
||||
rb_undef_method(CLASS_OF(rb_cSymbol), "allocate");
|
||||
rb_undef_method(CLASS_OF(rb_cSymbol), "new");
|
||||
|
||||
rb_define_method(rb_cSymbol, "to_i", sym_to_i, 0);
|
||||
rb_define_method(rb_cSymbol, "to_int", sym_to_i, 0);
|
||||
|
@ -1211,7 +1241,7 @@ Init_Object()
|
|||
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);
|
||||
|
||||
rb_define_singleton_method(rb_cModule, "new", rb_module_s_new, 0);
|
||||
rb_define_singleton_method(rb_cModule, "allocate", rb_module_s_alloc, 0);
|
||||
rb_define_method(rb_cModule, "initialize", rb_mod_initialize, -1);
|
||||
rb_define_method(rb_cModule, "instance_methods", rb_class_instance_methods, -1);
|
||||
rb_define_method(rb_cModule, "public_instance_methods", rb_class_instance_methods, -1);
|
||||
|
@ -1226,8 +1256,10 @@ Init_Object()
|
|||
rb_define_method(rb_cModule, "class_variables", rb_mod_class_variables, 0);
|
||||
rb_define_private_method(rb_cModule, "remove_class_variable", rb_mod_remove_cvar, 1);
|
||||
|
||||
rb_define_method(rb_cClass, "allocate", rb_class_allocate_instance, 0);
|
||||
rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);
|
||||
rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0);
|
||||
rb_undef_method(CLASS_OF(rb_cClass), "allocate");
|
||||
rb_define_singleton_method(rb_cClass, "new", rb_class_s_new, -1);
|
||||
rb_undef_method(rb_cClass, "extend_object");
|
||||
rb_undef_method(rb_cClass, "append_features");
|
||||
|
@ -1244,6 +1276,7 @@ Init_Object()
|
|||
rb_define_method(rb_cTrueClass, "&", true_and, 1);
|
||||
rb_define_method(rb_cTrueClass, "|", true_or, 1);
|
||||
rb_define_method(rb_cTrueClass, "^", true_xor, 1);
|
||||
rb_undef_method(CLASS_OF(rb_cTrueClass), "allocate");
|
||||
rb_undef_method(CLASS_OF(rb_cTrueClass), "new");
|
||||
rb_define_global_const("TRUE", Qtrue);
|
||||
|
||||
|
@ -1252,6 +1285,7 @@ Init_Object()
|
|||
rb_define_method(rb_cFalseClass, "&", false_and, 1);
|
||||
rb_define_method(rb_cFalseClass, "|", false_or, 1);
|
||||
rb_define_method(rb_cFalseClass, "^", false_xor, 1);
|
||||
rb_undef_method(CLASS_OF(rb_cFalseClass), "allocate");
|
||||
rb_undef_method(CLASS_OF(rb_cFalseClass), "new");
|
||||
rb_define_global_const("FALSE", Qfalse);
|
||||
|
||||
|
|
42
re.c
42
re.c
|
@ -665,7 +665,11 @@ rb_reg_nth_defined(nth, match)
|
|||
{
|
||||
if (NIL_P(match)) return Qnil;
|
||||
if (nth >= RMATCH(match)->regs->num_regs) {
|
||||
return Qfalse;
|
||||
return Qnil;
|
||||
}
|
||||
if (nth < 0) {
|
||||
nth += RMATCH(match)->regs->num_regs;
|
||||
if (nth <= 0) return Qnil;
|
||||
}
|
||||
if (RMATCH(match)->BEG(nth) == -1) return Qfalse;
|
||||
return Qtrue;
|
||||
|
@ -683,6 +687,10 @@ rb_reg_nth_match(nth, match)
|
|||
if (nth >= RMATCH(match)->regs->num_regs) {
|
||||
return Qnil;
|
||||
}
|
||||
if (nth < 0) {
|
||||
nth += RMATCH(match)->regs->num_regs;
|
||||
if (nth <= 0) return Qnil;
|
||||
}
|
||||
start = RMATCH(match)->BEG(nth);
|
||||
if (start == -1) return Qnil;
|
||||
end = RMATCH(match)->END(nth);
|
||||
|
@ -881,6 +889,7 @@ rb_reg_new(s, len, options)
|
|||
long len;
|
||||
int options;
|
||||
{
|
||||
|
||||
NEWOBJ(re, struct RRegexp);
|
||||
OBJSETUP(re, rb_cRegexp, T_REGEXP);
|
||||
|
||||
|
@ -1033,16 +1042,16 @@ rb_reg_initialize_m(argc, argv, self)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
rb_reg_s_new(argc, argv, klass)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
rb_reg_s_alloc(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
NEWOBJ(re, struct RRegexp);
|
||||
OBJSETUP(re, klass, T_REGEXP);
|
||||
re->ptr = 0; re->len = 0; re->str = 0;
|
||||
rb_obj_call_init((VALUE)re, argc, argv);
|
||||
return (VALUE)re;
|
||||
VALUE re = rb_obj_alloc(klass);
|
||||
|
||||
RREGEXP(re)->ptr = 0;
|
||||
RREGEXP(re)->len = 0;
|
||||
RREGEXP(re)->str = 0;
|
||||
|
||||
return re;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -1152,13 +1161,15 @@ static VALUE
|
|||
rb_reg_clone(re)
|
||||
VALUE re;
|
||||
{
|
||||
NEWOBJ(clone, struct RRegexp);
|
||||
CLONESETUP(clone, re);
|
||||
VALUE clone = rb_obj_clone(re);
|
||||
|
||||
RREGEXP(clone)->ptr = 0;
|
||||
RREGEXP(clone)->len = 0;
|
||||
RREGEXP(clone)->str = 0;
|
||||
rb_reg_check(re);
|
||||
clone->ptr = 0; clone->len = 0; clone->str = 0;
|
||||
rb_reg_initialize(clone, RREGEXP(re)->str, RREGEXP(re)->len,
|
||||
rb_reg_options(re));
|
||||
return (VALUE)re;
|
||||
return clone;
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
@ -1387,8 +1398,8 @@ Init_Regexp()
|
|||
rb_define_virtual_variable("$-K", kcode_getter, kcode_setter);
|
||||
|
||||
rb_cRegexp = rb_define_class("Regexp", rb_cObject);
|
||||
rb_define_singleton_method(rb_cRegexp, "new", rb_reg_s_new, -1);
|
||||
rb_define_singleton_method(rb_cRegexp, "compile", rb_reg_s_new, -1);
|
||||
rb_define_singleton_method(rb_cRegexp, "allocate", rb_reg_s_alloc, 0);
|
||||
rb_define_singleton_method(rb_cRegexp, "compile", rb_class_new_instance, -1);
|
||||
rb_define_singleton_method(rb_cRegexp, "quote", rb_reg_s_quote, -1);
|
||||
rb_define_singleton_method(rb_cRegexp, "escape", rb_reg_s_quote, -1);
|
||||
rb_define_singleton_method(rb_cRegexp, "last_match", rb_reg_s_last_match, -1);
|
||||
|
@ -1415,6 +1426,7 @@ Init_Regexp()
|
|||
|
||||
rb_cMatch = rb_define_class("MatchData", rb_cObject);
|
||||
rb_define_global_const("MatchingData", rb_cMatch);
|
||||
rb_undef_method(CLASS_OF(rb_cMatch), "allocate");
|
||||
rb_undef_method(CLASS_OF(rb_cMatch), "new");
|
||||
|
||||
rb_define_method(rb_cMatch, "clone", match_clone, 0);
|
||||
|
|
4
regex.c
4
regex.c
|
@ -3412,7 +3412,7 @@ re_search(bufp, string, size, startpos, range, regs)
|
|||
\
|
||||
*stackp++ = pattern_place; \
|
||||
*stackp++ = string_place; \
|
||||
*stackp++ = (unsigned char*)options; /* current option status */ \
|
||||
*stackp++ = (unsigned char*)(long)options; /* current option status */ \
|
||||
*stackp++ = (unsigned char*)0; /* non-greedy flag */ \
|
||||
} while(0)
|
||||
|
||||
|
@ -4293,7 +4293,7 @@ re_match(bufp, string_arg, size, pos, regs)
|
|||
goto fail;
|
||||
}
|
||||
stackp--; /* discard greedy flag */
|
||||
options = (int)*--stackp;
|
||||
options = (long)*--stackp;
|
||||
d = *--stackp;
|
||||
p = *--stackp;
|
||||
/* Restore register info. */
|
||||
|
|
5
rubyio.h
5
rubyio.h
|
@ -35,6 +35,11 @@ typedef struct OpenFile {
|
|||
#define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
|
||||
|
||||
#define MakeOpenFile(obj, fp) do {\
|
||||
if (RFILE(obj)->fptr) {\
|
||||
rb_io_close(obj);\
|
||||
free(RFILE(obj)->fptr);\
|
||||
RFILE(obj)->fptr = 0;\
|
||||
}\
|
||||
fp = 0;\
|
||||
fp = RFILE(obj)->fptr = ALLOC(OpenFile);\
|
||||
fp->f = fp->f2 = NULL;\
|
||||
|
|
145
string.c
145
string.c
|
@ -32,24 +32,35 @@ VALUE rb_cString;
|
|||
|
||||
VALUE rb_fs;
|
||||
|
||||
static VALUE
|
||||
rb_str_s_alloc(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
NEWOBJ(str, struct RString);
|
||||
OBJSETUP(str, klass, T_STRING);
|
||||
|
||||
str->ptr = 0;
|
||||
str->len = 0;
|
||||
str->orig = 0;
|
||||
|
||||
return (VALUE)str;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_str_new0(klass, ptr, len)
|
||||
VALUE klass;
|
||||
const char *ptr;
|
||||
long len;
|
||||
{
|
||||
NEWOBJ(str, struct RString);
|
||||
OBJSETUP(str, klass, T_STRING);
|
||||
VALUE str = rb_obj_alloc(klass);
|
||||
|
||||
str->ptr = 0;
|
||||
str->len = len;
|
||||
str->orig = 0;
|
||||
str->ptr = ALLOC_N(char,len+1);
|
||||
RSTRING(str)->len = len;
|
||||
RSTRING(str)->ptr = ALLOC_N(char,len+1);
|
||||
if (ptr) {
|
||||
memcpy(str->ptr, ptr, len);
|
||||
memcpy(RSTRING(str)->ptr, ptr, len);
|
||||
}
|
||||
str->ptr[len] = '\0';
|
||||
return (VALUE)str;
|
||||
RSTRING(str)->ptr[len] = '\0';
|
||||
return str;
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
@ -92,15 +103,14 @@ VALUE
|
|||
rb_str_new3(str)
|
||||
VALUE str;
|
||||
{
|
||||
NEWOBJ(str2, struct RString);
|
||||
OBJSETUP(str2, rb_cString, T_STRING);
|
||||
VALUE str2 = rb_obj_alloc(rb_cString);
|
||||
|
||||
str2->len = RSTRING(str)->len;
|
||||
str2->ptr = RSTRING(str)->ptr;
|
||||
str2->orig = str;
|
||||
RSTRING(str2)->len = RSTRING(str)->len;
|
||||
RSTRING(str2)->ptr = RSTRING(str)->ptr;
|
||||
RSTRING(str2)->orig = str;
|
||||
OBJ_INFECT(str2, str);
|
||||
|
||||
return (VALUE)str2;
|
||||
return str2;
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
@ -124,17 +134,16 @@ rb_str_new4(orig)
|
|||
return str;
|
||||
}
|
||||
else {
|
||||
NEWOBJ(str, struct RString);
|
||||
OBJSETUP(str, klass, T_STRING);
|
||||
VALUE str = rb_obj_alloc(klass);
|
||||
|
||||
str->len = RSTRING(orig)->len;
|
||||
str->ptr = RSTRING(orig)->ptr;
|
||||
RSTRING(orig)->orig = (VALUE)str;
|
||||
str->orig = 0;
|
||||
RSTRING(str)->len = RSTRING(orig)->len;
|
||||
RSTRING(str)->ptr = RSTRING(orig)->ptr;
|
||||
RSTRING(orig)->orig = str;
|
||||
RSTRING(str)->orig = 0;
|
||||
OBJ_INFECT(str, orig);
|
||||
OBJ_FREEZE(str);
|
||||
|
||||
return (VALUE)str;
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,19 +162,18 @@ VALUE
|
|||
rb_str_buf_new(capa)
|
||||
long capa;
|
||||
{
|
||||
NEWOBJ(str, struct RString);
|
||||
OBJSETUP(str, rb_cString, T_STRING);
|
||||
VALUE str = rb_obj_alloc(rb_cString);
|
||||
|
||||
FL_SET(str, STR_NO_ORIG);
|
||||
if (capa < STR_BUF_MIN_SIZE)
|
||||
capa = STR_BUF_MIN_SIZE;
|
||||
str->ptr = 0;
|
||||
str->len = 0;
|
||||
str->orig = LONG2FIX(capa);
|
||||
str->ptr = ALLOC_N(char, capa+1);
|
||||
str->ptr[0] = '\0';
|
||||
RSTRING(str)->ptr = 0;
|
||||
RSTRING(str)->len = 0;
|
||||
RSTRING(str)->orig = LONG2FIX(capa);
|
||||
RSTRING(str)->ptr = ALLOC_N(char, capa+1);
|
||||
RSTRING(str)->ptr[0] = '\0';
|
||||
|
||||
return (VALUE)str;
|
||||
return str;
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
@ -306,18 +314,6 @@ rb_str_clone(str)
|
|||
return clone;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_str_s_new(argc, argv, klass)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE klass;
|
||||
{
|
||||
VALUE str = rb_str_new0(klass, 0, 0);
|
||||
|
||||
rb_obj_call_init(str, argc, argv);
|
||||
return str;
|
||||
}
|
||||
|
||||
static VALUE rb_str_replace _((VALUE, VALUE));
|
||||
|
||||
static VALUE
|
||||
|
@ -1071,12 +1067,12 @@ rb_str_upto_m(beg, end)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
rb_str_subpat(str, re, offset)
|
||||
rb_str_subpat(str, re, nth)
|
||||
VALUE str, re;
|
||||
int offset;
|
||||
int nth;
|
||||
{
|
||||
if (rb_reg_search(re, str, 0, 0) >= 0) {
|
||||
return rb_reg_nth_match(offset, rb_backref_get());
|
||||
return rb_reg_nth_match(nth, rb_backref_get());
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
|
@ -1153,15 +1149,16 @@ rb_str_update(str, beg, len, val)
|
|||
VALUE val;
|
||||
{
|
||||
if (len < 0) rb_raise(rb_eIndexError, "negative length %d", len);
|
||||
if (beg < 0) {
|
||||
beg += RSTRING(str)->len;
|
||||
}
|
||||
if (beg < 0 || RSTRING(str)->len < beg) {
|
||||
if (beg < 0) {
|
||||
beg -= RSTRING(str)->len;
|
||||
}
|
||||
if (RSTRING(str)->len < beg) {
|
||||
out_of_range:
|
||||
rb_raise(rb_eIndexError, "index %d out of string", beg);
|
||||
}
|
||||
if (beg < 0) {
|
||||
if (-beg > RSTRING(str)->len) {
|
||||
goto out_of_range;
|
||||
}
|
||||
beg += RSTRING(str)->len;
|
||||
}
|
||||
if (RSTRING(str)->len < beg + len) {
|
||||
len = RSTRING(str)->len - beg;
|
||||
}
|
||||
|
@ -1189,9 +1186,9 @@ rb_str_update(str, beg, len, val)
|
|||
}
|
||||
|
||||
static void
|
||||
rb_str_subpat_set(str, re, offset, val)
|
||||
rb_str_subpat_set(str, re, nth, val)
|
||||
VALUE str, re;
|
||||
int offset;
|
||||
int nth;
|
||||
VALUE val;
|
||||
{
|
||||
VALUE match;
|
||||
|
@ -1201,15 +1198,22 @@ rb_str_subpat_set(str, re, offset, val)
|
|||
rb_raise(rb_eIndexError, "regexp not matched");
|
||||
}
|
||||
match = rb_backref_get();
|
||||
if (offset >= RMATCH(match)->regs->num_regs) {
|
||||
rb_raise(rb_eIndexError, "index %d out of regexp", offset);
|
||||
if (nth >= RMATCH(match)->regs->num_regs) {
|
||||
out_of_range:
|
||||
rb_raise(rb_eIndexError, "index %d out of regexp", nth);
|
||||
}
|
||||
if (nth < 0) {
|
||||
if (-nth >= RMATCH(match)->regs->num_regs) {
|
||||
goto out_of_range;
|
||||
}
|
||||
nth += RMATCH(match)->regs->num_regs;
|
||||
}
|
||||
|
||||
start = RMATCH(match)->BEG(offset);
|
||||
start = RMATCH(match)->BEG(nth);
|
||||
if (start == -1) {
|
||||
rb_raise(rb_eIndexError, "regexp group %d not matched", offset);
|
||||
rb_raise(rb_eIndexError, "regexp group %d not matched", nth);
|
||||
}
|
||||
end = RMATCH(match)->END(offset);
|
||||
end = RMATCH(match)->END(nth);
|
||||
len = end - start;
|
||||
rb_str_update(str, start, len, val);
|
||||
}
|
||||
|
@ -1225,12 +1229,15 @@ rb_str_aset(str, indx, val)
|
|||
case T_FIXNUM:
|
||||
num_index:
|
||||
idx = NUM2INT(indx);
|
||||
if (idx < 0) {
|
||||
idx += RSTRING(str)->len;
|
||||
}
|
||||
if (idx < 0 || RSTRING(str)->len <= idx) {
|
||||
if (RSTRING(str)->len <= idx) {
|
||||
out_of_range:
|
||||
rb_raise(rb_eIndexError, "index %d out of string", idx);
|
||||
}
|
||||
if (idx < 0) {
|
||||
if (-idx > RSTRING(str)->len)
|
||||
goto out_of_range;
|
||||
idx += RSTRING(str)->len;
|
||||
}
|
||||
if (FIXNUM_P(val)) {
|
||||
if (RSTRING(str)->len == idx) {
|
||||
RSTRING(str)->len += 1;
|
||||
|
@ -1522,12 +1529,11 @@ str_gsub(argc, argv, str, bang)
|
|||
}
|
||||
}
|
||||
else {
|
||||
NEWOBJ(dup, struct RString);
|
||||
OBJSETUP(dup, rb_cString, T_STRING);
|
||||
VALUE dup = rb_obj_alloc(rb_obj_class(str));
|
||||
|
||||
OBJ_INFECT(dup, str);
|
||||
RBASIC(dup)->klass = rb_obj_class(str);
|
||||
str = (VALUE)dup;
|
||||
dup->orig = 0;
|
||||
str = dup;
|
||||
RSTRING(dup)->orig = 0;
|
||||
}
|
||||
RSTRING(str)->ptr = buf;
|
||||
RSTRING(str)->len = len = bp - buf;
|
||||
|
@ -2564,6 +2570,7 @@ rb_str_each_line(argc, argv, str)
|
|||
(rslen <= 1 ||
|
||||
rb_memcmp(RSTRING(rs)->ptr, p-rslen, rslen) == 0)) {
|
||||
line = rb_str_new5(str, s, p - s);
|
||||
OBJ_INFECT(line, str);
|
||||
rb_yield(line);
|
||||
if (RSTRING(str)->ptr != ptr || RSTRING(str)->len != len)
|
||||
rb_raise(rb_eArgError, "string modified");
|
||||
|
@ -3054,7 +3061,7 @@ Init_String()
|
|||
rb_cString = rb_define_class("String", rb_cObject);
|
||||
rb_include_module(rb_cString, rb_mComparable);
|
||||
rb_include_module(rb_cString, rb_mEnumerable);
|
||||
rb_define_singleton_method(rb_cString, "new", rb_str_s_new, -1);
|
||||
rb_define_singleton_method(rb_cString, "allocate", rb_str_s_alloc, 0);
|
||||
rb_define_method(rb_cString, "initialize", rb_str_init, -1);
|
||||
rb_define_method(rb_cString, "clone", rb_str_clone, 0);
|
||||
rb_define_method(rb_cString, "dup", rb_str_dup, 0);
|
||||
|
|
29
struct.c
29
struct.c
|
@ -14,7 +14,7 @@
|
|||
|
||||
VALUE rb_cStruct;
|
||||
|
||||
static VALUE struct_alloc _((int, VALUE*, VALUE));
|
||||
static VALUE struct_alloc _((VALUE));
|
||||
|
||||
VALUE
|
||||
rb_struct_iv_get(c, name)
|
||||
|
@ -168,8 +168,9 @@ make_struct(name, member, klass)
|
|||
rb_iv_set(nstr, "__size__", INT2NUM(RARRAY(member)->len));
|
||||
rb_iv_set(nstr, "__member__", member);
|
||||
|
||||
rb_define_singleton_method(nstr, "new", struct_alloc, -1);
|
||||
rb_define_singleton_method(nstr, "[]", struct_alloc, -1);
|
||||
rb_define_singleton_method(nstr, "allocate", struct_alloc, 0);
|
||||
rb_define_singleton_method(nstr, "new", rb_class_new_instance, -1);
|
||||
rb_define_singleton_method(nstr, "[]", rb_class_new_instance, -1);
|
||||
rb_define_singleton_method(nstr, "members", rb_struct_s_members, 0);
|
||||
for (i=0; i< RARRAY(member)->len; i++) {
|
||||
ID id = SYM2ID(RARRAY(member)->ptr[i]);
|
||||
|
@ -269,14 +270,11 @@ rb_struct_initialize(self, values)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
struct_alloc(argc, argv, klass)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
struct_alloc(klass)
|
||||
VALUE klass;
|
||||
{
|
||||
VALUE size;
|
||||
long n;
|
||||
|
||||
NEWOBJ(st, struct RStruct);
|
||||
OBJSETUP(st, klass, T_STRUCT);
|
||||
|
||||
|
@ -286,7 +284,6 @@ struct_alloc(argc, argv, klass)
|
|||
st->ptr = ALLOC_N(VALUE, n);
|
||||
rb_mem_clear(st->ptr, n);
|
||||
st->len = n;
|
||||
rb_obj_call_init((VALUE)st, argc, argv);
|
||||
|
||||
return (VALUE)st;
|
||||
}
|
||||
|
@ -295,7 +292,7 @@ VALUE
|
|||
rb_struct_alloc(klass, values)
|
||||
VALUE klass, values;
|
||||
{
|
||||
return struct_alloc(RARRAY(values)->len, RARRAY(values)->ptr, klass);
|
||||
return rb_class_new_instance(RARRAY(values)->len, RARRAY(values)->ptr, klass);
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
@ -320,7 +317,7 @@ rb_struct_new(klass, va_alist)
|
|||
}
|
||||
va_end(args);
|
||||
|
||||
return struct_alloc(size, mem, klass);
|
||||
return rb_class_new_instance(size, mem, klass);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -409,13 +406,13 @@ static VALUE
|
|||
rb_struct_clone(s)
|
||||
VALUE s;
|
||||
{
|
||||
NEWOBJ(clone, struct RStruct);
|
||||
CLONESETUP(clone, s);
|
||||
clone->ptr = ALLOC_N(VALUE, RSTRUCT(s)->len);
|
||||
clone->len = RSTRUCT(s)->len;
|
||||
MEMCPY(clone->ptr, RSTRUCT(s)->ptr, VALUE, clone->len);
|
||||
VALUE clone = rb_obj_clone(s);
|
||||
|
||||
return (VALUE)clone;
|
||||
RSTRUCT(clone)->ptr = ALLOC_N(VALUE, RSTRUCT(s)->len);
|
||||
RSTRUCT(clone)->len = RSTRUCT(s)->len;
|
||||
MEMCPY(RSTRUCT(clone)->ptr, RSTRUCT(s)->ptr, VALUE, RSTRUCT(clone)->len);
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
|
14
time.c
14
time.c
|
@ -60,18 +60,6 @@ time_s_now(klass)
|
|||
return obj;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
time_s_new(argc, argv, klass)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE klass;
|
||||
{
|
||||
VALUE obj = time_s_now(klass);
|
||||
|
||||
rb_obj_call_init(obj, argc, argv);
|
||||
return obj;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
time_new_internal(klass, sec, usec)
|
||||
VALUE klass;
|
||||
|
@ -1212,7 +1200,7 @@ Init_Time()
|
|||
rb_include_module(rb_cTime, rb_mComparable);
|
||||
|
||||
rb_define_singleton_method(rb_cTime, "now", time_s_now, 0);
|
||||
rb_define_singleton_method(rb_cTime, "new", time_s_new, -1);
|
||||
rb_define_singleton_method(rb_cTime, "allocate", time_s_now, 0);
|
||||
rb_define_singleton_method(rb_cTime, "at", time_s_at, -1);
|
||||
rb_define_singleton_method(rb_cTime, "utc", time_s_mkutc, -1);
|
||||
rb_define_singleton_method(rb_cTime, "gm", time_s_mkutc, -1);
|
||||
|
|
|
@ -187,8 +187,13 @@ rb_class_path(klass)
|
|||
char buf[256];
|
||||
char *s = "Class";
|
||||
|
||||
if (TYPE(klass) == T_MODULE) s = "Module";
|
||||
sprintf(buf, "#<%s 0lx%lx>", s, klass);
|
||||
if (TYPE(klass) == T_MODULE) {
|
||||
if (rb_obj_class(klass) == rb_cModule)
|
||||
s = "Module";
|
||||
else
|
||||
s = rb_class2name(RBASIC(klass)->klass);
|
||||
}
|
||||
sprintf(buf, "#<%s:0x%lx>", s, klass);
|
||||
return rb_str_new2(buf);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue