From 5d08d5e27c1d2430ba25f6903d47d7acb422f144 Mon Sep 17 00:00:00 2001 From: Emmanuel Bouthenot Date: Mon, 8 May 2006 20:22:42 +0000 Subject: [PATCH] - fix a crash in ruby when a function return nothing (close bug #16552) - add a warning when a function return nothing (python, ruby) --- src/plugins/scripts/python/weechat-python.c | 10 ++++++++-- src/plugins/scripts/ruby/weechat-ruby.c | 6 ++++++ weechat/src/plugins/scripts/python/weechat-python.c | 10 ++++++++-- weechat/src/plugins/scripts/ruby/weechat-ruby.c | 6 ++++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c index 4e50072a7..8f024fde4 100644 --- a/src/plugins/scripts/python/weechat-python.c +++ b/src/plugins/scripts/python/weechat-python.c @@ -91,14 +91,20 @@ weechat_python_exec (t_weechat_plugin *plugin, else rc = PyObject_CallFunction (evFunc, ""); + + if (rc == Py_None) + { + python_plugin->print_server (python_plugin, "Python error: function \"%s\" must return a valid value", function); + return PLUGIN_RC_OK; + } + if (rc) { ret = (int) PyInt_AsLong(rc); Py_XDECREF(rc); } - if (PyErr_Occurred ()) - PyErr_Print (); + if (PyErr_Occurred ()) PyErr_Print (); if (ret < 0) return PLUGIN_RC_OK; diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c index 8a35cbf5a..6e0767f6b 100644 --- a/src/plugins/scripts/ruby/weechat-ruby.c +++ b/src/plugins/scripts/ruby/weechat-ruby.c @@ -153,6 +153,12 @@ weechat_ruby_exec (t_weechat_plugin *plugin, return PLUGIN_RC_KO; } + + if (ruby_retcode == Qnil) + { + ruby_plugin->print_server (ruby_plugin, "Ruby error: function \"%s\" must return a valid value", function); + return PLUGIN_RC_OK; + } return NUM2INT(ruby_retcode); } diff --git a/weechat/src/plugins/scripts/python/weechat-python.c b/weechat/src/plugins/scripts/python/weechat-python.c index 4e50072a7..8f024fde4 100644 --- a/weechat/src/plugins/scripts/python/weechat-python.c +++ b/weechat/src/plugins/scripts/python/weechat-python.c @@ -91,14 +91,20 @@ weechat_python_exec (t_weechat_plugin *plugin, else rc = PyObject_CallFunction (evFunc, ""); + + if (rc == Py_None) + { + python_plugin->print_server (python_plugin, "Python error: function \"%s\" must return a valid value", function); + return PLUGIN_RC_OK; + } + if (rc) { ret = (int) PyInt_AsLong(rc); Py_XDECREF(rc); } - if (PyErr_Occurred ()) - PyErr_Print (); + if (PyErr_Occurred ()) PyErr_Print (); if (ret < 0) return PLUGIN_RC_OK; diff --git a/weechat/src/plugins/scripts/ruby/weechat-ruby.c b/weechat/src/plugins/scripts/ruby/weechat-ruby.c index 8a35cbf5a..6e0767f6b 100644 --- a/weechat/src/plugins/scripts/ruby/weechat-ruby.c +++ b/weechat/src/plugins/scripts/ruby/weechat-ruby.c @@ -153,6 +153,12 @@ weechat_ruby_exec (t_weechat_plugin *plugin, return PLUGIN_RC_KO; } + + if (ruby_retcode == Qnil) + { + ruby_plugin->print_server (ruby_plugin, "Ruby error: function \"%s\" must return a valid value", function); + return PLUGIN_RC_OK; + } return NUM2INT(ruby_retcode); }