85327d2
--- perl-5.8.8.orig/regcomp.c	2006-01-08 20:59:27.000000000 +0000
85327d2
+++ perl-5.8.8/regcomp.c	2007-10-19 22:49:41.000000000 +0100
85327d2
@@ -136,6 +136,7 @@
85327d2
     I32		seen_zerolen;
85327d2
     I32		seen_evals;
85327d2
     I32		utf8;
85327d2
+    I32		orig_utf8;
85327d2
 #if ADD_TO_REGEXEC
85327d2
     char 	*starttry;		/* -Dr: where regtry was called. */
85327d2
 #define RExC_starttry	(pRExC_state->starttry)
85327d2
@@ -161,6 +162,7 @@
85327d2
 #define RExC_seen_zerolen	(pRExC_state->seen_zerolen)
85327d2
 #define RExC_seen_evals	(pRExC_state->seen_evals)
85327d2
 #define RExC_utf8	(pRExC_state->utf8)
85327d2
+#define RExC_orig_utf8 (pRExC_state->orig_utf8)
85327d2
 
85327d2
 #define	ISMULT1(c)	((c) == '*' || (c) == '+' || (c) == '?')
85327d2
 #define	ISMULT2(s)	((*s) == '*' || (*s) == '+' || (*s) == '?' || \
85327d2
@@ -1749,15 +1751,17 @@
85327d2
     if (exp == NULL)
85327d2
 	FAIL("NULL regexp argument");
85327d2
 
85327d2
-    RExC_utf8 = pm->op_pmdynflags & PMdf_CMP_UTF8;
85327d2
+    RExC_orig_utf8 = RExC_utf8 = pm->op_pmdynflags & PMdf_CMP_UTF8;
85327d2
 
85327d2
-    RExC_precomp = exp;
85327d2
     DEBUG_r({
85327d2
 	 if (!PL_colorset) reginitcolors();
85327d2
 	 PerlIO_printf(Perl_debug_log, "%sCompiling REx%s `%s%*s%s'\n",
85327d2
 		       PL_colors[4],PL_colors[5],PL_colors[0],
85327d2
-		       (int)(xend - exp), RExC_precomp, PL_colors[1]);
85327d2
+		       (int)(xend - exp), exp, PL_colors[1]);
85327d2
     });
85327d2
+
85327d2
+redo_first_pass:
85327d2
+    RExC_precomp = exp;
85327d2
     RExC_flags = pm->op_pmflags;
85327d2
     RExC_sawback = 0;
85327d2
 
85327d2
@@ -1783,6 +1787,17 @@
85327d2
 	RExC_precomp = Nullch;
85327d2
 	return(NULL);
85327d2
     }
85327d2
+    if (RExC_utf8 && !RExC_orig_utf8) {
85327d2
+    	STRLEN len = xend-exp;
85327d2
+    	DEBUG_r(PerlIO_printf(Perl_debug_log,
85327d2
+	   "UTF8 mismatch! Converting to utf8 for resizing and compile\n"));
85327d2
+	exp = (char*)Perl_bytes_to_utf8(aTHX_ (U8*)exp, &len;;
85327d2
+	xend = exp + len;
85327d2
+	RExC_orig_utf8 = RExC_utf8;
85327d2
+	SAVEFREEPV(exp);
85327d2
+	goto redo_first_pass;
85327d2
+    }
85327d2
+
85327d2
     DEBUG_r(PerlIO_printf(Perl_debug_log, "size %"IVdf" ", (IV)RExC_size));
85327d2
 
85327d2
     /* Small enough for pointer-storage convention?