mirror of
https://github.com/python/cpython.git
synced 2025-08-25 03:04:55 +00:00
bpo-35713: Rework Python initialization (GH-11647)
* The PyByteArray_Init() and PyByteArray_Fini() functions have been removed. They did nothing since Python 2.7.4 and Python 3.2.0, were excluded from the limited API (stable ABI), and were not documented. * Move "_PyXXX_Init()" and "_PyXXX_Fini()" declarations from Include/cpython/pylifecycle.h to Include/internal/pycore_pylifecycle.h. Replace "PyAPI_FUNC(TYPE)" with "extern TYPE". * _PyExc_Init() now returns an error on failure rather than calling Py_FatalError(). Move macros inside _PyExc_Init() and undefine them when done. Rewrite macros to make them look more like statement: add ";" when using them, add "do { ... } while (0)". * _PyUnicode_Init() now returns a _PyInitError error rather than call Py_FatalError(). * Move stdin check from _PySys_BeginInit() to init_sys_streams(). * _Py_ReadyTypes() now returns a _PyInitError error rather than calling Py_FatalError().
This commit is contained in:
parent
35ca1820e1
commit
bf4ac2d2fd
9 changed files with 286 additions and 268 deletions
|
@ -15199,7 +15199,8 @@ PyTypeObject PyUnicode_Type = {
|
|||
|
||||
/* Initialize the Unicode implementation */
|
||||
|
||||
int _PyUnicode_Init(void)
|
||||
_PyInitError
|
||||
_PyUnicode_Init(void)
|
||||
{
|
||||
/* XXX - move this array to unicodectype.c ? */
|
||||
Py_UCS2 linebreak[] = {
|
||||
|
@ -15215,28 +15216,31 @@ int _PyUnicode_Init(void)
|
|||
|
||||
/* Init the implementation */
|
||||
_Py_INCREF_UNICODE_EMPTY();
|
||||
if (!unicode_empty)
|
||||
Py_FatalError("Can't create empty string");
|
||||
if (!unicode_empty) {
|
||||
return _Py_INIT_ERR("Can't create empty string");
|
||||
}
|
||||
Py_DECREF(unicode_empty);
|
||||
|
||||
if (PyType_Ready(&PyUnicode_Type) < 0)
|
||||
Py_FatalError("Can't initialize 'unicode'");
|
||||
if (PyType_Ready(&PyUnicode_Type) < 0) {
|
||||
return _Py_INIT_ERR("Can't initialize unicode type");
|
||||
}
|
||||
|
||||
/* initialize the linebreak bloom filter */
|
||||
bloom_linebreak = make_bloom_mask(
|
||||
PyUnicode_2BYTE_KIND, linebreak,
|
||||
Py_ARRAY_LENGTH(linebreak));
|
||||
|
||||
if (PyType_Ready(&EncodingMapType) < 0)
|
||||
Py_FatalError("Can't initialize encoding map type");
|
||||
if (PyType_Ready(&EncodingMapType) < 0) {
|
||||
return _Py_INIT_ERR("Can't initialize encoding map type");
|
||||
}
|
||||
if (PyType_Ready(&PyFieldNameIter_Type) < 0) {
|
||||
return _Py_INIT_ERR("Can't initialize field name iterator type");
|
||||
}
|
||||
if (PyType_Ready(&PyFormatterIter_Type) < 0) {
|
||||
return _Py_INIT_ERR("Can't initialize formatter iter type");
|
||||
}
|
||||
|
||||
if (PyType_Ready(&PyFieldNameIter_Type) < 0)
|
||||
Py_FatalError("Can't initialize field name iterator type");
|
||||
|
||||
if (PyType_Ready(&PyFormatterIter_Type) < 0)
|
||||
Py_FatalError("Can't initialize formatter iter type");
|
||||
|
||||
return 0;
|
||||
return _Py_INIT_OK();
|
||||
}
|
||||
|
||||
/* Finalize the Unicode implementation */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue