Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 6a7ba14

Browse files
committed
Move omc_assert functions to the threadData
WIP: Note: OMEdit, etc would need to initialize the assertion routines. This could be done from Main.init() to help that.
1 parent 9c4635f commit 6a7ba14

5 files changed

Lines changed: 15 additions & 9 deletions

File tree

Compiler/Template/CodegenCFunctions.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4779,7 +4779,7 @@ template indexSubs(list<Dimension> dims, list<Subscript> subs, Context context,
47794779
::=
47804780
if intNe(listLength(dims),listLength(subs)) then
47814781
error(sourceInfo(),'indexSubs got different number of dimensions and subscripts')
4782-
else '[calc_base_index_dims_subs(<%listLength(dims)%><%
4782+
else '[calc_base_index_dims_subs(threadData, <%listLength(dims)%><%
47834783
dims |> dim => ', <%dimension(dim)%>'%><%
47844784
subs |> INDEX(__) => ', <%daeSubscriptExp(exp, context, &preExp, &varDecls, &auxFunction)%>'
47854785
%>)]'

SimulationRuntime/c/gc/omc_gc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ extern "C" {
5252
#if defined(_MSC_VER)
5353
#include "omc_inline.h"
5454
#endif
55+
typedef struct assertions_s assertions_t;
5556

5657
typedef struct {
5758
void (*init)(void);
@@ -138,6 +139,7 @@ typedef struct threadData_s {
138139
void *plotClassPointer;
139140
PlotCallback plotCB;
140141
void *stackBottom; /* Actually offset 64 kB from bottom, just to never reach the bottom */
142+
assertions_t *assert;
141143
} threadData_t;
142144

143145
typedef threadData_t* OpenModelica_threadData_ThreadData;

SimulationRuntime/c/util/base_array.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ size_t calc_base_index(int ndims, const _index_t *idx_vec, const base_array_t *a
305305
return index;
306306
}
307307

308-
size_t calc_base_index_dims_subs(int ndims,...)
308+
size_t calc_base_index_dims_subs(threadData_t *threadData, int ndims,...)
309309
{
310310

311311
int i;
@@ -327,8 +327,7 @@ size_t calc_base_index_dims_subs(int ndims,...)
327327
index = 0;
328328
for(i = 0; i < ndims; ++i) {
329329
if (subs[i] < 0 || subs[i] >= dims[i]) {
330-
FILE_INFO info = omc_dummyFileInfo;
331-
omc_assert(NULL, info, "Dimension %d has bounds 1..%d, got array subscript %d", i+1, dims[i], subs[i]+1);
330+
threadData->assert->error(threadData, NULL, "Dimension %d has bounds 1..%d, got array subscript %d", i+1, dims[i], subs[i]+1);
332331
}
333332
index = (index * dims[i]) + subs[i];
334333
}

SimulationRuntime/c/util/base_array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ size_t calc_base_index_spec(int ndims, const _index_t* idx_vec,
100100
size_t calc_base_index(int ndims, const _index_t *idx_vec, const base_array_t *arr);
101101
size_t calc_base_index_va(const base_array_t *source, int ndims, va_list ap);
102102

103-
size_t calc_base_index_dims_subs(int ndims,...);
103+
size_t calc_base_index_dims_subs(threadData_t *threadData, int ndims, ...);
104104

105105
int index_spec_fit_base_array(const index_spec_t *s, const base_array_t *a);
106106

SimulationRuntime/c/util/omc_error.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#ifndef OMC_ERROR_H
3333
#define OMC_ERROR_H
3434

35+
typedef struct threadData_s threadData_t;
36+
3537
#include "openmodelica.h"
3638
#include "omc_msvc.h"
3739

@@ -56,10 +58,13 @@ typedef struct _FILE_INFO
5658
#define omc_dummyFileInfo {"",0,0,0,0,0}
5759

5860
DLLExport extern void printInfo(FILE *stream, FILE_INFO info);
59-
DLLExport extern void (*omc_assert)(threadData_t*, FILE_INFO, const char*, ...) __attribute__ ((noreturn));
60-
DLLExport extern void (*omc_assert_warning)(FILE_INFO, const char*, ...);
61-
DLLExport extern void (*omc_terminate)(FILE_INFO, const char*, ...);
62-
DLLExport extern void (*omc_throw)(threadData_t*) __attribute__ ((noreturn));
61+
62+
typedef struct assertions_s {
63+
void (*error)(threadData_t*, FILE_INFO*, const char*, ...) __attribute__ ((noreturn));
64+
void (*warning)(threadData_t*, FILE_INFO*, const char*, ...);
65+
void (*terminate)(threadData_t*, FILE_INFO*, const char*, ...);
66+
void (*mmc_throw)(threadData_t*) __attribute__ ((noreturn));
67+
} assertions_t;
6368

6469
DLLExport extern void (*omc_assert_withEquationIndexes)(threadData_t*,FILE_INFO, const int*, const char*, ...) __attribute__ ((noreturn));
6570
DLLExport extern void (*omc_assert_warning_withEquationIndexes)(FILE_INFO, const int*, const char*, ...);

0 commit comments

Comments
 (0)