Skip to content

Commit 72a6f31

Browse files
authored
Merge pull request #8114 from The-OpenROAD-Project-staging/odb-tcl-exceptions
odb: check for invalid strings being converted to enums in TCL
2 parents ea001a1 + 26b28fc commit 72a6f31

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

src/odb/src/swig/tcl/dbenums.i

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@
5151
$1 = odb::dbOrientType::Value::MX;
5252
} else if (strcasecmp(str, "MXR90") == 0) {
5353
$1 = odb::dbOrientType::Value::MXR90;
54+
} else {
55+
SWIG_exception(SWIG_ValueError, "Unknown orientation");
5456
}
55-
}
57+
}
5658
%typemap(typecheck) odb::dbOrientType, dbOrientType {
5759
char *str = Tcl_GetStringFromObj($input, 0);
5860
bool found = false;
@@ -129,6 +131,8 @@
129131
$1 = odb::dbSigType::Value::SCAN;
130132
} else if (strcasecmp(str, "TIEOFF") == 0) {
131133
$1 = odb::dbSigType::Value::TIEOFF;
134+
} else {
135+
SWIG_exception(SWIG_ValueError, "Unknown signal type");
132136
}
133137
}
134138
%typemap(typecheck) odb::dbSigType, dbSigType {
@@ -187,6 +191,8 @@
187191
$1 = odb::dbIoType::Value::INOUT;
188192
} else if (strcasecmp(str, "FEEDTHRU") == 0) {
189193
$1 = odb::dbIoType::Value::FEEDTHRU;
194+
} else {
195+
SWIG_exception(SWIG_ValueError, "Unknown io type");
190196
}
191197
}
192198
%typemap(typecheck) odb::dbIoType, dbIoType {
@@ -237,6 +243,8 @@
237243
$1 = odb::dbMTermShapeType::Value::FEEDTHRU;
238244
} else if (strcasecmp(str, "ABUTMENT") == 0) {
239245
$1 = odb::dbMTermShapeType::Value::ABUTMENT;
246+
} else {
247+
SWIG_exception(SWIG_ValueError, "Unknown shape type");
240248
}
241249
}
242250
%typemap(typecheck) odb::dbMTermShapeType, dbMTermShapeType {
@@ -303,6 +311,8 @@
303311
$1 = odb::dbPlacementStatus::Value::FIRM;
304312
} else if (strcasecmp(str, "COVER") == 0) {
305313
$1 = odb::dbPlacementStatus::Value::COVER;
314+
} else {
315+
SWIG_exception(SWIG_ValueError, "Unknown placement status");
306316
}
307317
}
308318
%typemap(typecheck) odb::dbPlacementStatus, dbPlacementStatus {
@@ -534,6 +544,8 @@
534544
$1 = odb::dbMasterType::Value::ENDCAP_LEF58_RIGHTTOPCORNER;
535545
} else if (strcasecmp(str, "ENDCAP_LEF58_LEFTTOPCORNER") == 0) {
536546
$1 = odb::dbMasterType::Value::ENDCAP_LEF58_LEFTTOPCORNER;
547+
} else {
548+
SWIG_exception(SWIG_ValueError, "Unknown master type");
537549
}
538550
}
539551
%typemap(typecheck) odb::dbMasterType, dbMasterType {
@@ -731,6 +743,8 @@
731743
$1 = odb::dbTechLayerType::Value::IMPLANT;
732744
} else if (strcasecmp(str, "NONE") == 0) {
733745
$1 = odb::dbTechLayerType::Value::NONE;
746+
} else {
747+
SWIG_exception(SWIG_ValueError, "Unknown layer type");
734748
}
735749
}
736750
%typemap(in) odb::dbTechLayer::LEF58_TYPE, dbTechLayer::LEF58_TYPE {
@@ -774,6 +788,8 @@
774788
$1 = odb::dbTechLayer::LEF58_TYPE::PADMETAL;
775789
} else if (strcasecmp(str, "POLYROUTING") == 0) {
776790
$1 = odb::dbTechLayer::LEF58_TYPE::POLYROUTING;
791+
} else {
792+
SWIG_exception(SWIG_ValueError, "Unknown lef58 layer type");
777793
}
778794
}
779795
%typemap(typecheck) odb::dbTechLayerType, dbTechLayerType {
@@ -875,6 +891,8 @@
875891
$1 = odb::dbTechLayerDir::Value::HORIZONTAL;
876892
} else if (strcasecmp(str, "VERTICAL") == 0) {
877893
$1 = odb::dbTechLayerDir::Value::VERTICAL;
894+
} else {
895+
SWIG_exception(SWIG_ValueError, "Unknown layer dir");
878896
}
879897
}
880898
%typemap(typecheck) odb::dbTechLayerDir, dbTechLayerDir {
@@ -913,6 +931,8 @@
913931
$1 = odb::dbRowDir::Value::HORIZONTAL;
914932
} else if (strcasecmp(str, "VERTICAL") == 0) {
915933
$1 = odb::dbRowDir::Value::VERTICAL;
934+
} else {
935+
SWIG_exception(SWIG_ValueError, "Unknown row dir");
916936
}
917937
}
918938
%typemap(typecheck) odb::dbRowDir, dbRowDir {
@@ -1009,6 +1029,8 @@
10091029
$1 = odb::dbBoxOwner::Value::BPIN;
10101030
} else if (strcasecmp(str, "PBOX") == 0) {
10111031
$1 = odb::dbBoxOwner::Value::PBOX;
1032+
} else {
1033+
SWIG_exception(SWIG_ValueError, "Unknown box owner");
10121034
}
10131035
}
10141036
%typemap(typecheck) odb::dbBoxOwner, dbBoxOwner {
@@ -1079,6 +1101,8 @@
10791101
$1 = odb::dbPolygonOwner::Value::OBSTRUCTION;
10801102
} else if (strcasecmp(str, "SWIRE") == 0) {
10811103
$1 = odb::dbPolygonOwner::Value::SWIRE;
1104+
} else {
1105+
SWIG_exception(SWIG_ValueError, "Unknown polygon owner");
10821106
}
10831107
}
10841108
%typemap(typecheck) odb::dbPolygonOwner, dbPolygonOwner {
@@ -1139,6 +1163,8 @@
11391163
$1 = odb::dbWireType::Value::SHIELD;
11401164
} else if (strcasecmp(str, "NOSHIELD") == 0) {
11411165
$1 = odb::dbWireType::Value::NOSHIELD;
1166+
} else {
1167+
SWIG_exception(SWIG_ValueError, "Unknown wire type");
11421168
}
11431169
}
11441170
%typemap(typecheck) odb::dbWireType, dbWireType {
@@ -1233,6 +1259,8 @@
12331259
$1 = odb::dbWireShapeType::Value::FILLWIRE;
12341260
} else if (strcasecmp(str, "DRCFILL") == 0) {
12351261
$1 = odb::dbWireShapeType::Value::DRCFILL;
1262+
} else {
1263+
SWIG_exception(SWIG_ValueError, "Unknown wire shape type");
12361264
}
12371265
}
12381266
%typemap(typecheck) odb::dbWireShapeType, dbWireShapeType {
@@ -1294,6 +1322,8 @@
12941322
$1 = odb::dbSiteClass::Value::PAD;
12951323
} else if (strcasecmp(str, "CORE") == 0) {
12961324
$1 = odb::dbSiteClass::Value::CORE;
1325+
} else {
1326+
SWIG_exception(SWIG_ValueError, "Unknown site clas");
12971327
}
12981328
}
12991329
%typemap(typecheck) odb::dbSiteClass, dbSiteClass {
@@ -1332,6 +1362,8 @@
13321362
$1 = odb::dbOnOffType::Value::OFF;
13331363
} else if (strcasecmp(str, "ON") == 0) {
13341364
$1 = odb::dbOnOffType::Value::ON;
1365+
} else {
1366+
SWIG_exception(SWIG_ValueError, "Unknown on-off type");
13351367
}
13361368
}
13371369
%typemap(typecheck) odb::dbOnOffType, dbOnOffType {
@@ -1368,6 +1400,8 @@
13681400
$1 = odb::dbClMeasureType::Value::EUCLIDEAN;
13691401
} else if (strcasecmp(str, "MAXXY") == 0) {
13701402
$1 = odb::dbClMeasureType::Value::MAXXY;
1403+
} else {
1404+
SWIG_exception(SWIG_ValueError, "Unknown measure type");
13711405
}
13721406
}
13731407
%typemap(typecheck) odb::dbClMeasureType, dbClMeasureType {
@@ -1414,6 +1448,8 @@
14141448
$1 = odb::dbJournalEntryType::Value::ADD;
14151449
} else if (strcasecmp(str, "DESTROY") == 0) {
14161450
$1 = odb::dbJournalEntryType::Value::DESTROY;
1451+
} else {
1452+
SWIG_exception(SWIG_ValueError, "Unknown journal entry");
14171453
}
14181454
}
14191455
%typemap(typecheck) odb::dbJournalEntryType, dbJournalEntryType {
@@ -1479,6 +1515,8 @@
14791515
$1 = odb::dbDirection::Value::UP;
14801516
} else if (strcasecmp(str, "DOWN") == 0) {
14811517
$1 = odb::dbDirection::Value::DOWN;
1518+
} else {
1519+
SWIG_exception(SWIG_ValueError, "Unknown direction");
14821520
}
14831521
}
14841522
%typemap(typecheck) odb::dbDirection, dbDirection {
@@ -1530,6 +1568,8 @@
15301568
$1 = odb::dbRegionType::Value::EXCLUSIVE;
15311569
} else if (strcasecmp(str, "SUGGESTED") == 0) {
15321570
$1 = odb::dbRegionType::Value::SUGGESTED;
1571+
} else {
1572+
SWIG_exception(SWIG_ValueError, "Unknown region type");
15331573
}
15341574
}
15351575
%typemap(typecheck) odb::dbRegionType, dbRegionType {
@@ -1588,6 +1628,8 @@
15881628
$1 = odb::dbSourceType::Value::TIMING;
15891629
} else if (strcasecmp(str, "TEST") == 0) {
15901630
$1 = odb::dbSourceType::Value::TEST;
1631+
} else {
1632+
SWIG_exception(SWIG_ValueError, "Unknown source type");
15911633
}
15921634
}
15931635
%typemap(typecheck) odb::dbSourceType, dbSourceType {
@@ -1642,6 +1684,8 @@
16421684
$1 = odb::dbGroupType::POWER_DOMAIN;
16431685
} else if (strcasecmp(str, "VISUAL_DEBUG") == 0) {
16441686
$1 = odb::dbGroupType::VISUAL_DEBUG;
1687+
} else {
1688+
SWIG_exception(SWIG_ValueError, "Unknown group type");
16451689
}
16461690
}
16471691
%typemap(typecheck) odb::dbGroupType, dbGroupType {
@@ -1690,8 +1734,10 @@
16901734
$1 = odb::dbTechLayerCutSpacingTableDefRule::LOOKUP_STRATEGY::SECOND;
16911735
} else if (strcasecmp(str, "MAX") == 0) {
16921736
$1 = odb::dbTechLayerCutSpacingTableDefRule::LOOKUP_STRATEGY::MAX;
1693-
} else {
1737+
} else if (strcasecmp(str, "MIN") == 0) {
16941738
$1 = odb::dbTechLayerCutSpacingTableDefRule::LOOKUP_STRATEGY::MIN;
1739+
} else {
1740+
SWIG_exception(SWIG_ValueError, "Unknown lookup strategy");
16951741
}
16961742
}
16971743
%typemap(typecheck) odb::dbTechLayerCutSpacingTableDefRule::LOOKUP_STRATEGY, dbTechLayerCutSpacingTableDefRule_LOOKUP_STRATEGY {

src/odb/test/edit_def.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if { [$swire getNet] != "$net" } {
1919
exit 1
2020
}
2121
set site [lindex [$lib getSites] 0]
22-
set row [odb::dbRow_create $block "row0" $site 0 0 "RO" "HORIZONTAL" 1 10]
22+
set row [odb::dbRow_create $block "row0" $site 0 0 "R0" "HORIZONTAL" 1 10]
2323
if { $row == "NULL" } {
2424
puts "FAIL: row error"
2525
exit 1

src/pad/src/pad.i

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ utl::Logger* getLogger();
2323
%import <std_vector.i>
2424
%import "dbtypes.i"
2525
%import "dbenums.i"
26+
%include "exception.i"
2627
%include "../../Exception.i"
2728

2829

0 commit comments

Comments
 (0)