Skip to content

Commit

Permalink
Undo accidental python.mod changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thommey committed Jun 15, 2024
1 parent 5f046d3 commit 99da770
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 22 deletions.
16 changes: 1 addition & 15 deletions src/mod/python.mod/pycmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ static PyObject *py_displayhook(PyObject *self, PyObject *o) {
Py_RETURN_NONE;
}

// Safety: only callable in main thread
static void cmd_python(struct userrec *u, int idx, char *par) {
PyObject *pobj, *ptype, *pvalue, *ptraceback;
PyObject *pystr, *module_name, *pymodule, *pyfunc, *pyval, *item;
Expand Down Expand Up @@ -139,7 +138,6 @@ static PyObject *py_findircuser(PyObject *self, PyObject *args) {
Py_RETURN_NONE;
}

// Safety: Python GIL?
static int tcl_call_python(ClientData cd, Tcl_Interp *irp, int objc, Tcl_Obj *const objv[])
{
PyObject *args = PyTuple_New(objc > 1 ? objc - 1: 0);
Expand Down Expand Up @@ -316,16 +314,12 @@ static Tcl_Obj *py_to_tcl_obj(PyObject *o) {
}
}

// Safety: One thread at a time, main thread must be in select() or calling this
static PyObject *python_call_tcl(PyObject *self, PyObject *args, PyObject *kwargs) {
pthread_mutex_lock(&tclmtx);

TclFunc *tf = (TclFunc *)self;
Py_ssize_t argc = PyTuple_Size(args);
Tcl_DString ds;
const char *result;
int retcode;
PyObject *ret;

Tcl_DStringInit(&ds);
Tcl_DStringAppendElement(&ds, tf->tclcmdname);
Expand All @@ -337,24 +331,19 @@ static PyObject *python_call_tcl(PyObject *self, PyObject *args, PyObject *kwarg

if (retcode != TCL_OK) {
PyErr_Format(EggdropError, "Tcl error: %s", Tcl_GetStringResult(tclinterp));
pthread_mutex_unlock(&tclmtx);
return NULL;
}
result = Tcl_GetStringResult(tclinterp);
//putlog(LOG_MISC, "*", "Python called '%s' -> '%s'", Tcl_DStringValue(&ds), result);

if (!*result) {
// Empty string means okay
pthread_mutex_unlock(&tclmtx);
Py_RETURN_NONE;
}

ret = PyUnicode_DecodeUTF8(result, strlen(result), NULL);
pthread_mutex_unlock(&tclmtx);
return ret;
return PyUnicode_DecodeUTF8(result, strlen(result), NULL);
}

// Safety: One thread at a time, main thread must be in select() or calling this
static PyObject *py_findtclfunc(PyObject *self, PyObject *args) {
char *cmdname;
TclFunc *result;
Expand All @@ -363,16 +352,13 @@ static PyObject *py_findtclfunc(PyObject *self, PyObject *args) {
PyErr_SetString(EggdropError, "wrong arguments");
return NULL;
}
pthread_mutex_lock(&tclmtx);
// TODO: filter a bit better what is available to Python, specify return types ("list of string"), etc.
if (!(Tcl_FindCommand(tclinterp, cmdname, NULL, TCL_GLOBAL_ONLY))) {
PyErr_SetString(PyExc_AttributeError, cmdname);
pthread_mutex_unlock(&tclmtx);
return NULL;
}
result = PyObject_New(TclFunc, &TclFuncType);
strcpy(result->tclcmdname, cmdname);
pthread_mutex_unlock(&tclmtx);
return (PyObject *)result;
}

Expand Down
6 changes: 0 additions & 6 deletions src/mod/python.mod/python.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

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

#undef global
static Function *global = NULL, *irc_funcs = NULL;
Expand All @@ -56,7 +55,6 @@ static int python_expmem()

// TODO: Do we really have to exit eggdrop on module load failure?
static void init_python() {
pthread_mutexattr_t mtxattr;
PyObject *pmodule;
PyStatus status;
PyConfig config;
Expand Down Expand Up @@ -102,10 +100,6 @@ static void init_python() {
PyRun_SimpleString("import eggdrop");
PyRun_SimpleString("sys.displayhook = eggdrop.__displayhook__");

pthread_mutexattr_init(&mtxattr);
pthread_mutexattr_settype(&mtxattr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&tclmtx, &mtxattr);

return;
}

Expand Down
1 change: 0 additions & 1 deletion src/mod/python.mod/tclpython.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

// Safety: only callable from main thread
static int tcl_pysource STDVAR
{
FILE *fp;
Expand Down

0 comments on commit 99da770

Please sign in to comment.