@@ -2037,36 +2037,43 @@ _clear_preinit_entries(_Py_PreInitEntry *optionlist)
20372037 PyMem_SetAllocator (PYMEM_DOMAIN_RAW , & old_alloc );
20382038}
20392039
2040- static void
2041- _clear_all_preinit_options (void )
2040+
2041+ PyStatus
2042+ _PySys_ReadPreinitWarnOptions (PyConfig * config )
20422043{
2044+ PyStatus status ;
2045+ _Py_PreInitEntry entry ;
2046+
2047+ for (entry = _preinit_warnoptions ; entry != NULL ; entry = entry -> next ) {
2048+ status = PyWideStringList_Append (& config -> warnoptions , entry -> value );
2049+ if (_PyStatus_EXCEPTION (status )) {
2050+ return status ;
2051+ }
2052+ }
2053+
20432054 _clear_preinit_entries (& _preinit_warnoptions );
2044- _clear_preinit_entries ( & _preinit_xoptions );
2055+ return _PyStatus_OK ( );
20452056}
20462057
2047- static int
2048- sys_read_preinit_options (PyThreadState * tstate )
2058+
2059+ PyStatus
2060+ _PySys_ReadPreinitXOptions (PyConfig * config )
20492061{
2050- /* Rerun the add commands with the actual sys module available */
2051- if (tstate == NULL ) {
2052- /* Still don't have a thread state, so something is wrong! */
2053- return -1 ;
2054- }
2055- _Py_PreInitEntry entry = _preinit_warnoptions ;
2056- while (entry != NULL ) {
2057- PySys_AddWarnOption (entry -> value );
2058- entry = entry -> next ;
2059- }
2060- entry = _preinit_xoptions ;
2061- while (entry != NULL ) {
2062- PySys_AddXOption (entry -> value );
2063- entry = entry -> next ;
2062+ PyStatus status ;
2063+ _Py_PreInitEntry entry ;
2064+
2065+ for (entry = _preinit_xoptions ; entry != NULL ; entry = entry -> next ) {
2066+ status = PyWideStringList_Append (& config -> xoptions , entry -> value );
2067+ if (_PyStatus_EXCEPTION (status )) {
2068+ return status ;
2069+ }
20642070 }
20652071
2066- _clear_all_preinit_options ( );
2067- return 0 ;
2072+ _clear_preinit_entries ( & _preinit_xoptions );
2073+ return _PyStatus_OK () ;
20682074}
20692075
2076+
20702077static PyObject *
20712078get_warnoptions (PyThreadState * tstate )
20722079{
@@ -2235,9 +2242,7 @@ PySys_AddXOption(const wchar_t *s)
22352242 }
22362243 if (_PySys_AddXOptionWithError (s ) < 0 ) {
22372244 /* No return value, therefore clear error state if possible */
2238- if (tstate ) {
2239- _PyErr_Clear (tstate );
2240- }
2245+ _PyErr_Clear (tstate );
22412246 }
22422247}
22432248
@@ -2898,11 +2903,6 @@ _PySys_InitMain(_PyRuntimeState *runtime, PyThreadState *tstate)
28982903 if (get_xoptions (tstate ) == NULL )
28992904 return -1 ;
29002905
2901- /* Transfer any sys.warnoptions and sys._xoptions set directly
2902- * by an embedding application from the linked list to the module. */
2903- if (sys_read_preinit_options (tstate ) != 0 )
2904- return -1 ;
2905-
29062906 if (_PyErr_Occurred (tstate )) {
29072907 goto err_occurred ;
29082908 }
0 commit comments