@@ -411,9 +411,26 @@ int __lsan_is_turned_off(void) { return 1; }
411411
412412
413413int LLVMFuzzerInitialize (int * argc , char * * * argv ) {
414- wchar_t * wide_program_name = Py_DecodeLocale (* argv [0 ], NULL );
415- Py_SetProgramName (wide_program_name );
414+ PyConfig config ;
415+ PyConfig_InitPythonConfig (& config );
416+ config .install_signal_handlers = 0 ;
417+ PyStatus status ;
418+ status = PyConfig_SetBytesString (& config , & config .program_name , * argv [0 ]);
419+ if (PyStatus_Exception (status )) {
420+ goto fail ;
421+ }
422+
423+ status = Py_InitializeFromConfig (& config );
424+ if (PyStatus_Exception (status )) {
425+ goto fail ;
426+ }
427+ PyConfig_Clear (& config );
428+
416429 return 0 ;
430+
431+ fail :
432+ PyConfig_Clear (& config );
433+ Py_ExitStatusException (status );
417434}
418435
419436/* Fuzz test interface.
@@ -424,12 +441,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) {
424441 (And we bitwise or when running multiple tests to verify that normally we
425442 only return 0.) */
426443int LLVMFuzzerTestOneInput (const uint8_t * data , size_t size ) {
427- if (!Py_IsInitialized ()) {
428- /* LLVMFuzzerTestOneInput is called repeatedly from the same process,
429- with no separate initialization phase, sadly, so we need to
430- initialize CPython ourselves on the first run. */
431- Py_InitializeEx (0 );
432- }
444+ assert (Py_IsInitialized ());
433445
434446 int rv = 0 ;
435447
0 commit comments