int LLVMFuzzerInitialize(int *argc, char ***argv) {
- wchar_t* wide_program_name = Py_DecodeLocale(*argv[0], NULL);
- Py_SetProgramName(wide_program_name);
+ PyConfig config;
+ PyConfig_InitPythonConfig(&config);
+ config.install_signal_handlers = 0;
+ PyStatus status;
+ status = PyConfig_SetBytesString(&config, &config.program_name, *argv[0]);
+ if (PyStatus_Exception(status)) {
+ goto fail;
+ }
+
+ status = Py_InitializeFromConfig(&config);
+ if (PyStatus_Exception(status)) {
+ goto fail;
+ }
+ PyConfig_Clear(&config);
+
return 0;
+
+fail:
+ PyConfig_Clear(&config);
+ Py_ExitStatusException(status);
}
/* Fuzz test interface.
(And we bitwise or when running multiple tests to verify that normally we
only return 0.) */
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
- if (!Py_IsInitialized()) {
- /* LLVMFuzzerTestOneInput is called repeatedly from the same process,
- with no separate initialization phase, sadly, so we need to
- initialize CPython ourselves on the first run. */
- Py_InitializeEx(0);
- }
+ assert(Py_IsInitialized());
int rv = 0;