Skip to content

Commit af03d95

Browse files
sjoelundmahge
andauthored
Give the error functions default values. (#8073)
* Give the error functions default values. - The default values given to the are the 'functions' versions, e.g. `omc_assert = omc_assert_function` - This way we do not have to initialize them in every executable code that links to the OpenModelicaRuntimeC. If you do not specify anything you get the default value. - For simulations set them to the 'simulation' versions in the simulation executables 'main' function, e.g, `omc_assert = omc_assert_simulation` - Windows tests are now on track to start working without complaining about undefined references in 'function' mode. - The testcase is intended to test parameter overriding. However it had a terminate statement that fired when t > 1 but also specified an experiment stop time of 2. Use the default stop time of 1 so the test does not terminate before doing what is is supposed to test. Co-authored-by: Mahder Gebremedhin <mahder.geb@gmail.com>
1 parent 0ea1e76 commit af03d95

File tree

19 files changed

+92
-67
lines changed

19 files changed

+92
-67
lines changed

OMCompiler/Compiler/.cmake/omc_entry_point.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ omc_Main_main
1414
#endif
1515
(threadData_t*,modelica_metatype);
1616

17-
void (*omc_assert)(threadData_t*,FILE_INFO info,const char *msg,...) __attribute__((noreturn)) = omc_assert_function;
18-
void (*omc_assert_warning)(FILE_INFO info,const char *msg,...) = omc_assert_warning_function;
19-
void (*omc_terminate)(FILE_INFO info,const char *msg,...) = omc_terminate_function;
20-
void (*omc_throw)(threadData_t*) __attribute__ ((noreturn)) = omc_throw_function;
21-
2217
#ifdef _OPENMP
2318
#include<omp.h>
2419
/* Hack to make gcc-4.8 link in the OpenMP runtime if -fopenmp is given */

OMCompiler/Compiler/Template/CodegenC.tpl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ end translateModel;
118118
#include "simulation/simulation_runtime.h"
119119
#include "util/omc_error.h"
120120
#include "util/parallel_helper.h"
121+
#include "simulation/simulation_omc_assert.h"
121122
#include "simulation/solver/model_help.h"
122123
#include "simulation/solver/delay.h"
123124
#include "simulation/solver/linearSystem.h"
@@ -1223,6 +1224,18 @@ template simulationFile(SimCode simCode, String guid, String isModelExchangeFMU)
12231224
/* call the simulation runtime main from our main! */
12241225
int main(int argc, char**argv)
12251226
{
1227+
/*
1228+
Set the error functions to be used for simulation.
1229+
The default value for them is 'functions' version. Change it here to 'simulation' versions
1230+
*/
1231+
omc_assert = omc_assert_simulation;
1232+
omc_assert_withEquationIndexes = omc_assert_simulation_withEquationIndexes;
1233+
1234+
omc_assert_warning_withEquationIndexes = omc_assert_warning_simulation_withEquationIndexes;
1235+
omc_assert_warning = omc_assert_warning_simulation;
1236+
omc_terminate = omc_terminate_simulation;
1237+
omc_throw = omc_throw_simulation;
1238+
12261239
int res;
12271240
DATA data;
12281241
MODEL_DATA modelData;

OMCompiler/Compiler/Template/CodegenCFunctions.tpl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ extern void
4848
#endif
4949
(threadData_t*,modelica_metatype);
5050

51-
void (*omc_assert)(threadData_t*,FILE_INFO info,const char *msg,...) __attribute__((noreturn)) = omc_assert_function;
52-
void (*omc_assert_warning)(FILE_INFO info,const char *msg,...) = omc_assert_warning_function;
53-
void (*omc_terminate)(FILE_INFO info,const char *msg,...) = omc_terminate_function;
54-
void (*omc_throw)(threadData_t*) __attribute__ ((noreturn)) = omc_throw_function;
55-
5651
#ifdef _OPENMP
5752
#include<omp.h>
5853
/* Hack to make gcc-4.8 link in the OpenMP runtime if -fopenmp is given */
@@ -1430,11 +1425,6 @@ template generateInFunc(Text fname, list<Variable> functionArguments, list<Varia
14301425
return 1;
14311426
}
14321427

1433-
void (*omc_assert)(threadData_t*,FILE_INFO info,const char *msg,...) __attribute__((noreturn)) = omc_assert_function;
1434-
void (*omc_assert_warning)(FILE_INFO info,const char *msg,...) = omc_assert_warning_function;
1435-
void (*omc_terminate)(FILE_INFO info,const char *msg,...) = omc_terminate_function;
1436-
void (*omc_throw)(threadData_t*) __attribute__ ((noreturn)) = omc_throw_function;
1437-
14381428
int main(int argc, char **argv) {
14391429
MMC_INIT(0);
14401430
{

OMCompiler/Compiler/boot/Makefile.common

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ bootstrap-from-tarball2:
7272
$(MAKE) -f $(defaultMakefileTarget) --no-print-directory clean OMC="$(BOOTSTRAP_OMC)"
7373
$(MAKE) -f $(defaultMakefileTarget) --no-print-directory runtime-depends OMBUILDDIR=$(OMBUILDDIR) OMC="$(BOOTSTRAP_OMC)"
7474
OPENMODELICA_BACKEND_STUBS=1 $(MAKE) -f $(defaultMakefileTarget) generate-files-in-steps OMC="$(BOOTSTRAP_OMC)" OMC_EXTRA_FLAGS= TEMPLATES_TARGET=templates-bootstrap
75+
cp bootstrap-sources/build/_main.c build/
7576
# We have not compiled OpenModelicaScriptingAPI.mo yet
7677
touch build/OpenModelicaScriptingAPI.h
7778
$(MAKE) -f $(defaultMakefileTarget) install INCLUDESOURCES=1 OMC="$(BOOTSTRAP_OMC)" CPPFLAGS="$(CPPFLAGS) -DOMC_BOOTSTRAPPING_STAGE_2"

OMCompiler/Compiler/boot/bootstrap-sources/build/_main.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ extern void
1919
omc_Main_main
2020
#endif
2121
(threadData_t*,modelica_metatype);
22-
void (*omc_assert)(threadData_t*,FILE_INFO info,const char *msg,...) __attribute__((noreturn)) = omc_assert_function;
23-
void (*omc_assert_warning)(FILE_INFO info,const char *msg,...) = omc_assert_warning_function;
24-
void (*omc_terminate)(FILE_INFO info,const char *msg,...) = omc_terminate_function;
25-
void (*omc_throw)(threadData_t*) __attribute__ ((noreturn)) = omc_throw_function;
2622
#ifdef _OPENMP
2723
#include<omp.h>
2824
int (*force_link_omp)(void) = omp_get_num_threads;

OMCompiler/SimulationRuntime/OMSICpp/omcWrapper/omcCAPI/include/OMCFunctions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
#include "scripting-API/OpenModelicaScriptingAPI.h"
88

99
extern "C" {
10-
void (*omc_assert)(threadData_t*, FILE_INFO info, const char* msg,...) __attribute__((noreturn)) = omc_assert_function;
11-
void (*omc_assert_warning)(FILE_INFO info, const char* msg,...) = omc_assert_warning_function;
12-
void (*omc_terminate)(FILE_INFO info, const char* msg,...) = omc_terminate_function;
13-
void (*omc_throw)(threadData_t*) __attribute__((noreturn)) = omc_throw_function;
1410
int omc_Main_handleCommand(void* threadData, void* imsg, void** omsg);
1511
void* omc_Main_init(void* threadData, void* args);
1612
void omc_Main_readSettings(void* threadData, void* args);

OMCompiler/SimulationRuntime/c/Makefile.common

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ RUNTIMESIMULATION_HEADERS = ./simulation/modelinfo.h \
6565
./simulation/options.h \
6666
./simulation/simulation_info_json.h \
6767
./simulation/simulation_input_xml.h \
68+
./simulation/simulation_omc_assert.h \
6869
./simulation/simulation_runtime.h \
6970
./simulation/omc_simulation_util.h
7071

OMCompiler/SimulationRuntime/c/Makefile.objs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ SIM_HFILES = ../dataReconciliation/dataReconciliation.h \
259259
omc_simulation_util.h \
260260
simulation_info_json.h \
261261
simulation_input_xml.h \
262+
simulation_omc_assert.h \
262263
simulation_runtime.h \
263264
socket.h \
264265
options.h

OMCompiler/SimulationRuntime/c/simulation/simulation_omc_assert.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@
3030

3131
#include <stdarg.h>
3232
#include <stddef.h>
33-
#include "../util/omc_error.h"
3433
#include "../util/utility.h"
3534
#include "../meta/meta_modelica.h"
35+
#include "simulation_omc_assert.h"
3636
#include "simulation_runtime.h"
3737

38+
39+
void (*omc_assert_withEquationIndexes)(threadData_t*, FILE_INFO info, const int *indexes, const char *msg, ...) __attribute__ ((noreturn)) = omc_assert_simulation_withEquationIndexes;
40+
41+
void (*omc_assert_warning_withEquationIndexes)(FILE_INFO info, const int *indexes, const char *msg, ...) = omc_assert_warning_simulation_withEquationIndexes;
42+
43+
3844
int terminationTerminate = 0; /* Becomes non-zero when user terminates simulation. */
3945
FILE_INFO TermInfo; /* message for termination. */
4046
char* TermMsg; /* message for termination. */
@@ -63,11 +69,6 @@ static void setTermMsg(const char *msg, va_list ap)
6369
}
6470
}
6571

66-
static void omc_assert_simulation(threadData_t *threadData, FILE_INFO info, const char *msg, ...) __attribute__ ((noreturn));
67-
static void omc_assert_simulation_withEquationIndexes(threadData_t *threadData, FILE_INFO info, const int *indexes, const char *msg, ...) __attribute__ ((noreturn));
68-
static void omc_throw_simulation(threadData_t* threadData) __attribute__ ((noreturn));
69-
static void va_omc_assert_simulation_withEquationIndexes(threadData_t *threadData, FILE_INFO info, const int *indexes, const char *msg, va_list args) __attribute__ ((noreturn));
70-
7172
static void va_omc_assert_simulation_withEquationIndexes(threadData_t *threadData, FILE_INFO info, const int *indexes, const char *msg, va_list args)
7273
{
7374
threadData = threadData ? threadData : (threadData_t*)pthread_getspecific(mmc_thread_data_key);
@@ -105,15 +106,15 @@ static void va_omc_assert_simulation_withEquationIndexes(threadData_t *threadDat
105106
}
106107
}
107108

108-
static void omc_assert_simulation(threadData_t *threadData, FILE_INFO info, const char *msg, ...)
109+
void omc_assert_simulation(threadData_t *threadData, FILE_INFO info, const char *msg, ...)
109110
{
110111
va_list args;
111112
va_start(args, msg);
112113
va_omc_assert_simulation_withEquationIndexes(threadData, info, NULL, msg, args);
113114
va_end(args);
114115
}
115116

116-
static void omc_assert_simulation_withEquationIndexes(threadData_t *threadData, FILE_INFO info, const int *indexes, const char *msg, ...)
117+
void omc_assert_simulation_withEquationIndexes(threadData_t *threadData, FILE_INFO info, const int *indexes, const char *msg, ...)
117118
{
118119
va_list args;
119120
va_start(args, msg);
@@ -127,23 +128,23 @@ static void va_omc_assert_warning_simulation(FILE_INFO info, const int *indexes,
127128
va_warningStreamPrintWithEquationIndexes(LOG_ASSERT, 0, indexes, msg, args);
128129
}
129130

130-
static void omc_assert_warning_simulation(FILE_INFO info, const char *msg, ...)
131+
void omc_assert_warning_simulation(FILE_INFO info, const char *msg, ...)
131132
{
132133
va_list args;
133134
va_start(args, msg);
134135
va_omc_assert_warning_simulation(info, NULL, msg, args);
135136
va_end(args);
136137
}
137138

138-
static void omc_assert_warning_simulation_withEquationIndexes(FILE_INFO info, const int *indexes, const char *msg, ...)
139+
void omc_assert_warning_simulation_withEquationIndexes(FILE_INFO info, const int *indexes, const char *msg, ...)
139140
{
140141
va_list args;
141142
va_start(args, msg);
142143
va_omc_assert_warning_simulation(info, indexes, msg, args);
143144
va_end(args);
144145
}
145146

146-
static void omc_terminate_simulation(FILE_INFO info, const char *msg, ...)
147+
void omc_terminate_simulation(FILE_INFO info, const char *msg, ...)
147148
{
148149
va_list ap;
149150
va_start(ap,msg);
@@ -164,18 +165,10 @@ void setTermMsg_empty_va_list(const char *msg, ...) {
164165
va_end(dummy);
165166
}
166167

167-
static void omc_throw_simulation(threadData_t* threadData)
168+
void omc_throw_simulation(threadData_t* threadData)
168169
{
169170
setTermMsg_empty_va_list("Assertion triggered by external C function");
170171
set_struct(FILE_INFO, TermInfo, omc_dummyFileInfo);
171172
threadData = threadData ? threadData : (threadData_t*)pthread_getspecific(mmc_thread_data_key);
172173
longjmp(*threadData->globalJumpBuffer, 1);
173174
}
174-
175-
void (*omc_assert)(threadData_t*, FILE_INFO info, const char *msg, ...) __attribute__ ((noreturn)) = omc_assert_simulation;
176-
void (*omc_assert_withEquationIndexes)(threadData_t*, FILE_INFO info, const int *indexes, const char *msg, ...) __attribute__ ((noreturn)) = omc_assert_simulation_withEquationIndexes;
177-
178-
void (*omc_assert_warning_withEquationIndexes)(FILE_INFO info, const int *indexes, const char *msg, ...) = omc_assert_warning_simulation_withEquationIndexes;
179-
void (*omc_assert_warning)(FILE_INFO info, const char *msg, ...) = omc_assert_warning_simulation;
180-
void (*omc_terminate)(FILE_INFO info, const char *msg, ...) = omc_terminate_simulation;
181-
void (*omc_throw)(threadData_t*) __attribute__ ((noreturn)) = omc_throw_simulation;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* This file is part of OpenModelica.
3+
*
4+
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
5+
* c/o Linköpings universitet, Department of Computer and Information Science,
6+
* SE-58183 Linköping, Sweden.
7+
*
8+
* All rights reserved.
9+
*
10+
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE
11+
* GPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
12+
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13+
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
14+
* ACCORDING TO RECIPIENTS CHOICE.
15+
*
16+
* The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17+
* Public License (OSMC-PL) are obtained from OSMC, either from the above
18+
* address, from the URLs: http://www.openmodelica.org or
19+
* http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica
20+
* distribution. GNU version 3 is obtained from:
21+
* http://www.gnu.org/copyleft/gpl.html. The New BSD License is obtained from:
22+
* http://www.opensource.org/licenses/BSD-3-Clause.
23+
*
24+
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
25+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS
26+
* EXPRESSLY SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE
27+
* CONDITIONS OF OSMC-PL.
28+
*
29+
*/
30+
31+
#ifndef OMC_SIMULATION_OMC_ASSERT_H
32+
#define OMC_SIMULATION_OMC_ASSERT_H
33+
34+
#include "../util/omc_error.h"
35+
36+
DLLExport extern void (*omc_assert_withEquationIndexes)(threadData_t*, FILE_INFO info, const int *indexes, const char *msg, ...) __attribute__ ((noreturn));
37+
38+
DLLExport extern void (*omc_assert_warning_withEquationIndexes)(FILE_INFO info, const int *indexes, const char *msg, ...);
39+
40+
41+
42+
void omc_assert_simulation_withEquationIndexes(threadData_t *threadData, FILE_INFO info, const int *indexes, const char *msg, ...) __attribute__ ((noreturn));
43+
44+
void omc_assert_warning_simulation_withEquationIndexes(FILE_INFO info, const int *indexes, const char *msg, ...);
45+
46+
void omc_assert_simulation(threadData_t *threadData, FILE_INFO info, const char *msg, ...);
47+
void omc_terminate_simulation(FILE_INFO info, const char *msg, ...);
48+
void omc_throw_simulation(threadData_t* threadData);
49+
void omc_assert_warning_simulation(FILE_INFO info, const char *msg, ...);
50+
51+
#endif // Header

0 commit comments

Comments
 (0)