@@ -297,35 +297,24 @@ _PyPreConfig_InitIsolatedConfig(_PyPreConfig *config)
297297}
298298
299299
300- int
300+ void
301301_PyPreConfig_Copy (_PyPreConfig * config , const _PyPreConfig * config2 )
302302{
303303#define COPY_ATTR (ATTR ) config->ATTR = config2->ATTR
304- #define COPY_STR_ATTR (ATTR ) \
305- do { \
306- if (config2->ATTR != NULL) { \
307- config->ATTR = _PyMem_RawStrdup(config2->ATTR); \
308- if (config->ATTR == NULL) { \
309- return -1; \
310- } \
311- } \
312- } while (0)
313304
314305 COPY_ATTR (isolated );
315306 COPY_ATTR (use_environment );
316307 COPY_ATTR (configure_locale );
317308 COPY_ATTR (dev_mode );
318309 COPY_ATTR (coerce_c_locale );
319310 COPY_ATTR (coerce_c_locale_warn );
311+ COPY_ATTR (utf8_mode );
312+ COPY_ATTR (allocator );
320313#ifdef MS_WINDOWS
321314 COPY_ATTR (legacy_windows_fs_encoding );
322315#endif
323- COPY_ATTR (utf8_mode );
324- COPY_ATTR (allocator );
325316
326317#undef COPY_ATTR
327- #undef COPY_STR_ATTR
328- return 0 ;
329318}
330319
331320
@@ -750,9 +739,7 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
750739 /* Save the config to be able to restore it if encodings change */
751740 _PyPreConfig save_config ;
752741 _PyPreConfig_Init (& save_config );
753- if (_PyPreConfig_Copy (& save_config , config ) < 0 ) {
754- return _Py_INIT_NO_MEMORY ();
755- }
742+ _PyPreConfig_Copy (& save_config , config );
756743
757744 /* Set LC_CTYPE to the user preferred locale */
758745 if (config -> configure_locale ) {
@@ -835,10 +822,7 @@ _PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
835822 just keep UTF-8 Mode value. */
836823 int new_utf8_mode = config -> utf8_mode ;
837824 int new_coerce_c_locale = config -> coerce_c_locale ;
838- if (_PyPreConfig_Copy (config , & save_config ) < 0 ) {
839- err = _Py_INIT_NO_MEMORY ();
840- goto done ;
841- }
825+ _PyPreConfig_Copy (config , & save_config );
842826 config -> utf8_mode = new_utf8_mode ;
843827 config -> coerce_c_locale = new_coerce_c_locale ;
844828
@@ -900,13 +884,7 @@ _PyPreConfig_Write(const _PyPreConfig *config)
900884 }
901885
902886 /* Write the new pre-configuration into _PyRuntime */
903- PyMemAllocatorEx old_alloc ;
904- _PyMem_SetDefaultAllocator (PYMEM_DOMAIN_RAW , & old_alloc );
905- int res = _PyPreConfig_Copy (& _PyRuntime .preconfig , config );
906- PyMem_SetAllocator (PYMEM_DOMAIN_RAW , & old_alloc );
907- if (res < 0 ) {
908- return _Py_INIT_NO_MEMORY ();
909- }
887+ _PyPreConfig_Copy (& _PyRuntime .preconfig , config );
910888
911889 return _Py_INIT_OK ();
912890}
0 commit comments