Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 84793:fc718c177ee6
Issue #18520: Add a new PyStructSequence_InitType2() function, same than
PyStructSequence_InitType() except that it has a return value (0 on success,
-1 on error).
* PyStructSequence_InitType2() now raises MemoryError on memory allocation failure
* Fix also some calls to PyDict_SetItemString(): handle error
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Mon, 22 Jul 2013 22:24:54 +0200 |
| parents | 01597384531f |
| children | 31796b188bec |
comparison
equal
deleted
inserted
replaced
| 84792:ffe9d73b5f8d | 84793:fc718c177ee6 |
|---|---|
| 1632 SET_SYS_FROM_STRING("float_info", | 1632 SET_SYS_FROM_STRING("float_info", |
| 1633 PyFloat_GetInfo()); | 1633 PyFloat_GetInfo()); |
| 1634 SET_SYS_FROM_STRING("int_info", | 1634 SET_SYS_FROM_STRING("int_info", |
| 1635 PyLong_GetInfo()); | 1635 PyLong_GetInfo()); |
| 1636 /* initialize hash_info */ | 1636 /* initialize hash_info */ |
| 1637 if (Hash_InfoType.tp_name == 0) | 1637 if (Hash_InfoType.tp_name == NULL) { |
| 1638 PyStructSequence_InitType(&Hash_InfoType, &hash_info_desc); | 1638 if (PyStructSequence_InitType2(&Hash_InfoType, &hash_info_desc) < 0) |
| 1639 return NULL; | |
| 1640 } | |
| 1639 SET_SYS_FROM_STRING("hash_info", | 1641 SET_SYS_FROM_STRING("hash_info", |
| 1640 get_hash_info()); | 1642 get_hash_info()); |
| 1641 SET_SYS_FROM_STRING("maxunicode", | 1643 SET_SYS_FROM_STRING("maxunicode", |
| 1642 PyLong_FromLong(0x10FFFF)); | 1644 PyLong_FromLong(0x10FFFF)); |
| 1643 SET_SYS_FROM_STRING("builtin_module_names", | 1645 SET_SYS_FROM_STRING("builtin_module_names", |
| 1674 if (v != NULL) { | 1676 if (v != NULL) { |
| 1675 PyDict_SetItemString(sysdict, "_xoptions", v); | 1677 PyDict_SetItemString(sysdict, "_xoptions", v); |
| 1676 } | 1678 } |
| 1677 | 1679 |
| 1678 /* version_info */ | 1680 /* version_info */ |
| 1679 if (VersionInfoType.tp_name == 0) | 1681 if (VersionInfoType.tp_name == NULL) { |
| 1680 PyStructSequence_InitType(&VersionInfoType, &version_info_desc); | 1682 if (PyStructSequence_InitType2(&VersionInfoType, |
| 1683 &version_info_desc) < 0) | |
| 1684 return NULL; | |
| 1685 } | |
| 1681 version_info = make_version_info(); | 1686 version_info = make_version_info(); |
| 1682 SET_SYS_FROM_STRING("version_info", version_info); | 1687 SET_SYS_FROM_STRING("version_info", version_info); |
| 1683 /* prevent user from creating new instances */ | 1688 /* prevent user from creating new instances */ |
| 1684 VersionInfoType.tp_init = NULL; | 1689 VersionInfoType.tp_init = NULL; |
| 1685 VersionInfoType.tp_new = NULL; | 1690 VersionInfoType.tp_new = NULL; |
| 1686 | 1691 |
| 1687 /* implementation */ | 1692 /* implementation */ |
| 1688 SET_SYS_FROM_STRING("implementation", make_impl_info(version_info)); | 1693 SET_SYS_FROM_STRING("implementation", make_impl_info(version_info)); |
| 1689 | 1694 |
| 1690 /* flags */ | 1695 /* flags */ |
| 1691 if (FlagsType.tp_name == 0) | 1696 if (FlagsType.tp_name == 0) { |
| 1692 PyStructSequence_InitType(&FlagsType, &flags_desc); | 1697 if (PyStructSequence_InitType2(&FlagsType, &flags_desc) < 0) |
| 1698 return NULL; | |
| 1699 } | |
| 1693 SET_SYS_FROM_STRING("flags", make_flags()); | 1700 SET_SYS_FROM_STRING("flags", make_flags()); |
| 1694 /* prevent user from creating new instances */ | 1701 /* prevent user from creating new instances */ |
| 1695 FlagsType.tp_init = NULL; | 1702 FlagsType.tp_init = NULL; |
| 1696 FlagsType.tp_new = NULL; | 1703 FlagsType.tp_new = NULL; |
| 1697 | 1704 |
| 1698 | 1705 |
| 1699 #if defined(MS_WINDOWS) | 1706 #if defined(MS_WINDOWS) |
| 1700 /* getwindowsversion */ | 1707 /* getwindowsversion */ |
| 1701 if (WindowsVersionType.tp_name == 0) | 1708 if (WindowsVersionType.tp_name == 0) |
| 1702 PyStructSequence_InitType(&WindowsVersionType, &windows_version_desc); | 1709 if (PyStructSequence_InitType2(&WindowsVersionType, |
| 1710 &windows_version_desc) < 0) | |
| 1711 return NULL; | |
| 1703 /* prevent user from creating new instances */ | 1712 /* prevent user from creating new instances */ |
| 1704 WindowsVersionType.tp_init = NULL; | 1713 WindowsVersionType.tp_init = NULL; |
| 1705 WindowsVersionType.tp_new = NULL; | 1714 WindowsVersionType.tp_new = NULL; |
| 1706 #endif | 1715 #endif |
| 1707 | 1716 |
