* io.c (rb_io_reopen): should clear allocated OpenFile. pointed

out by Guy Decoux. [ruby-core:03288]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2004-08-17 08:31:02 +00:00
parent 5a72ce5cfa
commit ecf157699d
6 changed files with 159 additions and 186 deletions

View file

@ -1,3 +1,8 @@
Tue Aug 17 17:20:59 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_io_reopen): should clear allocated OpenFile. pointed
out by Guy Decoux. [ruby-core:03288]
Tue Aug 17 01:36:32 2004 Dave Thomas <dave@pragprog.com> Tue Aug 17 01:36:32 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/usage.rb: Remove extra indent. Tidy 'ri' option * lib/rdoc/usage.rb: Remove extra indent. Tidy 'ri' option

View file

@ -353,10 +353,7 @@ exc_initialize(argc, argv, exc)
{ {
VALUE arg; VALUE arg;
if (rb_scan_args(argc, argv, "01", &arg) == 1) { rb_scan_args(argc, argv, "01", &arg);
VALUE mesg = arg;
StringValue(mesg); /* ensure mesg can be converted to String */
}
rb_iv_set(exc, "mesg", arg); rb_iv_set(exc, "mesg", arg);
rb_iv_set(exc, "bt", Qnil); rb_iv_set(exc, "bt", Qnil);

1
eval.c
View file

@ -4594,7 +4594,6 @@ break_jump(retval)
VALUE retval; VALUE retval;
{ {
struct tag *tt = prot_tag; struct tag *tt = prot_tag;
int yield = Qfalse;
if (retval == Qundef) retval = Qnil; if (retval == Qundef) retval = Qnil;
while (tt) { while (tt) {

2
io.c
View file

@ -3155,6 +3155,7 @@ rb_io_reopen(argc, argv, file)
fptr = RFILE(file)->fptr; fptr = RFILE(file)->fptr;
if (!fptr) { if (!fptr) {
fptr = RFILE(file)->fptr = ALLOC(OpenFile); fptr = RFILE(file)->fptr = ALLOC(OpenFile);
MEMZERO(fptr, OpenFile, 1);
} }
if (!NIL_P(nmode)) { if (!NIL_P(nmode)) {
@ -3178,7 +3179,6 @@ rb_io_reopen(argc, argv, file)
fclose(fptr->f2); fclose(fptr->f2);
fptr->f2 = 0; fptr->f2 = 0;
} }
return file; return file;
} }

View file

@ -222,7 +222,7 @@ Also ignores spaces after parenthesis when 'space."
(make-variable-buffer-local 'comment-column) (make-variable-buffer-local 'comment-column)
(setq comment-column ruby-comment-column) (setq comment-column ruby-comment-column)
(make-variable-buffer-local 'comment-start-skip) (make-variable-buffer-local 'comment-start-skip)
(setq comment-start-skip "\\(^\\|\\s-\\);?#+ *") (setq comment-start-skip "#+ *")
(setq indent-tabs-mode ruby-indent-tabs-mode) (setq indent-tabs-mode ruby-indent-tabs-mode)
(make-local-variable 'parse-sexp-ignore-comments) (make-local-variable 'parse-sexp-ignore-comments)
(setq parse-sexp-ignore-comments t) (setq parse-sexp-ignore-comments t)
@ -561,181 +561,156 @@ The variable ruby-indent-level controls the amount of indentation.
(defun ruby-indent-size (pos nest) (defun ruby-indent-size (pos nest)
(+ pos (* (or nest 1) ruby-indent-level))) (+ pos (* (or nest 1) ruby-indent-level)))
(defconst ruby-assign-re "\\s *\\(&&\\|||\\|<<\\|>>\\|[-+*/%&|^]\\)?=\\s *")
(defun ruby-beginning-of-arg (start end)
(save-restriction
(narrow-to-region start (1+ end))
(goto-char start)
(let ((beg t) arg)
(while
(progn
(skip-chars-forward " \t\n")
(and (not (eobp))
(= (ruby-forward-sexp) 0)))
(skip-syntax-forward " ")
(cond ((looking-at ",")
(forward-char)
(setq arg start beg t))
((ruby-expr-beg) t)
((looking-at "=>\\s *")
(goto-char (match-end 0))
(setq arg nil beg nil))
((looking-at ruby-assign-re)
(goto-char (match-end 0))
(if beg (setq beg nil arg (point))))
((looking-at ruby-operator-re)
(goto-char (match-end 0))
(if beg (setq beg nil arg (match-end 0))))
((not (eq (char-syntax (char-after)) ?\())
(setq start (point)))))
(goto-char (or arg start)))))
(defun ruby-calculate-indent (&optional parse-start) (defun ruby-calculate-indent (&optional parse-start)
(save-excursion (save-excursion
(beginning-of-line) (beginning-of-line)
(let ((indent-point (point)) (let ((indent-point (point))
(case-fold-search nil) (case-fold-search nil)
state bol eol begin state bol eol begin op-end
(paren (progn (skip-syntax-forward " ") (paren (progn (skip-syntax-forward " ")
(and (char-after) (matching-paren (char-after))))) (and (char-after) (matching-paren (char-after)))))
(indent 0)) (indent 0))
(if parse-start (if parse-start
(goto-char parse-start) (goto-char parse-start)
(ruby-beginning-of-indent) (ruby-beginning-of-indent)
(setq parse-start (point))) (setq parse-start (point)))
(back-to-indentation) (back-to-indentation)
(setq indent (current-column)) (setq indent (current-column))
(setq state (ruby-parse-region parse-start indent-point)) (setq state (ruby-parse-region parse-start indent-point))
(cond (cond
((nth 0 state) ; within string ((nth 0 state) ; within string
(setq indent nil)) ; do nothing (setq indent nil)) ; do nothing
((car (nth 1 state)) ; in paren ((car (nth 1 state)) ; in paren
(goto-char (setq begin (cdr (nth 1 state)))) (goto-char (setq begin (cdr (nth 1 state))))
(let ((deep (ruby-deep-indent-paren-p (car (nth 1 state))))) (let ((deep (ruby-deep-indent-paren-p (car (nth 1 state)))))
(if deep (if deep
(cond ((and (eq deep t) (eq (car (nth 1 state)) paren)) (cond ((and (eq deep t) (eq (car (nth 1 state)) paren))
(skip-syntax-backward " ") (skip-syntax-backward " ")
(setq indent (1- (current-column)))) (setq indent (1- (current-column))))
((let ((s (ruby-parse-region (point) indent-point))) ((let ((s (ruby-parse-region (point) indent-point)))
(and (nth 2 s) (> (nth 2 s) 0) (and (nth 2 s) (> (nth 2 s) 0)
(or (goto-char (cdr (nth 1 s))) t))) (or (goto-char (cdr (nth 1 s))) t)))
(forward-word -1) (forward-word -1)
(setq indent (ruby-indent-size (current-column) (nth 2 state)))) (setq indent (ruby-indent-size (current-column) (nth 2 state))))
(t (t
(setq indent (current-column)) (setq indent (current-column))
(cond ((eq deep 'space)) (cond ((eq deep 'space))
(paren (setq indent (1- indent))) (paren (setq indent (1- indent)))
(t (setq indent (ruby-indent-size (1- indent) 1)))))) (t (setq indent (ruby-indent-size (1- indent) 1))))))
(if (nth 3 state) (goto-char (nth 3 state))
(goto-char parse-start) (back-to-indentation))
(setq indent (ruby-indent-size (current-column) (nth 2 state))))))
((and (nth 2 state) (> (nth 2 state) 0)) ; in nest
(if (null (cdr (nth 1 state)))
(error "invalid nest"))
(goto-char (cdr (nth 1 state)))
(forward-word -1) ; skip back a keyword
(setq begin (point))
(cond
((looking-at "do\\>[^_]") ; iter block is a special case
(if (nth 3 state) (goto-char (nth 3 state)) (if (nth 3 state) (goto-char (nth 3 state))
(goto-char parse-start) (back-to-indentation)) (goto-char parse-start) (back-to-indentation))
(setq indent (ruby-indent-size (current-column) (nth 2 state)))) (setq indent (ruby-indent-size (current-column) (nth 2 state))))))
(t ((and (nth 2 state) (> (nth 2 state) 0)) ; in nest
(setq indent (+ (current-column) ruby-indent-level))))) (if (null (cdr (nth 1 state)))
(error "invalid nest"))
((and (nth 2 state) (< (nth 2 state) 0)) ; in negative nest (goto-char (cdr (nth 1 state)))
(setq indent (ruby-indent-size (current-column) (nth 2 state))))) (forward-word -1) ; skip back a keyword
(when indent (setq begin (point))
(goto-char indent-point) (cond
(end-of-line) ((looking-at "do\\>[^_]") ; iter block is a special case
(setq eol (point)) (if (nth 3 state) (goto-char (nth 3 state))
(beginning-of-line) (goto-char parse-start) (back-to-indentation))
(cond (setq indent (ruby-indent-size (current-column) (nth 2 state))))
((and (not (ruby-deep-indent-paren-p paren)) (t
(re-search-forward ruby-negative eol t)) (setq indent (+ (current-column) ruby-indent-level)))))
(and (not (eq ?_ (char-after (match-end 0))))
(setq indent (- indent ruby-indent-level)))) ((and (nth 2 state) (< (nth 2 state) 0)) ; in negative nest
;;operator terminated lines (setq indent (ruby-indent-size (current-column) (nth 2 state)))))
((and (when indent
(save-excursion (goto-char indent-point)
(beginning-of-line) (end-of-line)
(not (bobp))) (setq eol (point))
(or (ruby-deep-indent-paren-p t) (beginning-of-line)
(null (car (nth 1 state))))) (cond
;; goto beginning of non-empty no-comment line ((and (not (ruby-deep-indent-paren-p paren))
(let (end done) (re-search-forward ruby-negative eol t))
(while (not done) (and (not (eq ?_ (char-after (match-end 0))))
(skip-chars-backward " \t\n") (setq indent (- indent ruby-indent-level))))
(setq end (point)) ((and
(beginning-of-line) (save-excursion
(if (re-search-forward "^\\s *#" end t) (beginning-of-line)
(beginning-of-line) (not (bobp)))
(setq done t)))) (or (ruby-deep-indent-paren-p t)
(setq bol (point)) (null (car (nth 1 state)))))
(end-of-line) ;; goto beginning of non-empty no-comment line
(skip-chars-backward " \t") (let (end done)
(let (end (pos (point))) (while (not done)
(skip-chars-backward " \t\n")
(setq end (point))
(beginning-of-line) (beginning-of-line)
(while (and (re-search-forward "#" pos t) (if (re-search-forward "^\\s *#" end t)
(setq end (1- (point))) (beginning-of-line)
(ruby-special-char-p end)) (setq done t))))
(setq end nil)) (setq bol (point))
(goto-char (or end pos)) (end-of-line)
(skip-chars-backward " \t") ;; skip the comment at the end
(and (skip-chars-backward " \t")
(setq state (ruby-parse-region parse-start (point))) (let (end (pos (point)))
(nth 0 state) (beginning-of-line)
(setq begin (cdr (nth 1 state))) (while (and (re-search-forward "#" pos t)
(goto-char pos))) (setq end (1- (point)))
(or (bobp) (forward-char -1)) (or (ruby-special-char-p end)
(and (and (setq state (ruby-parse-region parse-start end))
(or (and (looking-at ruby-symbol-re) (nth 0 state))))
(skip-chars-backward ruby-symbol-chars) (setq end nil))
(looking-at (concat "\\<\\(" ruby-block-hanging-re "\\)\\>")) (goto-char (or end pos))
(not (eq (point) (nth 3 state))) (skip-chars-backward " \t")
(save-excursion (setq begin (if (nth 0 state) pos (cdr (nth 1 state))))
(goto-char (match-end 0)) (setq state (ruby-parse-region parse-start (point))))
(not (looking-at "[a-z_]")))) (or (bobp) (forward-char -1))
(and (looking-at ruby-operator-re) (and
(not (ruby-special-char-p)) (or (and (looking-at ruby-symbol-re)
(let ((c (char-after (point)))) (skip-chars-backward ruby-symbol-chars)
(and (looking-at (concat "\\<\\(" ruby-block-hanging-re "\\)\\>"))
(or (not (eq ?, c)) (not (eq (point) (nth 3 state)))
(null begin) (save-excursion
(save-excursion (goto-char (match-end 0))
(goto-char begin) (not (looking-at "[a-z_]"))))
(skip-chars-forward " \t") (and (looking-at ruby-operator-re)
(not (or (eolp) (looking-at "#") (not (ruby-special-char-p))
(and (eq (car (nth 1 state)) ?{) ;; operator at the end of line
(looking-at "|")))))) (let ((c (char-after (point))))
(or (not (eq ?/ c)) (and
(null (nth 0 (ruby-parse-region (or begin parse-start) (point))))) ;; (or (null begin)
(or (not (eq ?| (char-after (point)))) ;; (save-excursion
(save-excursion ;; (goto-char begin)
(or (eolp) (forward-char -1)) ;; (skip-chars-forward " \t")
(cond ;; (not (or (eolp) (looking-at "#")
((search-backward "|" nil t) ;; (and (eq (car (nth 1 state)) ?{)
(skip-chars-backward " \t\n") ;; (looking-at "|"))))))
(and (not (eolp)) (or (not (eq ?/ c))
(progn (null (nth 0 (ruby-parse-region (or begin parse-start) (point)))))
(forward-char -1) (or (not (eq ?| (char-after (point))))
(not (looking-at "{"))) (save-excursion
(progn (or (eolp) (forward-char -1))
(forward-word -1) (cond
(not (looking-at "do\\>[^_]"))))) ((search-backward "|" nil t)
(t t)))))))) (skip-chars-backward " \t\n")
(setq indent (and (not (eolp))
(cond (progn
((and (forward-char -1)
(not (looking-at (concat "\\<\\(" ruby-block-hanging-re "\\)\\>"))) (not (looking-at "{")))
(eq (ruby-deep-indent-paren-p t) 'space) (progn
(not (bobp))) (forward-word -1)
(ruby-beginning-of-arg (or begin parse-start) (point)) (not (looking-at "do\\>[^_]")))))
(current-column)) (t t))))
(t (not (eq ?, c))
(+ indent ruby-indent-level)))))))) (setq op-end t)))))
indent))) (setq indent
(cond
((and
(null op-end)
(not (looking-at (concat "\\<\\(" ruby-block-hanging-re "\\)\\>")))
(eq (ruby-deep-indent-paren-p t) 'space)
(not (bobp)))
(save-excursion
(widen)
(goto-char (or begin parse-start))
(skip-syntax-forward " ")
(current-column)))
(t
(+ indent ruby-indent-level))))))))
indent)))
(defun ruby-electric-brace (arg) (defun ruby-electric-brace (arg)
(interactive "P") (interactive "P")
@ -802,9 +777,9 @@ An end of a defun is found by moving forward from the beginning of one."
((> start pos) ((> start pos)
(setq done t))))) (setq done t)))))
(if done (if done
(progn (save-excursion
(back-to-indentation) (back-to-indentation)
(if (looking-at (concat ("\\<\\(" ruby-block-mid-re "\\)\\>"))) (if (looking-at (concat "\\<\\(" ruby-block-mid-re "\\)\\>"))
(setq done nil)))))) (setq done nil))))))
(back-to-indentation)) (back-to-indentation))
@ -832,7 +807,9 @@ An end of a defun is found by moving forward from the beginning of one."
(skip-chars-forward ",.:;|&^~=!?\\+\\-\\*") (skip-chars-forward ",.:;|&^~=!?\\+\\-\\*")
(looking-at "\\s(")) (looking-at "\\s("))
(goto-char (scan-sexps (point) 1))) (goto-char (scan-sexps (point) 1)))
((looking-at (concat "\\<\\(" ruby-block-beg-re "\\)\\>")) ((and (looking-at (concat "\\<\\(" ruby-block-beg-re "\\)\\>"))
(not (eq (char-before (point)) ?.))
(not (eq (char-before (point)) ?:)))
(ruby-end-of-block) (ruby-end-of-block)
(forward-word 1)) (forward-word 1))
((looking-at "\\(\\$\\|@@?\\)?\\sw") ((looking-at "\\(\\$\\|@@?\\)?\\sw")
@ -1013,10 +990,6 @@ balanced expression is found."
("\\(^\\|[=(,~?:;]\\|\\(^\\|\\s \\)\\(if\\|elsif\\|unless\\|while\\|until\\|when\\|and\\|or\\|&&\\|||\\)\\|g?sub!?\\|scan\\|split!?\\)\\s *\\(/\\)[^/\n\\\\]*\\(\\\\.[^/\n\\\\]*\\)*\\(/\\)" ("\\(^\\|[=(,~?:;]\\|\\(^\\|\\s \\)\\(if\\|elsif\\|unless\\|while\\|until\\|when\\|and\\|or\\|&&\\|||\\)\\|g?sub!?\\|scan\\|split!?\\)\\s *\\(/\\)[^/\n\\\\]*\\(\\\\.[^/\n\\\\]*\\)*\\(/\\)"
(4 (7 . ?/)) (4 (7 . ?/))
(6 (7 . ?/))) (6 (7 . ?/)))
;; %Q!...!
("\\(^\\|[[ \t\n<+(,=]\\)%[xrqQwW]?\\([^<[{(a-zA-Z0-9 \n]\\)[^\n\\\\]*\\(\\\\.[^\n\\\\]*\\)*\\(\\2\\)"
(2 (7 . nil))
(4 (7 . nil)))
("^\\(=\\)begin\\(\\s \\|$\\)" 1 (7 . nil)) ("^\\(=\\)begin\\(\\s \\|$\\)" 1 (7 . nil))
("^\\(=\\)end\\(\\s \\|$\\)" 1 (7 . nil)))) ("^\\(=\\)end\\(\\s \\|$\\)" 1 (7 . nil))))
@ -1098,7 +1071,6 @@ balanced expression is found."
t) t)
nil))) nil)))
(defvar ruby-font-lock-keywords (defvar ruby-font-lock-keywords
(list (list
;; functions ;; functions
@ -1168,6 +1140,9 @@ balanced expression is found."
0 font-lock-string-face t) 0 font-lock-string-face t)
`(,ruby-here-doc-beg-re `(,ruby-here-doc-beg-re
0 font-lock-string-face t) 0 font-lock-string-face t)
;; general delimited string
'("\\(^\\|[[ \t\n<+(,=]\\)\\(%[xrqQwW]?\\([^<[{(a-zA-Z0-9 \n]\\)[^\n\\\\]*\\(\\\\.[^\n\\\\]*\\)*\\(\\3\\)\\)"
(2 font-lock-string-face))
;; constants ;; constants
'("\\(^\\|[^_]\\)\\b\\([A-Z]+\\(\\w\\|_\\)*\\)" '("\\(^\\|[^_]\\)\\b\\([A-Z]+\\(\\w\\|_\\)*\\)"
2 font-lock-type-face) 2 font-lock-type-face)

View file

@ -1242,9 +1242,6 @@ static VALUE
rb_str_match(x, y) rb_str_match(x, y)
VALUE x, y; VALUE x, y;
{ {
VALUE reg;
long start;
switch (TYPE(y)) { switch (TYPE(y)) {
case T_STRING: case T_STRING:
rb_raise(rb_eTypeError, "type mismatch: String given"); rb_raise(rb_eTypeError, "type mismatch: String given");