Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
1588be66
Unverified
Kaydet (Commit)
1588be66
authored
Kas 12, 2017
tarafından
xdegaye
Kaydeden (comit)
GitHub
Kas 12, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-28180: Fix the implementation of PEP 538 on Android (GH-4334)
üst
9e78dc25
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
90 additions
and
24 deletions
+90
-24
pylifecycle.h
Include/pylifecycle.h
+1
-0
test_c_locale_coercion.py
Lib/test/test_c_locale_coercion.py
+18
-3
2017-11-12-11-44-22.bpo-28180.HQX000.rst
...ore and Builtins/2017-11-12-11-44-22.bpo-28180.HQX000.rst
+4
-0
readline.c
Modules/readline.c
+1
-1
python.c
Programs/python.c
+1
-8
pylifecycle.c
Python/pylifecycle.c
+65
-12
No files found.
Include/pylifecycle.h
Dosyayı görüntüle @
1588be66
...
@@ -137,6 +137,7 @@ PyAPI_FUNC(int) _PyOS_URandomNonblock(void *buffer, Py_ssize_t size);
...
@@ -137,6 +137,7 @@ PyAPI_FUNC(int) _PyOS_URandomNonblock(void *buffer, Py_ssize_t size);
#ifndef Py_LIMITED_API
#ifndef Py_LIMITED_API
PyAPI_FUNC
(
void
)
_Py_CoerceLegacyLocale
(
void
);
PyAPI_FUNC
(
void
)
_Py_CoerceLegacyLocale
(
void
);
PyAPI_FUNC
(
int
)
_Py_LegacyLocaleDetected
(
void
);
PyAPI_FUNC
(
int
)
_Py_LegacyLocaleDetected
(
void
);
PyAPI_FUNC
(
char
*
)
_Py_SetLocaleFromEnv
(
int
category
);
#endif
#endif
#ifdef __cplusplus
#ifdef __cplusplus
...
...
Lib/test/test_c_locale_coercion.py
Dosyayı görüntüle @
1588be66
...
@@ -6,7 +6,6 @@ import os
...
@@ -6,7 +6,6 @@ import os
import
sys
import
sys
import
sysconfig
import
sysconfig
import
shutil
import
shutil
import
subprocess
from
collections
import
namedtuple
from
collections
import
namedtuple
import
test.support
import
test.support
...
@@ -18,9 +17,12 @@ from test.support.script_helper import (
...
@@ -18,9 +17,12 @@ from test.support.script_helper import (
# Set our expectation for the default encoding used in the C locale
# Set our expectation for the default encoding used in the C locale
# for the filesystem encoding and the standard streams
# for the filesystem encoding and the standard streams
# AIX uses iso8859-1 in the C locale, other *nix platforms use ASCII
# While most *nix platforms default to ASCII in the C locale, some use a
# different encoding.
if
sys
.
platform
.
startswith
(
"aix"
):
if
sys
.
platform
.
startswith
(
"aix"
):
C_LOCALE_STREAM_ENCODING
=
"iso8859-1"
C_LOCALE_STREAM_ENCODING
=
"iso8859-1"
elif
test
.
support
.
is_android
:
C_LOCALE_STREAM_ENCODING
=
"utf-8"
else
:
else
:
C_LOCALE_STREAM_ENCODING
=
"ascii"
C_LOCALE_STREAM_ENCODING
=
"ascii"
...
@@ -301,6 +303,19 @@ class LocaleCoercionTests(_LocaleHandlingTestCase):
...
@@ -301,6 +303,19 @@ class LocaleCoercionTests(_LocaleHandlingTestCase):
# See https://bugs.python.org/issue30672 for discussion
# See https://bugs.python.org/issue30672 for discussion
if
locale_to_set
==
"POSIX"
:
if
locale_to_set
==
"POSIX"
:
continue
continue
# Platforms using UTF-8 in the C locale do not print
# CLI_COERCION_WARNING when all the locale envt variables are
# not set or set to the empty string.
_expected_warnings
=
expected_warnings
for
_env_var
in
base_var_dict
:
if
base_var_dict
[
_env_var
]:
break
else
:
if
(
C_LOCALE_STREAM_ENCODING
==
"utf-8"
and
locale_to_set
==
""
and
coerce_c_locale
==
"warn"
):
_expected_warnings
=
None
with
self
.
subTest
(
env_var
=
env_var
,
with
self
.
subTest
(
env_var
=
env_var
,
nominal_locale
=
locale_to_set
,
nominal_locale
=
locale_to_set
,
PYTHONCOERCECLOCALE
=
coerce_c_locale
):
PYTHONCOERCECLOCALE
=
coerce_c_locale
):
...
@@ -312,7 +327,7 @@ class LocaleCoercionTests(_LocaleHandlingTestCase):
...
@@ -312,7 +327,7 @@ class LocaleCoercionTests(_LocaleHandlingTestCase):
self
.
_check_child_encoding_details
(
var_dict
,
self
.
_check_child_encoding_details
(
var_dict
,
fs_encoding
,
fs_encoding
,
stream_encoding
,
stream_encoding
,
expected_warnings
,
_
expected_warnings
,
coercion_expected
)
coercion_expected
)
def
test_test_PYTHONCOERCECLOCALE_not_set
(
self
):
def
test_test_PYTHONCOERCECLOCALE_not_set
(
self
):
...
...
Misc/NEWS.d/next/Core and Builtins/2017-11-12-11-44-22.bpo-28180.HQX000.rst
0 → 100644
Dosyayı görüntüle @
1588be66
A new internal ``_Py_SetLocaleFromEnv(category)`` helper function has been
added in order to improve the consistency of behaviour across different
``libc`` implementations (e.g. Android doesn't support setting the locale from
the environment by default).
Modules/readline.c
Dosyayı görüntüle @
1588be66
...
@@ -1245,7 +1245,7 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
...
@@ -1245,7 +1245,7 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
char
*
saved_locale
=
strdup
(
setlocale
(
LC_CTYPE
,
NULL
));
char
*
saved_locale
=
strdup
(
setlocale
(
LC_CTYPE
,
NULL
));
if
(
!
saved_locale
)
if
(
!
saved_locale
)
Py_FatalError
(
"not enough memory to save locale"
);
Py_FatalError
(
"not enough memory to save locale"
);
setlocale
(
LC_CTYPE
,
""
);
_Py_SetLocaleFromEnv
(
LC_CTYPE
);
#endif
#endif
if
(
sys_stdin
!=
rl_instream
||
sys_stdout
!=
rl_outstream
)
{
if
(
sys_stdin
!=
rl_instream
||
sys_stdout
!=
rl_outstream
)
{
...
...
Programs/python.c
Dosyayı görüntüle @
1588be66
...
@@ -54,15 +54,8 @@ main(int argc, char **argv)
...
@@ -54,15 +54,8 @@ main(int argc, char **argv)
return
1
;
return
1
;
}
}
#ifdef __ANDROID__
/* Passing "" to setlocale() on Android requests the C locale rather
* than checking environment variables, so request C.UTF-8 explicitly
*/
setlocale
(
LC_ALL
,
"C.UTF-8"
);
#else
/* Reconfigure the locale to the default for this process */
/* Reconfigure the locale to the default for this process */
setlocale
(
LC_ALL
,
""
);
_Py_SetLocaleFromEnv
(
LC_ALL
);
#endif
/* The legacy C locale assumes ASCII as the default text encoding, which
/* The legacy C locale assumes ASCII as the default text encoding, which
* causes problems not only for the CPython runtime, but also other
* causes problems not only for the CPython runtime, but also other
...
...
Python/pylifecycle.c
Dosyayı görüntüle @
1588be66
...
@@ -459,7 +459,7 @@ _coerce_default_locale_settings(const _LocaleCoercionTarget *target)
...
@@ -459,7 +459,7 @@ _coerce_default_locale_settings(const _LocaleCoercionTarget *target)
const
char
*
newloc
=
target
->
locale_name
;
const
char
*
newloc
=
target
->
locale_name
;
/* Reset locale back to currently configured defaults */
/* Reset locale back to currently configured defaults */
setlocale
(
LC_ALL
,
""
);
_Py_SetLocaleFromEnv
(
LC_ALL
);
/* Set the relevant locale environment variable */
/* Set the relevant locale environment variable */
if
(
setenv
(
"LC_CTYPE"
,
newloc
,
1
))
{
if
(
setenv
(
"LC_CTYPE"
,
newloc
,
1
))
{
...
@@ -472,7 +472,7 @@ _coerce_default_locale_settings(const _LocaleCoercionTarget *target)
...
@@ -472,7 +472,7 @@ _coerce_default_locale_settings(const _LocaleCoercionTarget *target)
}
}
/* Reconfigure with the overridden environment variables */
/* Reconfigure with the overridden environment variables */
setlocale
(
LC_ALL
,
""
);
_Py_SetLocaleFromEnv
(
LC_ALL
);
}
}
#endif
#endif
...
@@ -503,13 +503,14 @@ _Py_CoerceLegacyLocale(void)
...
@@ -503,13 +503,14 @@ _Py_CoerceLegacyLocale(void)
const
char
*
new_locale
=
setlocale
(
LC_CTYPE
,
const
char
*
new_locale
=
setlocale
(
LC_CTYPE
,
target
->
locale_name
);
target
->
locale_name
);
if
(
new_locale
!=
NULL
)
{
if
(
new_locale
!=
NULL
)
{
#if !defined(__APPLE__) && defined(HAVE_LANGINFO_H) && defined(CODESET)
#if !defined(__APPLE__) && !defined(__ANDROID__) && \
defined(HAVE_LANGINFO_H) && defined(CODESET)
/* Also ensure that nl_langinfo works in this locale */
/* Also ensure that nl_langinfo works in this locale */
char
*
codeset
=
nl_langinfo
(
CODESET
);
char
*
codeset
=
nl_langinfo
(
CODESET
);
if
(
!
codeset
||
*
codeset
==
'\0'
)
{
if
(
!
codeset
||
*
codeset
==
'\0'
)
{
/* CODESET is not set or empty, so skip coercion */
/* CODESET is not set or empty, so skip coercion */
new_locale
=
NULL
;
new_locale
=
NULL
;
setlocale
(
LC_CTYPE
,
""
);
_Py_SetLocaleFromEnv
(
LC_CTYPE
);
continue
;
continue
;
}
}
#endif
#endif
...
@@ -524,6 +525,65 @@ _Py_CoerceLegacyLocale(void)
...
@@ -524,6 +525,65 @@ _Py_CoerceLegacyLocale(void)
#endif
#endif
}
}
/* _Py_SetLocaleFromEnv() is a wrapper around setlocale(category, "") to
* isolate the idiosyncrasies of different libc implementations. It reads the
* appropriate environment variable and uses its value to select the locale for
* 'category'. */
char
*
_Py_SetLocaleFromEnv
(
int
category
)
{
#ifdef __ANDROID__
const
char
*
locale
;
const
char
**
pvar
;
#ifdef PY_COERCE_C_LOCALE
const
char
*
coerce_c_locale
;
#endif
const
char
*
utf8_locale
=
"C.UTF-8"
;
const
char
*
env_var_set
[]
=
{
"LC_ALL"
,
"LC_CTYPE"
,
"LANG"
,
NULL
,
};
/* Android setlocale(category, "") doesn't check the environment variables
* and incorrectly sets the "C" locale at API 24 and older APIs. We only
* check the environment variables listed in env_var_set. */
for
(
pvar
=
env_var_set
;
*
pvar
;
pvar
++
)
{
locale
=
getenv
(
*
pvar
);
if
(
locale
!=
NULL
&&
*
locale
!=
'\0'
)
{
if
(
strcmp
(
locale
,
utf8_locale
)
==
0
||
strcmp
(
locale
,
"en_US.UTF-8"
)
==
0
)
{
return
setlocale
(
category
,
utf8_locale
);
}
return
setlocale
(
category
,
"C"
);
}
}
/* Android uses UTF-8, so explicitly set the locale to C.UTF-8 if none of
* LC_ALL, LC_CTYPE, or LANG is set to a non-empty string.
* Quote from POSIX section "8.2 Internationalization Variables":
* "4. If the LANG environment variable is not set or is set to the empty
* string, the implementation-defined default locale shall be used." */
#ifdef PY_COERCE_C_LOCALE
coerce_c_locale
=
getenv
(
"PYTHONCOERCECLOCALE"
);
if
(
coerce_c_locale
==
NULL
||
strcmp
(
coerce_c_locale
,
"0"
)
!=
0
)
{
/* Some other ported code may check the environment variables (e.g. in
* extension modules), so we make sure that they match the locale
* configuration */
if
(
setenv
(
"LC_CTYPE"
,
utf8_locale
,
1
))
{
fprintf
(
stderr
,
"Warning: failed setting the LC_CTYPE "
"environment variable to %s
\n
"
,
utf8_locale
);
}
}
#endif
return
setlocale
(
category
,
utf8_locale
);
#else
/* __ANDROID__ */
return
setlocale
(
category
,
""
);
#endif
/* __ANDROID__ */
}
/* Global initializations. Can be undone by Py_Finalize(). Don't
/* Global initializations. Can be undone by Py_Finalize(). Don't
call this twice without an intervening Py_Finalize() call.
call this twice without an intervening Py_Finalize() call.
...
@@ -599,19 +659,12 @@ void _Py_InitializeCore(const _PyCoreConfig *config)
...
@@ -599,19 +659,12 @@ void _Py_InitializeCore(const _PyCoreConfig *config)
exit
(
1
);
exit
(
1
);
}
}
#ifdef __ANDROID__
/* Passing "" to setlocale() on Android requests the C locale rather
* than checking environment variables, so request C.UTF-8 explicitly
*/
setlocale
(
LC_CTYPE
,
"C.UTF-8"
);
#else
#ifndef MS_WINDOWS
#ifndef MS_WINDOWS
/* Set up the LC_CTYPE locale, so we can obtain
/* Set up the LC_CTYPE locale, so we can obtain
the locale's charset without having to switch
the locale's charset without having to switch
locales. */
locales. */
setlocale
(
LC_CTYPE
,
""
);
_Py_SetLocaleFromEnv
(
LC_CTYPE
);
_emit_stderr_warning_for_legacy_locale
();
_emit_stderr_warning_for_legacy_locale
();
#endif
#endif
#endif
if
((
p
=
Py_GETENV
(
"PYTHONDEBUG"
))
&&
*
p
!=
'\0'
)
if
((
p
=
Py_GETENV
(
"PYTHONDEBUG"
))
&&
*
p
!=
'\0'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment