diff --git a/crlcore/src/pyCRL/PyCellGauge.cpp b/crlcore/src/pyCRL/PyCellGauge.cpp index 95d04f2c..9e6a20c1 100644 --- a/crlcore/src/pyCRL/PyCellGauge.cpp +++ b/crlcore/src/pyCRL/PyCellGauge.cpp @@ -39,6 +39,8 @@ namespace CRL { using Isobar::ParseOneArg; using Isobar::ParseTwoArg; using Isobar::__cs; + using Isobar::PyAny_AsLong; + using Isobar::PyDbU_FromLong; extern "C" { @@ -69,23 +71,23 @@ extern "C" { HTRY char* name; char* pinLayerName; - long pitch; - long sliceHeight; - long sliceStep; + PyObject* pyPitch = NULL; + PyObject* pySliceHeight = NULL; + PyObject* pySliceStep = NULL; if (PyArg_ParseTuple( args - , "sslll:CellGauge.create" + , "ssOOO:CellGauge.create" , &name , &pinLayerName - , &pitch - , &sliceHeight - , &sliceStep + , &pyPitch + , &pySliceHeight + , &pySliceStep )) { cg = CellGauge::create( name , pinLayerName - , pitch - , sliceHeight - , sliceStep + , PyAny_AsLong(pyPitch) + , PyAny_AsLong(pySliceHeight) + , PyAny_AsLong(pySliceStep) ); } else { PyErr_SetString ( ConstructorError, "Bad parameters given to CellGauge.create()." ); diff --git a/crlcore/src/pyCRL/PyRoutingLayerGauge.cpp b/crlcore/src/pyCRL/PyRoutingLayerGauge.cpp index a50a1eb0..3fb37ea6 100644 --- a/crlcore/src/pyCRL/PyRoutingLayerGauge.cpp +++ b/crlcore/src/pyCRL/PyRoutingLayerGauge.cpp @@ -43,6 +43,8 @@ namespace CRL { using Isobar::PyLayer; using Isobar::PyTypeLayer; using Isobar::PyLayer_LinkDerived; + using Isobar::PyAny_AsLong; + using Isobar::PyDbU_FromLong; extern "C" { @@ -71,24 +73,24 @@ extern "C" { int type; int depth; double density; - long offset; - long pitch; - long wireWidth; - long viaWidth; - long obsDw; + PyObject* pyOffset = NULL; + PyObject* pyPitch = NULL; + PyObject* pyWireWidth = NULL; + PyObject* pyViaWidth = NULL; + PyObject* pyObsDw = NULL; if (PyArg_ParseTuple( args - , "OIIIdlllll:RoutingLayerGauge.create" + , "OIIIdOOOOO:RoutingLayerGauge.create" , &pyLayer , &direction , &type , &depth , &density - , &offset - , &pitch - , &wireWidth - , &viaWidth - , &obsDw + , &pyOffset + , &pyPitch + , &pyWireWidth + , &pyViaWidth + , &pyObsDw )) { if ( not PyObject_IsInstance(pyLayer,(PyObject*)&PyTypeLayer) ) { PyErr_SetString ( ConstructorError, "Bad type for layer argument of RoutingLayerGauge.create()." ); @@ -114,11 +116,11 @@ extern "C" { , (Constant::LayerGaugeType)type , depth , density - , offset - , pitch - , wireWidth - , viaWidth - , obsDw + , PyAny_AsLong(pyOffset) + , PyAny_AsLong(pyPitch) + , PyAny_AsLong(pyWireWidth) + , PyAny_AsLong(pyViaWidth) + , PyAny_AsLong(pyObsDw) ); } else { PyErr_SetString ( ConstructorError, "Bad parameters given to RoutingLayerGauge.create()." ); @@ -177,11 +179,11 @@ extern "C" { HTRY METHOD_HEAD("RoutingLayerGauge.getTrackNumber()") - long start = 0; - long stop = 0; + PyObject* pyStart = NULL; + PyObject* pyStop = NULL; - if (PyArg_ParseTuple( args, "ll:RoutingLayerGauge.getTrackNumber", &start, &stop)) { - trackNumber = rlg->getTrackNumber( (DbU::Unit)start, (DbU::Unit)stop ); + if (PyArg_ParseTuple( args, "OO:RoutingLayerGauge.getTrackNumber", &pyStart, &pyStop)) { + trackNumber = rlg->getTrackNumber( PyAny_AsLong(pyStart), PyAny_AsLong(pyStop) ); } else { PyErr_SetString ( ConstructorError, "Bad parameters given to RoutingLayerGauge.getTrackNumber()." ); return NULL; @@ -201,12 +203,12 @@ extern "C" { HTRY METHOD_HEAD("RoutingLayerGauge.getTrackIndex()") - long start = 0; - long stop = 0; - long position = 0; - long mode = 0; + PyObject* pyStart = NULL; + PyObject* pyStop = NULL; + PyObject* pyPosition = NULL; + long mode = 0; - if (PyArg_ParseTuple( args, "lllI:RoutingLayerGauge.getTrackIndex", &start, &stop, &position, &mode)) { + if (PyArg_ParseTuple( args, "OOOI:RoutingLayerGauge.getTrackIndex", &pyStart, &pyStop, &pyPosition, &mode)) { switch(mode) { case Constant::Superior: case Constant::Inferior: @@ -216,9 +218,9 @@ extern "C" { PyErr_SetString ( ConstructorError, "RoutingLayerGauge.getTrackIndex(): The parameter has an invalid value ." ); return NULL; } - trackIndex = rlg->getTrackIndex( (DbU::Unit)start - , (DbU::Unit)stop - , (DbU::Unit)position + trackIndex = rlg->getTrackIndex( PyAny_AsLong(pyStart) + , PyAny_AsLong(pyStop) + , PyAny_AsLong(pyPosition) , (unsigned int)mode ); } else { PyErr_SetString ( ConstructorError, "Bad parameters given to RoutingLayerGauge.getTrackIndex()." ); @@ -239,18 +241,18 @@ extern "C" { HTRY METHOD_HEAD("RoutingLayerGauge.getTrackPosition()") - long start = 0; - unsigned int depth = 0; + PyObject* pyStart = NULL; + unsigned int depth = 0; - if (PyArg_ParseTuple( args, "lI:RoutingLayerGauge.getTrackIndex", &start, &depth)) { - trackPosition = rlg->getTrackNumber( (DbU::Unit)start , depth); + if (PyArg_ParseTuple( args, "OI:RoutingLayerGauge.getTrackIndex", &pyStart, &depth)) { + trackPosition = rlg->getTrackNumber( PyAny_AsLong(pyStart), depth); } else { PyErr_SetString ( ConstructorError, "Bad parameters given to RoutingLayerGauge.getTrackPosition()." ); return NULL; } HCATCH - return PyLong_FromLong((long)trackPosition); + return PyDbU_FromLong(trackPosition); } diff --git a/hurricane/src/hurricane/DbU.cpp b/hurricane/src/hurricane/DbU.cpp index 81f7227f..319b8954 100644 --- a/hurricane/src/hurricane/DbU.cpp +++ b/hurricane/src/hurricane/DbU.cpp @@ -54,8 +54,8 @@ namespace Hurricane { DbU::UnitPower DbU::_stringModeUnitPower = DbU::Nano; DbU::Unit DbU::_symbolicSnapGridStep = DbU::fromLambda( 1.0); DbU::Unit DbU::_realSnapGridStep = DbU::fromGrid (10.0); - const DbU::Unit DbU::Min = std::numeric_limits::min(); - const DbU::Unit DbU::Max = std::numeric_limits::max(); + const DbU::Unit DbU::Min = std::numeric_limits::min(); + const DbU::Unit DbU::Max = std::numeric_limits::max(); // ------------------------------------------------------------------- @@ -301,17 +301,18 @@ namespace Hurricane { string DbU::getValueString ( DbU::Unit u, int mode ) { - char buffer[1024]; - char unitPower = 'u'; - char unitSymbol = '\0'; + ostringstream os; + char unitPower = ' '; + char unitSymbol = 'u'; - if ( _stringMode == Grid ) { - unitPower = 'g'; - snprintf ( buffer, 1024, "%.1f", getGrid(u) ); - } else if ( _stringMode == Symbolic ) { - unitPower = 'l'; - snprintf ( buffer, 1024, "%.1f", getLambda(u) ); - } else if ( _stringMode == Physical ) { + os << fixed; + if (_stringMode == Grid) { + unitSymbol = 'g'; + os << setprecision(1) << toGrid(u); + } else if (_stringMode == Symbolic) { + unitSymbol = 'l'; + os << setprecision(1) << toLambda(u); + } else if (_stringMode == Physical) { unitSymbol = 'm'; switch ( _stringModeUnitPower ) { case Pico: unitPower = 'p'; break; @@ -322,42 +323,46 @@ namespace Hurricane { case Kilo: unitPower = 'k'; break; default: unitPower = '?'; break; } - snprintf ( buffer, 1024, "%.3f", getPhysical(u,_stringModeUnitPower) ); + os << setprecision(3) << toPhysical(u,_stringModeUnitPower); } else { - if ( _stringMode != Db ) + if (_stringMode != Db) cerr << "[ERROR] Unknown Unit representation mode: " << _stringMode << endl; - snprintf ( buffer, 1024, "%ld", u ); + os << u; } - size_t length = strlen(buffer) - 1; - if ( mode & SmartTruncate ) { - for ( ; length > 0 ; length-- ) { - if ( buffer[length] == '.' ) { length--; break; } - if ( buffer[length] != '0' ) break; + string s = os.str(); + if (mode & SmartTruncate) { + + size_t dot = s.rfind( '.' ); + if (dot != string::npos) { + size_t end = dot+1; + for ( ; end < s.size() ; ++end ) if (s[end] != '0') break; + if (end == s.size()) s.erase( dot ); } } - buffer[++length] = unitPower; - if ( unitSymbol ) buffer[++length] = unitSymbol; - buffer[++length] = '\0'; - return buffer; + if (unitPower != ' ') s += unitPower; + s += unitSymbol; + + return s; } string DbU::getValueString ( double u, int mode ) { - char buffer[1024]; - char unitPower = 'u'; - char unitSymbol = '\0'; + ostringstream os; + char unitPower = ' '; + char unitSymbol = 'u'; - if ( _stringMode == Grid ) { - unitPower = 'g'; - snprintf ( buffer, 1024, "%.1f", getGrid(u) ); - } else if ( _stringMode == Symbolic ) { - unitPower = 'l'; - snprintf ( buffer, 1024, "%.1f", getLambda(u) ); - } else if ( _stringMode == Physical ) { + os << fixed; + if (_stringMode == Grid) { + unitSymbol = 'g'; + os << setprecision(1) << toGrid(u); + } else if (_stringMode == Symbolic) { + unitSymbol = 'l'; + os << setprecision(1) << toLambda(u); + } else if (_stringMode == Physical) { unitSymbol = 'm'; switch ( _stringModeUnitPower ) { case Pico: unitPower = 'p'; break; @@ -368,26 +373,28 @@ namespace Hurricane { case Kilo: unitPower = 'k'; break; default: unitPower = '?'; break; } - snprintf ( buffer, 1024, "%.3f", getPhysical(u,_stringModeUnitPower) ); + os << setprecision(3) << toPhysical(u,_stringModeUnitPower); } else { - if ( _stringMode != Db ) + if (_stringMode != Db) cerr << "[ERROR] Unknown Unit representation mode: " << _stringMode << endl; - snprintf ( buffer, 1024, "%f", u ); + os << u; } - size_t length = strlen(buffer) - 1; - if ( mode & SmartTruncate ) { - for ( ; length > 0 ; length-- ) { - if ( buffer[length] == '.' ) { length--; break; } - if ( buffer[length] != '0' ) break; + string s = os.str(); + if (mode & SmartTruncate) { + size_t dot = s.rfind( '.' ); + if (dot != string::npos) { + size_t end = dot+1; + for ( ; end < s.size() ; ++end ) if (s[end] != '0') break; + if (end == s.size()) s.erase( dot ); } } - buffer[++length] = unitPower; - if ( unitSymbol ) buffer[++length] = unitSymbol; - buffer[++length] = '\0'; - return buffer; + if (unitPower != ' ') s += unitPower; + s += unitSymbol; + + return s; } diff --git a/hurricane/src/hurricane/hurricane/DbU.h b/hurricane/src/hurricane/hurricane/DbU.h index c8ecabf9..debff378 100644 --- a/hurricane/src/hurricane/hurricane/DbU.h +++ b/hurricane/src/hurricane/hurricane/DbU.h @@ -71,12 +71,12 @@ namespace Hurricane { static void checkLambdaBound ( double value ); static void checkPhysicalBound ( double value, UnitPower p ); // User to DB Converters. - static inline Unit fromDb ( long value ); + static inline Unit fromDb ( Unit value ); static inline Unit fromGrid ( double value ); static inline Unit fromLambda ( double value ); static inline Unit fromPhysical ( double value, UnitPower p ); // Old naming scheme (was not very clear). - static inline Unit db ( long value ); + static inline Unit db ( Unit value ); static inline Unit grid ( double value ); static inline Unit lambda ( double value ); static inline Unit physicalToDbu ( double value, UnitPower p ); @@ -103,7 +103,7 @@ namespace Hurricane { static DbU::Unit getOnCustomGrid ( DbU::Unit u, DbU::Unit step, SnapMode mode=Nearest ); static inline DbU::Unit getOnPhysicalGrid ( DbU::Unit u, SnapMode mode=Superior ); // Conversions. - static inline long toDb ( Unit u ); + static inline Unit toDb ( Unit u ); static inline double toGrid ( Unit u ); static inline double toGrid ( double u ); static inline double toLambda ( Unit u ); @@ -111,7 +111,7 @@ namespace Hurricane { static inline double toPhysical ( Unit u, UnitPower p ); static inline double toPhysical ( double u, UnitPower p ); // Old naming scheme (not very clear). - static inline long getDb ( Unit u ); + static inline Unit getDb ( Unit u ); static inline double getGrid ( Unit u ); static inline double getGrid ( double u ); static inline double getLambda ( Unit u ); @@ -150,11 +150,11 @@ namespace Hurricane { // Inline Functions. // New converter naming scheme. - inline DbU::Unit DbU::fromDb ( long value ) { return value; } - inline DbU::Unit DbU::fromGrid ( double value ) { checkGridBound (value); return (long)rint( value/_resolution ); } + inline DbU::Unit DbU::fromDb ( DbU::Unit value ) { return value; } + inline DbU::Unit DbU::fromGrid ( double value ) { checkGridBound (value); return (Unit)rint( value/_resolution ); } inline DbU::Unit DbU::fromLambda ( double value ) { checkLambdaBound (value); return fromGrid(value*_gridsPerLambda); } inline DbU::Unit DbU::fromPhysical ( double value, UnitPower p ) { checkPhysicalBound(value,p); return fromGrid((value*getUnitPower(p))/_physicalsPerGrid); } - inline long DbU::toDb ( DbU::Unit u ) { return u; } + inline DbU::Unit DbU::toDb ( DbU::Unit u ) { return u; } inline double DbU::toGrid ( DbU::Unit u ) { return _resolution*(double)u; } inline double DbU::toGrid ( double u ) { return _resolution*u; } inline double DbU::toLambda ( DbU::Unit u ) { return toGrid(u)/_gridsPerLambda; } @@ -163,11 +163,11 @@ namespace Hurricane { inline double DbU::toPhysical ( double u, UnitPower p ) { return (_physicalsPerGrid*_resolution*u)/getUnitPower(p); } // Old converter naming scheme. - inline DbU::Unit DbU::db ( long value ) { return fromDb(value); } + inline DbU::Unit DbU::db ( DbU::Unit value ) { return fromDb(value); } inline DbU::Unit DbU::grid ( double value ) { return fromGrid(value); } inline DbU::Unit DbU::lambda ( double value ) { return fromLambda(value); } inline DbU::Unit DbU::physicalToDbu ( double value, UnitPower p ) { return fromPhysical(value,p); } - inline long DbU::getDb ( DbU::Unit u ) { return toDb(u); } + inline DbU::Unit DbU::getDb ( DbU::Unit u ) { return toDb(u); } inline double DbU::getGrid ( DbU::Unit u ) { return toGrid(u); } inline double DbU::getGrid ( double u ) { return toGrid(u); } inline double DbU::getLambda ( DbU::Unit u ) { return toLambda(u); } diff --git a/hurricane/src/isobar/PyBasicLayer.cpp b/hurricane/src/isobar/PyBasicLayer.cpp index 316fc8c2..ff789d8d 100644 --- a/hurricane/src/isobar/PyBasicLayer.cpp +++ b/hurricane/src/isobar/PyBasicLayer.cpp @@ -52,21 +52,21 @@ extern "C" { BasicLayer* basicLayer = NULL; HTRY - PyObject* pyTechnology = NULL; - char* name = NULL; - PyObject* pyMaterial = NULL; - unsigned int extractNumber = 0; - long minimalSize = 0; - long minimalSpacing = 0; + PyObject* pyTechnology = NULL; + char* name = NULL; + PyObject* pyMaterial = NULL; + unsigned int extractNumber = 0; + PyObject* pyMinimalSize = NULL; + PyObject* pyMinimalSpacing = NULL; if (PyArg_ParseTuple( args - , "OsO|Ill:BasicLayer.create" + , "OsO|IOO:BasicLayer.create" , &pyTechnology , &name , &pyMaterial , &extractNumber - , &minimalSize - , &minimalSpacing + , &pyMinimalSize + , &pyMinimalSpacing )) { if (not IsPyTechnology(pyTechnology)) { PyErr_SetString ( ConstructorError, "Hurricane.create(): First argument is not of type Technology." ); @@ -81,8 +81,8 @@ extern "C" { , Name(name) , *PYMATERIAL_O(pyMaterial) , extractNumber - , minimalSize - , minimalSpacing + , (pyMinimalSize) ? PyAny_AsLong(pyMinimalSize) : 0 + , (pyMinimalSpacing) ? PyAny_AsLong(pyMinimalSpacing) : 0 ); } else { PyErr_SetString ( ConstructorError, "Bad parameters given to BasicLayer.create()." ); diff --git a/hurricane/src/isobar/PyBox.cpp b/hurricane/src/isobar/PyBox.cpp index 6be21130..02cf7a28 100644 --- a/hurricane/src/isobar/PyBox.cpp +++ b/hurricane/src/isobar/PyBox.cpp @@ -368,11 +368,17 @@ extern "C" { HTRY METHOD_HEAD ( "Box.translate()" ) - DbU::Unit dx=0, dy=0; - if (PyArg_ParseTuple(args,"ll:Box.translate", &dx, &dy)) { - box->translate(dx, dy); + PyObject* arg0 = NULL; + PyObject* arg1 = NULL; + __cs.init ("Box.translate"); + if (PyArg_ParseTuple(args,"O&O&:Box.translate", Converter, &arg0, Converter, &arg1)) { + if (__cs.getObjectIds() == INTS2_ARG) box->translate( PyAny_AsLong(arg0), PyAny_AsLong(arg1) ); + else { + PyErr_SetString ( ConstructorError, "Box.translate(): Invalid type for parameter(s)." ); + return NULL; + } } else { - PyErr_SetString ( ConstructorError, "invalid number of parameters for Box.translate()" ); + PyErr_SetString ( ConstructorError, "Box.translate(): Invalid number of parameters." ); return NULL; } HCATCH @@ -432,9 +438,6 @@ extern "C" { // x=================================================================x - - - // --------------------------------------------------------------- // PyBox Object Definitions. @@ -442,14 +445,7 @@ extern "C" { # endif // End of Shared Library Code Part. - - - } // End of extern "C". - - - - } // End of Isobar namespace. diff --git a/hurricane/src/isobar/PyContact.cpp b/hurricane/src/isobar/PyContact.cpp index 70dae493..8ab2ce36 100644 --- a/hurricane/src/isobar/PyContact.cpp +++ b/hurricane/src/isobar/PyContact.cpp @@ -103,11 +103,17 @@ extern "C" { HTRY METHOD_HEAD ( "Contact.translate()" ) - DbU::Unit dx=0, dy=0; - if (PyArg_ParseTuple(args,"ll:Contact.translate", &dx, &dy)) { - contact->translate(dx, dy); + PyObject* arg0 = NULL; + PyObject* arg1 = NULL; + __cs.init ("Contact.translate"); + if (PyArg_ParseTuple(args,"O&O&:Contact.translate", Converter, &arg0, Converter, &arg1)) { + if (__cs.getObjectIds() == INTS2_ARG) contact->translate( PyAny_AsLong(arg0), PyAny_AsLong(arg1) ); + else { + PyErr_SetString ( ConstructorError, "Contact.translate(): Invalid type for parameter(s)." ); + return NULL; + } } else { - PyErr_SetString ( ConstructorError, "invalid number of parameters for Contact.translate()" ); + PyErr_SetString ( ConstructorError, "Contact.translate(): Invalid number of parameters." ); return NULL; } HCATCH diff --git a/hurricane/src/isobar/PyDbU.cpp b/hurricane/src/isobar/PyDbU.cpp index bda1d719..f31799ba 100644 --- a/hurricane/src/isobar/PyDbU.cpp +++ b/hurricane/src/isobar/PyDbU.cpp @@ -111,7 +111,7 @@ extern "C" { } HCATCH - return PyLong_FromLong(result); + return PyDbU_FromLong(result); } @@ -133,7 +133,7 @@ extern "C" { } HCATCH - return PyLong_FromLong(result); + return PyDbU_FromLong(result); } @@ -155,7 +155,7 @@ extern "C" { } HCATCH - return PyLong_FromLong(result); + return PyDbU_FromLong(result); } @@ -173,7 +173,7 @@ extern "C" { result = DbU::fromPhysical(value,(DbU::UnitPower)power); HCATCH - return PyLong_FromLong(result); + return PyDbU_FromLong(result); } @@ -282,37 +282,37 @@ extern "C" { extern PyObject* PyDbU_getRealSnapGridStep ( PyObject* ) - { return PyLong_FromLong(DbU::getRealSnapGridStep()); } + { return PyDbU_FromLong(DbU::getRealSnapGridStep()); } extern PyObject* PyDbU_getOnRealSnapGrid ( PyObject* , PyObject* args ) { - long value = 0; - int snap = DbU::Nearest; - DbU::Unit result = 0; + PyObject* value = NULL; + int snap = DbU::Nearest; + DbU::Unit result = 0; HTRY - if (not PyArg_ParseTuple(args,"l|i:DbU.getOnRealSnapGrid", &value, &snap) ) { + if (not PyArg_ParseTuple(args,"O|i:DbU.getOnRealSnapGrid", &value, &snap) ) { PyErr_SetString ( ConstructorError, "DbU.getOnRealSnapGrid(): Invalid/bad type parameters ." ); return NULL; } - result = DbU::getOnRealSnapGrid(DbU::db(value),(DbU::SnapMode)snap); + result = DbU::getOnRealSnapGrid(PyAny_AsLong(value),(DbU::SnapMode)snap); HCATCH - return PyLong_FromLong(result); + return PyDbU_FromLong(result); } extern PyObject* PyDbU_setRealSnapGridStep ( PyObject* , PyObject* args ) { - long step = 0; + PyObject* step = NULL; HTRY - if (not PyArg_ParseTuple(args,"l:DbU.setRealSnapGridStep", &step) ) { + if (not PyArg_ParseTuple(args,"O:DbU.setRealSnapGridStep", &step) ) { PyErr_SetString ( ConstructorError, "DbU.setRealSnapGridStep(): Invalid/bad type parameters ." ); return NULL; } - DbU::setRealSnapGridStep(DbU::db(step)); + DbU::setRealSnapGridStep(PyAny_AsLong(step)); HCATCH Py_RETURN_NONE; @@ -320,37 +320,37 @@ extern "C" { extern PyObject* PyDbU_getSymbolicSnapGridStep ( PyObject* ) - { return PyLong_FromLong(DbU::getSymbolicSnapGridStep()); } + { return PyDbU_FromLong(DbU::getSymbolicSnapGridStep()); } extern PyObject* PyDbU_getOnSymbolicSnapGrid ( PyObject* , PyObject* args ) { - long value = 0; + PyObject* pyValue = NULL; int snap = DbU::Nearest; DbU::Unit result = 0; HTRY - if (not PyArg_ParseTuple(args,"l|i:DbU.getOnSymbolicSnapGrid", &value, &snap) ) { + if (not PyArg_ParseTuple(args,"O|i:DbU.getOnSymbolicSnapGrid", &pyValue, &snap) ) { PyErr_SetString ( ConstructorError, "DbU.getOnSymbolicSnapGrid(): Invalid/bad type parameters ." ); return NULL; } - result = DbU::getOnSymbolicSnapGrid(DbU::db(value),(DbU::SnapMode)snap); + result = DbU::getOnSymbolicSnapGrid(PyAny_AsLong(pyValue),(DbU::SnapMode)snap); HCATCH - return PyLong_FromLong(result); + return PyDbU_FromLong(result); } extern PyObject* PyDbU_setSymbolicSnapGridStep ( PyObject* , PyObject* args ) { - long step = 0; + PyObject* step = NULL; HTRY - if (not PyArg_ParseTuple(args,"l:DbU.setSymbolicSnapGridStep", &step) ) { + if (not PyArg_ParseTuple(args,"O:DbU.setSymbolicSnapGridStep", &step) ) { PyErr_SetString ( ConstructorError, "DbU.setSymbolicSnapGridStep(): Invalid/bad type parameters ." ); return NULL; } - DbU::setSymbolicSnapGridStep(DbU::db(step)); + DbU::setSymbolicSnapGridStep(PyAny_AsLong(step)); HCATCH Py_RETURN_NONE; @@ -359,38 +359,38 @@ extern "C" { extern PyObject* PyDbU_getOnCustomGrid ( PyObject* , PyObject* args ) { - long value = 0; - long step = 1; - int snap = DbU::Nearest; - DbU::Unit result = 0; + PyObject* pyValue = NULL; + PyObject* pyStep = NULL; + DbU::Unit result = 0; + int snap = DbU::Nearest; HTRY - if (not PyArg_ParseTuple(args,"ll|i:DbU.getOnCustomGrid", &value, &step, &snap) ) { + if (not PyArg_ParseTuple(args,"OO|i:DbU.getOnCustomGrid", &pyValue, &pyStep, &snap) ) { PyErr_SetString ( ConstructorError, "DbU.getOnCustomGrid(): Invalid/bad type parameters ." ); return NULL; } - result = DbU::getOnCustomGrid(DbU::db(value),DbU::db(step),(DbU::SnapMode)snap); + result = DbU::getOnCustomGrid(PyAny_AsLong(pyValue),PyAny_AsLong(pyStep),(DbU::SnapMode)snap); HCATCH - return PyLong_FromLong(result); + return PyDbU_FromLong(result); } extern PyObject* PyDbU_getOnPhysicalGrid ( PyObject* , PyObject* args ) { - long value = 0; + PyObject* pyValue = NULL; int snap = DbU::Superior; DbU::Unit result = 0; HTRY - if (not PyArg_ParseTuple(args,"l|i:DbU.getOnPhysicalGrid", &value, &snap) ) { + if (not PyArg_ParseTuple(args,"O|i:DbU.getOnPhysicalGrid", &pyValue, &snap) ) { PyErr_SetString ( ConstructorError, "DbU.getOnPhysicalGrid(): Invalid/bad type parameters ." ); return NULL; } - result = DbU::getOnPhysicalGrid(DbU::db(value),(DbU::SnapMode)snap); + result = DbU::getOnPhysicalGrid(PyAny_AsLong(pyValue),(DbU::SnapMode)snap); HCATCH - return PyLong_FromLong(result); + return PyDbU_FromLong(result); } @@ -398,7 +398,7 @@ extern "C" { { PyObject* arg0; if ( not ParseOneArg( "DbU.toDb", args,INT_ARG, &arg0 ) ) return NULL; - return PyLong_FromLong(DbU::toDb((DbU::Unit)PyAny_AsLong(arg0))); + return PyDbU_FromLong(DbU::toDb((DbU::Unit)PyAny_AsLong(arg0))); } @@ -429,16 +429,16 @@ extern "C" { extern PyObject* PyDbU_getValueString ( PyObject* , PyObject* args ) { - long value = 0; - int mode = DbU::SmartTruncate; - string result = ""; + PyObject* value = NULL; + int mode = DbU::SmartTruncate; + string result = ""; HTRY - if (not PyArg_ParseTuple(args,"l|i:DbU.getValueString", &value, &mode) ) { + if (not PyArg_ParseTuple(args,"O|i:DbU.getValueString", &value, &mode) ) { PyErr_SetString ( ConstructorError, "DbU.getValueString(): Invalid/bad type parameters ." ); return NULL; } - result = DbU::getValueString(DbU::db(value),mode); + result = DbU::getValueString(PyAny_AsLong(value),mode); HCATCH return Py_BuildValue("s",result.c_str()); diff --git a/hurricane/src/isobar/PyHorizontal.cpp b/hurricane/src/isobar/PyHorizontal.cpp index 4dee3bf4..32f173ef 100644 --- a/hurricane/src/isobar/PyHorizontal.cpp +++ b/hurricane/src/isobar/PyHorizontal.cpp @@ -156,11 +156,17 @@ extern "C" { HTRY METHOD_HEAD ( "Horizontal.translate()" ) - DbU::Unit dx=0, dy=0; - if (PyArg_ParseTuple(args,"ll:Horizontal.translate", &dx, &dy)) { - horizontal->translate(dx, dy); + PyObject* arg0 = NULL; + PyObject* arg1 = NULL; + __cs.init ("Horizontal.translate"); + if (PyArg_ParseTuple(args,"O&O&:Horizontal.translate", Converter, &arg0, Converter, &arg1)) { + if (__cs.getObjectIds() == INTS2_ARG) horizontal->translate( PyAny_AsLong(arg0), PyAny_AsLong(arg1) ); + else { + PyErr_SetString ( ConstructorError, "Horizontal.translate(): Invalid type for parameter(s)." ); + return NULL; + } } else { - PyErr_SetString ( ConstructorError, "invalid number of parameters for Horizontal.translate()" ); + PyErr_SetString ( ConstructorError, "Horizontal.translate(): Invalid number of parameters." ); return NULL; } HCATCH diff --git a/hurricane/src/isobar/PyHurricane.cpp b/hurricane/src/isobar/PyHurricane.cpp index 6e69c871..0a492e1a 100644 --- a/hurricane/src/isobar/PyHurricane.cpp +++ b/hurricane/src/isobar/PyHurricane.cpp @@ -129,26 +129,6 @@ using namespace Hurricane; // +-----------------------------------------------------------------+ - int PyAny_AsInt ( PyObject* object ) - { - long value = 0; - - if (PyObject_IsInstance(object,(PyObject*)&PyInt_Type )) value = PyInt_AsLong ( object ); - else if (PyObject_IsInstance(object,(PyObject*)&PyLong_Type)) value = PyLong_AsLong( object ); - return (int)value; - } - - - long PyAny_AsLong ( PyObject* object ) - { - long value = 0; - - if (PyObject_IsInstance(object,(PyObject*)&PyInt_Type )) value = PyInt_AsLong ( object ); - else if (PyObject_IsInstance(object,(PyObject*)&PyLong_Type)) value = PyLong_AsLong( object ); - return value; - } - - // ------------------------------------------------------------------- // Method : "::ConverterState::ObjectType::PyEqual ()" diff --git a/hurricane/src/isobar/PyInterval.cpp b/hurricane/src/isobar/PyInterval.cpp index 97337d0c..4358422e 100644 --- a/hurricane/src/isobar/PyInterval.cpp +++ b/hurricane/src/isobar/PyInterval.cpp @@ -269,11 +269,16 @@ extern "C" { HTRY METHOD_HEAD( "Interval.translate()" ) - DbU::Unit delta = 0; - if (PyArg_ParseTuple(args,"l:Interval.translate", &delta)) { - interval->translate(delta); + PyObject* arg0 = NULL; + __cs.init ("Contact.translate"); + if (PyArg_ParseTuple(args,"O&:Interval.translate", Converter, &arg0)) { + if (__cs.getObjectIds() == INT_ARG) interval->translate( PyAny_AsLong(arg0) ); + else { + PyErr_SetString ( ConstructorError, "Interval.translate(): Invalid type for parameter." ); + return NULL; + } } else { - PyErr_SetString( ConstructorError, "invalid number of parameters for Interval.translate()" ); + PyErr_SetString ( ConstructorError, "Interval.translate(): Invalid number of parameters." ); return NULL; } HCATCH diff --git a/hurricane/src/isobar/PyLayer.cpp b/hurricane/src/isobar/PyLayer.cpp index a466ebb8..12eaf84d 100644 --- a/hurricane/src/isobar/PyLayer.cpp +++ b/hurricane/src/isobar/PyLayer.cpp @@ -176,15 +176,15 @@ extern "C" { # define updatorFromDbu(FUNC_NAME,PY_SELF_TYPE,SELF_TYPE) \ static PyObject* PY_SELF_TYPE##_##FUNC_NAME ( PY_SELF_TYPE* self, PyObject* args ) \ { \ - cdebug_log(20,0) << #PY_SELF_TYPE "_" #FUNC_NAME "()" << endl; \ + cdebug_log(20,0) << #PY_SELF_TYPE "_" #FUNC_NAME "()" << endl; \ \ HTRY \ GENERIC_METHOD_HEAD(SELF_TYPE,cobject,#SELF_TYPE"."#FUNC_NAME"()") \ \ - long dimension = 0; \ + PyObject* pyDimension = NULL; \ \ - if (PyArg_ParseTuple( args, "l:"#SELF_TYPE"."#FUNC_NAME"()", &dimension)) { \ - cobject->FUNC_NAME( dimension ); \ + if (PyArg_ParseTuple( args, "O:"#SELF_TYPE"."#FUNC_NAME"()", &pyDimension)) { \ + cobject->FUNC_NAME( PyAny_AsLong(pyDimension) ); \ } else { \ PyErr_SetString ( ConstructorError \ , #SELF_TYPE"."#FUNC_NAME"(): Parameter is not of long (DbU) type" ); \ @@ -205,16 +205,16 @@ extern "C" { GENERIC_METHOD_HEAD(SELF_TYPE,cobject,#SELF_TYPE"."#FUNC_NAME"()") \ \ PyObject* pyBasicLayer = NULL; \ - long dimension = 0; \ + PyObject* pyDimension = NULL; \ \ - if (PyArg_ParseTuple( args, "Ol:"#SELF_TYPE"."#FUNC_NAME"()", &pyBasicLayer, &dimension)) { \ + if (PyArg_ParseTuple( args, "OO:"#SELF_TYPE"."#FUNC_NAME"()", &pyBasicLayer, &pyDimension)) { \ BasicLayer* layer = PYBASICLAYER_O(pyBasicLayer); \ if (layer == NULL) { \ PyErr_SetString ( ConstructorError \ , #SELF_TYPE"."#FUNC_NAME"(): First parameter is not of BasicLayer type" ); \ return NULL; \ } \ - cobject->FUNC_NAME( layer, dimension ); \ + cobject->FUNC_NAME( layer, PyAny_AsLong(pyDimension) ); \ } else { \ PyErr_SetString ( ConstructorError \ , #SELF_TYPE"."#FUNC_NAME"(): Bad parameters types or numbers." ); \ diff --git a/hurricane/src/isobar/PyPad.cpp b/hurricane/src/isobar/PyPad.cpp index ba9f7610..d80375da 100644 --- a/hurricane/src/isobar/PyPad.cpp +++ b/hurricane/src/isobar/PyPad.cpp @@ -133,11 +133,17 @@ extern "C" { HTRY METHOD_HEAD ( "Pad.translate()" ) - DbU::Unit dx=0, dy=0; - if (PyArg_ParseTuple(args,"ll:Pad.translate", &dx, &dy)) { - pad->translate(dx, dy); + PyObject* arg0 = NULL; + PyObject* arg1 = NULL; + __cs.init ("Pad.translate"); + if (PyArg_ParseTuple(args,"O&O&:Pad.translate", Converter, &arg0, Converter, &arg1)) { + if (__cs.getObjectIds() == INTS2_ARG) pad->translate( PyAny_AsLong(arg0), PyAny_AsLong(arg1) ); + else { + PyErr_SetString ( ConstructorError, "Pad.translate(): Invalid type for parameter(s)." ); + return NULL; + } } else { - PyErr_SetString ( ConstructorError, "invalid number of parameters for Pad.translate()" ); + PyErr_SetString ( ConstructorError, "Pad.translate(): Invalid number of parameters." ); return NULL; } HCATCH diff --git a/hurricane/src/isobar/PyRoutingPad.cpp b/hurricane/src/isobar/PyRoutingPad.cpp index 1edda7d4..3bf3cb64 100644 --- a/hurricane/src/isobar/PyRoutingPad.cpp +++ b/hurricane/src/isobar/PyRoutingPad.cpp @@ -164,12 +164,17 @@ extern "C" { HTRY METHOD_HEAD ( "RoutingPad.translate()" ) - DbU::Unit dx = 0; - DbU::Unit dy = 0; - if (PyArg_ParseTuple(args,"ll:RoutingPad.translate", &dx, &dy)) { - rp->translate( dx, dy ); + PyObject* arg0 = NULL; + PyObject* arg1 = NULL; + __cs.init ("RoutingPad.translate"); + if (PyArg_ParseTuple(args,"O&O&:RoutingPad.translate", Converter, &arg0, Converter, &arg1)) { + if (__cs.getObjectIds() == INTS2_ARG) rp->translate( PyAny_AsLong(arg0), PyAny_AsLong(arg1) ); + else { + PyErr_SetString ( ConstructorError, "RoutingPad.translate(): Invalid type for parameter(s)." ); + return NULL; + } } else { - PyErr_SetString( ConstructorError, "invalid number of parameters for RoutingPad.translate()" ); + PyErr_SetString ( ConstructorError, "RoutingPad.translate(): Invalid number of parameters." ); return NULL; } HCATCH @@ -217,12 +222,17 @@ extern "C" { HTRY METHOD_HEAD ( "RoutingPad.setOffset()" ) - DbU::Unit dx = 0; - DbU::Unit dy = 0; - if (PyArg_ParseTuple(args,"ll:RoutingPad.setOffset", &dx, &dy)) { - rp->setOffset( dx, dy ); + PyObject* arg0 = NULL; + PyObject* arg1 = NULL; + __cs.init ("RoutingPad.setOffset"); + if (PyArg_ParseTuple(args,"O&O&:RoutingPad.setOffset", Converter, &arg0, Converter, &arg1)) { + if (__cs.getObjectIds() == INTS2_ARG) rp->setOffset( PyAny_AsLong(arg0), PyAny_AsLong(arg1) ); + else { + PyErr_SetString ( ConstructorError, "RoutingPad.setOffset(): Invalid type for parameter(s)." ); + return NULL; + } } else { - PyErr_SetString( ConstructorError, "invalid number of parameters for RoutingPad.setOffset()" ); + PyErr_SetString ( ConstructorError, "RoutingPad.setOffset(): Invalid number of parameters." ); return NULL; } HCATCH diff --git a/hurricane/src/isobar/PyTransformation.cpp b/hurricane/src/isobar/PyTransformation.cpp index 0710f6b2..82e6833a 100644 --- a/hurricane/src/isobar/PyTransformation.cpp +++ b/hurricane/src/isobar/PyTransformation.cpp @@ -173,27 +173,25 @@ extern "C" { METHOD_HEAD ( "Transformation.getX()" ) - PyObject* arg0; - PyObject* arg1; - long result = 0; + PyObject* arg0 = NULL; + PyObject* arg1 = NULL; + DbU::Unit result = 0; HTRY - - __cs.init ("Transformation.getX"); - if ( ! PyArg_ParseTuple(args,"|O&O&:Transformation.getX",Converter,&arg0,Converter,&arg1) ) - return ( NULL ); - - if ( __cs.getObjectIds() == POINT_ARG ) { result = transf->getX ( *PYPOINT_O(arg0) ); } - else if ( __cs.getObjectIds() == INTS2_ARG ) { result = transf->getX ( PyAny_AsLong(arg0) - , PyAny_AsLong(arg1) ); } - else { - PyErr_SetString ( ConstructorError, "invalid number of parameters for Tranformation.getX()." ); - return ( NULL ); - } - + __cs.init ("Transformation.getX"); + if ( ! PyArg_ParseTuple(args,"|O&O&:Transformation.getX",Converter,&arg0,Converter,&arg1) ) + return NULL; + + if ( __cs.getObjectIds() == POINT_ARG ) { result = transf->getX ( *PYPOINT_O(arg0) ); } + else if ( __cs.getObjectIds() == INTS2_ARG ) { result = transf->getX ( PyAny_AsLong(arg0) + , PyAny_AsLong(arg1) ); } + else { + PyErr_SetString ( ConstructorError, "invalid number of parameters for Tranformation.getX()." ); + return NULL; + } HCATCH - return ( (PyObject*)PyLong_FromLong(result) ); + return PyDbU_FromLong(result); } @@ -208,27 +206,25 @@ extern "C" { METHOD_HEAD ( "Transformation.getY()" ) - PyObject* arg0; - PyObject* arg1; - long result = 0; + PyObject* arg0 = NULL; + PyObject* arg1 = NULL; + DbU::Unit result = 0; HTRY - __cs.init ("Transformation.getY"); - if ( ! PyArg_ParseTuple(args,"|O&O&:Transformation.getY",Converter,&arg0,Converter,&arg1) ) - return ( NULL ); - - if ( __cs.getObjectIds() == POINT_ARG ) { result = transf->getY ( *PYPOINT_O(arg0) ); } - else if ( __cs.getObjectIds() == INTS2_ARG ) { result = transf->getY ( PyAny_AsLong(arg0) - , PyAny_AsLong(arg1) ); } - else { - PyErr_SetString ( ConstructorError, "invalid number of parameters for Tranformation.getY()." ); - return ( NULL ); - } - + if ( ! PyArg_ParseTuple(args,"|O&O&:Transformation.getY",Converter,&arg0,Converter,&arg1) ) + return NULL; + + if ( __cs.getObjectIds() == POINT_ARG ) { result = transf->getY ( *PYPOINT_O(arg0) ); } + else if ( __cs.getObjectIds() == INTS2_ARG ) { result = transf->getY ( PyAny_AsLong(arg0) + , PyAny_AsLong(arg1) ); } + else { + PyErr_SetString ( ConstructorError, "invalid number of parameters for Tranformation.getY()." ); + return NULL; + } HCATCH - return ( (PyObject*)PyLong_FromLong(result) ); + return PyDbU_FromLong(result); } @@ -243,18 +239,16 @@ extern "C" { METHOD_HEAD ( "Transformation.getDx()" ) - PyObject* arg0; - PyObject* arg1; - long result = 0; + PyObject* arg0 = NULL; + PyObject* arg1 = NULL; + DbU::Unit result = 0; HTRY - - if ( ! ParseTwoArg ( "Transformation.getDx", args, INTS2_ARG, &arg0, &arg1 ) ) return ( NULL ); - result = transf->getDx ( PyAny_AsLong(arg0), PyAny_AsLong(arg1) ); - + if ( ! ParseTwoArg ( "Transformation.getDx", args, INTS2_ARG, &arg0, &arg1 ) ) return ( NULL ); + result = transf->getDx ( PyAny_AsLong(arg0), PyAny_AsLong(arg1) ); HCATCH - return ( (PyObject*)PyLong_FromLong(result) ); + return PyDbU_FromLong(result); } @@ -269,18 +263,16 @@ extern "C" { METHOD_HEAD ( "Transformation.getDy()" ) - PyObject* arg0; - PyObject* arg1; - long result = 0; + PyObject* arg0 = NULL; + PyObject* arg1 = NULL; + DbU::Unit result = 0; HTRY - - if ( ! ParseTwoArg ( "Transformation.getDy", args, INTS2_ARG, &arg0, &arg1 ) ) return ( NULL ); - result = transf->getDy ( PyAny_AsLong(arg0), PyAny_AsLong(arg1) ); - + if ( ! ParseTwoArg ( "Transformation.getDy", args, INTS2_ARG, &arg0, &arg1 ) ) return ( NULL ); + result = transf->getDy ( PyAny_AsLong(arg0), PyAny_AsLong(arg1) ); HCATCH - return ( (PyObject*)PyLong_FromLong(result) ); + return PyDbU_FromLong(result); } diff --git a/hurricane/src/isobar/PyVertical.cpp b/hurricane/src/isobar/PyVertical.cpp index 9d631a82..72eed353 100644 --- a/hurricane/src/isobar/PyVertical.cpp +++ b/hurricane/src/isobar/PyVertical.cpp @@ -153,11 +153,17 @@ extern "C" { HTRY METHOD_HEAD ( "Vertical.translate()" ) - DbU::Unit dx=0, dy=0; - if (PyArg_ParseTuple(args,"ll:Vertical.translate", &dx, &dy)) { - vertical->translate(dx, dy); + PyObject* arg0 = NULL; + PyObject* arg1 = NULL; + __cs.init ("Vertical.translate"); + if (PyArg_ParseTuple(args,"O&O&:Vertical.translate", Converter, &arg0, Converter, &arg1)) { + if (__cs.getObjectIds() == INTS2_ARG) vertical->translate( PyAny_AsLong(arg0), PyAny_AsLong(arg1) ); + else { + PyErr_SetString ( ConstructorError, "Vertical.translate(): Invalid type for parameter(s)." ); + return NULL; + } } else { - PyErr_SetString ( ConstructorError, "invalid number of parameters for Vertical.translate()" ); + PyErr_SetString ( ConstructorError, "Vertical.translate(): Invalid number of parameters." ); return NULL; } HCATCH diff --git a/hurricane/src/isobar/hurricane/isobar/PyHurricane.h b/hurricane/src/isobar/hurricane/isobar/PyHurricane.h index a7b7037d..e01b91c6 100644 --- a/hurricane/src/isobar/hurricane/isobar/PyHurricane.h +++ b/hurricane/src/isobar/hurricane/isobar/PyHurricane.h @@ -31,12 +31,14 @@ #include "hurricane/Bug.h" #include "hurricane/Error.h" #include "hurricane/Warning.h" +#include "hurricane/DbU.h" #include "hurricane/isobar/ProxyProperty.h" namespace Isobar { -using namespace std; + using namespace std; + using Hurricane::DbU; // ------------------------------------------------------------------- @@ -107,8 +109,48 @@ using namespace std; extern ConverterState __cs; extern int __objectOffset; - int PyAny_AsInt ( PyObject* object ); - long PyAny_AsLong ( PyObject* object ); + + inline int PyAny_AsInt ( PyObject* object ) + { + long value = 0; + if (PyObject_IsInstance(object,(PyObject*)&PyInt_Type )) value = PyInt_AsLong ( object ); + else if (PyObject_IsInstance(object,(PyObject*)&PyLong_Type)) value = PyLong_AsLong( object ); + return (int)value; + } + + + template< typename T = DbU::Unit, typename enable_if< is_same::value, T >::type = 0 > + inline T PyAny_AsLong ( PyObject* object ) + { + T value = 0; + if (PyObject_IsInstance(object,(PyObject*)&PyInt_Type )) value = PyInt_AsLong ( object ); + else if (PyObject_IsInstance(object,(PyObject*)&PyLong_Type)) value = PyLong_AsLong( object ); + return value; + } + + + template< typename T = DbU::Unit, typename enable_if< is_same::value, T >::type = 0 > + inline T PyAny_AsLong ( PyObject* object ) + { + T value = 0; + if (PyObject_IsInstance(object,(PyObject*)&PyInt_Type )) value = PyInt_AsLong ( object ); + else if (PyObject_IsInstance(object,(PyObject*)&PyLong_Type)) value = PyLong_AsLongLong( object ); + + if (value > numeric_limits::max()) { + throw Error( "PyAny_AsLong(): Suspiciously big int %s, db:%li" + , DbU::getValueString(value).c_str(), value + ); + } + return value; + } + + + template< typename T = DbU::Unit, typename enable_if< is_same::value, T >::type = 0 > + inline PyObject* PyDbU_FromLong ( T unit ) { return PyLong_FromLong( unit ); } + + + template< typename T = DbU::Unit, typename enable_if< is_same::value, T >::type = 0 > + inline PyObject* PyDbU_FromLong ( T unit ) { return PyLong_FromLongLong( unit ); } extern "C" { @@ -316,7 +358,7 @@ extern "C" { static PyObject* PY_FUNC_NAME ( PY_SELF_TYPE *self, PyObject* args ) \ { \ GENERIC_METHOD_HEAD(SELF_TYPE,cobject,#FUNC_NAME"()") \ - return Py_BuildValue("l", cobject->FUNC_NAME()); \ + return Isobar::PyDbU_FromLong(cobject->FUNC_NAME()); \ }