From 255fe9274846a8975b1d5adcf406b776494d40f7 Mon Sep 17 00:00:00 2001 From: Uwe Vogt Date: Fri, 29 Mar 2024 23:04:24 +0100 Subject: [PATCH 1/7] Fix a bug when closing the logging thread Relates to [CANAPI-76] --- Sources/logger_w.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/logger_w.c b/Sources/logger_w.c index 91f9d9c..43e895e 100644 --- a/Sources/logger_w.c +++ b/Sources/logger_w.c @@ -49,9 +49,9 @@ * * @remarks Windows compatible variant (_WIN32 and _WIN64) * - * @author $Author: haumea $ + * @author $Author: quaoar $ * - * @version $Rev: 802 $ + * @version $Rev: 809 $ * * @addtogroup logger * @{ @@ -100,7 +100,7 @@ static HANDLE hThread = NULL; static HANDLE hMutex = NULL; static HANDLE hPipo, hPipi; static FILE *logger = NULL; -static int running = 0; +static volatile int running = 0; /* ----------- functions ---------------------------------------------- @@ -146,6 +146,7 @@ int log_init(const char *pathname/*, flags*/) if (pathname) { if ((fopen_s(&logger, pathname, "w+")) != 0) { /* errno set */ + CloseHandle(hThread); CloseHandle(hMutex); CloseHandle(hPipi); CloseHandle(hPipo); @@ -174,8 +175,10 @@ int log_exit(void) } /* kill the logging thread and release all resources */ running = 0; + (void)CancelIoEx(hPipo, NULL); // to cancel ReadPipe (void)SetEvent(hThread); (void)WaitForSingleObject(hThread, 3000); + (void)CloseHandle(hThread); (void)CloseHandle(hMutex); (void)CloseHandle(hPipi); (void)CloseHandle(hPipo); From e93a1fc20c4494f0caaced9821d132dfc9b1634d Mon Sep 17 00:00:00 2001 From: Uwe Vogt Date: Sat, 30 Mar 2024 11:06:13 +0100 Subject: [PATCH 2/7] Activate logging for the Trial program Relates to [CANAPI-76] --- Trial/Makefile | 2 +- Trial/slcan_test.vcxproj | 66 ++-------------------------------------- 2 files changed, 3 insertions(+), 65 deletions(-) diff --git a/Trial/Makefile b/Trial/Makefile index 8fbad87..0871919 100644 --- a/Trial/Makefile +++ b/Trial/Makefile @@ -27,7 +27,7 @@ OBJECTS = $(OUTDIR)/slcan.o $(OUTDIR)/serial.o \ $(OUTDIR)/buffer.o $(OUTDIR)/queue.o $(OUTDIR)/logger.o \ $(OUTDIR)/main.o -DEFINES = -DOPTION_SERIAL_DEBUG_LEVEL=1 \ +DEFINES = -DOPTION_SERIAL_DEBUG_LEVEL=3 \ -DOPTION_SLCAN_DEBUG_LEVEL=1 HEADERS = -I$(SOURCE_DIR) \ diff --git a/Trial/slcan_test.vcxproj b/Trial/slcan_test.vcxproj index 7d69e1c..8960bda 100644 --- a/Trial/slcan_test.vcxproj +++ b/Trial/slcan_test.vcxproj @@ -5,18 +5,10 @@ Debug Win32 - - Release - Win32 - Debug x64 - - Release - x64 - @@ -50,26 +42,12 @@ v143 Unicode - - Application - false - v143 - true - Unicode - Application true v143 Unicode - - Application - false - v143 - true - Unicode - @@ -78,43 +56,20 @@ - - - - - - Level3 true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);OPTION_SLCAN_DEBUG_LEVEL=3 - true - .\Sources;..\Sources;%(AdditionalIncludeDirectories) - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);OPTION_SERIAL_DEBUG_LEVEL=3;OPTION_SLCAN_DEBUG_LEVEL=1 true .\Sources;..\Sources;%(AdditionalIncludeDirectories) Console - true - true true @@ -122,29 +77,12 @@ Level3 true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions);OPTION_SLCAN_DEBUG_LEVEL=3 - true - .\Sources;..\Sources;%(AdditionalIncludeDirectories) - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;%(PreprocessorDefinitions);OPTION_SERIAL_DEBUG_LEVEL=3;OPTION_SLCAN_DEBUG_LEVEL=1 true .\Sources;..\Sources;%(AdditionalIncludeDirectories) Console - true - true true From 30af7acbb2dfea16771ee02acfab6dc4c130a87a Mon Sep 17 00:00:00 2001 From: Uwe McVogt Date: Sun, 31 Mar 2024 13:27:42 +0200 Subject: [PATCH 3/7] Update Makefile Relates to [CANAPI-76] --- Trial/Makefile | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Trial/Makefile b/Trial/Makefile index 0871919..d97a91a 100644 --- a/Trial/Makefile +++ b/Trial/Makefile @@ -33,7 +33,8 @@ DEFINES = -DOPTION_SERIAL_DEBUG_LEVEL=3 \ HEADERS = -I$(SOURCE_DIR) \ -I$(MAIN_DIR) -LIBRARIES = -lpthread + +ifeq ($(current_OS),Darwin) # macOS - libSerialCAN.dylib CFLAGS += -O2 -Wall -Wno-parentheses \ -fno-strict-aliasing \ @@ -53,21 +54,36 @@ CXXFLAGS += -arch arm64 -arch x86_64 LDFLAGS += -arch arm64 -arch x86_64 endif +LIBRARIES = -lpthread + CHECKER = warning,information IGNORE = -i *_w.c ifeq ($(HUNTER),BUGS) CHECKER += --bug-hunting endif -endif -ifeq ($(current_OS),Darwin) # macOS - libSLCAN.dylib CXX = clang++ CC = clang LD = clang++ else # Linux, Cygwin - libslcan.so + +CFLAGS += -O2 -Wall -Wno-parentheses \ + -fno-strict-aliasing \ + $(DEFINES) \ + $(HEADERS) + +CXXFLAGS += -g -Wall -Wextra -pthread \ + $(DEFINES) \ + $(HEADERS) + +LDFLAGS += + +LIBRARIES = -lpthread + CXX = g++ CC = gcc LD = g++ endif + RM = rm -f CP = cp -f From 050419e58320781a54bd97923f3e44d9a6f02948 Mon Sep 17 00:00:00 2001 From: Uwe McVogt Date: Sun, 31 Mar 2024 13:47:52 +0200 Subject: [PATCH 4/7] Update Makefile Relates to [CANAPI-76] --- Trial/Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Trial/Makefile b/Trial/Makefile index d97a91a..2b47822 100644 --- a/Trial/Makefile +++ b/Trial/Makefile @@ -34,7 +34,7 @@ HEADERS = -I$(SOURCE_DIR) \ -I$(MAIN_DIR) -ifeq ($(current_OS),Darwin) # macOS - libSerialCAN.dylib +ifeq ($(current_OS),Darwin) # macOS - libSLCAN.dylib CFLAGS += -O2 -Wall -Wno-parentheses \ -fno-strict-aliasing \ @@ -47,7 +47,6 @@ CXXFLAGS += -g -Wall -Wextra -pthread \ LDFLAGS += -ifeq ($(current_OS),Darwin) # macOS - libSLCAN.dylib ifeq ($(BINARY),UNIVERSAL) CFLAGS += -arch arm64 -arch x86_64 CXXFLAGS += -arch arm64 -arch x86_64 @@ -57,13 +56,15 @@ endif LIBRARIES = -lpthread CHECKER = warning,information -IGNORE = -i *_w.c +IGNORE = -i serial_w.c -i buffer_w.c -i queue_w.c -i logger_w.c ifeq ($(HUNTER),BUGS) CHECKER += --bug-hunting endif + CXX = clang++ CC = clang LD = clang++ + else # Linux, Cygwin - libslcan.so CFLAGS += -O2 -Wall -Wno-parentheses \ From 68b52e653a883c14ed0da8a1aa6b92360c001062 Mon Sep 17 00:00:00 2001 From: Uwe Vogt Date: Sun, 31 Mar 2024 14:50:33 +0200 Subject: [PATCH 5/7] Update MSBuild scripts Relates to CANAPI-76 --- x64_build.bat | 52 +++++++++++++++++++++++++++++++-------------------- x86_build.bat | 52 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 64 insertions(+), 40 deletions(-) diff --git a/x64_build.bat b/x64_build.bat index 124e175..494e518 100644 --- a/x64_build.bat +++ b/x64_build.bat @@ -1,17 +1,16 @@ @echo off -rem parse arguments: [[NOVARS] NOTRIAL] -if "%1" == "NOVARS" ( - set VCVARS="False" -) else ( - set VCVARS="True" -) +set VCVARS="True" +set TRIAL="True" +set LIBD="False" + +rem parse arguments: [NOVARS] [NOTRIAL] [DEBUG] +:LOOP +if "%1" == "NOVARS" set VCVARS="False" +if "%1" == "NOTRIAL" set TRIAL="False" +if "%1" == "DEBUG" set LIBD="True" SHIFT -if "%1" == "NOTRIAL" ( - set TRIAL="False" -) else ( - set TRIAL="True" -) +if not "%1" == "" goto LOOP rem set MSBuild environment variables if %VCVARS% == "True" ( @@ -33,26 +32,39 @@ rem build the SLCAN library (dynamic and static) call msbuild.exe .\Library\uvslcan.vcxproj /t:Clean;Build /p:"Configuration=Release_dll";"Platform=x64" if errorlevel 1 goto end -call msbuild.exe .\Library\uvslcan.vcxproj /t:Clean;Build /p:"Configuration=Debug_lib";"Platform=x64" +call msbuild.exe .\Library\uvslcan.vcxproj /t:Clean;Build /p:"Configuration=Release_lib";"Platform=x64" if errorlevel 1 goto end +if %LIBD% == "True" ( + call msbuild.exe .\Library\uvslcan.vcxproj /t:Clean;Build /p:"Configuration=Debug_lib";"Platform=x64" + if errorlevel 1 goto end +) rem copy the arifacts into the Binaries folder echo Copying artifacts... -set BIN=".\Binaries" +set BIN=.\Binaries if not exist %BIN% mkdir %BIN% -set BIN="%BIN%\x64" +set BIN=%BIN%\x64 if not exist %BIN% mkdir %BIN% copy /Y .\Library\x64\Release_dll\uvslcan.dll %BIN% +copy /Y .\Library\x64\Release_dll\uvslcan.exp %BIN% copy /Y .\Library\x64\Release_dll\uvslcan.lib %BIN% -set BIN="%BIN%\lib" +copy /Y .\Library\x64\Release_dll\uvslcan.pdb %BIN% +set BIN=%BIN%\lib if not exist %BIN% mkdir %BIN% -copy /Y .\Library\x64\Debug_lib\uvslcan.lib %BIN% -copy /Y .\Library\x64\Debug_lib\uvslcan.pdb %BIN% -echo Static libraries (x86) > %BIN%\readme.txt - +copy /Y .\Library\x64\Release_lib\uvslcan.lib %BIN% +copy /Y .\Library\x64\Release_lib\uvslcan.pdb %BIN% +echo "Static library (x64)" > %BIN%\readme.txt +set BIN=%BIN%\Debug +if %LIBD% == "True" ( + if not exist %BIN% mkdir %BIN% + copy /Y .\Library\x64\Debug_lib\uvslcan.lib %BIN% + copy /Y .\Library\x64\Debug_lib\uvslcan.pdb %BIN% + copy /Y .\Library\x64\Debug_lib\uvslcan.idb %BIN% + echo "Static debug library (x64)" > %BIN%\readme.txt +) rem copy the header files into the Includes folder echo Copying header files... -set INC=".\Includes" +set INC=.\Includes if not exist %INC% mkdir %INC% copy /Y .\Sources\slcan.h %INC% copy /Y .\Sources\serial_attr.h %INC% diff --git a/x86_build.bat b/x86_build.bat index 3879f12..e54cea7 100644 --- a/x86_build.bat +++ b/x86_build.bat @@ -1,17 +1,16 @@ @echo off -rem parse arguments: [[NOVARS] NOTRIAL] -if "%1" == "NOVARS" ( - set VCVARS="False" -) else ( - set VCVARS="True" -) +set VCVARS="True" +set TRIAL="True" +set LIBD="False" + +rem parse arguments: [NOVARS] [NOTRIAL] [DEBUG] +:LOOP +if "%1" == "NOVARS" set VCVARS="False" +if "%1" == "NOTRIAL" set TRIAL="False" +if "%1" == "DEBUG" set LIBD="True" SHIFT -if "%1" == "NOTRIAL" ( - set TRIAL="False" -) else ( - set TRIAL="True" -) +if not "%1" == "" goto LOOP rem set MSBuild environment variables if %VCVARS% == "True" ( @@ -33,26 +32,39 @@ rem build the SLCAN library (dynamic and static) call msbuild.exe .\Library\uvslcan.vcxproj /t:Clean;Build /p:"Configuration=Release_dll";"Platform=Win32" if errorlevel 1 goto end -call msbuild.exe .\Library\uvslcan.vcxproj /t:Clean;Build /p:"Configuration=Debug_lib";"Platform=Win32" +call msbuild.exe .\Library\uvslcan.vcxproj /t:Clean;Build /p:"Configuration=Release_lib";"Platform=Win32" if errorlevel 1 goto end +if %LIBD% == "True" ( + call msbuild.exe .\Library\uvslcan.vcxproj /t:Clean;Build /p:"Configuration=Debug_lib";"Platform=Win32" + if errorlevel 1 goto end +) rem copy the arifacts into the Binaries folder echo Copying artifacts... -set BIN=".\Binaries" +set BIN=.\Binaries if not exist %BIN% mkdir %BIN% -set BIN="%BIN%\x86" +set BIN=%BIN%\x86 if not exist %BIN% mkdir %BIN% copy /Y .\Library\Release_dll\uvslcan.dll %BIN% +copy /Y .\Library\Release_dll\uvslcan.exp %BIN% copy /Y .\Library\Release_dll\uvslcan.lib %BIN% -set BIN="%BIN%\lib" +copy /Y .\Library\Release_dll\uvslcan.pdb %BIN% +set BIN=%BIN%\lib if not exist %BIN% mkdir %BIN% -copy /Y .\Library\Debug_lib\uvslcan.lib %BIN% -copy /Y .\Library\Debug_lib\uvslcan.pdb %BIN% -echo Static libraries (x86) > %BIN%\readme.txt - +copy /Y .\Library\Release_lib\uvslcan.lib %BIN% +copy /Y .\Library\Release_lib\uvslcan.pdb %BIN% +echo "Static library (x64)" > %BIN%\readme.txt +set BIN=%BIN%\Debug +if %LIBD% == "True" ( + if not exist %BIN% mkdir %BIN% + copy /Y .\Library\Debug_lib\uvslcan.lib %BIN% + copy /Y .\Library\Debug_lib\uvslcan.pdb %BIN% + copy /Y .\Library\Debug_lib\uvslcan.idb %BIN% + echo "Static debug library (x64)" > %BIN%\readme.txt +) rem copy the header files into the Includes folder echo Copying header files... -set INC=".\Includes" +set INC=.\Includes if not exist %INC% mkdir %INC% copy /Y .\Sources\slcan.h %INC% copy /Y .\Sources\serial_attr.h %INC% From fc7b9894176c07ee7e12d7a09fce2b578260fc17 Mon Sep 17 00:00:00 2001 From: Uwe McVogt Date: Sun, 31 Mar 2024 15:08:34 +0200 Subject: [PATCH 6/7] Update .gitignore --- .gitignore | 15 ++++++++------- Library/.gitignore | 6 ------ 2 files changed, 8 insertions(+), 13 deletions(-) delete mode 100644 Library/.gitignore diff --git a/.gitignore b/.gitignore index 210056f..1907303 100644 --- a/.gitignore +++ b/.gitignore @@ -7,27 +7,28 @@ Trial/x86 Trial/Debug Trial/Release Trial/slcan_test -Trial/slcan_test.exe Trial/*.sln Trial/*.vcxproj.user Library/.objects +Library/*.dylib +Library/*.so.* +Library/*.a Library/.vs Library/x64 Library/x86 -Library/Debug_dll -Library/Debug_lib -Library/Release_dll -Library/Release_lib +Library/Debug_* +Library/Release_* Library/uvslcan -Library/*.so.* -Library/*.dylib Library/*.sln Library/*.aps Library/*.vcxproj.user slcan-cppcheck-build-dir checker.txt +artifacts Binaries Includes Testing .vscode +*.exe *.log +*.pdf diff --git a/Library/.gitignore b/Library/.gitignore deleted file mode 100644 index ab3311e..0000000 --- a/Library/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -.objects -*.dylib -*.so.* -*.dll -*.lib -*.a From a5db412464a5464932a0ab65d8aac12a13b69f67 Mon Sep 17 00:00:00 2001 From: Uwe McVogt Date: Sun, 31 Mar 2024 15:09:08 +0200 Subject: [PATCH 7/7] Update GitHub actions --- .github/workflows/macOS-Build.yml | 2 +- .github/workflows/msbuild-x64.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/macOS-Build.yml b/.github/workflows/macOS-Build.yml index 6ad763f..9c816ff 100644 --- a/.github/workflows/macOS-Build.yml +++ b/.github/workflows/macOS-Build.yml @@ -1,4 +1,4 @@ -name: macOS CI +name: macOS Build on: push: diff --git a/.github/workflows/msbuild-x64.yml b/.github/workflows/msbuild-x64.yml index c5d0e67..2d23a42 100644 --- a/.github/workflows/msbuild-x64.yml +++ b/.github/workflows/msbuild-x64.yml @@ -33,7 +33,7 @@ jobs: - name: Add MSBuild to PATH uses: microsoft/setup-msbuild@v1.0.2 - - name: Build for x64 Architecture + - name: Build for x64 working-directory: ${{env.GITHUB_WORKSPACE}} # Add additional options to the MSBuild command line here (like platform or verbosity level). # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference