From 438634b718374f3e6eaaa77c7cf8397c6f47eb28 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Thu, 22 Nov 2018 13:47:37 +0000 Subject: [PATCH] nicer python error log errors. git-svn-id: file:///svn/unbound/trunk@4970 be551aaa-1e26-0410-a405-d3ace91eadb9 --- pythonmod/pythonmod.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pythonmod/pythonmod.c b/pythonmod/pythonmod.c index a17d977e9..a668ecc23 100644 --- a/pythonmod/pythonmod.c +++ b/pythonmod/pythonmod.c @@ -115,6 +115,7 @@ static void log_py_err(void) { char *result = NULL; + const char* iomod = "cStringIO"; PyObject *modStringIO = NULL; PyObject *modTB = NULL; PyObject *obFuncStringIO = NULL; @@ -133,10 +134,16 @@ log_py_err(void) /* Import the modules we need - cStringIO and traceback */ modStringIO = PyImport_ImportModule("cStringIO"); - if (modStringIO==NULL) /* python 1.4 and before */ + if (modStringIO==NULL) { + /* python 1.4 and before */ modStringIO = PyImport_ImportModule("StringIO"); - if (modStringIO==NULL) /* python 3 */ + iomod = "StringIO"; + } + if (modStringIO==NULL) { + /* python 3 */ modStringIO = PyImport_ImportModule("io"); + iomod = "io"; + } if (modStringIO==NULL) { log_err("pythonmod: cannot print exception, " "cannot ImportModule cStringIO or StringIO or io"); @@ -153,13 +160,13 @@ log_py_err(void) obFuncStringIO = PyObject_GetAttrString(modStringIO, "StringIO"); if (obFuncStringIO==NULL) { log_err("pythonmod: cannot print exception, " - "cannot GetAttrString cStringIO.StringIO"); + "cannot GetAttrString %s.StringIO", iomod); goto cleanup; } obStringIO = PyObject_CallObject(obFuncStringIO, NULL); if (obStringIO==NULL) { log_err("pythonmod: cannot print exception, " - "cannot call cStringIO.StringIO()"); + "cannot call %s.StringIO()", iomod); goto cleanup; } @@ -192,21 +199,21 @@ log_py_err(void) obFuncStringIO = PyObject_GetAttrString(obStringIO, "getvalue"); if (obFuncStringIO==NULL) { log_err("pythonmod: cannot print exception, " - "cannot GetAttrString cStringIO.getvalue"); + "cannot GetAttrString StringIO.getvalue"); goto cleanup; } Py_DECREF(obResult); obResult = PyObject_CallObject(obFuncStringIO, NULL); if (obResult==NULL) { log_err("pythonmod: cannot print exception, " - "call cStringIO.getvalue() failed"); + "call StringIO.getvalue() failed"); goto cleanup; } /* And it should be a string all ready to go - duplicate it. */ if (!PyString_Check(obResult) && !PyUnicode_Check(obResult)) { log_err("pythonmod: cannot print exception, " - "cStringIO.getvalue() result did not String_Check" + "StringIO.getvalue() result did not String_Check" " or Unicode_Check"); goto cleanup; } -- 2.47.3