1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 1998-06-08 01:40:08 +00:00
parent 5196e8609b
commit 7acc47fe82
4 changed files with 63 additions and 49 deletions

View file

@ -21,7 +21,17 @@ class Delegator
preserved -= ["__getobj__","to_s","nil?","to_a","hash","dup","==","=~"] preserved -= ["__getobj__","to_s","nil?","to_a","hash","dup","==","=~"]
for method in obj.methods for method in obj.methods
next if preserved.include? method next if preserved.include? method
eval "def self.#{method}(*args,&block); __getobj__.__send__(:#{method}, *args,&block); end" eval <<EOS
def self.#{method}(*args, &block)
begin
__getobj__.__send__(:#{method}, *args, &block)
rescue Exception
n = if /:in `__getobj__'$/ =~ $@[0] then 1 else 2 end #`
$@[1,n] = nil
raise
end
end
EOS
end end
end end
@ -53,6 +63,10 @@ SimpleDelegater = SimpleDelegator
if __FILE__ == $0 if __FILE__ == $0
foo = Object.new foo = Object.new
def foo.test
raise 'this is OK'
end
foo2 = SimpleDelegator.new(foo) foo2 = SimpleDelegator.new(foo)
p foo.hash == foo2.hash # => true p foo.hash == foo2.hash # => true
foo.test # raise error!
end end

View file

@ -41,14 +41,9 @@ class WeakRef<Delegator
def __getobj__ def __getobj__
unless ID_MAP[@__id] unless ID_MAP[@__id]
$@ = caller(1) raise RefError, "Illegal Reference - probably recycled", caller(2)
$! = RefError.new("Illegal Reference - probably recycled")
raise
end end
ObjectSpace._id2ref(@__id) ObjectSpace._id2ref(@__id)
# ObjectSpace.each_object do |obj|
# return obj if obj.id == @__id
# end
end end
def weakref_alive? def weakref_alive?
@ -66,9 +61,9 @@ end
if __FILE__ == $0 if __FILE__ == $0
foo = Object.new foo = Object.new
p foo.hash p foo.hash # original's hash value
foo = WeakRef.new(foo) foo = WeakRef.new(foo)
p foo.hash p foo.hash # should be same hash value
ObjectSpace.garbage_collect ObjectSpace.garbage_collect
p foo.hash p foo.hash # should raise exception (recycled)
end end

66
regex.c
View file

@ -897,8 +897,6 @@ calculate_must_string(start, end)
case casefold_off: case casefold_off:
return 0; /* should not check must_string */ return 0; /* should not check must_string */
case start_nowidth:
case stop_nowidth:
case pop_and_fail: case pop_and_fail:
case anychar: case anychar:
case begline: case begline:
@ -943,6 +941,8 @@ calculate_must_string(start, end)
if (mcnt > 0) p += mcnt; if (mcnt > 0) p += mcnt;
break; break;
case start_nowidth:
case stop_nowidth:
case finalize_jump: case finalize_jump:
case maybe_finalize_jump: case maybe_finalize_jump:
case finalize_push: case finalize_push:
@ -1622,7 +1622,7 @@ re_compile_pattern(pattern, size, bufp)
case '|': case '|':
/* Insert before the previous alternative a jump which /* Insert before the previous alternative a jump which
jumps to this alternative if the former fails. */ jumps to this alternative if the former fails. */
GET_BUFFER_SPACE(6); GET_BUFFER_SPACE(3);
insert_jump(on_failure_jump, begalt, b + 6, b); insert_jump(on_failure_jump, begalt, b + 6, b);
pending_exact = 0; pending_exact = 0;
b += 3; b += 3;
@ -1645,9 +1645,11 @@ re_compile_pattern(pattern, size, bufp)
if (fixup_alt_jump) if (fixup_alt_jump)
store_jump(fixup_alt_jump, jump_past_alt, b); store_jump(fixup_alt_jump, jump_past_alt, b);
/* Leave space for a jump after previous alternative---to be /* Mark and leave space for a jump after this alternative,
filled in later. */ to be filled in later either by next alternative or
when know we're at the end of a series of alternatives. */
fixup_alt_jump = b; fixup_alt_jump = b;
GET_BUFFER_SPACE(3);
b += 3; b += 3;
laststart = 0; laststart = 0;
@ -2630,8 +2632,13 @@ re_search(bufp, string, size, startpos, range, regs)
} }
} }
if (anchor && startpos > 0 && startpos < size if (anchor && startpos < size && string[startpos-1] != '\n') {
&& string[startpos-1] != '\n') goto advance; while (range > 0 && string[startpos] != '\n') {
range--;
startpos++;
}
goto advance;
}
if (fastmap && startpos == size && range >= 0 if (fastmap && startpos == size && range >= 0
&& (bufp->can_be_null == 0 || && (bufp->can_be_null == 0 ||
@ -2725,26 +2732,25 @@ typedef union
/* Macros used by re_match: */ /* Macros used by re_match: */
/* I.e., regstart, regend, and reg_info. */ /* I.e., regstart, regend, and reg_info. */
#define NUM_REG_ITEMS 3 #define NUM_REG_ITEMS 3
/* Individual items aside from the registers. */
#define NUM_NONREG_ITEMS 3
/* We push at most this many things on the stack whenever we /* We push at most this many things on the stack whenever we
fail. The `+ 2' refers to PATTERN_PLACE and STRING_PLACE, which are fail. The `+ 2' refers to PATTERN_PLACE and STRING_PLACE, which are
arguments to the PUSH_FAILURE_POINT macro. */ arguments to the PUSH_FAILURE_POINT macro. */
#define MAX_NUM_FAILURE_ITEMS (num_regs * NUM_REG_ITEMS + NUM_NONREG_ITEMS)
#define MAX_NUM_FAILURE_ITEMS (num_regs * NUM_REG_ITEMS + 2)
/* We push this many things on the stack whenever we fail. */ /* We push this many things on the stack whenever we fail. */
#define NUM_FAILURE_ITEMS (last_used_reg * NUM_REG_ITEMS + NUM_REG_ITEMS)
#define NUM_FAILURE_ITEMS (last_used_reg * NUM_REG_ITEMS + 2)
/* This pushes most of the information about the current state we will want /* This pushes most of the information about the current state we will want
if we ever fail back to it. */ if we ever fail back to it. */
#define PUSH_FAILURE_POINT(pattern_place, string_place) \ #define PUSH_FAILURE_POINT(pattern_place, string_place) \
{ \ do { \
long last_used_reg, this_reg; \ long last_used_reg, this_reg; \
\ \
/* Find out how many registers are active or have been matched. \ /* Find out how many registers are active or have been matched. \
@ -2781,19 +2787,19 @@ typedef union
*stackp++ = pattern_place; \ *stackp++ = pattern_place; \
*stackp++ = string_place; \ *stackp++ = string_place; \
*stackp++ = (unsigned char *)0; /* non-greedy flag */ \ *stackp++ = (unsigned char *)0; /* non-greedy flag */ \
} } while(0)
/* This pops what PUSH_FAILURE_POINT pushes. */ /* This pops what PUSH_FAILURE_POINT pushes. */
#define POP_FAILURE_POINT() \ #define POP_FAILURE_POINT() \
{ \ do { \
int temp; \ int temp; \
stackp -= 3; /* Remove failure points (and flag). */ \ stackp -= NUM_NONREG_ITEMS; /* Remove failure points (and flag). */ \
temp = (int) *--stackp; /* How many regs pushed. */ \ temp = (int) *--stackp; /* How many regs pushed. */ \
temp *= NUM_REG_ITEMS; /* How much to take off the stack. */ \ temp *= NUM_REG_ITEMS; /* How much to take off the stack. */ \
stackp -= temp; /* Remove the register info. */ \ stackp -= temp; /* Remove the register info. */ \
} } while(0)
/* Registers are set to a sentinel when they haven't yet matched. */ /* Registers are set to a sentinel when they haven't yet matched. */
#define REG_UNSET_VALUE ((unsigned char *) -1) #define REG_UNSET_VALUE ((unsigned char *) -1)
@ -2805,7 +2811,7 @@ typedef union
registers corresponding to the subexpressions of which we currently registers corresponding to the subexpressions of which we currently
are inside. */ are inside. */
#define SET_REGS_MATCHED \ #define SET_REGS_MATCHED \
{ unsigned this_reg; \ do { unsigned this_reg; \
for (this_reg = 0; this_reg < num_regs; this_reg++) \ for (this_reg = 0; this_reg < num_regs; this_reg++) \
{ \ { \
if (IS_ACTIVE(reg_info[this_reg])) \ if (IS_ACTIVE(reg_info[this_reg])) \
@ -2815,7 +2821,7 @@ typedef union
else \ else \
MATCHED_SOMETHING(reg_info[this_reg]) = 0; \ MATCHED_SOMETHING(reg_info[this_reg]) = 0; \
} \ } \
} } while(0)
#define AT_STRINGS_BEG(d) (d == string) #define AT_STRINGS_BEG(d) (d == string)
#define AT_STRINGS_END(d) (d == dend) #define AT_STRINGS_END(d) (d == dend)
@ -2891,7 +2897,6 @@ re_match(bufp, string_arg, size, pos, regs)
register unsigned char *d, *dend; register unsigned char *d, *dend;
register int mcnt; /* Multipurpose. */ register int mcnt; /* Multipurpose. */
int options = bufp->options; int options = bufp->options;
unsigned is_a_jump_n = 0;
/* Failure point stack. Each place that can handle a failure further /* Failure point stack. Each place that can handle a failure further
down the line pushes a failure point on this stack. It consists of down the line pushes a failure point on this stack. It consists of
@ -2998,7 +3003,6 @@ re_match(bufp, string_arg, size, pos, regs)
p - (unsigned char *) bufp->buffer, p - (unsigned char *) bufp->buffer,
*p); *p);
#endif #endif
is_a_jump_n = 0;
/* End of pattern means we might have succeeded. */ /* End of pattern means we might have succeeded. */
if (p == pend) if (p == pend)
{ {
@ -3114,7 +3118,8 @@ re_match(bufp, string_arg, size, pos, regs)
|| (enum regexpcode) p[-3] == start_memory) || (enum regexpcode) p[-3] == start_memory)
&& (p + 1) != pend) && (p + 1) != pend)
{ {
register unsigned char *p2 = p + 1; int is_a_jump_n = 0;
register unsigned char *p2 = p + 2;
mcnt = 0; mcnt = 0;
switch (*p2++) switch (*p2++)
{ {
@ -3136,8 +3141,8 @@ re_match(bufp, string_arg, size, pos, regs)
to an on_failure_jump, exit from the loop by forcing a to an on_failure_jump, exit from the loop by forcing a
failure after pushing on the stack the on_failure_jump's failure after pushing on the stack the on_failure_jump's
jump in the pattern, and d. */ jump in the pattern, and d. */
if (mcnt < 0 && (enum regexpcode) *p2++ == on_failure_jump if (mcnt < 0 && (enum regexpcode) *p2 == on_failure_jump
&& (enum regexpcode) p1[3] == start_memory && p1[4] == *p) && (enum regexpcode) p2[3] == start_memory && p2[4] == *p)
{ {
/* If this group ever matched anything, then restore /* If this group ever matched anything, then restore
what its registers were before trying this last what its registers were before trying this last
@ -3654,8 +3659,8 @@ re_match(bufp, string_arg, size, pos, regs)
/* Make the ones that weren't saved -1 or 0 again. */ /* Make the ones that weren't saved -1 or 0 again. */
for (this_reg = num_regs - 1; this_reg > last_used_reg; this_reg--) for (this_reg = num_regs - 1; this_reg > last_used_reg; this_reg--)
{ {
regend[this_reg] = (unsigned char *)(-1L); regend[this_reg] = REG_UNSET_VALUE;
regstart[this_reg] = (unsigned char *)(-1L); regstart[this_reg] = REG_UNSET_VALUE;
IS_ACTIVE(reg_info[this_reg]) = 0; IS_ACTIVE(reg_info[this_reg]) = 0;
MATCHED_SOMETHING(reg_info[this_reg]) = 0; MATCHED_SOMETHING(reg_info[this_reg]) = 0;
} }
@ -3667,7 +3672,6 @@ re_match(bufp, string_arg, size, pos, regs)
regend[this_reg] = *--stackp; regend[this_reg] = *--stackp;
regstart[this_reg] = *--stackp; regstart[this_reg] = *--stackp;
} }
if (p < pend) if (p < pend)
{ {
int is_a_jump_n = 0; int is_a_jump_n = 0;
@ -3684,7 +3688,7 @@ re_match(bufp, string_arg, size, pos, regs)
case finalize_jump: case finalize_jump:
case finalize_push: case finalize_push:
case jump: case jump:
p1 = p + 1; p1++;
EXTRACT_NUMBER_AND_INCR (mcnt, p1); EXTRACT_NUMBER_AND_INCR (mcnt, p1);
p1 += mcnt; p1 += mcnt;
@ -3799,10 +3803,10 @@ group_match_null_string_p (p, end, reg_info)
of the `jump_past_alt' just before it. `mcnt' contains of the `jump_past_alt' just before it. `mcnt' contains
the length of the alternative. */ the length of the alternative. */
EXTRACT_NUMBER (mcnt, p1 - 2); EXTRACT_NUMBER (mcnt, p1 - 2);
#if 0
if (!alt_match_null_string_p (p1, p1 + mcnt, reg_info)) if (!alt_match_null_string_p (p1, p1 + mcnt, reg_info))
return 0; return 0;
#endif
p1 += mcnt; /* Get past the n-th alternative. */ p1 += mcnt; /* Get past the n-th alternative. */
} /* if mcnt > 0 */ } /* if mcnt > 0 */
break; break;

View file

@ -7,25 +7,26 @@ class Tick
include Observable include Observable
def initialize def initialize
Thread.start do Thread.start do
while TRUE loop do
sleep 0.999 sleep 0.999
now = Time.now
changed changed
notify_observers(Time.now.strftime("%H:%M:%S")) notify_observers(now.hour, now.min, now.sec)
end end
end end
end end
end end
class Clock class Clock
def initialize def initialize(tick)
@tick = Tick.new @tick = tick
@tick.add_observer(self) @tick.add_observer(self)
end end
def update(time) def update(h, m, s)
print "\e[8D", time printf "\e[8D%02d:%02d:%02d", h, m, s
STDOUT.flush STDOUT.flush
end end
end end
clock = Clock.new clock = Clock.new(Tick.new)
sleep sleep