From 26610ba80c700abc46142d24d837e17835256cef Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Thu, 19 Dec 2019 01:18:11 +0100 Subject: [PATCH] Fixe bad Python exception catch for C-launched scripts. * In Hurricane::Viewer::Script::runFunction() & callFunction(), when the script returns NULL, do not immediately return but first check if an exception has been set. If so, print it *then* clear it. Due to not clearing the exception we where seeing one later with no relation to the true problem. * In Oroshi/python/Rules.py, a bad test structure was discarting all the "no layer rule with physical length" in the loading process. It was blocked by the physical unit rule special cases. --- hurricane/src/analog/LayoutGenerator.cpp | 6 ++++++ hurricane/src/viewer/Script.cpp | 16 ++++++++++------ oroshi/python/Rules.py | 16 ++++++++-------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/hurricane/src/analog/LayoutGenerator.cpp b/hurricane/src/analog/LayoutGenerator.cpp index e15c3843..546aff5b 100644 --- a/hurricane/src/analog/LayoutGenerator.cpp +++ b/hurricane/src/analog/LayoutGenerator.cpp @@ -202,6 +202,12 @@ namespace Analog { ) << endl; return false; } + if (not pCheckOk) { + cerr << Error( "%s\n A Python exception has occurred." + , _script->getFileName() + ) << endl; + return false; + } return true; } diff --git a/hurricane/src/viewer/Script.cpp b/hurricane/src/viewer/Script.cpp index 2bd2bb74..c0c8b487 100644 --- a/hurricane/src/viewer/Script.cpp +++ b/hurricane/src/viewer/Script.cpp @@ -136,15 +136,16 @@ namespace Isobar { _pyArgs = NULL; _pyKw = NULL; - if (_pyResult == NULL) { - cerr << "Something has gone slightly wrong" << endl; - } - if (PyErr_Occurred()) { PyErr_Print(); + PyErr_Clear(); returnCode = false; } + if (_pyResult == NULL) { + cerr << "Something has gone slightly wrong" << endl; + } + finalize(); return returnCode; @@ -167,13 +168,16 @@ namespace Isobar { _pyResult = PyObject_Call( _pyFunction, pyArgs, NULL ); + if (PyErr_Occurred()) { + PyErr_Print(); + PyErr_Clear(); + } + if (_pyResult == NULL) { cerr << "Something has gone slightly wrong" << endl; return NULL; } - if (PyErr_Occurred()) PyErr_Print(); - return _pyResult; } diff --git a/oroshi/python/Rules.py b/oroshi/python/Rules.py index 30726455..4296b15a 100644 --- a/oroshi/python/Rules.py +++ b/oroshi/python/Rules.py @@ -87,7 +87,7 @@ class Rules ( object ): , 'corrFactor90' , 'corrFactor135' , 'minRpolyhSquares' -] + ] def __init__ ( self, dtr ): trace( 100, '\tRules.__init__()\n' ) @@ -104,13 +104,13 @@ class Rules ( object ): words = attribute.split( '_' ) try: if len(words) == 1: - if words[0].endswith('Cap' ): value = self.dtr.getUnitRule( words[0] ).getValue() - if words[0].endswith('ContRes' ): value = self.dtr.getUnitRule( words[0] ).getValue() - if words[0].endswith('Res' ): value = self.dtr.getUnitRule( words[0] ).getValue() - if words[0].endswith('ctor90' ): value = self.dtr.getUnitRule( words[0] ).getValue() - if words[0].endswith('ctor135' ): value = self.dtr.getUnitRule( words[0] ).getValue() - if words[0].endswith('quares' ): value = self.dtr.getUnitRule( words[0] ).getValue() - elif len(words) < 4: + if words[0].endswith('Cap' ): value = self.dtr.getUnitRule( words[0] ).getValue() + elif words[0].endswith('ContRes' ): value = self.dtr.getUnitRule( words[0] ).getValue() + elif words[0].endswith('Res' ): value = self.dtr.getUnitRule( words[0] ).getValue() + elif words[0].endswith('ctor90' ): value = self.dtr.getUnitRule( words[0] ).getValue() + elif words[0].endswith('ctor135' ): value = self.dtr.getUnitRule( words[0] ).getValue() + elif words[0].endswith('quares' ): value = self.dtr.getUnitRule( words[0] ).getValue() + if (value is None) and len(words) < 4: value = self.dtr.getPhysicalRule( *tuple(words) ).getValue() except Exception, e: print e