summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-08-07 05:05:04 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-08-07 05:05:04 +0000
commit62da8d946520cb4b923853bcd428e529ffb0e317 (patch)
tree9fa8495ef1bc899635833c787033ea12081f9c6b
parent223327a4ad98024dc47d32cc6c9acbe33cb32214 (diff)
downloadruby-62da8d946520cb4b923853bcd428e529ffb0e317.tar.gz
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_4@876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--configure6
-rw-r--r--eval.c6
-rw-r--r--ext/tk/lib/tk.rb92
-rw-r--r--ext/tk/lib/tkfont.rb254
-rw-r--r--ext/tk/lib/tktext.rb88
-rw-r--r--lib/weakref.rb4
-rw-r--r--regex.c4
8 files changed, 309 insertions, 154 deletions
diff --git a/ChangeLog b/ChangeLog
index 98fe929573..564c0757f3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,18 @@
+Mon Aug 7 13:59:12 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * regex.c (re_match): check for stack depth was needed.
+
Sat Aug 5 16:43:43 2000 WATANABE Hirofumi <eban@os.rim.or.jp>
* lib/ftools.rb (compare, safe_unlink, chmod): avoid warnings.
* lib/ftools.rb (move): typo. not `tpath', but `to'.
+Wed Aug 2 18:27:47 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * eval.c (rb_continuation_call): prohibit Continuation#call across
+ threads.
+
Sat Jul 29 23:42:04 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
* dir.c (dir_each): should check whether dir is closed during the
diff --git a/configure b/configure
index f0e92c67a9..2b384f64c7 100644
--- a/configure
+++ b/configure
@@ -515,7 +515,6 @@ else
> $cache_file
fi
-echo $CC
ac_ext=c
# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
ac_cpp='$CPP $CPPFLAGS'
@@ -4692,9 +4691,12 @@ case "$host_os" in
openstep*)
CFLAGS="$CFLAGS -pipe"
;;
- rhasody*)
+ rhapsody*)
CFLAGS="$CFLAGS -pipe -no-precomp"
;;
+ os2_emx)
+ CFLAGS="$CFLAGS -DOS2"
+ ;;
*)
;;
esac
diff --git a/eval.c b/eval.c
index 723689c42d..fa12ce6653 100644
--- a/eval.c
+++ b/eval.c
@@ -7518,7 +7518,8 @@ rb_callcc(self)
for (tag=prot_tag; tag; tag=tag->prev) {
scope_dup(tag->scope);
}
- th->prev = th->next = 0;
+ th->prev = 0;
+ th->next = curr_thread;
if (THREAD_SAVE_CONTEXT(th)) {
return th->result;
}
@@ -7535,6 +7536,9 @@ rb_continuation_call(argc, argv, cont)
{
rb_thread_t th = rb_thread_check(cont);
+ if (th->next != curr_thread) {
+ rb_raise(rb_eRuntimeError, "continuation called across threads");
+ }
switch (argc) {
case 0:
th->result = Qnil;
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb
index 239a50532b..52ef088fdf 100644
--- a/ext/tk/lib/tk.rb
+++ b/ext/tk/lib/tk.rb
@@ -311,7 +311,7 @@ module TkComm
def install_bind(cmd, args=nil)
if args
- id = install_cmd(proc{|arg|
+ id = install_cmd(proc{|*arg|
TkUtil.eval_cmd cmd, *arg
})
id + " " + args
@@ -784,6 +784,96 @@ module Tk
end
end
+###########################################
+# convert kanji string to/from utf-8
+###########################################
+if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK
+ class TclTkIp
+ # from tkencoding.rb by ttate@jaist.ac.jp
+ alias __eval _eval
+ alias __invoke _invoke
+ private :__eval
+ private :__invoke
+
+ attr_accessor :encoding
+
+ def _eval(cmd)
+ if @encoding
+ _fromUTF8(__eval(_toUTF8(cmd, @encoding)), @encoding)
+ else
+ __eval(cmd)
+ end
+ end
+
+ def _invoke(*cmds)
+ if @encoding
+ cmds = cmds.collect{|cmd| _toUTF8(cmd, @encoding)}
+ _fromUTF8(__invoke(*cmds), @encoding)
+ else
+ __invoke(*cmds)
+ end
+ end
+ end
+
+ module Tk
+ def encoding=(name)
+ INTERP.encoding = name
+ end
+
+ def encoding
+ INTERP.encoding
+ end
+
+ def encoding_names
+ tk_split_simplelist(tk_call('encoding', 'names'))
+ end
+
+ def encoding_system
+ tk_call('encoding', 'system')
+ end
+
+ def encoding_system=(enc)
+ tk_call('encoding', 'system', enc)
+ end
+ end
+
+ # estimate encoding
+ case $KCODE
+ when /^e/i # EUC
+ Tk.encoding = 'euc-jp'
+ when /^s/i # SJIS
+ Tk.encoding = 'shiftjis'
+ when /^u/i # UTF8
+ Tk.encoding = 'utf-8'
+ else # NONE
+ begin
+ Tk.encoding = Tk.encoding_system
+ rescue StandardError, NameError
+ Tk.encoding = 'utf-8'
+ end
+ end
+
+else
+ # dummy methods
+ module Tk
+ def encoding=(name)
+ nil
+ end
+ def encoding
+ nil
+ end
+ def encoding_names
+ nil
+ end
+ def encoding_system
+ nil
+ end
+ def encoding_system=(enc)
+ nil
+ end
+ end
+end
+
module TkBindCore
def bind(context, cmd=Proc.new, args=nil)
Tk.bind(to_eval, context, cmd, args)
diff --git a/ext/tk/lib/tkfont.rb b/ext/tk/lib/tkfont.rb
index 297e73f49d..65842e0188 100644
--- a/ext/tk/lib/tkfont.rb
+++ b/ext/tk/lib/tkfont.rb
@@ -13,6 +13,7 @@ class TkFont
Tk_FontNameTBL = {}
Tk_FontUseTBL = {}
+ # set default font
case Tk::TK_VERSION
when /^4\.*/
DEFAULT_LATIN_FONT_NAME = 'a14'.freeze
@@ -33,22 +34,65 @@ class TkFont
'-compound'))
else
# unknown Tcl/Tk-JP
- ltn = 'Helvetica'
- knj = 'mincho'
+ platform = tk_call('set', 'tcl_platform(platform)')
+ case platform
+ when 'unix'
+ ltn = {'family'=>'Helvetica'.freeze, 'size'=>-12}
+ knj = 'k14'
+ #knj = '-misc-fixed-medium-r-normal--14-*-*-*-c-*-jisx0208.1983-0'
+ when 'windows'
+ ltn = {'family'=>'MS Sans Serif'.freeze, 'size'=>8}
+ knj = 'mincho'
+ when 'macintosh'
+ ltn = 'system'
+ knj = 'mincho'
+ else # unknown
+ ltn = 'Helvetica'
+ knj = 'mincho'
+ end
end
rescue
ltn = 'Helvetica'
knj = 'mincho'
end
- DEFAULT_LATIN_FONT_NAME = ltn.freeze
- DEFAULT_KANJI_FONT_NAME = knj.freeze
- else
- DEFAULT_LATIN_FONT_NAME = 'Helvetica'.freeze
- DEFAULT_KANJI_FONT_NAME = 'mincho'.freeze
+
+ else # not JAPANIZED_TK
+ begin
+ platform = tk_call('set', 'tcl_platform(platform)')
+ case platform
+ when 'unix'
+ ltn = {'family'=>'Helvetica'.freeze, 'size'=>-12}
+ knj = 'k14'
+ #knj = '-misc-fixed-medium-r-normal--14-*-*-*-c-*-jisx0208.1983-0'
+ when 'windows'
+ ltn = {'family'=>'MS Sans Serif'.freeze, 'size'=>8}
+ knj = 'mincho'
+ when 'macintosh'
+ ltn = 'system'
+ knj = 'mincho'
+ else # unknown
+ ltn = 'Helvetica'
+ knj = 'mincho'
+ end
+ rescue
+ ltn = 'Helvetica'
+ knj = 'mincho'
+ end
end
+
+ DEFAULT_LATIN_FONT_NAME = ltn.freeze
+ DEFAULT_KANJI_FONT_NAME = knj.freeze
+
+ else # unknown version
+ DEFAULT_LATIN_FONT_NAME = 'Helvetica'.freeze
+ DEFAULT_KANJI_FONT_NAME = 'mincho'.freeze
+
+ end
+
+ if $DEBUG
+ print "default latin font = "; p DEFAULT_LATIN_FONT_NAME
+ print "default kanji font = "; p DEFAULT_KANJI_FONT_NAME
end
- p "default latin font = #{DEFAULT_LATIN_FONT_NAME}" if $DEBUG
- p "default kanji font = #{DEFAULT_KANJI_FONT_NAME}" if $DEBUG
###################################
# class methods
@@ -167,14 +211,12 @@ class TkFont
###################################
private
###################################
- def initialize(ltn=DEFAULT_LATIN_FONT_NAME, knj=DEFAULT_KANJI_FONT_NAME,
- keys=nil)
+ def initialize(ltn=DEFAULT_LATIN_FONT_NAME, knj=nil, keys=nil)
@id = format("@font%.4d", Tk_FontID[0])
Tk_FontID[0] += 1
Tk_FontNameTBL[@id] = self
- create_latinfont(ltn)
- create_kanjifont(knj)
- create_compoundfont(keys)
+ knj = DEFAULT_KANJI_FONT_NAME if JAPANIZED_TK && !knj
+ create_compoundfont(ltn, knj, keys)
end
def _get_font_info_from_hash(font)
@@ -293,7 +335,10 @@ class TkFont
end
end
- def create_compoundfont_tk4x(keys)
+ def create_compoundfont_tk4x(ltn, knj, keys)
+ create_latinfont(ltn)
+ create_kanjifont(knj)
+
if JAPANIZED_TK
@compoundfont = [[@latinfont], [@kanjifont]]
@fontslot = {'font'=>@latinfont, 'kanjifont'=>@kanjifont}
@@ -339,63 +384,66 @@ class TkFont
end
tk_call('font', 'create', @latinfont, *hash_kv(keys))
end
- end
- end
- def create_kanjifont_tk80(font)
- unless JAPANIZED_TK
- @kanjifont = ""
- return
- end
-
- @kanjifont = @id + 'k'
-
- if font.kind_of? Hash
- if font['charset']
- tk_call('font', 'create', @kanjifont, *hash_kv(font))
- else
- tk_call('font', 'create', @kanjifont,
- '-charset', 'jisx0208.1983', *hash_kv(font))
+ if font && @compoundfont
+ keys = {}
+ actual_core(@latinfont).each{|key,val| keys[key] = val}
+ tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
end
- elsif font.kind_of? Array
- tk_call('font', 'create', @kanjifont, '-copy', array2tk_list(font))
- tk_call('font', 'configure', @kanjifont, '-charset', 'jisx0208.1983')
- elsif font.kind_of? TkFont
- tk_call('font', 'create', @kanjifont, '-copy', font.kanji_font)
- elsif font
- tk_call('font', 'create', @kanjifont, '-copy', font,
- '-charset', 'jisx0208.1983')
- else
- tk_call('font', 'create', @kanjifont, '-charset', 'jisx0208.1983')
end
end
- def create_kanjifont_tk81(font)
+ def create_kanjifont_tk8x(font)
@kanjifont = @id + 'k'
- if font.kind_of? Hash
- tk_call('font', 'create', @kanjifont, *hash_kv(font))
- else
- keys = {}
- if font.kind_of? Array
- actual_core(array2tk_list(font)).each{|key,val| keys[key] = val}
+ if JAPANIZED_TK
+ if font.kind_of? Hash
+ if font['charset']
+ tk_call('font', 'create', @kanjifont, *hash_kv(font))
+ else
+ tk_call('font', 'create', @kanjifont,
+ '-charset', 'jisx0208.1983', *hash_kv(font))
+ end
+ elsif font.kind_of? Array
+ tk_call('font', 'create', @kanjifont, '-copy', array2tk_list(font))
+ tk_call('font', 'configure', @kanjifont, '-charset', 'jisx0208.1983')
elsif font.kind_of? TkFont
- actual_core(font.kanji_font).each{|key,val| keys[key] = val}
+ tk_call('font', 'create', @kanjifont, '-copy', font.kanji_font)
elsif font
- actual_core(font).each{|key,val| keys[key] = val}
+ tk_call('font', 'create', @kanjifont, '-copy', font,
+ '-charset', 'jisx0208.1983')
+ else
+ tk_call('font', 'create', @kanjifont, '-charset', 'jisx0208.1983')
end
- tk_call('font', 'create', @kanjifont, *hash_kv(keys))
- end
+ # end of JAPANIZED_TK
- keys = {}
- actual_core(@kanjifont).each{|key,val| keys[key] = val}
- begin
- tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
- rescue
+ else
+ if font.kind_of? Hash
+ tk_call('font', 'create', @kanjifont, *hash_kv(font))
+ else
+ keys = {}
+ if font.kind_of? Array
+ actual_core(array2tk_list(font)).each{|key,val| keys[key] = val}
+ elsif font.kind_of? TkFont
+ actual_core(font.kanji_font).each{|key,val| keys[key] = val}
+ elsif font
+ actual_core(font).each{|key,val| keys[key] = val}
+ end
+ tk_call('font', 'create', @kanjifont, *hash_kv(keys))
+ end
+
+ if font && @compoundfont
+ keys = {}
+ actual_core(@kanjifont).each{|key,val| keys[key] = val}
+ tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
+ end
end
end
- def create_compoundfont_tk80(keys)
+ def create_compoundfont_tk8x(ltn, knj, keys)
+ create_latinfont(ltn)
+ create_kanjifont(knj)
+
@compoundfont = @id + 'c'
if JAPANIZED_TK
@fontslot = {'font'=>@compoundfont}
@@ -403,6 +451,7 @@ class TkFont
'-compound', [@latinfont, @kanjifont], *hash_kv(keys))
else
tk_call('font', 'create', @compoundfont)
+
latinkeys = {}
begin
actual_core(@latinfont).each{|key,val| latinkeys[key] = val}
@@ -412,37 +461,22 @@ class TkFont
if latinkeys != {}
tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys))
end
- @fontslot = {'font'=>@compoundfont}
- tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
- end
- end
- def create_compoundfont_tk81(keys)
- @compoundfont = @id + 'c'
- tk_call('font', 'create', @compoundfont)
-
- latinkeys = {}
- begin
- actual_core(@latinfont).each{|key,val| latinkeys[key] = val}
- rescue
- latinkeys {}
- end
- if latinkeys != {}
- tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys))
- end
+ if knj
+ kanjikeys = {}
+ begin
+ actual_core(@kanjifont).each{|key,val| kanjikeys[key] = val}
+ rescue
+ kanjikeys {}
+ end
+ if kanjikeys != {}
+ tk_call('font', 'configure', @compoundfont, *hash_kv(kanjikeys))
+ end
+ end
- kanjikeys = {}
- begin
- actual_core(@kanjifont).each{|key,val| kanjikeys[key] = val}
- rescue
- kanjikeys {}
- end
- if kanjikeys != {}
- tk_call('font', 'configure', @compoundfont, *hash_kv(kanjikeys))
+ @fontslot = {'font'=>@compoundfont}
+ tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
end
-
- @fontslot = {'font'=>@compoundfont}
- tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
end
def actual_core_tk4x(font, window=nil, option=nil)
@@ -623,9 +657,7 @@ class TkFont
self
end
- def kanji_replace_core_tk80(knj)
- return self unless JAPANIZED_TK
-
+ def kanji_replace_core_tk8x(knj)
begin
tk_call('font', 'delete', @kanjifont)
rescue
@@ -634,23 +666,6 @@ class TkFont
self
end
- def kanji_replace_core_tk81(knj)
- if font.kind_of? Hash
- tk_call('font', 'configure', @compoundfont, *hash_kv(knj))
- else
- keys = {}
- if knj.kind_of? Array
- actual_core(array2tk_list(knj)).each{|key,val| keys[key] = val}
- elsif knj.kind_of? TkFont
- actual_core(knj.latin_font).each{|key,val| keys[key] = val}
- else
- actual_core(knj).each{|key,val| keys[key] = val}
- end
- tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
- end
- self
- end
-
def measure_core_tk4x(window, text)
0
end
@@ -712,42 +727,29 @@ class TkFont
alias measure_core measure_core_tk4x
alias metrics_core metrics_core_tk4x
- when /^8\.0/
- alias create_latinfont create_latinfont_tk8x
- alias create_kanjifont create_kanjifont_tk80
- alias create_compoundfont create_compoundfont_tk80
- alias actual_core actual_core_tk8x
- alias configure_core configure_core_tk8x
- alias configinfo_core configinfo_core_tk8x
- alias delete_core delete_core_tk8x
- alias latin_replace_core latin_replace_core_tk8x
- alias kanji_replace_core kanji_replace_core_tk80
- alias measure_core measure_core_tk8x
- alias metrics_core metrics_core_tk8x
-
- when /^8\.[123]/
+ when /^8\.[0123]/
alias create_latinfont create_latinfont_tk8x
- alias create_kanjifont create_kanjifont_tk81
- alias create_compoundfont create_compoundfont_tk81
+ alias create_kanjifont create_kanjifont_tk8x
+ alias create_compoundfont create_compoundfont_tk8x
alias actual_core actual_core_tk8x
alias configure_core configure_core_tk8x
alias configinfo_core configinfo_core_tk8x
alias delete_core delete_core_tk8x
alias latin_replace_core latin_replace_core_tk8x
- alias kanji_replace_core kanji_replace_core_tk81
+ alias kanji_replace_core kanji_replace_core_tk8x
alias measure_core measure_core_tk8x
alias metrics_core metrics_core_tk8x
when /^8\.*/
alias create_latinfont create_latinfont_tk8x
- alias create_kanjifont create_kanjifont_tk81
- alias create_compoundfont create_compoundfont_tk81
+ alias create_kanjifont create_kanjifont_tk8x
+ alias create_compoundfont create_compoundfont_tk8x
alias actual_core actual_core_tk8x
alias configure_core configure_core_tk8x
alias configinfo_core configinfo_core_tk8x
alias delete_core delete_core_tk8x
alias latin_replace_core latin_replace_core_tk8x
- alias kanji_replace_core kanji_replace_core_tk81
+ alias kanji_replace_core kanji_replace_core_tk8x
alias measure_core measure_core_tk8x
alias metrics_core metrics_core_tk8x
diff --git a/ext/tk/lib/tktext.rb b/ext/tk/lib/tktext.rb
index f7b3f84ba7..c8b171c156 100644
--- a/ext/tk/lib/tktext.rb
+++ b/ext/tk/lib/tktext.rb
@@ -334,17 +334,42 @@ class TkText<TkTextWin
tk_split_simplelist(tk_send('tag', 'prevrange', tag, first, last))
end
+ def _ktext_length(txt)
+ if $KCODE !~ /n/i
+ return txt.gsub(/[^\Wa-zA-Z_\d]/, ' ').length
+ end
+
+ # $KCODE == 'NONE'
+ if JAPANIZED_TK
+ tk_call('kstring', 'length', txt).to_i
+ else
+ begin
+ tk_call('encoding', 'convertto', 'ascii', txt).length
+ rescue StandardError, NameError
+ # sorry, I have no plan
+ txt.length
+ end
+ end
+ end
+ private :_ktext_length
+
def search_with_length(pat,start,stop=None)
- pat = pat.char if pat.kind_of? Integer
+ pat = pat.chr if pat.kind_of? Integer
if stop != None
return ["", 0] if compare(start,'>=',stop)
txt = get(start,stop)
if (pos = txt.index(pat))
- pos = txt[0..(pos-1)].split('').length if pos > 0
+ match = $&
+ #pos = txt[0..(pos-1)].split('').length if pos > 0
+ pos = _ktext_length(txt[0..(pos-1)]) if pos > 0
if pat.kind_of? String
- return [index(start + " + #{pos} chars"), pat.split('').length]
+ #return [index(start + " + #{pos} chars"), pat.split('').length]
+ return [index(start + " + #{pos} chars"),
+ _ktext_length(pat), pat.dup]
else
- return [index(start + " + #{pos} chars"), $&.split('').length]
+ #return [index(start + " + #{pos} chars"), $&.split('').length]
+ return [index(start + " + #{pos} chars"),
+ _ktext_length(match), match]
end
else
return ["", 0]
@@ -352,20 +377,31 @@ class TkText<TkTextWin
else
txt = get(start,'end - 1 char')
if (pos = txt.index(pat))
- pos = txt[0..(pos-1)].split('').length if pos > 0
+ match = $&
+ #pos = txt[0..(pos-1)].split('').length if pos > 0
+ pos = _ktext_length(txt[0..(pos-1)]) if pos > 0
if pat.kind_of? String
- return [index(start + " + #{pos} chars"), pat.split('').length]
+ #return [index(start + " + #{pos} chars"), pat.split('').length]
+ return [index(start + " + #{pos} chars"),
+ _ktext_length(pat), pat.dup]
else
- return [index(start + " + #{pos} chars"), $&.split('').length]
+ #return [index(start + " + #{pos} chars"), $&.split('').length]
+ return [index(start + " + #{pos} chars"),
+ _ktext_length(match), match]
end
else
txt = get('1.0','end - 1 char')
if (pos = txt.index(pat))
- pos = txt[0..(pos-1)].split('').length if pos > 0
+ match = $&
+ #pos = txt[0..(pos-1)].split('').length if pos > 0
+ pos = _ktext_length(txt[0..(pos-1)]) if pos > 0
if pat.kind_of? String
- return [index("1.0 + #{pos} chars"), pat.split('').length]
+ #return [index("1.0 + #{pos} chars"), pat.split('').length]
+ return [index("1.0 + #{pos} chars"),
+ _ktext_length(pat), pat.dup]
else
- return [index("1.0 + #{pos} chars"), $&.split('').length]
+ #return [index("1.0 + #{pos} chars"), $&.split('').length]
+ return [index("1.0 + #{pos} chars"), _ktext_length(match), match]
end
else
return ["", 0]
@@ -379,16 +415,20 @@ class TkText<TkTextWin
end
def rsearch_with_length(pat,start,stop=None)
- pat = pat.char if pat.kind_of? Integer
+ pat = pat.chr if pat.kind_of? Integer
if stop != None
return ["", 0] if compare(start,'<=',stop)
txt = get(stop,start)
if (pos = txt.rindex(pat))
- pos = txt[0..(pos-1)].split('').length if pos > 0
+ match = $&
+ #pos = txt[0..(pos-1)].split('').length if pos > 0
+ pos = _ktext_length(txt[0..(pos-1)]) if pos > 0
if pat.kind_of? String
- return [index(stop + " + #{pos} chars"), pat.split('').length]
+ #return [index(stop + " + #{pos} chars"), pat.split('').length]
+ return [index(stop + " + #{pos} chars"), _ktext_length(pat), pat.dup]
else
- return [index(stop + " + #{pos} chars"), $&.split('').length]
+ #return [index(stop + " + #{pos} chars"), $&.split('').length]
+ return [index(stop + " + #{pos} chars"), _ktext_length(match), match]
end
else
return ["", 0]
@@ -396,20 +436,28 @@ class TkText<TkTextWin
else
txt = get('1.0',start)
if (pos = txt.rindex(pat))
- pos = txt[0..(pos-1)].split('').length if pos > 0
+ match = $&
+ #pos = txt[0..(pos-1)].split('').length if pos > 0
+ pos = _ktext_length(txt[0..(pos-1)]) if pos > 0
if pat.kind_of? String
- return [index("1.0 + #{pos} chars"), pat.split('').length]
+ #return [index("1.0 + #{pos} chars"), pat.split('').length]
+ return [index("1.0 + #{pos} chars"), _ktext_length(pat), pat.dup]
else
- return [index("1.0 + #{pos} chars"), $&.split('').length]
+ #return [index("1.0 + #{pos} chars"), $&.split('').length]
+ return [index("1.0 + #{pos} chars"), _ktext_length(match), match]
end
else
txt = get('1.0','end - 1 char')
if (pos = txt.rindex(pat))
- pos = txt[0..(pos-1)].split('').length if pos > 0
+ match = $&
+ #pos = txt[0..(pos-1)].split('').length if pos > 0
+ pos = _ktext_length(txt[0..(pos-1)]) if pos > 0
if pat.kind_of? String
- return [index("1.0 + #{pos} chars"), pat.split('').length]
+ #return [index("1.0 + #{pos} chars"), pat.split('').length]
+ return [index("1.0 + #{pos} chars"), _ktext_length(pat), pat.dup]
else
- return [index("1.0 + #{pos} chars"), $&.split('').length]
+ #return [index("1.0 + #{pos} chars"), $&.split('').length]
+ return [index("1.0 + #{pos} chars"), _ktext_length(match), match]
end
else
return ["", 0]
diff --git a/lib/weakref.rb b/lib/weakref.rb
index 3dff9038eb..c86d532936 100644
--- a/lib/weakref.rb
+++ b/lib/weakref.rb
@@ -20,8 +20,8 @@ class WeakRef<Delegator
ID_REV_MAP = {} # ref -> obj
ObjectSpace.add_finalizer(lambda{|id|
__old_status = Thread.critical
- Thread.critical = true
begin
+ Thread.critical = true
rids = ID_MAP[id]
if rids
for rid in rids
@@ -45,8 +45,8 @@ class WeakRef<Delegator
@__id = orig.__id__
ObjectSpace.call_finalizer orig
ObjectSpace.call_finalizer self
+ __old_status = Thread.critical
begin
- __old_status = Thread.critical
Thread.critical = true
ID_MAP[@__id] = [] unless ID_MAP[@__id]
ensure
diff --git a/regex.c b/regex.c
index 11f73cabdb..c0b8676645 100644
--- a/regex.c
+++ b/regex.c
@@ -3837,7 +3837,7 @@ re_match(bufp, string_arg, size, pos, regs)
because didn't fail. Also remove the register information
put on by the on_failure_jump. */
case finalize_jump:
- if (stackp[-2] == d) {
+ if (stackp > stackb && stackp[-2] == d) {
p = stackp[-3];
POP_FAILURE_POINT();
continue;
@@ -3945,7 +3945,7 @@ re_match(bufp, string_arg, size, pos, regs)
case finalize_push:
POP_FAILURE_POINT();
EXTRACT_NUMBER_AND_INCR(mcnt, p);
- if (mcnt < 0 && stackp[-2] == d) /* avoid infinit loop */
+ if (mcnt < 0 && stackp > stackb && stackp[-2] == d) /* avoid infinit loop */
goto fail;
PUSH_FAILURE_POINT(p + mcnt, d);
stackp[-1] = NON_GREEDY;