Skip to content

Commit

Permalink
Restore and modernize ModelicaUtilities.h (modelica#4535)
Browse files Browse the repository at this point in the history
* refs modelica#4484: Restore ModelicaUtilities.h

Revert "refs modelica#3867: Remove LICENSE_ModelicaUtilities.txt"

This reverts commit 7fe506f.

Revert "refs modelica#3867: Remove ModelicaUtilities.h"

This reverts commit 1bb1d40.

* Configure MODELICA_UTILITIES_INCLUDE_DIR for CMake

* Modernize and simplify noreturn function attribute/specifier

* Handle C23
* Remove fallback to legacy clang extension
* Remove fallback to legacy gcc2/gcc3 extensions
  • Loading branch information
beutlich authored Feb 25, 2025
1 parent 7c4858b commit 2ed982f
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 123 deletions.
6 changes: 3 additions & 3 deletions .CI/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,14 @@ def allAutotools() {
def autotools(CC, CPPFLAGS, config, nostatic, dotest) {
sh label: "Build $CC $CPPFLAGS", script: """
export CC=$CC
export CPPFLAGS="$CPPFLAGS -I${WORKSPACE}/.CI/Test"
export CPPFLAGS=$CPPFLAGS
export CFLAGS="-Os -fPIC"
rm -rf Modelica/Resources/Library/*
mkdir -p Modelica/Resources/Library/\$LIBDIR
cd Modelica/Resources/BuildProjects/autotools
git clean -fdx .
./autogen.sh
./configure --libdir="${WORKSPACE}/Modelica/Resources/Library/\$LIBDIR" $config
./configure --libdir="\$PWD/../../Library/\$LIBDIR" $config
make --output-sync -j${numPhysicalCPU()}
make install
"""
Expand All @@ -223,7 +223,7 @@ def makefile(CC, dotest) {
rm -rf Modelica/Resources/Library/*
mkdir -p "Modelica/Resources/Library/$LIBDIR"
cd Modelica/Resources/BuildProjects/gcc
make --output-sync -j${numPhysicalCPU()} TARGETDIR="$LIBDIR" CPPFLAGS="-I${WORKSPACE}/.CI/Test"
make --output-sync -j${numPhysicalCPU()} TARGETDIR="$LIBDIR"
"""
sh label: "Test $CC", script: """
export CC=$CC
Expand Down
2 changes: 1 addition & 1 deletion .CI/Test/Common.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ModelicaUtilities.h"
#include "../../Modelica/Resources/C-Sources/ModelicaUtilities.h"
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/checkCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
pushd Modelica/Resources/BuildProjects/autotools
git clean -fdx .
./autogen.sh
./configure --libdir="$PWD/../../Library/$LIBDIR" --enable-static --disable-shared --enable-static-zlib --disable-hdf5 CPPFLAGS="-I${GITHUB_WORKSPACE}/.CI/Test"
./configure --libdir="$PWD/../../Library/$LIBDIR" --enable-static --disable-shared --enable-static-zlib --disable-hdf5
popd
env:
LIBDIR: linux64
Expand Down Expand Up @@ -79,15 +79,14 @@ jobs:
- name: Configure
run: |
if [ "${{ matrix.compiler }}" == "msvc" ]; then
cmake -S "$SRCDIR" -B build -DMODELICA_UTILITIES_INCLUDE_DIR="$TESTDIR" -DMODELICA_DEBUG_TIME_EVENTS=ON
cmake -S "$SRCDIR" -B build -DMODELICA_DEBUG_TIME_EVENTS=ON
elif [ "${{ matrix.compiler }}" == "mingw" ]; then
cmake -S "$SRCDIR" -B build -DMODELICA_UTILITIES_INCLUDE_DIR="$TESTDIR" -DMODELICA_DEBUG_TIME_EVENTS=ON -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -G "MinGW Makefiles"
cmake -S "$SRCDIR" -B build -DMODELICA_DEBUG_TIME_EVENTS=ON -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -G "MinGW Makefiles"
else
cmake -S "$SRCDIR" -B build -DMODELICA_UTILITIES_INCLUDE_DIR="$TESTDIR" -DMODELICA_DEBUG_TIME_EVENTS=ON -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DCMAKE_C_FLAGS="-std=c89 -Wall -Wextra"
cmake -S "$SRCDIR" -B build -DMODELICA_DEBUG_TIME_EVENTS=ON -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DCMAKE_C_FLAGS="-std=c89 -Wall -Wextra"
fi
env:
SRCDIR: ${{ github.workspace }}/Modelica/Resources
TESTDIR: ${{ github.workspace }}/.CI/Test
- name: Build with ${{ matrix.compiler }}
run: |
if [ "${{ matrix.compiler }}" == "msvc" ]; then
Expand Down Expand Up @@ -120,12 +119,11 @@ jobs:
- name: Configure
run: |
export PATH=/usr/bin:$PATH
cmake -S "$(cygpath ${SRCDIR})" -B build -DMODELICA_UTILITIES_INCLUDE_DIR="$(cygpath ${TESTDIR})" -DMODELICA_DEBUG_TIME_EVENTS=ON -DCMAKE_BUILD_TYPE=Debug -G Ninja
cmake -S "$(cygpath ${SRCDIR})" -B build -DMODELICA_DEBUG_TIME_EVENTS=ON -DCMAKE_BUILD_TYPE=Debug -G Ninja
shell: C:\cygwin\bin\bash.exe -eo pipefail -o igncr '{0}'
env:
CYGWIN_NOWINPATH: 1
SRCDIR: ${{ github.workspace }}/Modelica/Resources
TESTDIR: ${{ github.workspace }}/.CI/Test
- name: Build with gcc
run: |
export PATH=/usr/bin:$PATH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(MODELICA_UTILITIES_INCLUDE)&quot;"
AdditionalIncludeDirectories=""
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;MODELICAIO_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
Expand Down Expand Up @@ -106,7 +106,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(MODELICA_UTILITIES_INCLUDE)&quot;"
AdditionalIncludeDirectories=""
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;MODELICAIO_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
Expand Down Expand Up @@ -168,7 +168,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(MODELICA_UTILITIES_INCLUDE)&quot;"
AdditionalIncludeDirectories=""
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;MODELICAIO_EXPORTS;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="0"
ProgramDataBaseFileName="$(IntDir)\$(ProjectName).pdb"
Expand Down Expand Up @@ -228,7 +228,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(MODELICA_UTILITIES_INCLUDE)&quot;"
AdditionalIncludeDirectories=""
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;MODELICAIO_EXPORTS;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="0"
ProgramDataBaseFileName="$(IntDir)\$(ProjectName).pdb"
Expand Down Expand Up @@ -281,12 +281,16 @@
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath="..\..\C-Sources\ModelicaMatIO.h"
>
</File>
<File
RelativePath="..\..\C-Sources\ModelicaIO.h"
>
</File>
<File
RelativePath="..\..\C-Sources\ModelicaMatIO.h"
RelativePath="..\..\C-Sources\ModelicaUtilities.h"
>
</File>
</Filter>
Expand All @@ -297,6 +301,4 @@
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(MODELICA_UTILITIES_INCLUDE)&quot;;&quot;..\..\C-Sources\zlib\&quot;"
AdditionalIncludeDirectories="..\..\C-Sources\zlib\"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;MODELICAMATIO_EXPORTS;PSNIP_SAFE_FORCE_PORTABLE;HAVE_ZLIB=1"
MinimalRebuild="true"
BasicRuntimeChecks="3"
Expand Down Expand Up @@ -106,7 +106,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(MODELICA_UTILITIES_INCLUDE)&quot;;&quot;..\..\C-Sources\zlib\&quot;"
AdditionalIncludeDirectories="..\..\C-Sources\zlib\"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;MODELICAMATIO_EXPORTS;PSNIP_SAFE_FORCE_PORTABLE;HAVE_ZLIB=1"
MinimalRebuild="true"
BasicRuntimeChecks="3"
Expand Down Expand Up @@ -168,7 +168,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(MODELICA_UTILITIES_INCLUDE)&quot;;&quot;..\..\C-Sources\zlib\&quot;"
AdditionalIncludeDirectories="..\..\C-Sources\zlib\"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;MODELICAMATIO_EXPORTS;PSNIP_SAFE_FORCE_PORTABLE;_CRT_SECURE_NO_WARNINGS;HAVE_ZLIB=1"
RuntimeLibrary="0"
ProgramDataBaseFileName="$(IntDir)\$(ProjectName).pdb"
Expand Down Expand Up @@ -228,7 +228,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(MODELICA_UTILITIES_INCLUDE)&quot;;&quot;..\..\C-Sources\zlib\&quot;"
AdditionalIncludeDirectories="..\..\C-Sources\zlib\"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;MODELICAMATIO_EXPORTS;PSNIP_SAFE_FORCE_PORTABLE;_CRT_SECURE_NO_WARNINGS;HAVE_ZLIB=1"
RuntimeLibrary="0"
ProgramDataBaseFileName="$(IntDir)\$(ProjectName).pdb"
Expand Down Expand Up @@ -289,6 +289,10 @@
RelativePath="..\..\C-Sources\ModelicaMatIO.h"
>
</File>
<File
RelativePath="..\..\C-Sources\ModelicaUtilities.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(MODELICA_UTILITIES_INCLUDE)&quot;"
AdditionalIncludeDirectories=""
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;MODELICASTANDARDTABLES_EXPORTS;DEBUG_TIME_EVENTS;TABLE_SHARE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
Expand Down Expand Up @@ -106,7 +106,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(MODELICA_UTILITIES_INCLUDE)&quot;"
AdditionalIncludeDirectories=""
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;MODELICASTANDARDTABLES_EXPORTS;DEBUG_TIME_EVENTS;TABLE_SHARE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
Expand Down Expand Up @@ -168,7 +168,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(MODELICA_UTILITIES_INCLUDE)&quot;"
AdditionalIncludeDirectories=""
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;MODELICASTANDARDTABLES_EXPORTS;_CRT_SECURE_NO_WARNINGS;TABLE_SHARE"
RuntimeLibrary="0"
ProgramDataBaseFileName="$(IntDir)\$(ProjectName).pdb"
Expand Down Expand Up @@ -228,7 +228,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(MODELICA_UTILITIES_INCLUDE)&quot;"
AdditionalIncludeDirectories=""
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;MODELICASTANDARDTABLES_EXPORTS;_CRT_SECURE_NO_WARNINGS;TABLE_SHARE"
RuntimeLibrary="0"
ProgramDataBaseFileName="$(IntDir)\$(ProjectName).pdb"
Expand Down Expand Up @@ -293,6 +293,10 @@
RelativePath="..\..\C-Sources\ModelicaStandardTables.h"
>
</File>
<File
RelativePath="..\..\C-Sources\ModelicaUtilities.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Expand Down
8 changes: 2 additions & 6 deletions Modelica/Resources/BuildProjects/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ from the C-code under ../C-Sources
The intention is that interested tool vendors can build these libraries
by using the provided build projects as a start.

The tool vendors are responsible for building the binary libraries
Note, the tool vendors are responsible for building the binary libraries
and including them in their tools.

When building the binary libraries by VisualStudio2005 the environment
variable MODELICA_UTILITIES_INCLUDE needs to be set to the path of the
(tool-vendor-specific) ModelicaUtilities.h header file.

September 24, 2021
May 17, 2018
53 changes: 10 additions & 43 deletions Modelica/Resources/C-Sources/ModelicaIO.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ModelicaIO.c - Array I/O functions
Copyright (C) 2016-2024, Modelica Association and contributors
Copyright (C) 2016-2025, Modelica Association and contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -101,55 +101,23 @@
external Modelica C-code in most compilers, noreturn attributes need to
be present to avoid warnings or errors.
The following macros handle noreturn attributes according to the
C11/C++11 standard with fallback to GNU, Clang or MSVC extensions if using
an older compiler.
The following macro handles the noreturn attribute according to the
C23/C11/C++11 standard with fallback to the MSVC/Borland extension.
*/
#undef MODELICA_NORETURN
#undef MODELICA_NORETURNATTR
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#define MODELICA_NORETURN _Noreturn
#define MODELICA_NORETURNATTR
#elif defined(__cplusplus) && __cplusplus >= 201103L
#if (defined(__GNUC__) && __GNUC__ >= 5) || \
(defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 4 && __GNUC_MINOR__ >= 8)
#define MODELICA_NORETURN [[noreturn]]
#define MODELICA_NORETURNATTR
#elif (defined(__GNUC__) && __GNUC__ >= 3) || \
(defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 2 && __GNUC_MINOR__ >= 8)
#define MODELICA_NORETURN
#define MODELICA_NORETURNATTR __attribute__((noreturn))
#elif defined(__GNUC__)
#define MODELICA_NORETURN
#define MODELICA_NORETURNATTR
#else
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || \
(defined(__cplusplus) && __cplusplus >= 201103L && \
(!defined(__GNUC__) || __GNUC__ >= 5 || (__GNUC__ == 4 && defined(__GNUC_MINOR__) && __GNUC_MINOR__ >= 8)))
#define MODELICA_NORETURN [[noreturn]]
#define MODELICA_NORETURNATTR
#endif
#elif defined(__clang__)
/* Encapsulated for Clang since GCC fails to process __has_attribute */
#if __has_attribute(noreturn)
#define MODELICA_NORETURN
#define MODELICA_NORETURNATTR __attribute__((noreturn))
#else
#define MODELICA_NORETURN
#define MODELICA_NORETURNATTR
#endif
#elif (defined(__GNUC__) && __GNUC__ >= 3) || \
(defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 2 && __GNUC_MINOR__ >= 8) || \
(defined(__SUNPRO_C) && __SUNPRO_C >= 0x5110)
#define MODELICA_NORETURN
#define MODELICA_NORETURNATTR __attribute__((noreturn))
#elif (defined(_MSC_VER) && _MSC_VER >= 1200) || \
defined(__BORLANDC__)
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#define MODELICA_NORETURN _Noreturn
#elif (defined(_MSC_VER) && _MSC_VER >= 1200) || defined(__BORLANDC__)
#define MODELICA_NORETURN __declspec(noreturn)
#define MODELICA_NORETURNATTR
#else
#define MODELICA_NORETURN
#define MODELICA_NORETURNATTR
#endif

MODELICA_NORETURN static void ModelicaNotExistError(const char* name) MODELICA_NORETURNATTR;
MODELICA_NORETURN static void ModelicaNotExistError(const char* name);
static void ModelicaNotExistError(const char* name) {
/* Print error message if a function is not implemented */
ModelicaFormatError("C-Function \"%s\" is called "
Expand All @@ -159,7 +127,6 @@ static void ModelicaNotExistError(const char* name) {
}

#undef MODELICA_NORETURN
#undef MODELICA_NORETURNATTR

void ModelicaIO_readMatrixSizes(_In_z_ const char* fileName,
_In_z_ const char* matrixName, _Out_ int* dim) {
Expand Down
Loading

0 comments on commit 2ed982f

Please sign in to comment.