Fix the pthread compiler flag detection.

2006-08-25  Matthias Clasen  <mclasen@redhat.com>

	* configure.in: Fix the pthread compiler flag detection.

	* glib/gunicode.h:
	* glib/gutf8.c (_g_utf8_make_valid): Rename make_valid_utf8
	from gconvert.c, move it to gutf8.c, and export it privately.

	* glib/gconvert.c (g_filename_display_name): Adjust callers.

	* glib/gkeyfile.c: Use _g_utf8_make_valid() in a number of
	places to ensure error messages are valid UTF-8.  (#351853,
	Simon Budig)
This commit is contained in:
Matthias Clasen 2006-08-26 03:44:45 +00:00 committed by Matthias Clasen
parent c2441aea68
commit 8f05c1da81
6 changed files with 111 additions and 50 deletions

View File

@ -1,3 +1,17 @@
2006-08-25 Matthias Clasen <mclasen@redhat.com>
* configure.in: Fix the pthread compiler flag detection.
* glib/gunicode.h:
* glib/gutf8.c (_g_utf8_make_valid): Rename make_valid_utf8
from gconvert.c, move it to gutf8.c, and export it privately.
* glib/gconvert.c (g_filename_display_name): Adjust callers.
* glib/gkeyfile.c: Use _g_utf8_make_valid() in a number of
places to ensure error messages are valid UTF-8. (#351853,
Simon Budig)
2006-08-22 Matthias Clasen <mclasen@redhat.com> 2006-08-22 Matthias Clasen <mclasen@redhat.com>
* Branch for 2.12 * Branch for 2.12

View File

@ -856,6 +856,12 @@ AC_MSG_RESULT(unsigned $glib_size_type)
# Check for some functions # Check for some functions
AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf stpcpy strcasecmp strncasecmp poll getcwd nanosleep vasprintf setenv unsetenv getc_unlocked readlink symlink) AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf stpcpy strcasecmp strncasecmp poll getcwd nanosleep vasprintf setenv unsetenv getc_unlocked readlink symlink)
AC_CHECK_FUNCS(clock_gettime, [], [
AC_CHECK_LIB(rt, clock_gettime, [
AC_DEFINE(HAVE_CLOCK_GETTIME, 1)
LIBS="$LIBS -lrt"
])
])
AC_CHECK_HEADERS(crt_externs.h) AC_CHECK_HEADERS(crt_externs.h)
AC_CHECK_FUNCS(_NSGetEnviron) AC_CHECK_FUNCS(_NSGetEnviron)
@ -1539,6 +1545,7 @@ dnl
dnl Test program for basic POSIX threads functionality dnl Test program for basic POSIX threads functionality
dnl dnl
m4_define([glib_thread_test],[ m4_define([glib_thread_test],[
#include <stdlib.h>
#include <pthread.h> #include <pthread.h>
int check_me = 0; int check_me = 0;
void* func(void* data) {check_me = 42; return &check_me;} void* func(void* data) {check_me = 42; return &check_me;}

View File

@ -31,6 +31,7 @@
#include "glib.h" #include "glib.h"
#include "gprintfint.h" #include "gprintfint.h"
#include "gthreadprivate.h" #include "gthreadprivate.h"
#include "gunicode.h"
#ifdef G_PLATFORM_WIN32 #ifdef G_PLATFORM_WIN32
#define STRICT #define STRICT
@ -1972,44 +1973,6 @@ g_uri_list_extract_uris (const gchar *uri_list)
return result; return result;
} }
static gchar *
make_valid_utf8 (const gchar *name)
{
GString *string;
const gchar *remainder, *invalid;
gint remaining_bytes, valid_bytes;
string = NULL;
remainder = name;
remaining_bytes = strlen (name);
while (remaining_bytes != 0)
{
if (g_utf8_validate (remainder, remaining_bytes, &invalid))
break;
valid_bytes = invalid - remainder;
if (string == NULL)
string = g_string_sized_new (remaining_bytes);
g_string_append_len (string, remainder, valid_bytes);
/* append U+FFFD REPLACEMENT CHARACTER */
g_string_append (string, "\357\277\275");
remaining_bytes -= valid_bytes + 1;
remainder = invalid + 1;
}
if (string == NULL)
return g_strdup (name);
g_string_append (string, remainder);
g_assert (g_utf8_validate (string->str, -1, NULL));
return g_string_free (string, FALSE);
}
/** /**
* g_filename_display_basename: * g_filename_display_basename:
* @filename: an absolute pathname in the GLib file name encoding * @filename: an absolute pathname in the GLib file name encoding
@ -2110,7 +2073,7 @@ g_filename_display_name (const gchar *filename)
* by a question mark * by a question mark
*/ */
if (!display_name) if (!display_name)
display_name = make_valid_utf8 (filename); display_name = _g_utf8_make_valid (filename);
return display_name; return display_name;
} }

