diff options
| author | Eli Zaretskii | 2014-08-30 11:19:24 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2014-08-30 11:19:24 +0300 |
| commit | e7027eab55d9b3b63ddc1c26f3e222692c8c9499 (patch) | |
| tree | 62f5b2569c009499c0c5ff5c896a0df9b4b49f30 /src | |
| parent | e1a9bbbd4f719a2256bd180ae9e9fffb64db63e4 (diff) | |
| download | emacs-e7027eab55d9b3b63ddc1c26f3e222692c8c9499.tar.gz emacs-e7027eab55d9b3b63ddc1c26f3e222692c8c9499.zip | |
Improve error checking and error messages in string-collation functions.
src/sysdep.c (str_collate) [__STDC_ISO_10646__]: Improve the
wording of the error messages.
(str_collate) [WINDOWSNT]: Signal an error if w32_compare_strings
sets errno.
src/w32proc.c (get_lcid_callback): Accept locale specifications
without the country part, as in "enu" vs "enu_USA".
(w32_compare_strings): Signal an error if a locale was specified,
but couldn't be translated into a valid LCID.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 12 | ||||
| -rw-r--r-- | src/sysdep.c | 18 | ||||
| -rw-r--r-- | src/w32proc.c | 8 |
3 files changed, 35 insertions, 3 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 19e9985b082..0e0fdb2e738 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2014-08-30 Eli Zaretskii <eliz@gnu.org> | ||
| 2 | |||
| 3 | * sysdep.c (str_collate) [__STDC_ISO_10646__]: Improve the | ||
| 4 | wording of the error messages. | ||
| 5 | (str_collate) [WINDOWSNT]: Signal an error if w32_compare_strings | ||
| 6 | sets errno. | ||
| 7 | |||
| 8 | * w32proc.c (get_lcid_callback): Accept locale specifications | ||
| 9 | without the country part, as in "enu" vs "enu_USA". | ||
| 10 | (w32_compare_strings): Signal an error if a locale was specified, | ||
| 11 | but couldn't be translated into a valid LCID. | ||
| 12 | |||
| 1 | 2014-08-29 Michael Albinus <michael.albinus@gmx.de> | 13 | 2014-08-29 Michael Albinus <michael.albinus@gmx.de> |
| 2 | 14 | ||
| 3 | * sysdep.c (str_collate) [__STDC_ISO_10646__]: Move up setting errno. | 15 | * sysdep.c (str_collate) [__STDC_ISO_10646__]: Move up setting errno. |
diff --git a/src/sysdep.c b/src/sysdep.c index e1da2f87eb2..8b62c8c4f62 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -3747,7 +3747,7 @@ str_collate (Lisp_Object s1, Lisp_Object s2, | |||
| 3747 | locale_t loc = newlocale (LC_COLLATE_MASK | LC_CTYPE_MASK, | 3747 | locale_t loc = newlocale (LC_COLLATE_MASK | LC_CTYPE_MASK, |
| 3748 | SSDATA (locale), 0); | 3748 | SSDATA (locale), 0); |
| 3749 | if (!loc) | 3749 | if (!loc) |
| 3750 | error ("Wrong locale: %s", strerror (errno)); | 3750 | error ("Invalid locale %s: %s", SSDATA (locale), strerror (errno)); |
| 3751 | 3751 | ||
| 3752 | if (! NILP (ignore_case)) | 3752 | if (! NILP (ignore_case)) |
| 3753 | for (int i = 1; i < 3; i++) | 3753 | for (int i = 1; i < 3; i++) |
| @@ -3774,8 +3774,13 @@ str_collate (Lisp_Object s1, Lisp_Object s2, | |||
| 3774 | res = wcscoll (p1, p2); | 3774 | res = wcscoll (p1, p2); |
| 3775 | err = errno; | 3775 | err = errno; |
| 3776 | } | 3776 | } |
| 3777 | # ifndef HAVE_NEWLOCALE | ||
| 3777 | if (err) | 3778 | if (err) |
| 3778 | error ("Wrong argument: %s", strerror (err)); | 3779 | error ("Invalid locale or string for collation: %s", strerror (err)); |
| 3780 | # else | ||
| 3781 | if (err) | ||
| 3782 | error ("Invalid string for collation: %s", strerror (err)); | ||
| 3783 | # endif | ||
| 3779 | 3784 | ||
| 3780 | SAFE_FREE (); | 3785 | SAFE_FREE (); |
| 3781 | return res; | 3786 | return res; |
| @@ -3789,7 +3794,14 @@ str_collate (Lisp_Object s1, Lisp_Object s2, | |||
| 3789 | { | 3794 | { |
| 3790 | 3795 | ||
| 3791 | char *loc = STRINGP (locale) ? SSDATA (locale) : NULL; | 3796 | char *loc = STRINGP (locale) ? SSDATA (locale) : NULL; |
| 3797 | int res, err = errno; | ||
| 3792 | 3798 | ||
| 3793 | return w32_compare_strings (SDATA (s1), SDATA (s2), loc, !NILP (ignore_case)); | 3799 | errno = 0; |
| 3800 | res = w32_compare_strings (SDATA (s1), SDATA (s2), loc, !NILP (ignore_case)); | ||
| 3801 | if (errno) | ||
| 3802 | error ("Invalid string for collation: %s", strerror (errno)); | ||
| 3803 | |||
| 3804 | errno = err; | ||
| 3805 | return res; | ||
| 3794 | } | 3806 | } |
| 3795 | #endif /* WINDOWSNT */ | 3807 | #endif /* WINDOWSNT */ |
diff --git a/src/w32proc.c b/src/w32proc.c index 0b441d45186..399ed009ce3 100644 --- a/src/w32proc.c +++ b/src/w32proc.c | |||
| @@ -3164,6 +3164,12 @@ get_lcid_callback (LPTSTR locale_num_str) | |||
| 3164 | if (GetLocaleInfo (try_lcid, LOCALE_SABBREVLANGNAME, | 3164 | if (GetLocaleInfo (try_lcid, LOCALE_SABBREVLANGNAME, |
| 3165 | locval, LOCALE_NAME_MAX_LENGTH)) | 3165 | locval, LOCALE_NAME_MAX_LENGTH)) |
| 3166 | { | 3166 | { |
| 3167 | /* This is for when they only specify the language, as in "ENU". */ | ||
| 3168 | if (stricmp (locval, lname) == 0) | ||
| 3169 | { | ||
| 3170 | found_lcid = try_lcid; | ||
| 3171 | return FALSE; | ||
| 3172 | } | ||
| 3167 | strcat (locval, "_"); | 3173 | strcat (locval, "_"); |
| 3168 | if (GetLocaleInfo (try_lcid, LOCALE_SABBREVCTRYNAME, | 3174 | if (GetLocaleInfo (try_lcid, LOCALE_SABBREVCTRYNAME, |
| 3169 | locval + strlen (locval), LOCALE_NAME_MAX_LENGTH)) | 3175 | locval + strlen (locval), LOCALE_NAME_MAX_LENGTH)) |
| @@ -3287,6 +3293,8 @@ w32_compare_strings (const char *s1, const char *s2, char *locname, | |||
| 3287 | 3293 | ||
| 3288 | if (new_lcid > 0) | 3294 | if (new_lcid > 0) |
| 3289 | lcid = new_lcid; | 3295 | lcid = new_lcid; |
| 3296 | else | ||
| 3297 | error ("Invalid locale %s: Invalid argument", locname); | ||
| 3290 | } | 3298 | } |
| 3291 | 3299 | ||
| 3292 | if (ignore_case) | 3300 | if (ignore_case) |