From 1951a27c9866854705f92212ce6304e553675268 Mon Sep 17 00:00:00 2001 From: ski Date: Thu, 7 Aug 2014 14:31:10 +0400 Subject: [PATCH] 0024863: CLang warnings -Wint-to-void-pointer-cast Warning was fixed. Remarks were applied. - class VMap in Draw was removed - NCollection_DataMap is used to store objects - name of object is used to associate Tcl variable with the object - creation and changing of objects are correclty handled Redundant casts were removed. Initial value is restored if variable is protected. Tests for bug #24863 were added. Some test cases and tcl command "save" were improved. Useless using of upvar was removed. --- src/Draw/Draw.cdl | 5 -- src/Draw/Draw_VariableCommands.cxx | 79 +++++++++----------------- src/DrawResources/StandardCommands.tcl | 5 +- tests/bugs/fclasses/bug24863_1 | 14 +++++ tests/bugs/fclasses/bug24863_2 | 18 ++++++ tests/bugs/fclasses/bug24863_3 | 19 +++++++ tests/bugs/modalg_2/bug298 | 2 +- tests/bugs/modalg_2/bug410_4 | 2 +- tests/bugs/modalg_2/bug485 | 2 +- tests/bugs/modalg_2/bug487 | 2 +- tests/bugs/modalg_2/bug5805_1 | 2 +- tests/bugs/moddata_2/bug23165 | 14 ++--- tests/bugs/moddata_2/bug332 | 10 ++-- tests/bugs/xde/bug945 | 2 +- tests/caf/nam/A5 | 11 ++-- tests/geometry/begin | 12 ++-- tests/mesh/end | 3 +- tests/offset/faces_type_i/C9 | 1 + tests/xml/begin | 2 +- 19 files changed, 111 insertions(+), 94 deletions(-) create mode 100644 tests/bugs/fclasses/bug24863_1 create mode 100644 tests/bugs/fclasses/bug24863_2 create mode 100644 tests/bugs/fclasses/bug24863_3 diff --git a/src/Draw/Draw.cdl b/src/Draw/Draw.cdl index b4acd3761f..bd2a1480ac 100644 --- a/src/Draw/Draw.cdl +++ b/src/Draw/Draw.cdl @@ -111,11 +111,6 @@ is class Printer; - class VMap instantiates - DataMap from TCollection(Integer, - Drawable3D from Draw, - MapIntegerHasher from TColStd); - class MapOfAsciiString instantiates IndexedMap from TCollection(AsciiString from TCollection,AsciiString from TCollection); Load(theDI: out Interpretor from Draw; diff --git a/src/Draw/Draw_VariableCommands.cxx b/src/Draw/Draw_VariableCommands.cxx index 2ab2e82725..e94de8fea9 100644 --- a/src/Draw/Draw_VariableCommands.cxx +++ b/src/Draw/Draw_VariableCommands.cxx @@ -30,9 +30,10 @@ #include #include #include -#include #include +#include + #include #ifdef WNT @@ -60,7 +61,7 @@ extern Draw_Interpretor theCommands; // The Integer Value is the content of the TCl variable //=============================================== -static Draw_VMap theVariables; +static NCollection_DataMap theVariables; //======================================================================= //function : FindVariable @@ -310,8 +311,9 @@ static Standard_Integer erase(Draw_Interpretor& di, Standard_Integer n, const ch // sauvegarde des proteges visibles Draw_SequenceOfDrawable3D prot; - for (i = 1; i <= theVariables.Extent(); i++) { - const Handle(Draw_Drawable3D)& D = *((Handle(Draw_Drawable3D)*)&theVariables(i)); + NCollection_DataMap::Iterator aMapIt (theVariables); + for (; aMapIt.More(); aMapIt.Next()) { + const Handle(Draw_Drawable3D)& D = aMapIt.Value(); if (!D.IsNull()) { if (D->Protected() && D->Visible()) prot.Append(D); @@ -723,27 +725,21 @@ void Draw::Set(const Standard_CString name, } // MKV 29.03.05 -#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST) -static char* tracevar(ClientData CD, Tcl_Interp*,const char*,const char*, Standard_Integer) -#else -static char* tracevar(ClientData CD, Tcl_Interp*, char*, char*, Standard_Integer) -#endif +static char* tracevar(ClientData, Tcl_Interp*,const char* name,const char*, Standard_Integer) { // protect if the map was destroyed before the interpretor if (theVariables.IsEmpty()) return NULL; - // MKV 29.03.05 -#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST) - Handle(Draw_Drawable3D)& D = *((Handle(Draw_Drawable3D)*)&theVariables((long)CD)); -#else - Standard_Integer index = (Standard_Integer) CD; - Handle(Draw_Drawable3D)& D = *((Handle(Draw_Drawable3D)*)&theVariables(index)); -#endif - if (D.IsNull()) + Handle(Draw_Drawable3D)& D = theVariables(name); + if (D.IsNull()) { + theVariables.UnBind(name); return NULL; - if (D->Protected()) + } + if (D->Protected()) { + D->Name(Tcl_SetVar(theCommands.Interp(),name,name,0)); return (char*) "variable is protected"; - else { + } else { + Tcl_UntraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,tracevar,NULL); if (D->Visible()) { dout.RemoveDrawable(D); if (D->Is3D()) @@ -752,6 +748,7 @@ static char* tracevar(ClientData CD, Tcl_Interp*, char*, char*, Standard_Integer repaint2d = Standard_True; } D.Nullify(); + theVariables.UnBind(name); return NULL; } } @@ -771,28 +768,27 @@ void Draw::Set(const Standard_CString name, } } else { - - Tcl_UnsetVar(theCommands.Interp(),name,0); + if (theVariables.IsBound(name)) { + if (theVariables(name)->Protected()) { + cout << "variable is protected" << endl; + return; + } + } if (!D.IsNull()) { - Standard_Integer ival = theVariables.Extent() + 1; - theVariables.Bind(ival,D); + Tcl_UnsetVar(theCommands.Interp(),name,0); + theVariables.Bind(name,D); // MKV 29.03.05 -#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST) D->Name(Tcl_SetVar(theCommands.Interp(),name,name,0)); -#else - D->Name(Tcl_SetVar(theCommands.Interp(),(char*)name,(char*)name,0)); -#endif - // set the trace function - Tcl_TraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS, - tracevar,(ClientData)ival); - + Tcl_TraceVar(theCommands.Interp(),name,TCL_TRACE_UNSETS | TCL_TRACE_WRITES,tracevar,NULL); if (displ) { if (!D->Visible()) dout << D; } else if (D->Visible()) dout.RemoveDrawable(D); + } else { + Tcl_UnsetVar(theCommands.Interp(),name,0); } } } @@ -823,11 +819,6 @@ void Draw::Set(const Standard_CString Name, const Standard_Real val) Handle(Draw_Drawable3D) Draw::Get(Standard_CString& name, const Standard_Boolean ) { -#if !((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) || defined(USE_NON_CONST) - Standard_PCharacter pName; - pName=(Standard_PCharacter)name; -#endif - // Standard_Boolean pick = ((name[0] == '.') && (name[1] == '\0')); Handle(Draw_Drawable3D) D; if (pick) { @@ -843,21 +834,7 @@ Handle(Draw_Drawable3D) Draw::Get(Standard_CString& name, } else { // MKV 29.03.05 -#if ((TCL_MAJOR_VERSION > 8) || ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4))) && !defined(USE_NON_CONST) - Standard_Address index = - Tcl_VarTraceInfo(theCommands.Interp(),name,TCL_TRACE_UNSETS, - tracevar, NULL); - if (index != 0) - D = Handle(Draw_Drawable3D)::DownCast(theVariables((long)index)); -#else - Standard_Integer index = (Standard_Integer) - Tcl_VarTraceInfo(theCommands.Interp(), - pName, - TCL_TRACE_UNSETS, - tracevar, NULL); - if (index != 0) - D = Handle(Draw_Drawable3D)::DownCast(theVariables(index)); -#endif + theVariables.Find(name,D); #if 0 if (D.IsNull() && complain) cout < 1. } { diff --git a/tests/bugs/moddata_2/bug23165 b/tests/bugs/moddata_2/bug23165 index 831d7a319e..5b05ca9aa1 100755 --- a/tests/bugs/moddata_2/bug23165 +++ b/tests/bugs/moddata_2/bug23165 @@ -96,15 +96,15 @@ restore [locate_data_file OCC23165-curve.rle] c mkedge result c 20 36 donly result -set result [bounding result] +set res [bounding result] fit -set x1 [lindex ${result} 0] -set y1 [lindex ${result} 1] -set z1 [lindex ${result} 2] -set x2 [lindex ${result} 3] -set y2 [lindex ${result} 4] -set z2 [lindex ${result} 5] +set x1 [lindex ${res} 0] +set y1 [lindex ${res} 1] +set z1 [lindex ${res} 2] +set x2 [lindex ${res} 3] +set y2 [lindex ${res} 4] +set z2 [lindex ${res} 5] set good_x1 -17.6105835090592 set good_y1 -4.7133570660117909 diff --git a/tests/bugs/moddata_2/bug332 b/tests/bugs/moddata_2/bug332 index 82893296a6..dbf2c8356b 100755 --- a/tests/bugs/moddata_2/bug332 +++ b/tests/bugs/moddata_2/bug332 @@ -72,11 +72,11 @@ if { ${listLength} < 20 } { regexp {Mass +: +([-0-9.+eE]+)} $props_6 full CircleLength_6 # Calculation -set pi [expr 2. * asin(1.0)] -set TheoryCircleLength_4 [expr ${pi} * ${dia1}] -set TheoryCircleLength_3 [expr ${pi} * (${dia1} + 2 * ${wall_thickness}) ] -set TheoryCircleLength_6 [expr ${pi} * ${dia2}] -set TheoryCircleLength_5 [expr ${pi} * (${dia2} + 2 * ${wall_thickness}) ] +set Pi [expr 2. * asin(1.0)] +set TheoryCircleLength_4 [expr ${Pi} * ${dia1}] +set TheoryCircleLength_3 [expr ${Pi} * (${dia1} + 2 * ${wall_thickness}) ] +set TheoryCircleLength_6 [expr ${Pi} * ${dia2}] +set TheoryCircleLength_5 [expr ${Pi} * (${dia2} + 2 * ${wall_thickness}) ] set delta_3 [expr abs(${CircleLength_3} - ${TheoryCircleLength_3}) / ${TheoryCircleLength_3} * 100] set delta_4 [expr abs(${CircleLength_4} - ${TheoryCircleLength_4}) / ${TheoryCircleLength_4} * 100] diff --git a/tests/bugs/xde/bug945 b/tests/bugs/xde/bug945 index ec12e25a4c..6ae44a57a0 100755 --- a/tests/bugs/xde/bug945 +++ b/tests/bugs/xde/bug945 @@ -17,7 +17,7 @@ if { [regexp "Faulty" $che] == 1 } { puts "OCC945: Source shape is valid." } -if [catch {fixshape result a 29.9 } result] { +if [catch {fixshape result a 29.9 } res] { puts "Faulty OCC945: here is problem with FIXSHAPE function" } else { decho off diff --git a/tests/caf/nam/A5 b/tests/caf/nam/A5 index b758609081..1496c35bf3 100644 --- a/tests/caf/nam/A5 +++ b/tests/caf/nam/A5 @@ -1,20 +1,19 @@ #################### select shape and check selection procedure #################### proc Select {lab shape context} { global D IsDone TestError - upvar 1 $shape myshape $context mycontext set res "" if {[string compare $context ""] == 0} { - if {[catch {set res [SelectShape D $lab myshape]}]} { + if {[catch {set res [SelectShape D $lab $shape]}]} { set IsDone 0 - set TestError "$TestError # SelectShape bad result for args: $lab myshape" + set TestError "$TestError # SelectShape bad result for args: $lab shape" } } else { - if {[catch {set res [SelectShape D $lab myshape mycontext]}]} { + if {[catch {set res [SelectShape D $lab $shape $context]}]} { set IsDone 0 - set TestError "$TestError # SelectShape bad result for args: $lab myshape" + set TestError "$TestError # SelectShape bad result for args: $lab shape" } } - return [CenterOfShape myshape] + return [CenterOfShape $shape] } if {[catch {set TestLab}] == 1} { diff --git a/tests/geometry/begin b/tests/geometry/begin index b161e346c3..8bf5f4596e 100755 --- a/tests/geometry/begin +++ b/tests/geometry/begin @@ -21,12 +21,11 @@ if { [info exists test_image ] == 0 } { proc val2d { c u1 u2 n } { dset du ($u2-$u1)/$n - upvar $c cc set i 1 for {dset u $u1} { [dval u] <= $u2} {dset u ($u1+$i*[dval du])} { - 2dcvalue cc u x y dx dy d2x d2y ; + 2dcvalue $c u x y dx dy d2x d2y ; global p_$i d1_$i d2_$i point p_$i x y; puts "u = [dval u]" @@ -47,12 +46,11 @@ proc val2d { c u1 u2 n } { proc val3d { c u1 u2 n } { dset du ($u2-$u1)/$n - upvar $c cc set i 1 for {dset u $u1} { [dval u] <= $u2} {dset u (u+[dval du])} { - cvalue cc u x y z dx dy dz d2x d2y d2z ; + cvalue $c u x y z dx dy dz d2x d2y d2z ; point p_$i x y z; puts "u = [dval u]" puts "p_$i [dval x ] [dval y ] [dval z]"; @@ -75,10 +73,8 @@ proc compare {r1 r2 tol} { } proc comparepnt2d {p1 p2 tol} { - upvar $p1 pp1 - upvar $p2 pp2 - coord pp1 x1 y1 - coord pp2 x2 y2 + coord $p1 x1 y1 + coord $p2 x2 y2 compare [dval x1] [dval x2] $tol compare [dval y1] [dval y2] $tol } diff --git a/tests/mesh/end b/tests/mesh/end index 5640b83cee..ecd803637a 100644 --- a/tests/mesh/end +++ b/tests/mesh/end @@ -138,8 +138,7 @@ puts " " # Check if area of triangles is valid proc CheckTriArea {shape {eps 0}} { - upvar #0 $shape a - set area [triarea a $eps] + set area [triarea $shape $eps] set t_area [lindex $area 0] set g_area [expr abs([lindex $area 1])] puts "area by triangles: $t_area" diff --git a/tests/offset/faces_type_i/C9 b/tests/offset/faces_type_i/C9 index f1f655c5a0..5dfd985d36 100644 --- a/tests/offset/faces_type_i/C9 +++ b/tests/offset/faces_type_i/C9 @@ -2,6 +2,7 @@ puts "TODO ?OCC23748 ALL: ERROR. offsetperform operation not done." puts "TODO ?OCC23748 ALL: Tcl Exception: ERROR. offsetperform operation not done." puts "TODO ?OCC23748 ALL: Faulty shapes in variables faulty_1 to faulty_" puts "TODO ?OCC23748 ALL: Error : The volume of the resulting shape is" +puts "TODO ?OCC23748 ALL: Error : The area of face result_. of the resulting shape is negative" puts "TODO ?OCC23748 ALL: TEST INCOMPLETE" puts "TODO ?DEBUG_OCC24121 : Error : The area of face" puts "TODO ?OCC24156 MacOS: Error : The area of face" diff --git a/tests/xml/begin b/tests/xml/begin index f5cc9f73cc..8308f7e191 100755 --- a/tests/xml/begin +++ b/tests/xml/begin @@ -43,7 +43,7 @@ proc SaveToFile { aD aFile } { upvar $aD D global FileSuffix ValidatorCheck catch {[file delete ${aFile}]} - SaveAs D $aFile + SaveAs $D $aFile if { [file exists $aFile] } { if { $FileSuffix == "xml" && $ValidatorCheck} { ValidateXml $aFile