From: ljsebald <ljs...@us...> - 2023-08-29 21:55:40
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A serial program loader for the Dreamcast.". The branch, master has been updated via 9d0777ed7d74e809c314fb10c3c8cf3d694f1085 (commit) from 9ff1c322d00cfc861514faa2188b2007ee8ab44a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 9d0777ed7d74e809c314fb10c3c8cf3d694f1085 Author: SiZiOUS <si...@gm...> Date: Tue Aug 29 23:55:06 2023 +0200 `dc-tool`: Updating compatibility layer (shim) for MinGW/MSYS (#19) * `dc-tool`: Updating compatibility layer (shim) for MinGW/MSYS This shim will be required if dc-tool is compiled on MinGW/MSYS while using a toolchain built on MinGW-w64/MSYS2. The shim has been updated for GCC 13.2. * `dc-tool`: Removing outdated comment. * `dc-tool`: Improving comments in shim. * Update host-src/tool/shim.c ----------------------------------------------------------------------- Summary of changes: host-src/tool/Makefile | 2 +- host-src/tool/shim.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++ host-src/tool/utils.c | 78 ----------------------------------- 3 files changed, 109 insertions(+), 79 deletions(-) create mode 100644 host-src/tool/shim.c delete mode 100644 host-src/tool/utils.c diff --git a/host-src/tool/Makefile b/host-src/tool/Makefile index edc894e..763557e 100644 --- a/host-src/tool/Makefile +++ b/host-src/tool/Makefile @@ -48,7 +48,7 @@ endif DCTOOL = dc-tool-ser$(EXECUTABLEEXTENSION) -OBJECTS = dc-tool.o minilzo.o syscalls.o unlink.o utils.o +OBJECTS = dc-tool.o minilzo.o syscalls.o unlink.o shim.o LZOFILES = $(LZOPATH)/minilzo.c $(LZOPATH)/minilzo.h $(LZOPATH)/lzoconf.h .c.o: diff --git a/host-src/tool/shim.c b/host-src/tool/shim.c new file mode 100644 index 0000000..0596a4e --- /dev/null +++ b/host-src/tool/shim.c @@ -0,0 +1,108 @@ +/* + * This file is part of the dcload Dreamcast serial loader + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> + +#ifdef __MINGW32__ +#include <_mingw.h> +#include <windows.h> + +/* Detect MinGW/MSYS vs. MinGW-w64/MSYS2 */ +# ifdef __MINGW64_VERSION_MAJOR +# define __RT_MINGW_W64__ +# else +# define __RT_MINGW_ORG__ +# endif + +#endif /* __MINGW32__ */ + +/* + * Compatibility layer ('shim') for the original, legacy MinGW/MSYS environment. + * This allow toolchains built on MinGW-w64/MSYS2 to be usable with MinGW/MSYS. + * Mainly, this is for linking 'dc-tool' with 'libbfd'. Declaring these + * functions will let us to build 'dc-tool' even if 'sh-elf' toolchain was built + * on MinGW-w64/MSYS2. + * + * Of course this will work if the compiler used on MinGW-w64/MSYS2 and + * MinGW/MSYS are in the same family (e.g., GCC 9.x on both environments). + */ +#ifdef __RT_MINGW_ORG__ + +// See: https://github.com/mingw-w64/mingw-w64/blob/master/mingw-w64-crt/stdio/mingw_vasprintf.c +int vasprintf(char ** __restrict__ ret, + const char * __restrict__ format, + va_list ap) { + int len; + /* Get Length */ + len = __mingw_vsnprintf(NULL,0,format,ap); + if (len < 0) return -1; + /* +1 for \0 terminator. */ + *ret = malloc(len + 1); + /* Check malloc fail*/ + if (!*ret) return -1; + /* Write String */ + __mingw_vsnprintf(*ret,len+1,format,ap); + /* Terminate explicitly */ + (*ret)[len] = '\0'; + return len; +} + +// Thanks to Dietrich Epp +// See: https://stackoverflow.com/a/40160038 +int __cdecl __MINGW_NOTHROW libintl_asprintf(char **strp, + const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + + int r = vasprintf(strp, fmt, ap); + va_end(ap); + + return r; +} + +int __cdecl __MINGW_NOTHROW libintl_vasprintf(char **restrict strp, + const char *restrict fmt, + va_list arg ) { + return vasprintf(strp, fmt, arg); +} + +// See: https://stackoverflow.com/a/60380005 +int __cdecl __MINGW_NOTHROW __ms_vsnprintf(char *buffer, + size_t count, + const char *format, + va_list argptr) { + return __mingw_vsnprintf(buffer, count, format, argptr); +} + +// Thanks to Kenji Uno and god +// See: https://github.com/HiraokaHyperTools/libacrt_iob_func +// See: https://stackoverflow.com/a/30894349 +FILE * __cdecl __MINGW_NOTHROW _imp____acrt_iob_func(int handle) { + switch (handle) { + case 0: return stdin; + case 1: return stdout; + case 2: return stderr; + } + + return NULL; +} + +#endif /* __RT_MINGW_ORG__ */ diff --git a/host-src/tool/utils.c b/host-src/tool/utils.c deleted file mode 100644 index 645fb49..0000000 --- a/host-src/tool/utils.c +++ /dev/null @@ -1,78 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> - -/* Detect MinGW/MSYS vs. MinGW-w64/MSYS2 */ -#ifdef __MINGW32__ -#include <_mingw.h> -# ifdef __MINGW64_VERSION_MAJOR -# define __RT_MINGW_W64__ -# else -# define __RT_MINGW_ORG__ -# endif -#endif /* __MINGW32__ */ - -#ifdef __RT_MINGW_ORG__ - -/* - * Compatibility layer for original, legacy MinGW/MSYS environment. - * This allow toolchains built on MinGW-w64/MSYS2 to be usable with MinGW/MSYS. - * Mainly, this is for linking 'dc-tool' with 'libbfd'. Declaring these - * functions will let us to build 'dc-tool' even if 'sh-elf' toolchain was built - * on MinGW-w64/MSYS2. - */ - -// Thanks to Dietrich Epp -// See: https://stackoverflow.com/a/40160038 -int vasprintf(char **strp, const char *fmt, va_list ap) { - int len = _vscprintf(fmt, ap); - if(len == -1) { - return -1; - } - - size_t size = (size_t)len + 1; - char *str = malloc(size); - if(!str) { - return -1; - } - - int r = __mingw_vsnprintf(str, len + 1, fmt, ap); - if(r == -1) { - free(str); - return -1; - } - *strp = str; - return r; -} - -// Thanks to Dietrich Epp -// See: https://stackoverflow.com/a/40160038 -int __cdecl __MINGW_NOTHROW libintl_asprintf(char **strp, const char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - - int r = vasprintf(strp, fmt, ap); - va_end(ap); - - return r; -} - -// See: https://stackoverflow.com/a/60380005 -int __cdecl __MINGW_NOTHROW __ms_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr) { - return __mingw_vsnprintf(buffer, count, format, argptr); -} - -// Thanks to Kenji Uno and god -// See: https://github.com/HiraokaHyperTools/libacrt_iob_func -// See: https://stackoverflow.com/a/30894349 -FILE * __cdecl __MINGW_NOTHROW _imp____acrt_iob_func(int handle) { - switch (handle) { - case 0: return stdin; - case 1: return stdout; - case 2: return stderr; - } - - return NULL; -} - -#endif /* __RT_MINGW_ORG__ */ hooks/post-receive -- A serial program loader for the Dreamcast. |