Skip to content

Commit 031c4bf

Browse files
embrayncoghlan
authored andcommitted
bpo-31877: Add _Py_LegacyLocaleDetected and _PyCoerceLegacyLocale to pylifecycle.h (pythonGH-4134)
Only declaring these as interns inside the CLI's main C module caused build problems on some platforms (notably Cygwin), so this switches them to a regular underscore prefixed "private" C API declaration.
1 parent 2f3d699 commit 031c4bf

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

Include/pylifecycle.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ PyAPI_FUNC(int) _PyOS_URandom(void *buffer, Py_ssize_t size);
133133
PyAPI_FUNC(int) _PyOS_URandomNonblock(void *buffer, Py_ssize_t size);
134134
#endif /* !Py_LIMITED_API */
135135

136+
/* Legacy locale support */
137+
#ifndef Py_LIMITED_API
138+
PyAPI_FUNC(void) _Py_CoerceLegacyLocale(void);
139+
PyAPI_FUNC(int) _Py_LegacyLocaleDetected(void);
140+
#endif
141+
136142
#ifdef __cplusplus
137143
}
138144
#endif

Programs/python.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,6 @@ wmain(int argc, wchar_t **argv)
1515
}
1616
#else
1717

18-
/* Access private pylifecycle helper API to better handle the legacy C locale
19-
*
20-
* The legacy C locale assumes ASCII as the default text encoding, which
21-
* causes problems not only for the CPython runtime, but also other
22-
* components like GNU readline.
23-
*
24-
* Accordingly, when the CLI detects it, it attempts to coerce it to a
25-
* more capable UTF-8 based alternative.
26-
*
27-
* See the documentation of the PYTHONCOERCECLOCALE setting for more details.
28-
*
29-
*/
30-
extern int _Py_LegacyLocaleDetected(void);
31-
extern void _Py_CoerceLegacyLocale(void);
3218

3319
int
3420
main(int argc, char **argv)
@@ -78,6 +64,16 @@ main(int argc, char **argv)
7864
setlocale(LC_ALL, "");
7965
#endif
8066

67+
/* The legacy C locale assumes ASCII as the default text encoding, which
68+
* causes problems not only for the CPython runtime, but also other
69+
* components like GNU readline.
70+
*
71+
* Accordingly, when the CLI detects it, it attempts to coerce it to a
72+
* more capable UTF-8 based alternative.
73+
*
74+
* See the documentation of the PYTHONCOERCECLOCALE setting for more
75+
* details.
76+
*/
8177
if (_Py_LegacyLocaleDetected()) {
8278
_Py_CoerceLegacyLocale();
8379
}

0 commit comments

Comments
 (0)