Skip to content

Commit

Permalink
remove DecodeLocale
Browse files Browse the repository at this point in the history
  • Loading branch information
vanosg committed Jan 2, 2024
1 parent e6e8db5 commit af7362f
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/mod/python.mod/python.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/*
* twitch.c -- part of twitch.mod
* will cease to work. Buyer beware.
*
* Originally written by Geo April 2020
* python.c -- part of python.mod
*/

/*
Expand All @@ -25,6 +22,7 @@

#define MODULE_NAME "python"
#define MAKING_PYTHON
#define PY_SSIZE_T_CLEAN /* Not required for 3.13+ but here for back compat */

#define ARRAYCOUNT(x) (sizeof (x) / sizeof *(x))

Expand Down Expand Up @@ -68,24 +66,17 @@ static void init_python() {
PyObject *pmodule;
PyStatus status;
PyConfig config;
wchar_t *program;

if (PY_VERSION_HEX < 0x0308) {
fprintf(stderr, "Python: Python version %d is lower than 3.8, not loading Python module", PY_VERSION_HEX);
return;
}
PyConfig_InitPythonConfig(&config);
program = Py_DecodeLocale(argv0, NULL);
if (!program) {
PyConfig_Clear(&config);
fprintf(stderr, "Python: Fatal error: This should never happen\n");
fatal(1);
}
status = PyConfig_SetString(&config, &config.program_name, program);
status = PyConfig_SetBytesString(&config, &config.program_name, argv0);
if (PyStatus_Exception(status)) {
PyConfig_Clear(&config);
fprintf(stderr, "Python: Fatal error: Could not set program base path\n");
fatal(1);
Py_ExitStatusException(status);
}
if (PyImport_AppendInittab("eggdrop", &PyInit_eggdrop) == -1) {
fprintf(stderr, "Error: could not extend in-built modules table\n");
Expand All @@ -97,6 +88,7 @@ static void init_python() {
fprintf(stderr, "Python: Fatal error: Could not initialize config\n");
fatal(1);
}
PyConfig_Clear(&config);
PyDateTime_IMPORT;
pmodule = PyImport_ImportModule("eggdrop");
if (!pmodule) {
Expand All @@ -119,7 +111,6 @@ static void kill_python() {
if (Py_FinalizeEx() < 0) {
exit(120);
}
PyMem_RawFree(Py_DecodeLocale("eggdrop", NULL));
return;
}

Expand Down

0 comments on commit af7362f

Please sign in to comment.