From c9f19c9980b34d7e09128689a7a409324ad862b1 Mon Sep 17 00:00:00 2001 From: abd Date: Mon, 21 Apr 2008 11:25:48 +0000 Subject: [PATCH] Fix run-time errors during debug of Windows version --- src/HDFPersist/HDFascii.cc | 15 ++++++++++++--- src/SALOMEDS/SALOMEDS_GenericAttribute_i.cxx | 6 ++++-- .../SALOMEDSImpl_GenericAttribute.cxx | 14 ++++++++++---- .../SALOMEDSImpl_GenericAttribute.hxx | 4 ++-- src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx | 18 +++++++++--------- src/TOOLSDS/SALOMEDS_Tool.cxx | 2 +- 6 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/HDFPersist/HDFascii.cc b/src/HDFPersist/HDFascii.cc index ca86b9f25..4c265f63e 100644 --- a/src/HDFPersist/HDFascii.cc +++ b/src/HDFPersist/HDFascii.cc @@ -36,6 +36,9 @@ #include #include #include +#define dir_separator '\\' +#else +#define dir_separator '/' #endif using namespace std; @@ -654,11 +657,12 @@ string GetTmpDir() char *Tmp_dir = getenv("SALOME_TMP_DIR"); if(Tmp_dir != NULL) { aTmpDir = string(Tmp_dir); -#ifdef WIN32 + if(aTmpDir[aTmpDir.size()-1] != dir_separator) aTmpDir+=dir_separator; +/*#ifdef WIN32 if(aTmpDir[aTmpDir.size()-1] != '\\') aTmpDir+='\\'; #else if(aTmpDir[aTmpDir.size()-1] != '/') aTmpDir+='/'; -#endif +#endif*/ } else { #ifdef WIN32 @@ -677,11 +681,14 @@ string GetTmpDir() aTmpDir += aSubDir; //Get RND sub directory + if(aTmpDir[aTmpDir.size()-1] != dir_separator) aTmpDir+=dir_separator; +/* #ifdef WIN32 if(aTmpDir[aTmpDir.size()-1] != '\\') aTmpDir+='\\'; #else if(aTmpDir[aTmpDir.size()-1] != '/') aTmpDir+='/'; #endif + */ string aDir = aTmpDir; @@ -691,12 +698,14 @@ string GetTmpDir() } #ifdef WNT + //fuction CreateDirectory create only final directory, but not intermediate + CreateDirectory(aTmpDir.c_str(), NULL); CreateDirectory(aDir.c_str(), NULL); #else mkdir(aDir.c_str(), 0x1ff); #endif - return aDir; + return aDir + dir_separator; } char* makeName(char* name) diff --git a/src/SALOMEDS/SALOMEDS_GenericAttribute_i.cxx b/src/SALOMEDS/SALOMEDS_GenericAttribute_i.cxx index 6c25a767a..0bcb49844 100644 --- a/src/SALOMEDS/SALOMEDS_GenericAttribute_i.cxx +++ b/src/SALOMEDS/SALOMEDS_GenericAttribute_i.cxx @@ -79,7 +79,8 @@ char* SALOMEDS_GenericAttribute_i::Type() { SALOMEDS::Locker lock; if (_impl) { - return CORBA::string_dup(SALOMEDSImpl_GenericAttribute::Impl_GetType(_impl)); + string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(_impl); + return CORBA::string_dup(type.c_str()); } return ""; @@ -89,7 +90,8 @@ char* SALOMEDS_GenericAttribute_i::GetClassType() { SALOMEDS::Locker lock; if (_impl) { - return CORBA::string_dup(SALOMEDSImpl_GenericAttribute::Impl_GetClassType(_impl)); + string class_type = SALOMEDSImpl_GenericAttribute::Impl_GetClassType(_impl); + return CORBA::string_dup(class_type.c_str()); } return ""; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.cxx index 168645bb0..37caac3fb 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.cxx @@ -28,16 +28,22 @@ using namespace std; -char* SALOMEDSImpl_GenericAttribute::Impl_GetType(DF_Attribute* theAttr) +string SALOMEDSImpl_GenericAttribute::Impl_GetType(DF_Attribute* theAttr) { SALOMEDSImpl_GenericAttribute* ga = dynamic_cast(theAttr); - return (char*)ga->Type().c_str(); + if (ga) + return ga->Type(); + + return ""; } -char* SALOMEDSImpl_GenericAttribute::Impl_GetClassType(DF_Attribute* theAttr) +string SALOMEDSImpl_GenericAttribute::Impl_GetClassType(DF_Attribute* theAttr) { SALOMEDSImpl_GenericAttribute* ga = dynamic_cast(theAttr); - return (char*)ga->GetClassType().c_str(); + if (ga) + return ga->GetClassType(); + + return ""; } void SALOMEDSImpl_GenericAttribute::Impl_CheckLocked(DF_Attribute* theAttr) diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.hxx index b774dfa94..0fcdb3f5c 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.hxx @@ -50,8 +50,8 @@ public: SALOMEDSImpl_SObject GetSObject(); void SetModifyFlag(); - static char* Impl_GetType(DF_Attribute* theAttr); - static char* Impl_GetClassType(DF_Attribute* theAttr); + static std::string Impl_GetType(DF_Attribute* theAttr); + static std::string Impl_GetClassType(DF_Attribute* theAttr); static void Impl_CheckLocked(DF_Attribute* theAttr); }; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx index 428c5b636..bd904c91b 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx @@ -462,7 +462,7 @@ bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const string& aUrl, HDFdataset *hdf_dataset =0; hdf_size size[1]; hdf_int32 name_len = 0; - char *component_name = 0; + string component_name; if(!aStudy) { _errorCode = "Study is null"; @@ -609,12 +609,12 @@ bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const string& aUrl, hdf_sco_group2->CreateOnDisk(); SaveAttributes(SC, hdf_sco_group2); // ComponentDataType treatment - component_name = (char*)SC.ComponentDataType().c_str(); - name_len = (hdf_int32)strlen(component_name); + component_name = SC.ComponentDataType(); + name_len = (hdf_int32)component_name.length(); size[0] = name_len +1 ; hdf_dataset = new HDFdataset("COMPONENTDATATYPE",hdf_sco_group2,HDF_STRING,size,1); hdf_dataset->CreateOnDisk(); - hdf_dataset->WriteOnDisk(component_name); + hdf_dataset->WriteOnDisk((char*)component_name.c_str()); hdf_dataset->CloseOnDisk(); hdf_dataset=0; //will be deleted by hdf_sco_group destructor Impl_SaveObject(SC, hdf_sco_group2); @@ -638,12 +638,12 @@ bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const string& aUrl, //----------------------------------------------------------------------- //5 - Write the Study Properties //----------------------------------------------------------------------- - name_len = (hdf_int32) aStudy->Name().size(); + string study_name = aStudy->Name(); + name_len = (hdf_int32) study_name.size(); size[0] = name_len +1 ; hdf_dataset = new HDFdataset("STUDY_NAME",hdf_group_study_structure,HDF_STRING,size,1); hdf_dataset->CreateOnDisk(); - char* studid = (char*)aStudy->Name().c_str(); - hdf_dataset->WriteOnDisk(studid); + hdf_dataset->WriteOnDisk((char*)study_name.c_str()); hdf_dataset->CloseOnDisk(); hdf_dataset=0; // will be deleted by hdf_group_study_structure destructor @@ -717,8 +717,8 @@ bool SALOMEDSImpl_StudyManager::Impl_SaveObject(const SALOMEDSImpl_SObject& SC, SALOMEDSImpl_SObject SO = SALOMEDSImpl_Study::SObject(itchild.Value()); - char* scoid = (char*) SO.GetID().c_str(); - hdf_group_sobject = new HDFgroup(scoid, hdf_group_datatype); + string scoid = SO.GetID(); + hdf_group_sobject = new HDFgroup(scoid.c_str(), hdf_group_datatype); hdf_group_sobject->CreateOnDisk(); SaveAttributes(SO, hdf_group_sobject); Impl_SaveObject(SO, hdf_group_sobject); diff --git a/src/TOOLSDS/SALOMEDS_Tool.cxx b/src/TOOLSDS/SALOMEDS_Tool.cxx index e206c4374..444f54558 100644 --- a/src/TOOLSDS/SALOMEDS_Tool.cxx +++ b/src/TOOLSDS/SALOMEDS_Tool.cxx @@ -52,7 +52,7 @@ bool Exists(const string thePath) { #ifdef WNT if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) { - if ( GetLastError () != ERROR_FILE_NOT_FOUND ) { + if ( GetLastError () == ERROR_FILE_NOT_FOUND ) { return false; } } -- 2.39.2