mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
regexp literal (e.g. \202) match, etc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@526 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a1b57d0add
commit
69a3aaf154
15 changed files with 200 additions and 70 deletions
43
ChangeLog
43
ChangeLog
|
@ -1,3 +1,46 @@
|
|||
Wed Sep 1 00:28:27 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||
|
||||
* eval.c (rb_call): call rb_undefined() if a method appears not to
|
||||
be exist explicitly from cache.
|
||||
|
||||
* eval.c (rb_method_boundp): check method cache before calling
|
||||
rb_get_method_body().
|
||||
|
||||
* eval.c (rb_get_method_body): store method non-existence
|
||||
information in the cache.
|
||||
|
||||
* random.c (rb_f_srand): use getpid(2) to generate seed.
|
||||
|
||||
* regex.c (re_match): do not apply partial mbc match for
|
||||
charset_not.
|
||||
|
||||
* regex.c (re_compile_pattern): put extended literal prefix (0xff)
|
||||
only before numeric literals, not before all >0x80 char.
|
||||
|
||||
* regex.c (re_compile_pattern): put numeric literal in extended
|
||||
charset region, not normal charset bits.
|
||||
|
||||
* regex.c (re_compile_fastmap): calculate fastmap for charset and
|
||||
charset_not to treat numeric literal (e.g. \246) specially.
|
||||
|
||||
Fri Aug 28 17:32:55 1999 Yasuhiro Fukuma <yasuf@big.or.jp>
|
||||
|
||||
* eval.c (rb_eval): should set return value (nil) explicitly if a
|
||||
value is ommited for return statement.
|
||||
|
||||
Thu Aug 26 15:06:11 1999 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
|
||||
|
||||
* gc.c (rb_gc): local variables may be placed beyond stack_end, so
|
||||
use an address from alloca(1) on non C_ALLOCA platforms.
|
||||
|
||||
Thu Aug 26 01:24:17 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||
|
||||
* sprintf.c (rb_f_sprintf): "%%" is legal, but "%3.14%" is not.
|
||||
|
||||
Mon Aug 23 00:00:54 1999 Tsukada Takuya <tsukada@fminn.nagano.nagano.jp>
|
||||
|
||||
* regex.c (re_compile_fastmap): wrong macro caused memory leak.
|
||||
|
||||
Sat Aug 21 11:30:51 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||
|
||||
* eval.c (ADJ): should not adjust addresses to data on heap.
|
||||
|
|
41
configure
vendored
41
configure
vendored
|
@ -4031,7 +4031,7 @@ echo "configure:4028: checking whether OS depend dynamic link works" >&5
|
|||
openstep*) ;;
|
||||
rhapsody*) ;;
|
||||
human*) ;;
|
||||
bsdi3*) ;;
|
||||
bsdi*) ;;
|
||||
cygwin*) ;;
|
||||
netbsd*) CCDLFLAGS=-fpic
|
||||
case "$host_cpu" in
|
||||
|
@ -4092,6 +4092,9 @@ echo "configure:4028: checking whether OS depend dynamic link works" >&5
|
|||
*shlicc*) LDSHARED="$CC -r"
|
||||
rb_cv_dlopen=yes ;;
|
||||
esac ;;
|
||||
bsdi*) LDSHARED="ld -shared"
|
||||
LDFLAGS="-rdynamic -Wl,-rpath,/usr/local/lib/ruby/1.4/i386-bsdi4.0"
|
||||
rb_cv_dlopen=yes ;;
|
||||
nextstep*) LDSHARED='cc -r -nostdlib'
|
||||
LDFLAGS="-u libsys_s"
|
||||
DLDFLAGS="$ARCH_FLAG"
|
||||
|
@ -4138,12 +4141,12 @@ if test "$ac_cv_header_a_out_h" = yes; then
|
|||
if test "$with_dln_a_out" = yes || test "$rb_cv_dlopen" = unknown; then
|
||||
cat confdefs.h > config.h
|
||||
echo $ac_n "checking whether matz's dln works""... $ac_c" 1>&6
|
||||
echo "configure:4142: checking whether matz's dln works" >&5
|
||||
echo "configure:4145: checking whether matz's dln works" >&5
|
||||
if eval "test \"`echo '$''{'rb_cv_dln_a_out'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 4147 "configure"
|
||||
#line 4150 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#define USE_DLN_A_OUT
|
||||
|
@ -4153,7 +4156,7 @@ int main() {
|
|||
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:4157: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
|
||||
if { (eval echo configure:4160: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
|
||||
rm -rf conftest*
|
||||
rb_cv_dln_a_out=yes
|
||||
else
|
||||
|
@ -4260,7 +4263,7 @@ fi
|
|||
case "$host_os" in
|
||||
human*)
|
||||
echo $ac_n "checking for _harderr in -lsignal""... $ac_c" 1>&6
|
||||
echo "configure:4264: checking for _harderr in -lsignal" >&5
|
||||
echo "configure:4267: checking for _harderr in -lsignal" >&5
|
||||
ac_lib_var=`echo signal'_'_harderr | sed 'y%./+-%__p_%'`
|
||||
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
|
@ -4268,7 +4271,7 @@ else
|
|||
ac_save_LIBS="$LIBS"
|
||||
LIBS="-lsignal $LIBS"
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 4272 "configure"
|
||||
#line 4275 "configure"
|
||||
#include "confdefs.h"
|
||||
/* Override any gcc2 internal prototype to avoid an error. */
|
||||
/* We use char because int might match the return type of a gcc2
|
||||
|
@ -4279,7 +4282,7 @@ int main() {
|
|||
_harderr()
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:4283: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
if { (eval echo configure:4286: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
rm -rf conftest*
|
||||
eval "ac_cv_lib_$ac_lib_var=yes"
|
||||
else
|
||||
|
@ -4307,7 +4310,7 @@ else
|
|||
fi
|
||||
|
||||
echo $ac_n "checking for hmemset in -lhmem""... $ac_c" 1>&6
|
||||
echo "configure:4311: checking for hmemset in -lhmem" >&5
|
||||
echo "configure:4314: checking for hmemset in -lhmem" >&5
|
||||
ac_lib_var=`echo hmem'_'hmemset | sed 'y%./+-%__p_%'`
|
||||
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
|
@ -4315,7 +4318,7 @@ else
|
|||
ac_save_LIBS="$LIBS"
|
||||
LIBS="-lhmem $LIBS"
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 4319 "configure"
|
||||
#line 4322 "configure"
|
||||
#include "confdefs.h"
|
||||
/* Override any gcc2 internal prototype to avoid an error. */
|
||||
/* We use char because int might match the return type of a gcc2
|
||||
|
@ -4326,7 +4329,7 @@ int main() {
|
|||
hmemset()
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:4330: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
if { (eval echo configure:4333: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
rm -rf conftest*
|
||||
eval "ac_cv_lib_$ac_lib_var=yes"
|
||||
else
|
||||
|
@ -4356,12 +4359,12 @@ fi
|
|||
for ac_func in select
|
||||
do
|
||||
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
|
||||
echo "configure:4360: checking for $ac_func" >&5
|
||||
echo "configure:4363: checking for $ac_func" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 4365 "configure"
|
||||
#line 4368 "configure"
|
||||
#include "confdefs.h"
|
||||
/* System header to define __stub macros and hopefully few prototypes,
|
||||
which can conflict with char $ac_func(); below. */
|
||||
|
@ -4384,7 +4387,7 @@ $ac_func();
|
|||
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:4388: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
if { (eval echo configure:4391: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
rm -rf conftest*
|
||||
eval "ac_cv_func_$ac_func=yes"
|
||||
else
|
||||
|
@ -4409,7 +4412,7 @@ fi
|
|||
done
|
||||
|
||||
echo $ac_n "checking whether PD libc _dtos18 fail to convert big number""... $ac_c" 1>&6
|
||||
echo "configure:4413: checking whether PD libc _dtos18 fail to convert big number" >&5
|
||||
echo "configure:4416: checking whether PD libc _dtos18 fail to convert big number" >&5
|
||||
if eval "test \"`echo '$''{'rb_cv_missing__dtos18'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
|
@ -4417,7 +4420,7 @@ else
|
|||
rb_cv_missing__dtos18=no
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 4421 "configure"
|
||||
#line 4424 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -4429,7 +4432,7 @@ main ()
|
|||
}
|
||||
|
||||
EOF
|
||||
if { (eval echo configure:4433: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
|
||||
if { (eval echo configure:4436: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
|
||||
then
|
||||
rb_cv_missing__dtos18=yes
|
||||
else
|
||||
|
@ -4451,7 +4454,7 @@ EOF
|
|||
|
||||
fi
|
||||
echo $ac_n "checking whether PD libc fconvert fail to round""... $ac_c" 1>&6
|
||||
echo "configure:4455: checking whether PD libc fconvert fail to round" >&5
|
||||
echo "configure:4458: checking whether PD libc fconvert fail to round" >&5
|
||||
if eval "test \"`echo '$''{'rb_cv_missing_fconvert'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
|
@ -4459,7 +4462,7 @@ else
|
|||
rb_cv_missing_fconvert=no
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 4463 "configure"
|
||||
#line 4466 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -4472,7 +4475,7 @@ main ()
|
|||
}
|
||||
|
||||
EOF
|
||||
if { (eval echo configure:4476: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
|
||||
if { (eval echo configure:4479: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
|
||||
then
|
||||
rb_cv_missing_fconvert=yes
|
||||
else
|
||||
|
|
|
@ -375,7 +375,7 @@ if test "$with_dln_a_out" != yes; then
|
|||
openstep*) ;;
|
||||
rhapsody*) ;;
|
||||
human*) ;;
|
||||
bsdi3*) ;;
|
||||
bsdi*) ;;
|
||||
cygwin*) ;;
|
||||
netbsd*) CCDLFLAGS=-fpic
|
||||
case "$host_cpu" in
|
||||
|
@ -436,6 +436,9 @@ if test "$with_dln_a_out" != yes; then
|
|||
*shlicc*) LDSHARED="$CC -r"
|
||||
rb_cv_dlopen=yes ;;
|
||||
esac ;;
|
||||
bsdi*) LDSHARED="ld -shared"
|
||||
LDFLAGS="-rdynamic -Wl,-rpath,/usr/local/lib/ruby/1.4/i386-bsdi4.0"
|
||||
rb_cv_dlopen=yes ;;
|
||||
nextstep*) LDSHARED='cc -r -nostdlib'
|
||||
LDFLAGS="-u libsys_s"
|
||||
DLDFLAGS="$ARCH_FLAG"
|
||||
|
|
28
eval.c
28
eval.c
|
@ -168,10 +168,17 @@ rb_get_method_body(klassp, idp, noexp)
|
|||
NODE * volatile body;
|
||||
struct cache_entry *ent;
|
||||
|
||||
if ((body = search_method(klass, id, &origin)) == 0) {
|
||||
if ((body = search_method(klass, id, &origin)) == 0 || !body->nd_body) {
|
||||
/* store in cache */
|
||||
ent = cache + EXPR1(klass, id);
|
||||
ent->klass = klass;
|
||||
ent->origin = klass;
|
||||
ent->mid = ent->mid0 = id;
|
||||
ent->noex = 0;
|
||||
ent->method = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
if (!body->nd_body) return 0;
|
||||
|
||||
/* store in cache */
|
||||
ent = cache + EXPR1(klass, id);
|
||||
|
@ -327,8 +334,17 @@ rb_method_boundp(klass, id, ex)
|
|||
ID id;
|
||||
int ex;
|
||||
{
|
||||
struct cache_entry *ent;
|
||||
int noex;
|
||||
|
||||
/* is it in the method cache? */
|
||||
ent = cache + EXPR1(klass, id);
|
||||
if (ent->mid == id && ent->klass == klass) {
|
||||
if (ex && (ent->noex & NOEX_PRIVATE))
|
||||
return Qfalse;
|
||||
if (!ent->method) return Qfalse;
|
||||
return Qtrue;
|
||||
}
|
||||
if (rb_get_method_body(&klass, &id, &noex)) {
|
||||
if (ex && (noex & NOEX_PRIVATE))
|
||||
return Qfalse;
|
||||
|
@ -2140,8 +2156,12 @@ rb_eval(self, node)
|
|||
|
||||
case NODE_RETURN:
|
||||
if (node->nd_stts) {
|
||||
return_value(rb_eval(self, node->nd_stts));
|
||||
return_value(rb_eval(self, node->nd_stts));
|
||||
}
|
||||
else {
|
||||
return_value(Qnil);
|
||||
}
|
||||
return_value(rb_eval(self, node->nd_stts));
|
||||
return_check();
|
||||
JUMP_TAG(TAG_RETURN);
|
||||
break;
|
||||
|
@ -3976,6 +3996,8 @@ rb_call(klass, recv, mid, argc, argv, scope)
|
|||
/* is it in the method cache? */
|
||||
ent = cache + EXPR1(klass, mid);
|
||||
if (ent->mid == mid && ent->klass == klass) {
|
||||
if (!ent->method)
|
||||
return rb_undefined(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0);
|
||||
klass = ent->origin;
|
||||
id = ent->mid0;
|
||||
noex = ent->noex;
|
||||
|
|
6
gc.c
6
gc.c
|
@ -892,7 +892,9 @@ rb_gc()
|
|||
struct gc_list *list;
|
||||
struct FRAME * volatile frame; /* gcc 2.7.2.3 -O2 bug?? */
|
||||
jmp_buf save_regs_gc_mark;
|
||||
#ifdef C_ALLOCA
|
||||
VALUE stack_end;
|
||||
#endif
|
||||
|
||||
alloc_objects = 0;
|
||||
malloc_memories = 0;
|
||||
|
@ -923,7 +925,11 @@ rb_gc()
|
|||
/* This assumes that all registers are saved into the jmp_buf */
|
||||
setjmp(save_regs_gc_mark);
|
||||
mark_locations_array((VALUE*)save_regs_gc_mark, sizeof(save_regs_gc_mark) / sizeof(VALUE *));
|
||||
#ifdef C_ALLOCA
|
||||
rb_gc_mark_locations(rb_gc_stack_start, (VALUE*)&stack_end);
|
||||
#else
|
||||
rb_gc_mark_locations(rb_gc_stack_start, (VALUE*)alloca(1));
|
||||
#endif
|
||||
#if defined(THINK_C) || defined(__human68k__)
|
||||
#ifndef __human68k__
|
||||
mark_locations_array((VALUE*)((char*)save_regs_gc_mark+2),
|
||||
|
|
25
lib/date2.rb
25
lib/date2.rb
|
@ -1,5 +1,5 @@
|
|||
# date2.rb: Written by Tadayoshi Funaba 1998, 1999
|
||||
# $Id: date2.rb,v 1.13 1999/08/11 01:10:02 tadf Exp $
|
||||
# $Id: date2.rb,v 1.15 1999/08/29 15:23:52 tadf Exp $
|
||||
|
||||
class Date
|
||||
|
||||
|
@ -31,10 +31,10 @@ class Date
|
|||
y -= 1
|
||||
m += 12
|
||||
end
|
||||
a = (y / 100).to_i
|
||||
b = 2 - a + (a / 4).to_i
|
||||
jd = (365.25 * (y + 4716)).to_i +
|
||||
(30.6001 * (m + 1)).to_i +
|
||||
a = (y / 100.0).floor
|
||||
b = 2 - a + (a / 4.0).floor
|
||||
jd = (365.25 * (y + 4716)).floor +
|
||||
(30.6001 * (m + 1)).floor +
|
||||
d + b - 1524
|
||||
if os?(jd, sg)
|
||||
jd -= b
|
||||
|
@ -46,14 +46,14 @@ class Date
|
|||
if os?(jd, sg)
|
||||
a = jd
|
||||
else
|
||||
x = ((jd - 1867216.25) / 36524.25).to_i
|
||||
a = jd + 1 + x - (x / 4).to_i
|
||||
x = ((jd - 1867216.25) / 36524.25).floor
|
||||
a = jd + 1 + x - (x / 4.0).floor
|
||||
end
|
||||
b = a + 1524
|
||||
c = ((b - 122.1) / 365.25).to_i
|
||||
d = (365.25 * c).to_i
|
||||
e = ((b - d) / 30.6001).to_i
|
||||
dom = b - d - (30.6001 * e).to_i
|
||||
c = ((b - 122.1) / 365.25).floor
|
||||
d = (365.25 * c).floor
|
||||
e = ((b - d) / 30.6001).floor
|
||||
dom = b - d - (30.6001 * e).floor
|
||||
if e <= 13
|
||||
m = e - 1
|
||||
y = c - 4716
|
||||
|
@ -70,8 +70,7 @@ class Date
|
|||
|
||||
def jd_to_ordinal(jd, sg=true)
|
||||
y = jd_to_civil(jd, sg)[0]
|
||||
pl = civil_to_jd(y - 1, 12, 31, ns?(jd, sg))
|
||||
doy = jd - pl
|
||||
doy = jd - civil_to_jd(y - 1, 12, 31, ns?(jd, sg))
|
||||
return y, doy
|
||||
end
|
||||
|
||||
|
|
|
@ -303,7 +303,7 @@ class GetoptLong
|
|||
when STATUS_YET
|
||||
@status = STATUS_STARTED
|
||||
when STATUS_TERMINATED
|
||||
return
|
||||
return nil
|
||||
end
|
||||
|
||||
#
|
||||
|
@ -320,7 +320,7 @@ class GetoptLong
|
|||
end
|
||||
if ARGV.length == 0
|
||||
terminate
|
||||
return
|
||||
return nil
|
||||
end
|
||||
$_ = ARGV.shift
|
||||
elsif @ordering == REQUIRE_ORDER
|
||||
|
|
|
@ -104,7 +104,7 @@ class String
|
|||
self.gsub!(pattern, last)
|
||||
else
|
||||
h = HashCache[from + "::" + to] ||= expand_ch_hash(from, to)
|
||||
self.gsub!(pattern) do |c| h[c] end
|
||||
self.gsub!(pattern) do |c| p [c,h[c]]; h[c] end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#
|
||||
# matrix.rb -
|
||||
# $Release Version: 1.0$
|
||||
# $Revision: 1.8 $
|
||||
# $Date: 1999/02/17 12:34:19 $
|
||||
# $Revision: 1.9 $
|
||||
# $Date: 1999/08/24 10:25:00 $
|
||||
# Original Version from Smalltalk-80 version
|
||||
# on July 23, 1985 at 8:37:17 am
|
||||
# by Keiju ISHITSUKA
|
||||
|
@ -593,6 +593,7 @@ class Matrix
|
|||
end while a[i][k] == 0
|
||||
a[i], a[k] = a[k], a[i]
|
||||
akk = a[k][k]
|
||||
det *= -1
|
||||
end
|
||||
(k + 1).upto(size) do
|
||||
|i|
|
||||
|
|
|
@ -73,7 +73,7 @@ module ParseDate
|
|||
elsif date.sub!(/\d\d/i, ' ')
|
||||
year = $&.to_i
|
||||
end
|
||||
if guess
|
||||
if guess and year
|
||||
if year < 100
|
||||
if year >= 69
|
||||
year += 1900
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#
|
||||
# rational.rb -
|
||||
# $Release Version: 0.5 $
|
||||
# $Revision: 1.3 $
|
||||
# $Date: 1998/03/11 14:09:03 $
|
||||
# $Revision: 1.7 $
|
||||
# $Date: 1999/08/24 12:49:28 $
|
||||
# by Keiju ISHITSUKA(SHL Japan Inc.)
|
||||
#
|
||||
# --
|
||||
|
@ -44,7 +44,7 @@ def Rational(a, b = 1)
|
|||
end
|
||||
|
||||
class Rational < Numeric
|
||||
@RCS_ID='-$Id: rational.rb,v 1.3 1998/03/11 14:09:03 keiju Exp keiju $-'
|
||||
@RCS_ID='-$Id: rational.rb,v 1.7 1999/08/24 12:49:28 keiju Exp keiju $-'
|
||||
|
||||
def Rational.reduce(num, den = 1)
|
||||
raise ZeroDivisionError, "denometor is 0" if den == 0
|
||||
|
@ -235,6 +235,10 @@ class Rational < Numeric
|
|||
self
|
||||
end
|
||||
|
||||
def inspect
|
||||
sprintf("Rational(%s, %s)", @numerator.inspect, @denominator.inspect)
|
||||
end
|
||||
|
||||
def hash
|
||||
@numerator ^ @denominator
|
||||
end
|
||||
|
@ -258,7 +262,27 @@ class Integer
|
|||
Rational(self, 1)
|
||||
end
|
||||
|
||||
def gcd(int)
|
||||
def gcd(n)
|
||||
m = self.abs
|
||||
n = n.abs
|
||||
|
||||
return n if m == 0
|
||||
return m if n == 0
|
||||
|
||||
b = 0
|
||||
while n[0] == 0 && m[0] == 0
|
||||
b += 1; n >>= 1; m >>= 1
|
||||
end
|
||||
m >>= 1 while m[0] == 0
|
||||
n >>= 1 while n[0] == 0
|
||||
while m != n
|
||||
m, n = n, m if n > m
|
||||
m -= n; m >>= 1 while m[0] == 0
|
||||
end
|
||||
m << b
|
||||
end
|
||||
|
||||
def gcd2(int)
|
||||
a = self.abs
|
||||
b = int.abs
|
||||
|
||||
|
@ -270,7 +294,7 @@ class Integer
|
|||
end
|
||||
return a
|
||||
end
|
||||
|
||||
|
||||
def lcm(int)
|
||||
a = self.abs
|
||||
b = int.abs
|
||||
|
|
5
random.c
5
random.c
|
@ -12,6 +12,9 @@
|
|||
|
||||
#include "ruby.h"
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
#ifndef NT
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
|
@ -92,7 +95,7 @@ rb_f_srand(argc, argv, obj)
|
|||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, 0);
|
||||
seed = tv.tv_sec ^ tv.tv_usec;
|
||||
seed = tv.tv_sec ^ tv.tv_usec ^ getpid();
|
||||
}
|
||||
else {
|
||||
seed = NUM2UINT(seed);
|
||||
|
|
60
regex.c
60
regex.c
|
@ -116,11 +116,11 @@ char *alloca();
|
|||
|
||||
#define RE_ALLOCATE xmalloc
|
||||
|
||||
#define FREE_VAR(var) if (var) free(var); var = NULL
|
||||
#define FREE_VAR(var) do { if (var) free(var); var = NULL; } while(0)
|
||||
#define FREE_VARIABLES()
|
||||
|
||||
#define FREE_AND_RETURN_VOID(stackb) free(stackb);return
|
||||
#define FREE_AND_RETURN(stackb,val) free(stackb);return(val)
|
||||
#define FREE_AND_RETURN_VOID(stackb) do { free(stackb); return; } while(0)
|
||||
#define FREE_AND_RETURN(stackb,val) do { free(stackb); return(val); } while(0)
|
||||
#define DOUBLE_STACK(stackx,stackb,len,type) \
|
||||
(type*)xrealloc(stackb, 2 * len * sizeof(type))
|
||||
#endif /* NO_ALLOCA */
|
||||
|
@ -452,7 +452,7 @@ re_set_syntax(syntax)
|
|||
} while(0)
|
||||
|
||||
#define WC2MBC1ST(c) \
|
||||
((current_mbctype != MBCTYPE_UTF8)?(((c)>>8)&0xff):utf8_firstbyte(c))
|
||||
((c<0x100)?(c):((current_mbctype != MBCTYPE_UTF8)?(((c)>>8)&0xff):utf8_firstbyte(c)))
|
||||
|
||||
static unsigned int
|
||||
utf8_firstbyte(c)
|
||||
|
@ -489,6 +489,9 @@ print_mbc(c)
|
|||
else if (c <= 0x7fffffff)
|
||||
printf("%c%c%c%c%c%c", utf8_firstbyte(c), (c>>24)&0x3f, (c>>18)&0x3f, (c>>12)&0x3f, (c>>6)&0x3f, c&0x3f);
|
||||
}
|
||||
else if (c < 0xff) {
|
||||
printf("\\%o", c);
|
||||
}
|
||||
else {
|
||||
printf("%c%c", c>>BYTEWIDTH, c&0xff);
|
||||
}
|
||||
|
@ -1178,6 +1181,7 @@ re_compile_pattern(pattern, size, bufp)
|
|||
|
||||
int range = 0;
|
||||
int had_mbchar = 0;
|
||||
int had_num_literal = 0;
|
||||
int had_char_class = 0;
|
||||
|
||||
int options = bufp->options;
|
||||
|
@ -1338,6 +1342,7 @@ re_compile_pattern(pattern, size, bufp)
|
|||
memset(b, 0, (1 << BYTEWIDTH) / BYTEWIDTH + 2);
|
||||
|
||||
had_mbchar = 0;
|
||||
had_num_literal = 0;
|
||||
had_char_class = 0;
|
||||
|
||||
/* charset_not matches newline according to a syntax bit. */
|
||||
|
@ -1441,6 +1446,7 @@ re_compile_pattern(pattern, size, bufp)
|
|||
case 'x':
|
||||
c = scan_hex(p, 2, &numlen);
|
||||
p += numlen;
|
||||
had_num_literal = 1;
|
||||
break;
|
||||
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
|
@ -1448,6 +1454,7 @@ re_compile_pattern(pattern, size, bufp)
|
|||
PATUNFETCH;
|
||||
c = scan_oct(p, 3, &numlen);
|
||||
p += numlen;
|
||||
had_num_literal = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -1558,8 +1565,10 @@ re_compile_pattern(pattern, size, bufp)
|
|||
last = ':';
|
||||
}
|
||||
}
|
||||
else if (had_mbchar == 0)
|
||||
else if (had_mbchar == 0 && (!current_mbctype || !had_num_literal)) {
|
||||
SET_LIST_BIT(c);
|
||||
had_num_literal = 0;
|
||||
}
|
||||
else
|
||||
set_list_bits(c, c, b);
|
||||
had_mbchar = 0;
|
||||
|
@ -2088,6 +2097,7 @@ re_compile_pattern(pattern, size, bufp)
|
|||
had_mbchar = 0;
|
||||
c = scan_hex(p, 2, &numlen);
|
||||
p += numlen;
|
||||
had_num_literal = 1;
|
||||
goto numeric_char;
|
||||
|
||||
/* octal */
|
||||
|
@ -2095,6 +2105,7 @@ re_compile_pattern(pattern, size, bufp)
|
|||
had_mbchar = 0;
|
||||
c = scan_oct(p, 3, &numlen);
|
||||
p += numlen;
|
||||
had_num_literal = 1;
|
||||
goto numeric_char;
|
||||
|
||||
/* back-ref or octal */
|
||||
|
@ -2118,6 +2129,7 @@ re_compile_pattern(pattern, size, bufp)
|
|||
c = scan_oct(p_save, 3, &numlen) & 0xff;
|
||||
p = p_save + numlen;
|
||||
c1 = 0;
|
||||
had_num_literal = 1;
|
||||
goto numeric_char;
|
||||
}
|
||||
}
|
||||
|
@ -2174,9 +2186,10 @@ re_compile_pattern(pattern, size, bufp)
|
|||
pending_exact = b;
|
||||
BUFPUSH(0);
|
||||
}
|
||||
if (!had_mbchar && c > 0x7f) {
|
||||
if (had_num_literal && current_mbctype) {
|
||||
BUFPUSH(0xff);
|
||||
(*pending_exact)++;
|
||||
had_num_literal = 0;
|
||||
}
|
||||
BUFPUSH(c);
|
||||
(*pending_exact)++;
|
||||
|
@ -2590,7 +2603,7 @@ re_compile_fastmap(bufp)
|
|||
register int j, k;
|
||||
unsigned is_a_succeed_n;
|
||||
|
||||
unsigned char **stackb = TMALLOC(NFAILURES, unsigned char*);
|
||||
unsigned char **stackb = RE_TALLOC(NFAILURES, unsigned char*);
|
||||
unsigned char **stackp = stackb;
|
||||
unsigned char **stacke = stackb + NFAILURES;
|
||||
int options = bufp->options;
|
||||
|
@ -2802,7 +2815,7 @@ re_compile_fastmap(bufp)
|
|||
for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--)
|
||||
if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) {
|
||||
int tmp = TRANSLATE_P()?translate[j]:j;
|
||||
fastmap[tmp] = (tmp>0x7f)?2:1;
|
||||
fastmap[tmp] = 1;
|
||||
}
|
||||
{
|
||||
unsigned short size;
|
||||
|
@ -2819,7 +2832,9 @@ re_compile_fastmap(bufp)
|
|||
while (beg <= end) {
|
||||
/* NOTE: Charset for multi-byte chars might contain
|
||||
single-byte chars. We must reject them. */
|
||||
if (ismbchar(beg))
|
||||
if (beg < 0x100)
|
||||
fastmap[beg] = 2;
|
||||
else if (ismbchar(beg))
|
||||
fastmap[beg] = 1;
|
||||
beg++;
|
||||
}
|
||||
|
@ -2848,14 +2863,10 @@ re_compile_fastmap(bufp)
|
|||
if (!ismbchar(j))
|
||||
fastmap[j] = 1;
|
||||
}
|
||||
if (current_mbctype) {
|
||||
for (j = 0x80; j < (1 << BYTEWIDTH); j++)
|
||||
if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))))
|
||||
fastmap[j] = 2;
|
||||
}
|
||||
{
|
||||
unsigned short size;
|
||||
unsigned long c, beg;
|
||||
int num_literal = 0;
|
||||
|
||||
p += p[-1] + 2;
|
||||
size = EXTRACT_UNSIGNED(&p[-2]);
|
||||
|
@ -2865,7 +2876,7 @@ re_compile_fastmap(bufp)
|
|||
fastmap[j] = 1;
|
||||
break;
|
||||
}
|
||||
for (j = 0,c = 0x80;j < (int)size; j++) {
|
||||
for (j = 0,c = 0;j < (int)size; j++) {
|
||||
int cc = EXTRACT_MBC(&p[j*8]);
|
||||
beg = WC2MBC1ST(cc);
|
||||
while (c < beg) {
|
||||
|
@ -2875,10 +2886,21 @@ re_compile_fastmap(bufp)
|
|||
}
|
||||
|
||||
cc = EXTRACT_MBC(&p[j*8+4]);
|
||||
c = WC2MBC1ST(cc) + 1;
|
||||
beg = WC2MBC1ST(cc);
|
||||
if (cc < 0xff) {
|
||||
num_literal = 1;
|
||||
while (c <= beg) {
|
||||
if (ismbchar(c))
|
||||
fastmap[c] = 1;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
c = beg + 1;
|
||||
}
|
||||
|
||||
for (j = c; j < (1 << BYTEWIDTH); j++)
|
||||
if (num_literal)
|
||||
fastmap[j] = 1;
|
||||
if (ismbchar(j))
|
||||
fastmap[j] = 1;
|
||||
}
|
||||
|
@ -3613,12 +3635,12 @@ re_match(bufp, string_arg, size, pos, regs)
|
|||
cc = c = (unsigned char)translate[c];
|
||||
|
||||
not = is_in_list(c, p);
|
||||
if (!not && cc != c) {
|
||||
part = not = is_in_list(cc, p);
|
||||
}
|
||||
if (*(p - 1) == (unsigned char)charset_not) {
|
||||
not = !not;
|
||||
}
|
||||
else if (!not && cc != c) {
|
||||
part = not = is_in_list(cc, p);
|
||||
}
|
||||
if (!not) goto fail;
|
||||
|
||||
p += 1 + *p + 2 + EXTRACT_UNSIGNED(&p[1 + *p])*8;
|
||||
|
|
|
@ -23,7 +23,7 @@ double strtod();
|
|||
#ifdef USE_CWGUSI
|
||||
static void fmt_setup();
|
||||
#else
|
||||
static void fmt_setup _((char*,char,int,int,int));
|
||||
static void fmt_setup _((char*,int,int,int,int));
|
||||
#endif
|
||||
|
||||
static char*
|
||||
|
@ -263,6 +263,9 @@ rb_f_sprintf(argc, argv)
|
|||
p--;
|
||||
case '\0':
|
||||
case '%':
|
||||
if (flags != FNONE) {
|
||||
rb_raise(rb_eArgError, "illegal format character - %%");
|
||||
}
|
||||
PUSH("%", 1);
|
||||
break;
|
||||
|
||||
|
@ -620,7 +623,8 @@ rb_f_sprintf(argc, argv)
|
|||
|
||||
static void
|
||||
fmt_setup(buf, c, flags, width, prec)
|
||||
char *buf, c;
|
||||
char *buf;
|
||||
int c;
|
||||
int flags, width, prec;
|
||||
{
|
||||
*buf++ = '%';
|
||||
|
|
|
@ -48,7 +48,7 @@ s%@LDSHARED@%cl -LD%g
|
|||
s%@DLEXT@%dll%g
|
||||
s%@STRIP@%%g
|
||||
s%@EXTSTATIC@%%g
|
||||
s%@setup@%Setup
|
||||
s%@setup@%Setup%g
|
||||
s%@LIBRUBY_LDSHARED@%%g
|
||||
s%@LIBRUBY_DLDFLAGS@%%g
|
||||
s%@RUBY_INSTALL_NAME@%ruby%g
|
||||
|
|
Loading…
Reference in a new issue