unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* make-regexp flag error check
@ 2004-07-23 23:15 Kevin Ryde
  0 siblings, 0 replies; only message in thread
From: Kevin Ryde @ 2004-07-23 23:15 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 369 bytes --]

This would be for 1.6, the new scm_to_int fixes it in the head.

        * regex-posix.c (scm_make_regexp): Use SCM_VALIDATE_INT_COPY on flag
        arguments, previously type was not checked.

In particular this raises an error if you pass regexp/icase etc as a
symbol instead of realizing it's a variable.  I think the docs can be
amended to make that clearer too.


[-- Attachment #2: regex-posix.c.make-args.diff --]
[-- Type: text/plain, Size: 814 bytes --]

--- regex-posix.c.~1.66.~	2004-07-14 10:19:36.000000000 +1000
+++ regex-posix.c	2004-07-23 17:33:52.000000000 +1000
@@ -163,7 +163,7 @@
 {
   SCM flag;
   regex_t *rx;
-  int status, cflags;
+  int status, cflags, argnum;
 
   SCM_VALIDATE_STRING (1, pat);
   SCM_VALIDATE_REST_ARGUMENT (flags);
@@ -172,13 +172,17 @@
      turn off REG_EXTENDED flag (on by default). */
   cflags = REG_EXTENDED;
   flag = flags;
+  argnum = 2;
   while (!SCM_NULLP (flag))
     {
-      if (SCM_INUM (SCM_CAR (flag)) == REG_BASIC)
+      int f;
+      SCM_VALIDATE_INT_COPY (argnum, SCM_CAR (flag), f);
+      if (f == REG_BASIC)
 	cflags &= ~REG_EXTENDED;
       else
-	cflags |= SCM_INUM (SCM_CAR (flag));
+	cflags |= f;
       flag = SCM_CDR (flag);
+      argnum++;
     }
 
   rx = scm_gc_malloc (sizeof(regex_t), "regex");

[-- Attachment #3: regexp.test.make-args.diff --]
[-- Type: text/plain, Size: 1256 bytes --]

--- regexp.test.~1.3.~	2002-08-07 10:52:21.000000000 +1000
+++ regexp.test	2004-07-23 17:50:39.000000000 +1000
@@ -1,7 +1,7 @@
 ;;;; regexp.test --- test Guile's regular expression functions -*- scheme -*-
 ;;;; Jim Blandy <jimb@red-bean.com> --- September 1999
 ;;;;
-;;;; 	Copyright (C) 1999 Free Software Foundation, Inc.
+;;;; 	Copyright (C) 1999, 2004 Free Software Foundation, Inc.
 ;;;; 
 ;;;; This program is free software; you can redistribute it and/or modify
 ;;;; it under the terms of the GNU General Public License as published by
@@ -39,6 +39,29 @@
    (lambda (port)
      (write obj port))))
 
+;;;
+;;; make-regexp
+;;;
+
+(with-test-prefix "make-regexp"
+
+  (pass-if-exception "no args" exception:wrong-num-args
+    (make-regexp))
+
+  (pass-if-exception "bad pat arg" exception:wrong-type-arg
+    (make-regexp 'blah))
+
+  ;; in guile prior to 1.6.5 make-regex didn't validate its flags args
+  (pass-if-exception "bad arg 2" exception:wrong-type-arg
+    (make-regexp "xyz" 'abc))
+
+  (pass-if-exception "bad arg 3" exception:wrong-type-arg
+    (make-regexp "xyz" regexp/icase 'abc)))
+
+;;;
+;;; regexp-substitute
+;;;
+
 (with-test-prefix "regexp-substitute"
   (let ((match
 	 (string-match "patleft(sub1)patmid(sub2)patright"

[-- Attachment #4: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-07-23 23:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-23 23:15 make-regexp flag error check Kevin Ryde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).