Skip to content

Commit

Permalink
Fix crash when restarting with python.mod loaded
Browse files Browse the repository at this point in the history
Found by: aleksandrov89
Patch by: michaelortmann
  • Loading branch information
michaelortmann authored Dec 1, 2024
1 parent 1e56584 commit 1d4c009
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ static void mainloop(int toplevel)
if (strcmp(p->name, "eggdrop") && strcmp(p->name, "encryption") &&
strcmp(p->name, "encryption2") && strcmp(p->name, "uptime")) {
f++;
debug1("stagnant module %s", p->name);
putlog(LOG_MISC, "*", "stagnant module %s", p->name);
}
}
if (f != 0) {
Expand Down
5 changes: 2 additions & 3 deletions src/mod/python.mod/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@ distclean: clean
../../../src/compat/inet_aton.h ../../../src/compat/snprintf.h \
../../../src/compat/explicit_bzero.h ../../../src/compat/strlcpy.h \
../../../src/mod/modvals.h ../../../src/tandem.h \
../../../src/mod/irc.mod/irc.h ../../../src/mod/server.mod/server.h \
.././python.mod/python.h .././python.mod/pycmds.c \
.././python.mod/tclpython.c
../../../src/mod/server.mod/server.h .././python.mod/python.h \
.././python.mod/pycmds.c .././python.mod/tclpython.c
33 changes: 13 additions & 20 deletions src/mod/python.mod/python.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@
#undef days
#include <Python.h>
#include <datetime.h>
#include "src/mod/irc.mod/irc.h"
#include "src/mod/server.mod/server.h"
#include "python.h"

//static PyObject *pymodobj;
static PyObject *pirp, *pglobals;

#undef global
static Function *global = NULL, *irc_funcs = NULL;
static Function *global = NULL;
static PyThreadState *_pythreadsave;
#include "pycmds.c"
#include "tclpython.c"
Expand Down Expand Up @@ -141,33 +140,27 @@ static Function python_table[] = {
char *python_start(Function *global_funcs)
{
char *s;

/* Assign the core function table. After this point you use all normal
* functions defined in src/mod/modules.h
*/
global = global_funcs;

/* Register the module. */
module_register(MODULE_NAME, python_table, 0, 1);

if (!module_depend(MODULE_NAME, "eggdrop", 109, 0)) {
module_undepend(MODULE_NAME);
return "This module requires Eggdrop 1.9.0 or later.";
}
// TODO: Is this dependency necessary? It auto-loads irc.mod, that might be undesired
if (!(irc_funcs = module_depend(MODULE_NAME, "irc", 1, 5))) {
module_undepend(MODULE_NAME);
return "This module requires irc module 1.5 or later.";
if (global_funcs) {
global = global_funcs;

/* Register the module. */
module_register(MODULE_NAME, python_table, 0, 1);
if (!module_depend(MODULE_NAME, "eggdrop", 109, 0)) {
module_undepend(MODULE_NAME);
return "This module requires Eggdrop 1.9.0 or later.";
}
if ((s = init_python()))
return s;
}
// irc.mod depends on server.mod and channels.mod, so those were implicitly loaded

if ((s = init_python()))
return s;

/* Add command table to bind list */
add_builtins(H_dcc, mydcc);
add_tcl_commands(my_tcl_cmds);
add_hook(HOOK_PRE_SELECT, (Function)python_gil_unlock);
add_hook(HOOK_POST_SELECT, (Function)python_gil_lock);

return NULL;
}

0 comments on commit 1d4c009

Please sign in to comment.