Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions 44 Lib/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ def _strxfrm(s):
return s

try:

from _locale import *

except ImportError:

# Locale emulation

CHAR_MAX = 127
Expand All @@ -60,7 +57,30 @@ def _strxfrm(s):
LC_TIME = 2
Error = ValueError

def localeconv():
def setlocale(category, value=None):
""" setlocale(integer,string=None) -> string.
Activates/queries locale processing.
"""
if value not in (None, '', 'C'):
raise Error('_locale emulation only supports "C" locale')
return 'C'


# These may or may not exist in _locale, so be sure to set them.
if 'strxfrm' not in globals():
strxfrm = _strxfrm
if 'strcoll' not in globals():
strcoll = _strcoll


try:
_localeconv = localeconv
except NameError:
# Locale emulation for localeconv() if the _locale module is missing
# or if the _locale module does not implement the localeconv() function
# (ex: Android API 19)

def _localeconv():
""" localeconv() -> dict.
Returns numeric and monetary locale-specific parameters.
"""
Expand All @@ -84,22 +104,6 @@ def localeconv():
'mon_decimal_point': '',
'int_frac_digits': 127}

def setlocale(category, value=None):
""" setlocale(integer,string=None) -> string.
Activates/queries locale processing.
"""
if value not in (None, '', 'C'):
raise Error('_locale emulation only supports "C" locale')
return 'C'

# These may or may not exist in _locale, so be sure to set them.
if 'strxfrm' not in globals():
strxfrm = _strxfrm
if 'strcoll' not in globals():
strcoll = _strcoll


_localeconv = localeconv

# With this dict, you can override some items of localeconv's return value.
# This is useful for testing purposes.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix compilation errors on Android API 19.
13 changes: 13 additions & 0 deletions 13 Modules/_localemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ This software comes with no warranty. Use at your own risk.
#include <windows.h>
#endif

#if defined(__ANDROID_API__) && __ANDROID_API__ < 20
/* Before Android API 20, localeconv() is defined but not implemented,
leading to linker error. */
# define MISSING_LOCALECONV
#endif


PyDoc_STRVAR(locale__doc__, "Support for POSIX locales.");

static PyObject *Error;
Expand Down Expand Up @@ -128,6 +135,8 @@ PyLocale_setlocale(PyObject* self, PyObject* args)
return result_object;
}


#ifndef MISSING_LOCALECONV
PyDoc_STRVAR(localeconv__doc__,
"() -> dict. Returns numeric and monetary locale-specific parameters.");

Expand Down Expand Up @@ -222,6 +231,8 @@ PyLocale_localeconv(PyObject* self)
Py_DECREF(result);
return NULL;
}
#endif


#if defined(HAVE_WCSCOLL)
PyDoc_STRVAR(strcoll__doc__,
Expand Down Expand Up @@ -605,8 +616,10 @@ PyIntl_bind_textdomain_codeset(PyObject* self,PyObject*args)
static struct PyMethodDef PyLocale_Methods[] = {
{"setlocale", (PyCFunction) PyLocale_setlocale,
METH_VARARGS, setlocale__doc__},
#ifndef MISSING_LOCALECONV
{"localeconv", (PyCFunction) PyLocale_localeconv,
METH_NOARGS, localeconv__doc__},
#endif
#ifdef HAVE_WCSCOLL
{"strcoll", (PyCFunction) PyLocale_strcoll,
METH_VARARGS, strcoll__doc__},
Expand Down
9 changes: 9 additions & 0 deletions 9 Modules/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
"Type \"help\", \"copyright\", \"credits\" or \"license\" " \
"for more information."

#if defined(__ANDROID_API__) && __ANDROID_API__ < 20
/* Before Android API 20, locales are completely broken. */
# define BROKEN_LOCALES
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -1938,11 +1943,13 @@ pymain_read_conf(_PyMain *pymain, _Py_CommandLineDetails *cmdline)
{
int res = -1;

#ifndef BROKEN_LOCALES
char *oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL));
if (oldloc == NULL) {
pymain->err = _Py_INIT_NO_MEMORY();
goto done;
}
#endif

/* Reconfigure the locale to the default for this process */
_Py_SetLocaleFromEnv(LC_ALL);
Expand Down Expand Up @@ -2021,10 +2028,12 @@ pymain_read_conf(_PyMain *pymain, _Py_CommandLineDetails *cmdline)
res = 0;

done:
#ifndef BROKEN_LOCALES
if (oldloc != NULL) {
setlocale(LC_ALL, oldloc);
PyMem_RawFree(oldloc);
}
#endif

return res;
}
Expand Down
7 changes: 7 additions & 0 deletions 7 Modules/mmapmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ my_getpagesize(void)
# define MAP_ANONYMOUS MAP_ANON
#endif

