From 307b85e331a96f0572930e681a75f35b7c950de5 Mon Sep 17 00:00:00 2001 From: PBerger Date: Thu, 6 Sep 2012 02:44:52 +0200 Subject: [PATCH] Edited static_sparse_matrix.h, replaced all calloc/malloc calls with std::new Removed calls to exceptions with parameter "const char *", is illegal Fixed a warning in read_tra_file.cpp --- .gitignore | 5 +++- CMakeLists.txt | 38 +++++++++++++++---------------- src/mrmc-cpp.cpp | 1 + src/parser/read_tra_file.cpp | 3 +++ src/sparse/static_sparse_matrix.h | 29 +++++++++++++---------- 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index 06524d5a2..96af89416 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,9 @@ *.unsuccessfulbuild ipch/ obj/ - +CMakeFiles/ # The build Dir build//CMakeLists.txt +/*.vcxproj +/*.filters +/*.sln diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dbad804b..3e8bb5d11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,12 +91,12 @@ endif() find_package(Pantheios REQUIRED COMPONENTS SimpleFrontEnd File) -IF (PANTHEIOS_FOUND) +if (PANTHEIOS_FOUND) include_directories(${PANTHEIOS_INCLUDE_DIR}) link_directories(${PANTHEIOS_LIBRARY_DIRS}) else() message(STATUS "NO PANTHEIOS!") -ENDIF() +endif() if(Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) @@ -131,25 +131,25 @@ COMMENT "Generating API documentation with Doxygen" VERBATIM endif(DOXYGEN_FOUND) if (GTEST_FOUND) -# For make-based builds, defines make target named test. -# For Visual Studio builds, defines Visual Studio project named RUN_TESTS. -enable_testing() - -include_directories(${GTEST_INCLUDE_DIRS}) -target_link_libraries(MRMC-tests ${GTEST_LIBRARIES}) - -add_test( - NAME MRMC-tests - COMMAND MRMC-tests -) - + # For make-based builds, defines make target named test. + # For Visual Studio builds, defines Visual Studio project named RUN_TESTS. + enable_testing() + + include_directories(${GTEST_INCLUDE_DIRS}) + target_link_libraries(MRMC-tests ${GTEST_LIBRARIES}) + + add_test( + NAME MRMC-tests + COMMAND MRMC-tests + ) + if( MSVC ) # VS2012 doesn't support correctly the tuples yet + add_definitions( /D _VARIADIC_MAX=10 ) + endif() endif(GTEST_FOUND) if (THREADS_FOUND) - -include_directories(${THREADS_INCLUDE_DIRS}) -target_link_libraries (MRMC-tests ${CMAKE_THREAD_LIBS_INIT}) -target_link_libraries (MRMC-cpp ${CMAKE_THREAD_LIBS_INIT}) - + include_directories(${THREADS_INCLUDE_DIRS}) + target_link_libraries (MRMC-tests ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries (MRMC-cpp ${CMAKE_THREAD_LIBS_INIT}) endif(THREADS_FOUND) \ No newline at end of file diff --git a/src/mrmc-cpp.cpp b/src/mrmc-cpp.cpp index aad1a2627..6308cd169 100644 --- a/src/mrmc-cpp.cpp +++ b/src/mrmc-cpp.cpp @@ -22,6 +22,7 @@ PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = "mrmc-cpp" #include "MRMCConfig.h" #include "src/sparse/static_sparse_matrix.h" +#include "src/dtmc/atomic_proposition.h" int main(int argc, char* argv[]) { // Logging init diff --git a/src/parser/read_tra_file.cpp b/src/parser/read_tra_file.cpp index 86dbb51c2..e7bfd8a9f 100644 --- a/src/parser/read_tra_file.cpp +++ b/src/parser/read_tra_file.cpp @@ -24,6 +24,9 @@ namespace mrmc { namespace parser{ +// Disable C4996 - This function or variable may be unsafe. +#pragma warning(disable:4996) + /*! * This method does the first pass through the .tra file and computes * the number of non zero elements that are not diagonal elements, diff --git a/src/sparse/static_sparse_matrix.h b/src/sparse/static_sparse_matrix.h index d1dfd1aa2..3fc68a7fa 100644 --- a/src/sparse/static_sparse_matrix.h +++ b/src/sparse/static_sparse_matrix.h @@ -2,6 +2,7 @@ #define MRMC_SPARSE_STATIC_SPARSE_MATRIX_H_ #include +#include #include "boost/integer/integer_mask.hpp" #include @@ -46,16 +47,20 @@ class StaticSparseMatrix { ~StaticSparseMatrix() { if (value_storage != NULL) { - free(value_storage); + //free(value_storage); + delete value_storage; } if (column_indications != NULL) { - free(column_indications); + //free(column_indications); + delete column_indications; } if (row_indications != NULL) { - free(row_indications); + //free(row_indications); + delete row_indications; } if (diagonal_storage != NULL) { - free(diagonal_storage); + //free(diagonal_storage); + delete diagonal_storage; } } @@ -116,22 +121,22 @@ class StaticSparseMatrix { storage_size = non_zero_entry_count; last_row = 0; - value_storage = static_cast(calloc(storage_size, sizeof(*value_storage))); + //value_storage = static_cast(calloc(storage_size, sizeof(*value_storage))); + value_storage = new (std::nothrow) T[storage_size](); - column_indications = static_cast(calloc(storage_size, sizeof(*column_indications))); + //column_indications = static_cast(calloc(storage_size, sizeof(*column_indications))); + column_indications = new (std::nothrow) uint_fast32_t[storage_size](); - row_indications = static_cast(calloc(row_count + 1, sizeof(*row_indications))); + //row_indications = static_cast(calloc(row_count + 1, sizeof(*row_indications))); + row_indications = new (std::nothrow) uint_fast32_t[row_count + 1](); // row_count + 1 so that access with 1-based indices can be direct without the overhead of a -1 each time - diagonal_storage = static_cast(calloc(row_count + 1, sizeof(*diagonal_storage))); + //diagonal_storage = static_cast(calloc(row_count + 1, sizeof(*diagonal_storage))); + diagonal_storage = new (std::nothrow) T[row_count + 1](); if ((value_storage == NULL) || (column_indications == NULL) || (row_indications == NULL) || (diagonal_storage == NULL)) { pantheios::log_ERROR("StaticSparseMatrix::initialize: Throwing bad_alloc: memory allocation failed"); -#ifdef _WIN32 - throw std::bad_alloc("mrmc::StaticSparseMatrix::initialize: memory allocation failed"); -#else throw std::bad_alloc(); -#endif } }