View File

@ -690,10 +690,14 @@ g_key_file_parse_line (GKeyFile *key_file,
&parse_error); &parse_error);
else else
{ {
gchar *line_utf8 = _g_utf8_make_valid (line);
g_set_error (error, G_KEY_FILE_ERROR, g_set_error (error, G_KEY_FILE_ERROR,
G_KEY_FILE_ERROR_PARSE, G_KEY_FILE_ERROR_PARSE,
_("Key file contains line '%s' which is not " _("Key file contains line '%s' which is not "
"a key-value pair, group, or comment"), line); "a key-value pair, group, or comment"),
line_utf8);
g_free (line_utf8);
return; return;
} }
@ -801,9 +805,12 @@ g_key_file_parse_key_value_pair (GKeyFile *key_file,
{ {
if (g_ascii_strcasecmp (value, "UTF-8") != 0) if (g_ascii_strcasecmp (value, "UTF-8") != 0)
{ {
gchar *value_utf8 = _g_utf8_make_valid (value);
g_set_error (error, G_KEY_FILE_ERROR, g_set_error (error, G_KEY_FILE_ERROR,
G_KEY_FILE_ERROR_UNKNOWN_ENCODING, G_KEY_FILE_ERROR_UNKNOWN_ENCODING,
_("Key file contains unsupported encoding '%s'"), value); _("Key file contains unsupported "
"encoding '%s'"), value_utf8);
g_free (value_utf8);
g_free (key); g_free (key);
g_free (value); g_free (value);
@ -1280,11 +1287,14 @@ g_key_file_get_string (GKeyFile *key_file,
if (!g_utf8_validate (value, -1, NULL)) if (!g_utf8_validate (value, -1, NULL))
{ {
gchar *value_utf8 = _g_utf8_make_valid (value);
g_set_error (error, G_KEY_FILE_ERROR, g_set_error (error, G_KEY_FILE_ERROR,
G_KEY_FILE_ERROR_UNKNOWN_ENCODING, G_KEY_FILE_ERROR_UNKNOWN_ENCODING,
_("Key file contains key '%s' with value '%s' " _("Key file contains key '%s' with value '%s' "
"which is not UTF-8"), key, value); "which is not UTF-8"), key, value_utf8);
g_free (value_utf8);
g_free (value); g_free (value);
return NULL; return NULL;
} }
@ -1389,11 +1399,14 @@ g_key_file_get_string_list (GKeyFile *key_file,
if (!g_utf8_validate (value, -1, NULL)) if (!g_utf8_validate (value, -1, NULL))
{ {
gchar *value_utf8 = _g_utf8_make_valid (value);
g_set_error (error, G_KEY_FILE_ERROR, g_set_error (error, G_KEY_FILE_ERROR,
G_KEY_FILE_ERROR_UNKNOWN_ENCODING, G_KEY_FILE_ERROR_UNKNOWN_ENCODING,
_("Key file contains key '%s' with value '%s' " _("Key file contains key '%s' with value '%s' "
"which is not UTF-8"), key, value); "which is not UTF-8"), key, value_utf8);
g_free (value_utf8);
g_free (value); g_free (value);
return NULL; return NULL;
} }
@ -1587,7 +1600,7 @@ g_key_file_get_locale_string (GKeyFile *key_file,
candidate_key, NULL); candidate_key, NULL);
g_free (candidate_key); g_free (candidate_key);
if (translated_value && g_utf8_validate (translated_value, -1, NULL)) if (translated_value)
break; break;
g_free (translated_value); g_free (translated_value);
@ -3432,19 +3445,27 @@ g_key_file_parse_value_as_integer (GKeyFile *key_file,
if (*value == '\0' || *end_of_valid_int != '\0') if (*value == '\0' || *end_of_valid_int != '\0')
{ {
gchar *value_utf8 = _g_utf8_make_valid (value);
g_set_error (error, G_KEY_FILE_ERROR, g_set_error (error, G_KEY_FILE_ERROR,
G_KEY_FILE_ERROR_INVALID_VALUE, G_KEY_FILE_ERROR_INVALID_VALUE,
_("Value '%s' cannot be interpreted as a number."), value); _("Value '%s' cannot be interpreted "
"as a number."), value_utf8);
g_free (value_utf8);
return 0; return 0;
} }
int_value = long_value; int_value = long_value;
if (int_value != long_value || errno == ERANGE) if (int_value != long_value || errno == ERANGE)
{ {
gchar *value_utf8 = _g_utf8_make_valid (value);
g_set_error (error, g_set_error (error,
G_KEY_FILE_ERROR, G_KEY_FILE_ERROR,
G_KEY_FILE_ERROR_INVALID_VALUE, G_KEY_FILE_ERROR_INVALID_VALUE,
_("Integer value '%s' out of range"), value); _("Integer value '%s' out of range"),
value_utf8);
g_free (value_utf8);
return 0; return 0;
} }
@ -3470,9 +3491,15 @@ g_key_file_parse_value_as_double (GKeyFile *key_file,
double_value = g_ascii_strtod (value, &end_of_valid_d); double_value = g_ascii_strtod (value, &end_of_valid_d);
if (*end_of_valid_d != '\0' || end_of_valid_d == value) if (*end_of_valid_d != '\0' || end_of_valid_d == value)
g_set_error (error, G_KEY_FILE_ERROR, {
G_KEY_FILE_ERROR_INVALID_VALUE, gchar *value_utf8 = _g_utf8_make_valid (value);
_("Value '%s' cannot be interpreted as a float number."), value); g_set_error (error, G_KEY_FILE_ERROR,
G_KEY_FILE_ERROR_INVALID_VALUE,
_("Value '%s' cannot be interpreted "
"as a float number."),
value_utf8);
g_free (value_utf8);
}
return double_value; return double_value;
} }
@ -3482,6 +3509,8 @@ g_key_file_parse_value_as_boolean (GKeyFile *key_file,
const gchar *value, const gchar *value,
GError **error) GError **error)
{ {
gchar *value_utf8;
if (value) if (value)
{ {
if (strcmp (value, "true") == 0 || strcmp (value, "1") == 0) if (strcmp (value, "true") == 0 || strcmp (value, "1") == 0)
@ -3490,9 +3519,12 @@ g_key_file_parse_value_as_boolean (GKeyFile *key_file,
return FALSE; return FALSE;
} }
value_utf8 = _g_utf8_make_valid (value);
g_set_error (error, G_KEY_FILE_ERROR, g_set_error (error, G_KEY_FILE_ERROR,
G_KEY_FILE_ERROR_INVALID_VALUE, G_KEY_FILE_ERROR_INVALID_VALUE,
_("Value '%s' cannot be interpreted as a boolean."), value); _("Value '%s' cannot be interpreted "
"as a boolean."), value_utf8);
g_free (value_utf8);
return FALSE; return FALSE;
} }

View File

@ -292,6 +292,11 @@ gchar *g_utf8_collate_key_for_filename (const gchar *str,
gboolean g_unichar_get_mirror_char (gunichar ch, gboolean g_unichar_get_mirror_char (gunichar ch,
gunichar *mirrored_ch); gunichar *mirrored_ch);
/* private */
gchar *_g_utf8_make_valid (const gchar *name);
G_END_DECLS G_END_DECLS
#endif /* __G_UNICODE_H__ */ #endif /* __G_UNICODE_H__ */

View File

@ -1799,5 +1799,45 @@ g_utf8_strreverse (const gchar *str,
return result; return result;
} }
gchar *
_g_utf8_make_valid (const gchar *name)
{
GString *string;
const gchar *remainder, *invalid;
gint remaining_bytes, valid_bytes;
string = NULL;
remainder = name;
remaining_bytes = strlen (name);
while (remaining_bytes != 0)
{
if (g_utf8_validate (remainder, remaining_bytes, &invalid))
break;
valid_bytes = invalid - remainder;
if (string == NULL)
string = g_string_sized_new (remaining_bytes);
g_string_append_len (string, remainder, valid_bytes);
/* append U+FFFD REPLACEMENT CHARACTER */
g_string_append (string, "\357\277\275");
remaining_bytes -= valid_bytes + 1;
remainder = invalid + 1;
}
if (string == NULL)
return g_strdup (name);
g_string_append (string, remainder);
g_assert (g_utf8_validate (string->str, -1, NULL));
return g_string_free (string, FALSE);
}
#define __G_UTF8_C__ #define __G_UTF8_C__
#include "galiasdef.c" #include "galiasdef.c"