Browse Source

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
tempestpy_adaptions
PBerger 12 years ago
parent
commit
307b85e331
  1. 5
      .gitignore
  2. 38
      CMakeLists.txt
  3. 1
      src/mrmc-cpp.cpp
  4. 3
      src/parser/read_tra_file.cpp
  5. 29
      src/sparse/static_sparse_matrix.h

5
.gitignore

@ -22,6 +22,9 @@
*.unsuccessfulbuild *.unsuccessfulbuild
ipch/ ipch/
obj/ obj/
CMakeFiles/
# The build Dir # The build Dir
build//CMakeLists.txt build//CMakeLists.txt
/*.vcxproj
/*.filters
/*.sln

38
CMakeLists.txt

@ -91,12 +91,12 @@ endif()
find_package(Pantheios REQUIRED COMPONENTS SimpleFrontEnd File) find_package(Pantheios REQUIRED COMPONENTS SimpleFrontEnd File)
IF (PANTHEIOS_FOUND)
if (PANTHEIOS_FOUND)
include_directories(${PANTHEIOS_INCLUDE_DIR}) include_directories(${PANTHEIOS_INCLUDE_DIR})
link_directories(${PANTHEIOS_LIBRARY_DIRS}) link_directories(${PANTHEIOS_LIBRARY_DIRS})
else() else()
message(STATUS "NO PANTHEIOS!") message(STATUS "NO PANTHEIOS!")
ENDIF()
endif()
if(Boost_FOUND) if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS}) include_directories(${Boost_INCLUDE_DIRS})
@ -131,25 +131,25 @@ COMMENT "Generating API documentation with Doxygen" VERBATIM
endif(DOXYGEN_FOUND) endif(DOXYGEN_FOUND)
if (GTEST_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) endif(GTEST_FOUND)
if (THREADS_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) endif(THREADS_FOUND)

1
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 "MRMCConfig.h"
#include "src/sparse/static_sparse_matrix.h" #include "src/sparse/static_sparse_matrix.h"
#include "src/dtmc/atomic_proposition.h"
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Logging init // Logging init

3
src/parser/read_tra_file.cpp

@ -24,6 +24,9 @@ namespace mrmc {
namespace parser{ 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 * This method does the first pass through the .tra file and computes
* the number of non zero elements that are not diagonal elements, * the number of non zero elements that are not diagonal elements,

29
src/sparse/static_sparse_matrix.h

@ -2,6 +2,7 @@
#define MRMC_SPARSE_STATIC_SPARSE_MATRIX_H_ #define MRMC_SPARSE_STATIC_SPARSE_MATRIX_H_
#include <exception> #include <exception>
#include <new>
#include "boost/integer/integer_mask.hpp" #include "boost/integer/integer_mask.hpp"
#include <pantheios/pantheios.hpp> #include <pantheios/pantheios.hpp>
@ -46,16 +47,20 @@ class StaticSparseMatrix {
~StaticSparseMatrix() { ~StaticSparseMatrix() {
if (value_storage != NULL) { if (value_storage != NULL) {
free(value_storage);
//free(value_storage);
delete value_storage;
} }
if (column_indications != NULL) { if (column_indications != NULL) {
free(column_indications);
//free(column_indications);
delete column_indications;
} }
if (row_indications != NULL) { if (row_indications != NULL) {
free(row_indications);
//free(row_indications);
delete row_indications;
} }
if (diagonal_storage != NULL) { 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; storage_size = non_zero_entry_count;
last_row = 0; last_row = 0;
value_storage = static_cast<T*>(calloc(storage_size, sizeof(*value_storage)));
//value_storage = static_cast<T*>(calloc(storage_size, sizeof(*value_storage)));
value_storage = new (std::nothrow) T[storage_size]();
column_indications = static_cast<uint_fast32_t*>(calloc(storage_size, sizeof(*column_indications)));
//column_indications = static_cast<uint_fast32_t*>(calloc(storage_size, sizeof(*column_indications)));
column_indications = new (std::nothrow) uint_fast32_t[storage_size]();
row_indications = static_cast<uint_fast32_t*>(calloc(row_count + 1, sizeof(*row_indications)));
//row_indications = static_cast<uint_fast32_t*>(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 // 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<T*>(calloc(row_count + 1, sizeof(*diagonal_storage)));
//diagonal_storage = static_cast<T*>(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)) { if ((value_storage == NULL) || (column_indications == NULL) || (row_indications == NULL) || (diagonal_storage == NULL)) {
pantheios::log_ERROR("StaticSparseMatrix::initialize: Throwing bad_alloc: memory allocation failed"); 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(); throw std::bad_alloc();
#endif
} }
} }

Loading…
Cancel
Save