--- vala-0.7.10.262-39688/codegen/valaccodebasemodule.vala	2010-03-25 11:33:29.000000000 +0200
+++ vala-0.7.10.262-39688-613943fix/codegen/valaccodebasemodule.vala	2010-03-26 15:04:40.000000000 +0200
@@ -3575,13 +3575,43 @@
 		var cdecl = new CCodeDeclaration ("GRegex*");
 
 		var cname = regex_var.name + "regex_" + next_regex_id.to_string ();
+		if (this.next_regex_id == 0) {
+			var fun = new CCodeFunction ("_thread_safe_regex_init", "GRegex*");
+			fun.modifiers = CCodeModifiers.STATIC | CCodeModifiers.INLINE;
+			fun.add_parameter (new CCodeFormalParameter ("re", "GRegex**"));
+			fun.add_parameter (new CCodeFormalParameter ("pattern", "const gchar *"));
+			fun.add_parameter (new CCodeFormalParameter ("match_options", "GRegexMatchFlags"));
+			fun.block = new CCodeBlock ();
+
+			var once_enter_call = new CCodeFunctionCall (new CCodeIdentifier ("g_once_init_enter"));
+			once_enter_call.add_argument (new CCodeConstant ("(volatile gsize*) re"));
+
+			var if_block = new CCodeBlock ();
+
+			var regex_new_call = new CCodeFunctionCall (new CCodeIdentifier ("g_regex_new"));
+			regex_new_call.add_argument (new CCodeConstant ("pattern"));
+			regex_new_call.add_argument (new CCodeConstant ("match_options"));
+			regex_new_call.add_argument (new CCodeConstant ("0"));
+			regex_new_call.add_argument (new CCodeConstant ("NULL"));
+			if_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("GRegex* val"), regex_new_call)));
+
+			var once_leave_call = new CCodeFunctionCall (new CCodeIdentifier ("g_once_init_leave"));
+			once_leave_call.add_argument (new CCodeConstant ("(volatile gsize*) re"));
+			once_leave_call.add_argument (new CCodeConstant ("(gsize) val"));
+			if_block.add_statement (new CCodeExpressionStatement (once_leave_call));
+
+			var if_stat = new CCodeIfStatement (once_enter_call, if_block);
+			fun.block.add_statement (if_stat);
+			fun.block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("*re")));
+ 
+			source_type_member_definition.append (fun);
+		}
 		this.next_regex_id++;
 
 		cdecl.add_declarator (new CCodeVariableDeclarator (cname + " = NULL"));
 		cdecl.modifiers = CCodeModifiers.STATIC;
 
-		var regex_const = new CCodeConstant ("(%s == NULL) ? (%s = g_regex_new (\"".printf (cname, cname)
-			+ re + "\", " + flags + ", 0, NULL)) : %s".printf (cname));
+		var regex_const = new CCodeConstant ("_thread_safe_regex_init (&%s, \"".printf (cname) + re + "\", " + flags + ")");
 
 		source_declarations.add_constant_declaration (cdecl);
 		expr.ccodenode = regex_const;
--- vala-0.7.10.262-39688/tests/objects/regex.vala	2010-03-25 11:33:29.000000000 +0200
+++ vala-0.7.10.262-39688-613943fix/tests/objects/regex.vala	2010-03-26 11:59:21.000000000 +0200
@@ -34,7 +34,7 @@
 	// Simple greedy regular expression matching, regex received as a function return value.
 	var str1 = "mississippi";
 	if (get_fixed ().match (str1, 0, out info)) {
-		stdout.printf ("Part of %s is '%s'...\n", str1, info.fetch (1));
+		stdout.printf ("Part of %s is '%s'...\n", str1, (string) info.fetch (1));
 	} else {
 		stdout.printf ("Did not match at all.\n");
 	}
@@ -42,7 +42,7 @@
 	// Match caseless.
 	var str2 = "demonStration";
 	if (/mon(str.*o)n/i.match (str2, 0, out info)) {
-		stdout.printf ("Part of %s is '%s'...\n", str2, info.fetch (1));
+		stdout.printf ("Part of %s is '%s'...\n", str2, (string) info.fetch (1));
 	} else {
 		stdout.printf ("%s did not match at all.\n", str2);
 	}
@@ -50,7 +50,7 @@
 	// Match and pick substrings.
 	var ts   = "Time: 10:42:12";
 	if (/Time: (..):(..):(..)/.match (ts, 0, out info)) {
-		stdout.printf ("%s\n\thours = %s\n\tminutes = %s\n\tseconds = %s\n\n", ts, info.fetch (1), info.fetch (2), info.fetch (3));
+		stdout.printf ("%s\n\thours = %s\n\tminutes = %s\n\tseconds = %s\n\n", ts, (string) info.fetch (1), (string) info.fetch (2), (string) info.fetch (3));
 	}
 
 	// Replace demo: word swapping
@@ -65,7 +65,7 @@
 	// Regex literals in an array
 	for (int i=0; i<4; i++) {
 		if (get_from_array (i).match ("23.3.2010", 0, out info)) {
-			stdout.printf ("Round %d: %s\n", i, info.fetch (1));
+			stdout.printf ("Round %d: %s\n", i, (string) info.fetch (1));
 		}
 	}
 
@@ -76,7 +76,7 @@
 
 	r = r1 ?? r2 ?? /match (this)/i;
 	if (r.match ("match THIS", 0, out info)) {
-		stdout.printf ("Match: %s\n", info.fetch (1));
+		stdout.printf ("Match: %s\n", (string) info.fetch (1));
 	}
 
 	// Escape sequences
@@ -91,12 +91,12 @@
 	var test = new Test ();
 	test.regexTest.connect ((s) => {
 		if (rc.match (s, 0, out info)) {
-			stdout.printf ("Lambda (closure var.): %s -> %s\n", s, info.fetch (1));
+			stdout.printf ("Lambda (closure var.): %s -> %s\n", s, (string) info.fetch (1));
 		} else {
 			stdout.printf ("Does not match.\n");
 		}
 		if (/foo(bar)/i.match (s, 0, out info)) {
-			stdout.printf ("Lambda (lit.): %s -> %s\n", s, info.fetch (1));
+			stdout.printf ("Lambda (lit.): %s -> %s\n", s, (string) info.fetch (1));
 		} else {
 			stdout.printf ("Does not match.\n");
 		}
