summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-10-30 15:33:03 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-10-30 15:33:03 +0000
commitc2a9b62fd2f5c107fcff2e21052e4e9e2294e8ce (patch)
treef6ffbb816a1fb52687c289d2e109fb02c32a5352
parente7bb5176f67ac39add861b6539fe40898f2af6c0 (diff)
* string.c (rb_str_locktmp): lock string temporarily.
* string.c (str_independent): add tmplock check. * io.c (io_write): lock output string temporarily. [ruby-dev:24649] * io.c (io_write): use rb_str_locktmp(). * io.c (read_all): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7149 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog22
-rw-r--r--array.c2
-rw-r--r--enum.c3
-rw-r--r--eval.c2
-rw-r--r--ext/win32ole/win32ole.c4
-rw-r--r--intern.h2
-rw-r--r--io.c10
-rw-r--r--misc/ruby-mode.el21
-rw-r--r--string.c20
9 files changed, 74 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 3e5416db12..f893703358 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+Sun Oct 31 00:22:28 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * string.c (rb_str_locktmp): lock string temporarily.
+
+ * string.c (str_independent): add tmplock check.
+
+ * io.c (io_write): lock output string temporarily.
+ [ruby-dev:24649]
+
+ * io.c (io_write): use rb_str_locktmp().
+
+ * io.c (read_all): ditto.
+
+Sat Oct 30 06:53:24 2004 Peter Vanbroekhoven <peter.vanbroekhoven@cs.kuleuven.ac.be>
+
+ * eval.c (rb_eval): NODE_XSTR should pass copy of literal string.
+
+Sat Oct 30 00:19:40 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * enum.c (enum_sort_by): protect continuation jump in.
+ [ruby-dev:24642]
+
Fri Oct 29 21:27:51 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (rb_io_check_initialized): new function to check uninitialized
diff --git a/array.c b/array.c
index 26f56be664..860cd644eb 100644
--- a/array.c
+++ b/array.c
@@ -50,7 +50,7 @@ rb_ary_modify_check(ary)
{
if (OBJ_FROZEN(ary)) rb_error_frozen("array");
if (FL_TEST(ary, ARY_TMPLOCK))
- rb_raise(rb_eTypeError, "can't modify array during iteration");
+ rb_raise(rb_eRuntimeError, "can't modify array during iteration");
if (!OBJ_TAINTED(ary) && rb_safe_level() >= 4)
rb_raise(rb_eSecurityError, "Insecure: can't modify array");
}
diff --git a/enum.c b/enum.c
index 2f931c7d8b..a745a6e604 100644
--- a/enum.c
+++ b/enum.c
@@ -494,6 +494,9 @@ enum_sort_by(obj)
if (RARRAY(ary)->len > 1) {
qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE), sort_by_cmp, 0);
}
+ if (RBASIC(ary)->klass) {
+ rb_raise(rb_eRuntimeError, "sort_by reentered");
+ }
for (i=0; i<RARRAY(ary)->len; i++) {
RARRAY(ary)->ptr[i] = RNODE(RARRAY(ary)->ptr[i])->u2.value;
}
diff --git a/eval.c b/eval.c
index 9bf2410ddc..be4cb91d65 100644
--- a/eval.c
+++ b/eval.c
@@ -3649,7 +3649,7 @@ rb_eval(self, n)
break;
case NODE_XSTR:
- result = rb_funcall(self, '`', 1, node->nd_lit);
+ result = rb_funcall(self, '`', 1, rb_str_new3(node->nd_lit));
break;
case NODE_LIT:
diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c
index 15daecc224..7a800986b5 100644
--- a/ext/win32ole/win32ole.c
+++ b/ext/win32ole/win32ole.c
@@ -1364,7 +1364,7 @@ ole_create_dcom(argc, argv, self)
if (!gole32)
gole32 = LoadLibrary("OLE32");
if (!gole32)
- rb_raise(rb_eRuntimeError, "Failed to load OLE32.");
+ rb_raise(rb_eRuntimeError, "Failed to load OLE32");
if (!gCoCreateInstanceEx)
gCoCreateInstanceEx = (FNCOCREATEINSTANCEEX*)
GetProcAddress(gole32, "CoCreateInstanceEx");
@@ -1879,7 +1879,7 @@ ole_invoke(argc, argv, self, wFlags)
rb_scan_args(argc, argv, "1*", &cmd, &paramS);
OLEData_Get_Struct(self, pole);
if(!pole->pDispatch) {
- rb_raise(rb_eRuntimeError, "Failed to get dispatch interface.");
+ rb_raise(rb_eRuntimeError, "Failed to get dispatch interface");
}
wcmdname = ole_mb2wc(StringValuePtr(cmd), -1);
hr = pole->pDispatch->lpVtbl->GetIDsOfNames( pole->pDispatch, &IID_NULL,
diff --git a/intern.h b/intern.h
index 61fb5b5ab8..f97afade46 100644
--- a/intern.h
+++ b/intern.h
@@ -403,6 +403,8 @@ VALUE rb_str_buf_cat2 _((VALUE, const char*));
VALUE rb_obj_as_string _((VALUE));
VALUE rb_check_string_type _((VALUE));
VALUE rb_str_dup _((VALUE));
+VALUE rb_str_locktmp _((VALUE));
+VALUE rb_str_unlocktmp _((VALUE));
VALUE rb_str_dup_frozen _((VALUE));
VALUE rb_str_plus _((VALUE, VALUE));
VALUE rb_str_times _((VALUE, VALUE));
diff --git a/io.c b/io.c
index 2de3de7f44..3a8edcc4c8 100644
--- a/io.c
+++ b/io.c
@@ -462,7 +462,9 @@ io_write(io, str)
rb_io_check_writable(fptr);
f = GetWriteFile(fptr);
+ rb_str_locktmp(str);
n = rb_io_fwrite(RSTRING(str)->ptr, RSTRING(str)->len, f);
+ rb_str_unlocktmp(str);
if (n == -1L) rb_sys_fail(fptr->path);
if (fptr->mode & FMODE_SYNC) {
io_fflush(f, fptr);
@@ -1011,10 +1013,10 @@ read_all(fptr, siz, str)
rb_str_resize(str, siz);
}
for (;;) {
- FL_SET(str, FL_FREEZE);
+ rb_str_locktmp(str);
READ_CHECK(fptr->f);
n = rb_io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr->f);
- FL_UNSET(str, FL_FREEZE);
+ rb_str_unlocktmp(str);
if (n == 0 && bytes == 0) {
rb_str_resize(str,0);
if (!fptr->f) break;
@@ -1080,10 +1082,10 @@ io_read(argc, argv, io)
}
if (len == 0) return str;
- FL_SET(str, FL_FREEZE);
+ rb_str_locktmp(str);
READ_CHECK(fptr->f);
n = rb_io_fread(RSTRING(str)->ptr, len, fptr->f);
- FL_UNSET(str, FL_FREEZE);
+ rb_str_unlocktmp(str);
if (n == 0) {
rb_str_resize(str,0);
if (!fptr->f) return Qnil;
diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el
index 462ec609be..041ddc66ff 100644
--- a/misc/ruby-mode.el
+++ b/misc/ruby-mode.el
@@ -521,10 +521,23 @@ The variable ruby-indent-level controls the amount of indentation.
(looking-at "<<\\(-\\)?\\(\\([\"'`]\\)\\([^\n]+?\\)\\3\\|\\sw+\\)"))
(setq re (regexp-quote (or (match-string 4) (match-string 2))))
(if (match-beginning 1) (setq re (concat "\\s *" re)))
- (if (re-search-forward (concat "^" re "$") end 'move)
- (forward-line 1)
- (setq in-string (match-end 0))
- (goto-char end)))
+ (let* ((id-end (goto-char (match-end 0)))
+ (line-end-position (save-excursion (end-of-line) (point)))
+ (state (list in-string nest depth pcol indent)))
+ ;; parse the rest of the line
+ (while (and (> line-end-position (point))
+ (setq state (apply 'ruby-parse-partial
+ line-end-position state))))
+ (setq in-string (car state)
+ nest (nth 1 state)
+ depth (nth 2 state)
+ pcol (nth 3 state)
+ indent (nth 4 state))
+ ;; skip heredoc section
+ (if (re-search-forward (concat "^" re "$") end 'move)
+ (forward-line 1)
+ (setq in-string id-end)
+ (goto-char end))))
(t
(goto-char pnt))))
((looking-at "^__END__$")
diff --git a/string.c b/string.c
index 2e5a955627..8a8a0d4e18 100644
--- a/string.c
+++ b/string.c
@@ -27,6 +27,7 @@
VALUE rb_cString;
+#define STR_TMPLOCK FL_USER1
#define STR_ASSOC FL_USER3
#define STR_NOCAPA (ELTS_SHARED|STR_ASSOC)
@@ -462,6 +463,9 @@ static int
str_independent(str)
VALUE str;
{
+ if (FL_TEST(str, STR_TMPLOCK)) {
+ rb_raise(rb_eRuntimeError, "can't modify string; temporarily locked");
+ }
if (OBJ_FROZEN(str)) rb_error_frozen("string");
if (!OBJ_TAINTED(str) && rb_safe_level() >= 4)
rb_raise(rb_eSecurityError, "Insecure: can't modify string");
@@ -633,6 +637,22 @@ rb_str_dup_frozen(str)
}
VALUE
+rb_str_locktmp(str)
+ VALUE str;
+{
+ FL_SET(str, STR_TMPLOCK);
+ return str;
+}
+
+VALUE
+rb_str_unlocktmp(str)
+ VALUE str;
+{
+ FL_UNSET(str, STR_TMPLOCK);
+ return str;
+}
+
+VALUE
rb_str_resize(str, len)
VALUE str;
long len;