2006-02-01 Ludovic Courtès <ludovic.courtes@laas.fr>
[bpt/guile.git] / libguile / regex-posix.c
index 1ffbb35..31f8c1d 100644 (file)
@@ -12,7 +12,7 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 
@@ -52,6 +52,7 @@
 #endif
 #endif
 
+#include "libguile/async.h"
 #include "libguile/smob.h"
 #include "libguile/symbols.h"
 #include "libguile/vectors.h"
@@ -186,7 +187,8 @@ SCM_DEFINE (scm_make_regexp, "make-regexp", 1, 0, 1,
                     scm_from_locale_string (FUNC_NAME),
                     errmsg,
                     SCM_BOOL_F,
-                    SCM_BOOL_F);
+                    scm_list_1 (pat));
+      
       /* never returns */
     }
   SCM_RETURN_NEWSMOB (scm_tc16_regex, rx);
@@ -220,15 +222,19 @@ SCM_DEFINE (scm_regexp_exec, "regexp-exec", 2, 2, 0,
   regmatch_t *matches;
   char *c_str;
   SCM mvec = SCM_BOOL_F;
+  SCM substr;
 
   SCM_VALIDATE_RGXP (1, rx);
   SCM_VALIDATE_STRING (2, str);
 
   if (SCM_UNBNDP (start))
-    offset = 0;
+    {
+      substr = str;
+      offset = 0;
+    }
   else
     {
-      str = scm_substring (str, start, SCM_UNDEFINED);
+      substr = scm_substring (str, start, SCM_UNDEFINED);
       offset = scm_to_int (start);
     }
 
@@ -239,9 +245,9 @@ SCM_DEFINE (scm_regexp_exec, "regexp-exec", 2, 2, 0,
      whole regexp, so add 1 to nmatches. */
 
   nmatches = SCM_RGX(rx)->re_nsub + 1;
-  SCM_DEFER_INTS;
+  SCM_CRITICAL_SECTION_START;
   matches = scm_malloc (sizeof (regmatch_t) * nmatches);
-  c_str = scm_to_locale_string (str);
+  c_str = scm_to_locale_string (substr);
   status = regexec (SCM_RGX (rx), c_str, nmatches, matches,
                    scm_to_int (flags));
   free (c_str);
@@ -252,25 +258,24 @@ SCM_DEFINE (scm_regexp_exec, "regexp-exec", 2, 2, 0,
       /* The match vector must include a cell for the string that was matched,
         so add 1. */
       mvec = scm_c_make_vector (nmatches + 1, SCM_UNSPECIFIED);
-      SCM_VECTOR_SET(mvec,0, str);
+      SCM_SIMPLE_VECTOR_SET(mvec,0, str);
       for (i = 0; i < nmatches; ++i)
        if (matches[i].rm_so == -1)
-         SCM_VECTOR_SET(mvec, i+1,
+         SCM_SIMPLE_VECTOR_SET(mvec, i+1,
                         scm_cons (scm_from_int (-1), scm_from_int (-1)));
        else
-         SCM_VECTOR_SET(mvec, i+1,
+         SCM_SIMPLE_VECTOR_SET(mvec, i+1,
                         scm_cons (scm_from_long (matches[i].rm_so + offset),
                                   scm_from_long (matches[i].rm_eo + offset)));
     }
   free (matches);
-  SCM_ALLOW_INTS;
+  SCM_CRITICAL_SECTION_END;
 
   if (status != 0 && status != REG_NOMATCH)
     scm_error_scm (scm_regexp_error_key,
                   scm_from_locale_string (FUNC_NAME),
                   scm_regexp_error_msg (status, SCM_RGX (rx)),
-                  SCM_BOOL_F,
-                  SCM_BOOL_F);
+                  SCM_BOOL_F, SCM_BOOL_F);
   return mvec;
 }
 #undef FUNC_NAME