Skip to content

Commit

Permalink
Make array inputs of external C functions const (introduced in Modeli…
Browse files Browse the repository at this point in the history
…ca 3.5) (modelica#3700)

* Make array inputs of external C functions const

* Make array inputs of external C functions const
  • Loading branch information
beutlich committed Jan 18, 2024
1 parent 24477ff commit b540e62
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Modelica/Blocks/Tables.mo
Expand Up @@ -1330,7 +1330,7 @@ protected
external \"C\" dummy_y = mydummyfunc(dummy_u);
annotation(IncludeDirectory=\"modelica://Modelica/Resources/Data/Tables\",
Include = \"#include \"usertab.c\"
double mydummyfunc(double* dummy_in) {
double mydummyfunc(const double* dummy_in) {
return 0;
}
\");
Expand Down
2 changes: 1 addition & 1 deletion Modelica/Resources/C-Sources/ModelicaFFT.c
Expand Up @@ -518,7 +518,7 @@ static void mrkiss_fftr(mrkiss_fftr_cfg st, const mrkiss_fft_scalar *timedata, m
}
}

int ModelicaFFT_kiss_fftr(_In_ double* u, size_t nu, _In_ double* work, size_t nwork,
int ModelicaFFT_kiss_fftr(_In_ const double* u, size_t nu, _In_ double* work, size_t nwork,
_Out_ double *amplitudes, _Out_ double *phases) {

/* Compute real FFT with mrkiss_fftr
Expand Down
2 changes: 1 addition & 1 deletion Modelica/Resources/C-Sources/ModelicaFFT.h
Expand Up @@ -69,7 +69,7 @@
#define _Out_
#endif

MODELICA_EXPORT int ModelicaFFT_kiss_fftr(_In_ double* u, size_t nu, _In_ double* work, size_t nwork,
MODELICA_EXPORT int ModelicaFFT_kiss_fftr(_In_ const double* u, size_t nu, _In_ double* work, size_t nwork,
_Out_ double *amplitudes, _Out_ double *phases) MODELICA_NONNULLATTR;

#endif
4 changes: 2 additions & 2 deletions Modelica/Resources/C-Sources/ModelicaIO.c
Expand Up @@ -112,7 +112,7 @@ void ModelicaIO_readRealMatrix(_In_z_ const char* fileName,
int verbose) {
ModelicaNotExistError("ModelicaIO_readRealMatrix"); }
int ModelicaIO_writeRealMatrix(_In_z_ const char* fileName,
_In_z_ const char* matrixName, _In_ double* matrix, size_t m, size_t n,
_In_z_ const char* matrixName, _In_ const double* matrix, size_t m, size_t n,
int append, _In_z_ const char* version) {
ModelicaNotExistError("ModelicaIO_writeRealMatrix"); return 0; }
double* ModelicaIO_readRealTable(_In_z_ const char* fileName,
Expand Down Expand Up @@ -290,7 +290,7 @@ void ModelicaIO_readRealMatrix(_In_z_ const char* fileName,

int ModelicaIO_writeRealMatrix(_In_z_ const char* fileName,
_In_z_ const char* matrixName,
_In_ double* matrix, size_t m, size_t n,
_In_ const double* matrix, size_t m, size_t n,
int append,
_In_z_ const char* version) {
int status;
Expand Down
2 changes: 1 addition & 1 deletion Modelica/Resources/C-Sources/ModelicaIO.h
Expand Up @@ -112,7 +112,7 @@ MODELICA_EXPORT void ModelicaIO_readRealMatrix(_In_z_ const char* fileName,

MODELICA_EXPORT int ModelicaIO_writeRealMatrix(_In_z_ const char* fileName,
_In_z_ const char* matrixName,
_In_ double* matrix, size_t m, size_t n,
_In_ const double* matrix, size_t m, size_t n,
int append,
_In_z_ const char* version) MODELICA_NONNULLATTR;
/* Write matrix to file
Expand Down
8 changes: 4 additions & 4 deletions Modelica/Resources/C-Sources/ModelicaRandom.c
Expand Up @@ -122,7 +122,7 @@ static void ModelicaRandom_deleteCS(void) {
#define ModelicaRandom_INVM64 5.42101086242752217004e-20 /* = 2^(-64) */
#define ModelicaRandom_RAND(INT64) ( (int64_t)(INT64) * ModelicaRandom_INVM64 + 0.5 )

void ModelicaRandom_xorshift64star(_In_ int* state_in,
void ModelicaRandom_xorshift64star(_In_ const int* state_in,
_Out_ int* state_out, _Out_ double* y) {
/* xorshift64* random number generator.
For details see http://xorshift.di.unimi.it/
Expand Down Expand Up @@ -172,7 +172,7 @@ void ModelicaRandom_xorshift64star(_In_ int* state_in,
*y = ModelicaRandom_RAND(x);
}

void ModelicaRandom_xorshift128plus(_In_ int* state_in,
void ModelicaRandom_xorshift128plus(_In_ const int* state_in,
_Out_ int* state_out, _Out_ double* y) {
/* xorshift128+ random number generator.
For details see http://xorshift.di.unimi.it
Expand Down Expand Up @@ -274,7 +274,7 @@ static void ModelicaRandom_xorshift1024star_internal(uint64_t s[], int* p, doubl
#endif
}

void ModelicaRandom_xorshift1024star(_In_ int* state_in,
void ModelicaRandom_xorshift1024star(_In_ const int* state_in,
_Out_ int* state_out, _Out_ double* y) {
/* xorshift1024* random number generator.
For details see http://xorshift.di.unimi.it
Expand Down Expand Up @@ -334,7 +334,7 @@ static uint64_t ModelicaRandom_s[ 16 ];
static int ModelicaRandom_p;
static int ModelicaRandom_id = 0;

void ModelicaRandom_setInternalState_xorshift1024star(_In_ int* state,
void ModelicaRandom_setInternalState_xorshift1024star(_In_ const int* state,
size_t nState, int id) {
/* Receive the external states from Modelica */
union s_tag {
Expand Down
8 changes: 4 additions & 4 deletions Modelica/Resources/C-Sources/ModelicaRandom.h
Expand Up @@ -69,14 +69,14 @@
#define _Out_
#endif

MODELICA_EXPORT void ModelicaRandom_xorshift64star(_In_ int* state_in,
MODELICA_EXPORT void ModelicaRandom_xorshift64star(_In_ const int* state_in,
_Out_ int* state_out, _Out_ double* y) MODELICA_NONNULLATTR;
MODELICA_EXPORT void ModelicaRandom_xorshift128plus(_In_ int* state_in,
MODELICA_EXPORT void ModelicaRandom_xorshift128plus(_In_ const int* state_in,
_Out_ int* state_out, _Out_ double* y) MODELICA_NONNULLATTR;
MODELICA_EXPORT void ModelicaRandom_xorshift1024star(_In_ int* state_in,
MODELICA_EXPORT void ModelicaRandom_xorshift1024star(_In_ const int* state_in,
_Out_ int* state_out, _Out_ double* y) MODELICA_NONNULLATTR;
MODELICA_EXPORT void ModelicaRandom_setInternalState_xorshift1024star(
_In_ int* state, size_t nState, int id) MODELICA_NONNULLATTR;
_In_ const int* state, size_t nState, int id) MODELICA_NONNULLATTR;
MODELICA_EXPORT double ModelicaRandom_impureRandom_xorshift1024star(int id);
MODELICA_EXPORT int ModelicaRandom_automaticGlobalSeed(double dummy);
MODELICA_EXPORT void ModelicaRandom_convertRealToIntegers(double d,
Expand Down
32 changes: 16 additions & 16 deletions Modelica/Resources/C-Sources/ModelicaStandardTables.c
@@ -1,6 +1,6 @@
/* ModelicaStandardTables.c - External table functions
Copyright (C) 2013-2022, Modelica Association and contributors
Copyright (C) 2013-2024, Modelica Association and contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -624,10 +624,10 @@ static void spline2DClose(CubicHermite2D** spline);

void* ModelicaStandardTables_CombiTimeTable_init(_In_z_ const char* tableName,
_In_z_ const char* fileName,
_In_ double* table, size_t nRow,
_In_ const double* table, size_t nRow,
size_t nColumn,
double startTime,
_In_ int* columns,
_In_ const int* columns,
size_t nCols, int smoothness,
int extrapolation) {
return ModelicaStandardTables_CombiTimeTable_init2(fileName,
Expand All @@ -637,10 +637,10 @@ void* ModelicaStandardTables_CombiTimeTable_init(_In_z_ const char* tableName,

void* ModelicaStandardTables_CombiTimeTable_init2(_In_z_ const char* fileName,
_In_z_ const char* tableName,
_In_ double* table, size_t nRow,
_In_ const double* table, size_t nRow,
size_t nColumn,
double startTime,
_In_ int* columns,
_In_ const int* columns,
size_t nCols, int smoothness,
int extrapolation,
double shiftTime,
Expand All @@ -653,10 +653,10 @@ void* ModelicaStandardTables_CombiTimeTable_init2(_In_z_ const char* fileName,

void* ModelicaStandardTables_CombiTimeTable_init3(_In_z_ const char* fileName,
_In_z_ const char* tableName,
_In_ double* table, size_t nRow,
_In_ const double* table, size_t nRow,
size_t nColumn,
double startTime,
_In_ int* columns,
_In_ const int* columns,
size_t nCols, int smoothness,
int extrapolation,
double shiftTime,
Expand Down Expand Up @@ -2090,9 +2090,9 @@ double ModelicaStandardTables_CombiTimeTable_read(void* _tableID, int force,

void* ModelicaStandardTables_CombiTable1D_init(_In_z_ const char* tableName,
_In_z_ const char* fileName,
_In_ double* table, size_t nRow,
_In_ const double* table, size_t nRow,
size_t nColumn,
_In_ int* columns,
_In_ const int* columns,
size_t nCols, int smoothness) {
return ModelicaStandardTables_CombiTable1D_init2(fileName, tableName,
table, nRow, nColumn, columns, nCols, smoothness, LAST_TWO_POINTS,
Expand All @@ -2101,9 +2101,9 @@ void* ModelicaStandardTables_CombiTable1D_init(_In_z_ const char* tableName,

void* ModelicaStandardTables_CombiTable1D_init2(_In_z_ const char* fileName,
_In_z_ const char* tableName,
_In_ double* table, size_t nRow,
_In_ const double* table, size_t nRow,
size_t nColumn,
_In_ int* columns,
_In_ const int* columns,
size_t nCols, int smoothness,
int extrapolation,
int verbose) {
Expand All @@ -2114,9 +2114,9 @@ void* ModelicaStandardTables_CombiTable1D_init2(_In_z_ const char* fileName,

void* ModelicaStandardTables_CombiTable1D_init3(_In_z_ const char* fileName,
_In_z_ const char* tableName,
_In_ double* table, size_t nRow,
_In_ const double* table, size_t nRow,
size_t nColumn,
_In_ int* columns,
_In_ const int* columns,
size_t nCols, int smoothness,
int extrapolation,
int verbose,
Expand Down Expand Up @@ -2902,15 +2902,15 @@ double ModelicaStandardTables_CombiTable1D_read(void* _tableID, int force,

void* ModelicaStandardTables_CombiTable2D_init(_In_z_ const char* tableName,
_In_z_ const char* fileName,
_In_ double* table, size_t nRow,
_In_ const double* table, size_t nRow,
size_t nColumn, int smoothness) {
return ModelicaStandardTables_CombiTable2D_init2(fileName, tableName,
table, nRow, nColumn, smoothness, LAST_TWO_POINTS, 1 /* verbose */);
}

void* ModelicaStandardTables_CombiTable2D_init2(_In_z_ const char* fileName,
_In_z_ const char* tableName,
_In_ double* table, size_t nRow,
_In_ const double* table, size_t nRow,
size_t nColumn, int smoothness,
int extrapolation,
int verbose) {
Expand All @@ -2920,7 +2920,7 @@ void* ModelicaStandardTables_CombiTable2D_init2(_In_z_ const char* fileName,

void* ModelicaStandardTables_CombiTable2D_init3(_In_z_ const char* fileName,
_In_z_ const char* tableName,
_In_ double* table, size_t nRow,
_In_ const double* table, size_t nRow,
size_t nColumn, int smoothness,
int extrapolation,
int verbose,
Expand Down

0 comments on commit b540e62

Please sign in to comment.