plugin python: Adjust the handling after PyRun_String() failed
PATCH 1/1 plugin python: Adjust the handling after PyRun_String() failed
Even though PyRun_String() failed,
just 0 will be returned but we need to return -1
that means error status, so fix it.
--- plugin_python.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
plugin_python.c +3 -2
@@ -24,7 +24,7 @@ static int load_plugin(struct pevent *pevent, const char *path, const char *name, void *data) { PyObject *globals = data; -int err; +int err, ret =0 ;int len =strlen (path) +strlen (name) +2 ;int nlen =strlen (name) +1 ;char *full =malloc (len);
@@ -50,12 +50,13 @@ static int load_plugin(struct pevent *pevent, const char *path,if (!res) {fprintf (stderr,"failed loading %s\n" , full);PyErr_Print (); + ret =-1 ; }else Py_DECREF (res);free (load); -return 0 ; +return ret; }int PEVENT_PLUGIN_LOADER (struct pevent *pevent)
Signature · 1 line
2.7.4
Quoted 14 lines · On Thu, 27 Apr 2017 08:46:21 +0900 Taeung Song <[email protected]> wrote:
Even though
PyRun_String()failed,
just 0 will be returned but we need to return -1
that means error status, so fix it.Signed-off-by Taeung Song <[email protected]>--- plugin_python.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)plugin_python.c +0
-0
plugin_python.c static int load_plugin(struct pevent *pevent, const char *path, · line 27
Quoted 5 lines
plugin_python.c +1
-1@@ -24,7 +24,7 @@ static int load_plugin(struct pevent *pevent, const char *path, const char *name, void *data) { PyObject *globals = data; -int err; +int err, ret =0 ;
Hmm, we can either reuse err.
Quoted 5 lines
plugin_python.c +0
-0int len =strlen (path) +strlen (name) +2 ;int nlen =strlen (name) +1 ;char *full =malloc (len);@@ -50,12 +50,13 @@ static int load_plugin(struct pevent *pevent, const char *path,if (!res) {
plugin_python.c static int load_plugin(struct pevent *pevent, const char *path, · line 59
Quoted 10 lines
plugin_python.c +2
-1fprintf (stderr,"failed loading %s\n" , full);PyErr_Print (); + ret =-1 ; }else Py_DECREF (res);free (load); -return 0 ; +return ret;
or do a: return res ? 0 : -1;
-- Steve
Quoted 3 lines
plugin_python.c +0
-0}int PEVENT_PLUGIN_LOADER (struct pevent *pevent)
Quoted 12 lines · Steven Rostedt
Quoted 9 lines · On Thu, 27 Apr 2017 08:46:21 +0900 Taeung Song <[email protected]> wrote:
Even though
PyRun_String()failed,
just 0 will be returned but we need to return -1
that means error status, so fix it.Signed-off-by Taeung Song <[email protected]>--- plugin_python.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 13 lines
plugin_python.c static int load_plugin(struct pevent *pevent, const char *path, · line 27
Quoted 10 lines
plugin_python.c +1
-1@@ -24,7 +24,7 @@ static int load_plugin(struct pevent *pevent, const char *path, const char *name, void *data) { PyObject *globals = data; -int err; +int err, ret =0 ;Hmm, we can either reuse err.
But return value of asprintf() can be more 1,
when it succeeded.
So I think it is better the below you said.
Quoted 11 lines
Quoted 11 lines
plugin_python.c +1
-0int len =strlen (path) +strlen (name) +2 ;int nlen =strlen (name) +1 ;char *full =malloc (len);@@ -50,12 +50,13 @@ static int load_plugin(struct pevent *pevent, const char *path,if (!res) {fprintf (stderr,"failed loading %s\n" , full);PyErr_Print (); + ret =-1 ; }else Py_DECREF (res);
Quoted 9 lines
plugin_python.c static int load_plugin(struct pevent *pevent, const char *path, · line 59
Quoted 4 lines
plugin_python.c +1
-1free (load); -return 0 ; +return ret;or do a: return res ? 0 : -1;
-- Steve
Okey! I'll resent the patch after modifying this!
Thanks,
Taeung
Quoted 27 lines · On Thu, 27 Apr 2017 11:52:14 +0900 Taeung Song <[email protected]> wrote:
Quoted 12 lines · Steven Rostedt
Quoted 9 lines · On Thu, 27 Apr 2017 08:46:21 +0900 Taeung Song <[email protected]> wrote:
Even though
PyRun_String()failed,
just 0 will be returned but we need to return -1
that means error status, so fix it.Signed-off-by Taeung Song <[email protected]>--- plugin_python.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)Quoted 13 lines
plugin_python.c static int load_plugin(struct pevent *pevent, const char *path, · line 27
Quoted 10 lines
plugin_python.c +1
-1@@ -24,7 +24,7 @@ static int load_plugin(struct pevent *pevent, const char *path, const char *name, void *data) { PyObject *globals = data; -int err; +int err, ret =0 ;Hmm, we can either reuse err.
Quoted 3 lines
But return value of
asprintf()can be more 1,
when it succeeded.
So I think it is better the below you said.
What I meant was to simply reset err = 0; and set it if we failed and returned that. No need to add more variables.
Quoted 19 lines
Quoted 19 lines
Quoted 6 lines
plugin_python.c +0
-0int len =strlen (path) +strlen (name) +2 ;int nlen =strlen (name) +1 ;char *full =malloc (len);@@ -50,12 +50,13 @@ static int load_plugin(struct pevent *pevent, const char *path,if (!res) {plugin_python.c static int load_plugin(struct pevent *pevent, const char *path, · line 59
Quoted 10 lines
plugin_python.c +2
-1fprintf (stderr,"failed loading %s\n" , full);PyErr_Print (); + ret =-1 ; }else Py_DECREF (res);free (load); -return 0 ; +return ret;or do a: return res ? 0 : -1;
Quoted 4 lines
Quoted 2 lines
-- Steve
Okey! I'll resent the patch after modifying this!
But this is fine as well.
-- Steve
Quoted 30 lines · Steven Rostedt
Quoted 27 lines · On Thu, 27 Apr 2017 11:52:14 +0900 Taeung Song <[email protected]> wrote:
Quoted 25 lines · Steven Rostedt
Quoted 14 lines · On Thu, 27 Apr 2017 08:46:21 +0900 Taeung Song <[email protected]> wrote:
Even though
PyRun_String()failed,
just 0 will be returned but we need to return -1
that means error status, so fix it.Signed-off-by Taeung Song <[email protected]>--- plugin_python.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)plugin_python.c +0
-0plugin_python.c static int load_plugin(struct pevent *pevent, const char *path, · line 27
Quoted 5 lines
plugin_python.c +1
-1@@ -24,7 +24,7 @@ static int load_plugin(struct pevent *pevent, const char *path, const char *name, void *data) { PyObject *globals = data; -int err; +int err, ret =0 ;Hmm, we can either reuse err.
Quoted 7 lines
Quoted 3 lines
But return value of
asprintf()can be more 1,
when it succeeded.
So I think it is better the below you said.What I meant was to simply reset err = 0; and set it if we failed and returned that. No need to add more variables.
I understood ! :)
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 6 lines
plugin_python.c +0
-0int len =strlen (path) +strlen (name) +2 ;int nlen =strlen (name) +1 ;char *full =malloc (len);@@ -50,12 +50,13 @@ static int load_plugin(struct pevent *pevent, const char *path,if (!res) {plugin_python.c static int load_plugin(struct pevent *pevent, const char *path, · line 59
Quoted 10 lines
plugin_python.c +2
-1fprintf (stderr,"failed loading %s\n" , full);PyErr_Print (); + ret =-1 ; }else Py_DECREF (res);free (load); -return 0 ; +return ret;or do a: return res ? 0 : -1;
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
-- Steve
Okey! I'll resent the patch after modifying this!
But this is fine as well.
-- Steve
Thank you !!
Have a nice day :)
Taeung