#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
/* mmap() is implemented but not declared in Android headers before API 21 */
extern void *mmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset);
#endif


typedef enum
{
ACCESS_DEFAULT,
Expand Down
7 changes: 7 additions & 0 deletions 7 Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ static int win32_can_symlink = 0;
#endif
#endif


#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
/* sendfile() is implemted but not declared in Android headers before API 21 */
extern ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);
#endif


#ifdef MS_WINDOWS
#define INITFUNC PyInit_nt
#define MODNAME "nt"
Expand Down
15 changes: 11 additions & 4 deletions 15 Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1432,14 +1432,21 @@ PyInit__signal(void)
if (PyModule_AddIntMacro(m, SIGXFSZ))
goto finally;
#endif
#ifdef SIGRTMIN

/* Before Android API 20, SIGRTMIN and SIGRTMAX are defined, but using
them lead to compilation error on the linker. Example:
"implicit declaration of function __libc_current_sigrtmin". */
#if !defined(__ANDROID_API__) || __ANDROID_API__ >= 20
# ifdef SIGRTMIN
if (PyModule_AddIntMacro(m, SIGRTMIN))
goto finally;
#endif
#ifdef SIGRTMAX
# endif
# ifdef SIGRTMAX
if (PyModule_AddIntMacro(m, SIGRTMAX))
goto finally;
#endif
# endif
#endif /* !defined(__ANDROID_API__) || __ANDROID_API__ >= 20 */

#ifdef SIGINFO
if (PyModule_AddIntMacro(m, SIGINFO))
goto finally;
Expand Down
6 changes: 6 additions & 0 deletions 6 Objects/obmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

#include <stdbool.h>

#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
/* mmap() is implemented but not declared in Android headers before API 21 */
extern void *mmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset);
#endif


/* Defined in tracemalloc.c */
extern void _PyMem_DumpTraceback(int fd, const void *ptr);
Expand Down
23 changes: 22 additions & 1 deletion 23 Python/fileutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,26 @@ int
_Py_GetLocaleconvNumeric(PyObject **decimal_point, PyObject **thousands_sep,
const char **grouping)
{
#if defined(__ANDROID_API__) && __ANDROID_API__ < 20
/* On Android, before API 20, localeconv() was broken. */
if (decimal_point != NULL) {
*decimal_point = PyUnicode_FromString(".");
if (*decimal_point == NULL) {
return -1;
}
}
if (thousands_sep != NULL) {
*thousands_sep = PyUnicode_FromString("");
if (*thousands_sep == NULL) {
return -1;
}
}

if (grouping != NULL) {
*grouping = "";
}
return 0;
#else
int res = -1;

struct lconv *lc = localeconv();
Expand All @@ -1783,7 +1803,7 @@ _Py_GetLocaleconvNumeric(PyObject **decimal_point, PyObject **thousands_sep,
if (change_locale) {
oldloc = setlocale(LC_CTYPE, NULL);
if (!oldloc) {
PyErr_SetString(PyExc_RuntimeWarning, "faild to get LC_CTYPE locale");
PyErr_SetString(PyExc_RuntimeWarning, "failed to get LC_CTYPE locale");
return -1;
}

Expand Down Expand Up @@ -1832,4 +1852,5 @@ _Py_GetLocaleconvNumeric(PyObject **decimal_point, PyObject **thousands_sep,
}
PyMem_Free(oldloc);
return res;
#endif
}
8 changes: 6 additions & 2 deletions 8 Python/pystrtod.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ _PyOS_ascii_strtod(const char *nptr, char **endptr)
{
char *fail_pos;
double val;
struct lconv *locale_data;
const char *decimal_point;
size_t decimal_point_len;
const char *p, *decimal_point_pos;
Expand All @@ -177,8 +176,13 @@ _PyOS_ascii_strtod(const char *nptr, char **endptr)

fail_pos = NULL;

locale_data = localeconv();
#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
/* Before Android API 21, localeconv() is broken. */
decimal_point = ".";
#else
struct lconv *locale_data = localeconv();
decimal_point = locale_data->decimal_point;
#endif
decimal_point_len = strlen(decimal_point);

assert(decimal_point_len != 0);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.