Skip to content

Commit

Permalink
- events: do not free if not malloc
Browse files Browse the repository at this point in the history
- error msg style

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10448 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Nov 11, 2011
1 parent fde99a0 commit f15b1a7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 42 deletions.
4 changes: 4 additions & 0 deletions SimulationRuntime/c/math-support/events.c
Expand Up @@ -109,6 +109,10 @@ initializeEventData()
void
deinitializeEventData()
{
if(!globalData)
{
return;
}
free(globalData->helpVars_saved);
free(globalData->states_saved);
free(globalData->statesDerivatives_saved);
Expand Down
78 changes: 40 additions & 38 deletions SimulationRuntime/c/simulation/simulation_data.c
@@ -1,34 +1,36 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2010, Linköpings University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THIS OSMC PUBLIC
* LICENSE (OSMC-PL). ANY USE, REPRODUCTION OR DISTRIBUTION OF
* THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THE OSMC
* PUBLIC LICENSE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from Linköpings University, either from the above address,
* from the URL: http://www.ida.liu.se/projects/OpenModelica
* and in the OpenModelica distribution.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
* OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2010, Linköpings University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THIS OSMC PUBLIC
* LICENSE (OSMC-PL). ANY USE, REPRODUCTION OR DISTRIBUTION OF
* THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THE OSMC
* PUBLIC LICENSE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from Linköpings University, either from the above address,
* from the URL: http://www.ida.liu.se/projects/OpenModelica
* and in the OpenModelica distribution.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
* OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/

#include "simulation_data.h"
#include "error.h"

#include <stdlib.h>
#include <malloc.h>

Expand All @@ -51,14 +53,14 @@ void initializeDataStruc(_X_DATA *data)
{
tmpSimData = ((SIMULATION_DATA*)getRingData(data->simulationData, (int)SIZERINGBUFFER));

tmpSimData->realVars = (modelica_real*)calloc(data->modelData.nVariablesReal, sizeof(modelica_real));
tmpSimData->integerVars = (modelica_integer*)calloc(data->modelData.nVariablesInteger, sizeof(modelica_integer));
tmpSimData->booleanVars = (modelica_boolean*)calloc(data->modelData.nVariablesBoolean, sizeof(modelica_boolean));
tmpSimData->stringVars = (modelica_string*)calloc(data->modelData.nVariablesString, sizeof(modelica_string));

tmpSimData->realVarsPre = (modelica_real*)calloc(data->modelData.nVariablesReal, sizeof(modelica_real));
tmpSimData->integerVarsPre = (modelica_integer*)calloc(data->modelData.nVariablesInteger, sizeof(modelica_integer));
tmpSimData->booleanVarsPre = (modelica_boolean*)calloc(data->modelData.nVariablesBoolean, sizeof(modelica_boolean));
tmpSimData->stringVarsPre = (modelica_string*)calloc(data->modelData.nVariablesString, sizeof(modelica_string));
tmpSimData->realVars = (modelica_real*)calloc(data->modelData.nVariablesReal, sizeof(modelica_real));
tmpSimData->integerVars = (modelica_integer*)calloc(data->modelData.nVariablesInteger, sizeof(modelica_integer));
tmpSimData->booleanVars = (modelica_boolean*)calloc(data->modelData.nVariablesBoolean, sizeof(modelica_boolean));
tmpSimData->stringVars = (modelica_string*)calloc(data->modelData.nVariablesString, sizeof(modelica_string));

tmpSimData->realVarsPre = (modelica_real*)calloc(data->modelData.nVariablesReal, sizeof(modelica_real));
tmpSimData->integerVarsPre = (modelica_integer*)calloc(data->modelData.nVariablesInteger, sizeof(modelica_integer));
tmpSimData->booleanVarsPre = (modelica_boolean*)calloc(data->modelData.nVariablesBoolean, sizeof(modelica_boolean));
tmpSimData->stringVarsPre = (modelica_string*)calloc(data->modelData.nVariablesString, sizeof(modelica_string));
}
}
1 change: 1 addition & 0 deletions SimulationRuntime/c/simulation/simulation_runtime.cpp
Expand Up @@ -1028,6 +1028,7 @@ initRuntimeAndSimulation(int argc, char**argv, _X_DATA *data)
<< endl;
EXIT(0);
}

globalData = initializeDataStruc2(initializeDataStruc());

if (!globalData) {
Expand Down
9 changes: 5 additions & 4 deletions SimulationRuntime/c/util/error.h
Expand Up @@ -34,6 +34,7 @@
#define ERROR_H

#include <setjmp.h>
#include <stdio.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -42,11 +43,11 @@ extern "C" {
/* Global JumpBuffer */
extern jmp_buf globalJmpbuf;

#define MSG(type,msg) { printf("%s | %s | %d\n |> %s\n", type, __FILE__, __LINE__, msg); fflush(NULL); }
#define MSG(type,stream,msg) { fprintf(stream,"%s | %d | %s\n |> %s\n", type, __LINE__, __FILE__, msg); fflush(NULL); }

#define INFO(msg) { MSG("info ", msg); }
#define WARNING(msg) { MSG("warning", msg); }
#define THROW(msg) { MSG("error ", msg); longjmp(globalJmpbuf, 1); }
#define INFO(msg) { MSG("info ", stdout, msg); }
#define WARNING(msg) { MSG("warning", stdout, msg); }
#define THROW(msg) { MSG("error ", stderr, msg); longjmp(globalJmpbuf, 1); }

#ifdef __cplusplus
}
Expand Down

0 comments on commit f15b1a7

Please sign in to comment.