Fix conversion from lower to upper case with Turkish locale
PATCH v2 1/1 Fix conversion from lower to upper case with Turkish locale
Some locale settings let make fail or create wrong results because tr '[:lower:]' '[:upper:]' which is used to convert from lower to upper case depends on the locale.
With locale tr_TR.UTF-8, lower case 'i' is not converted to 'I'. This results in wrong entries in config-host.h like these ones:
#define CONFIG_QEMU_PREFiX "/usr/local" #define CONFIG_QEMU_BiNDiR "/usr/local/bin"
This problem was reported by Emre Ersin.
The same problem occurs when configure creates the target specific files config-target.mak. They get wrong declarations:
TARGET_CRiS=y
TARGET_i386=y
TARGET_MiCROBLAZE=y
TARGET_MiPS64=y
TARGET_MiPS=y
TARGET_UNiCORE32=y
It is sufficient to restrict the conversion to the characters a-z.
Using this explicit range avoids the dependency on the locale settings and is also shorter.
v2:
POSIX says that 'tr a-z' is unspecified outside of the POSIX locale, so we must set LC_ALL=C to make sure that we are using POSIX (hint from Eric Blake, thanks).
--- configure | 6 +++--- scripts/create_config | 6 +++--- scripts/tracetool | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-)
configure +3 -3
@@ -3052,12 +3052,12 @@ if test "$cap_ng" = "yes" ; then echo "CONFIG_LIBCAP=y" >> $config_host_mak fi for card in $audio_card_list; do - def=CONFIG_`echo $card | tr '[:lower:]' '[:upper:]'` + def=CONFIG_`echo $card | LC_ALL=C tr '[a-z]' '[A-Z]'` echo "$def=y" >> $config_host_mak done echo "CONFIG_AUDIO_DRIVERS=$audio_drv_list" >> $config_host_mak for drv in $audio_drv_list; do - def=CONFIG_`echo $drv | tr '[:lower:]' '[:upper:]'` + def=CONFIG_`echo $drv | LC_ALL=C tr '[a-z]' '[A-Z]'` echo "$def=y" >> $config_host_mak if test "$drv" = "fmod"; then echo "FMOD_CFLAGS=-I$fmod_inc" >> $config_host_mak
@@ -3618,7 +3618,7 @@ echo "TARGET_INT_ALIGNMENT=$target_int_alignment" >> $config_target_mak echo "TARGET_LONG_ALIGNMENT=$target_long_alignment" >> $config_target_mak echo "TARGET_LLONG_ALIGNMENT=$target_llong_alignment" >> $config_target_mak echo "TARGET_ARCH=$TARGET_ARCH" >> $config_target_mak -target_arch_name="`echo $TARGET_ARCH | tr '[:lower:]' '[:upper:]'`" +target_arch_name="`echo $TARGET_ARCH | LC_ALL=C tr '[a-z]' '[A-Z]'`" echo "TARGET_$target_arch_name=y" >> $config_target_mak echo "TARGET_ARCH2=$target_arch2" >> $config_target_mak # TARGET_BASE_ARCH needs to be defined after TARGET_ARCH
scripts/create_config +3 -3
@@ -16,7 +16,7 @@ case $line in prefix=* | [a-z]*dir=*) # directory configuration name=${line%=*} value=${line#*=} - define_name=`echo $name | tr '[:lower:]' '[:upper:]'` + define_name=`echo $name | LC_ALL=C tr '[a-z]' '[A-Z]'` eval "define_value=\"$value\"" echo "#define CONFIG_QEMU_$define_name \"$define_value\"" # save for the next definitions
@@ -48,7 +48,7 @@ case $line in ;; ARCH=*) # configuration arch=${line#*=} - arch_name=`echo $arch | tr '[:lower:]' '[:upper:]'` + arch_name=`echo $arch | LC_ALL=C tr '[a-z]' '[A-Z]'` echo "#define HOST_$arch_name 1" ;; HOST_USB=*)
@@ -73,7 +73,7 @@ case $line in TARGET_BASE_ARCH=*) # configuration target_base_arch=${line#*=} if [ "$target_base_arch" != "$target_arch" ]; then - base_arch_name=`echo $target_base_arch | tr '[:lower:]' '[:upper:]'` + base_arch_name=`echo $target_base_arch | LC_ALL=C tr '[a-z]' '[A-Z]'` echo "#define TARGET_$base_arch_name 1" fi ;;
scripts/tracetool +2 -2
@@ -410,7 +410,7 @@ linetoh_dtrace() args=$(get_args "$1") argnames=$(get_argnames "$1", ",") - nameupper=`echo $name | tr '[:lower:]' '[:upper:]'` + nameupper=`echo $name | LC_ALL=C tr '[a-z]' '[A-Z]'` # Define an empty function for the trace event cat <<EOF
@@ -539,7 +539,7 @@ convert() fi if [ "$1" = "h" ]; then name=$(get_name "$str") - NAME=$(echo $name | tr '[:lower:]' '[:upper:]') + NAME=$(echo $name | LC_ALL=C tr '[a-z]' '[A-Z]') echo "#define TRACE_${NAME}_ENABLED ${enabled}" fi done
Signature · 1 line
1.7.9
Quoted 4 lines · Stefan Weil
Some locale settings let make fail or create wrong results because tr '[:lower:]' '[:upper:]' which is used to convert from lower to upper case depends on the locale.
...
Quoted 6 lines
v2:
POSIX says that 'tr a-z' is unspecified outside of the POSIX locale, so we must set LC_ALL=C to make sure that we are using POSIX (hint from Eric Blake, thanks).
Quoted 6 lines
Signed-off-by Stefan Weil <[email protected]>--- configure | 6 +++--- scripts/create_config | 6 +++--- scripts/tracetool | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-)
Not being a regular reviewer on this list, I'm not sure I know the subtle difference between 'Acked-by' and 'Reviewed-by' to know which one I should be adding; but this patch resolves my objection on v1.
[Side note - POSIX actually requires:
tr a-z A-Z
to do the 26-letter case conversion, and that use of '[a-z]' means you are transliterating 28 characters, by changing '[' and ']' to themselves. But on older Solaris tr, you had to provide the [] to get range expansion rather than transliteration of a literal '-', so your patch is the right approach for maximal portability]
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Blue Swirl
AppliedThanks, applied.
Quoted 124 lines · Stefan Weil
Some locale settings let make fail or create wrong results because tr '[:lower:]' '[:upper:]' which is used to convert from lower to upper case depends on the locale.
With locale tr_TR.UTF-8, lower case 'i' is not converted to 'I'. This results in wrong entries in
config-host.hlike these ones:#define
CONFIG_QEMU_PREFiX"/usr/local"
#defineCONFIG_QEMU_BiNDiR"/usr/local/bin"This problem was reported by Emre Ersin.
The same problem occurs when configure creates the target specific files config-target.mak. They get wrong declarations:
TARGET_CRiS=y
TARGET_i386=y
TARGET_MiCROBLAZE=y
TARGET_MiPS64=y
TARGET_MiPS=y
TARGET_UNiCORE32=yIt is sufficient to restrict the conversion to the characters a-z.
Using this explicit range avoids the dependency on the locale settings and is also shorter.
v2:
POSIX says that 'tr a-z' is unspecified outside of the POSIX locale, so we must set LC_ALL=C to make sure that we are using POSIX (hint from Eric Blake, thanks).Signed-off-by Stefan Weil <[email protected]>---
configure | 6 +++---
scripts/create_config | 6 +++---
scripts/tracetool | 4 ++--3 files changed, 8 insertions(+), 8 deletions(-)configure +0
-0@@ -3052,12 +3052,12 @@ if test "$cap_ng" = "yes" ; thenecho "
CONFIG_LIBCAP=y" >> $config_host_mak
fi
for card in $audio_card_list; do
- def=CONFIG_echo $card | tr '[:lower:]' '[:upper:]'
+ def=CONFIG_echo $card | LC_ALL=C tr '[a-z]' '[A-Z]'echo "$def=y" >> $config_host_mak
done
echo "CONFIG_AUDIO_DRIVERS=$audio_drv_list" >> $config_host_mak for drv in $audio_drv_list; do
- def=CONFIG_echo $drv | tr '[:lower:]' '[:upper:]'
+ def=CONFIG_echo $drv | LC_ALL=C tr '[a-z]' '[A-Z]'echo "$def=y" >> $config_host_mak
if test "$drv" = "fmod"; then
echo "FMOD_CFLAGS=-I$fmod_inc" >> $config_host_makconfigure +0
-0@@ -3618,7 +3618,7 @@ echo "TARGET_INT_ALIGNMENT=$target_int_alignment" >> $config_target_makecho "TARGET_LONG_ALIGNMENT=$target_long_alignment" >> $config_target_mak echo "TARGET_LLONG_ALIGNMENT=$target_llong_alignment" >> $config_target_mak echo "TARGET_ARCH=$TARGET_ARCH" >> $config_target_mak
configure +1
-1-target_arch_name="`echo $TARGET_ARCH | tr '[:lower:]' '[:upper:]'`" +target_arch_name="`echo $TARGET_ARCH | LC_ALL=C tr '[a-z]' '[A-Z]'`"echo "TARGET_$target_arch_name=y" >> $config_target_mak echo "TARGET_ARCH2=$target_arch2" >> $config_target_mak #
TARGET_BASE_ARCHneeds to be defined afterTARGET_ARCHscripts/create_config +0
-0@@ -16,7 +16,7 @@ case $line inprefix=* | [a-z]*dir=*) # directory configuration name=${line%=*}
value=${line#*=}
- define_name=echo $name | tr '[:lower:]' '[:upper:]'
+ define_name=echo $name | LC_ALL=C tr '[a-z]' '[A-Z]'eval "define_value=\"$value\""
echo "#define CONFIG_QEMU_$define_name \"$define_value\""# save for the next definitionsscripts/create_config +0
-0@@ -48,7 +48,7 @@ case $line in ;;ARCH=*) # configuration
arch=${line#*=}
- arch_name=echo $arch | tr '[:lower:]' '[:upper:]'
+ arch_name=echo $arch | LC_ALL=C tr '[a-z]' '[A-Z]'echo "#define HOST_$arch_name 1"
;;
HOST_USB=*)scripts/create_config +0
-0@@ -73,7 +73,7 @@ case $line inTARGET_BASE_ARCH=*) # configuration
target_base_arch=${line#*=}
if [ "$target_base_arch" != "$target_arch" ]; then
- base_arch_name=echo $target_base_arch | tr '[:lower:]' '[:upper:]'
+ base_arch_name=echo $target_base_arch | LC_ALL=C tr '[a-z]' '[A-Z]'echo "#define TARGET_$base_arch_name 1"
fi
;;scripts/tracetool +1
-1@@ -410,7 +410,7 @@ linetoh_dtrace() args=$(get_args "$1") argnames=$(get_argnames "$1", ",") - nameupper=`echo $name | tr '[:lower:]' '[:upper:]'` + nameupper=`echo $name | LC_ALL=C tr '[a-z]' '[A-Z]'` # Define an empty function for the trace eventcat <<EOF
scripts/tracetool +0
-0@@ -539,7 +539,7 @@ convert()fi
if [ "$1" = "h" ]; then
name=$(get_name "$str")
- NAME=$(echo $name | tr '[:lower:]' '[:upper:]')
+ NAME=$(echo $name | LC_ALL=C tr '[a-z]' '[A-Z]') echo "#define TRACE_${NAME}_ENABLED ${enabled}" fi
done
--
1.7.9