mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 09:34:43 +00:00
[GCC-COMPAT] Add support library for GCC's libsupc++ and libstdc++
__throw_out_of_range_fmt is implemented in libstdc++, but it is needed by libsupc++ and that would mean we would have to link all C++ code to libstdc++.
This commit is contained in:
parent
486a20dbc4
commit
fcbccaa194
6 changed files with 97 additions and 2 deletions
|
@ -579,8 +579,8 @@ add_library(libsupc++ STATIC IMPORTED GLOBAL)
|
|||
execute_process(COMMAND ${GXX_EXECUTABLE} -print-file-name=libsupc++.a OUTPUT_VARIABLE LIBSUPCXX_LOCATION)
|
||||
string(STRIP ${LIBSUPCXX_LOCATION} LIBSUPCXX_LOCATION)
|
||||
set_target_properties(libsupc++ PROPERTIES IMPORTED_LOCATION ${LIBSUPCXX_LOCATION})
|
||||
# libsupc++ requires libgcc
|
||||
target_link_libraries(libsupc++ INTERFACE libgcc)
|
||||
# libsupc++ requires libgcc and stdc++compat
|
||||
target_link_libraries(libsupc++ INTERFACE libgcc stdc++compat)
|
||||
|
||||
add_library(libmingwex STATIC IMPORTED)
|
||||
execute_process(COMMAND ${GXX_EXECUTABLE} -print-file-name=libmingwex.a OUTPUT_VARIABLE LIBMINGWEX_LOCATION)
|
||||
|
|
|
@ -17,6 +17,8 @@ add_subdirectory(cryptlib)
|
|||
if(MSVC)
|
||||
add_subdirectory(cpprt)
|
||||
add_subdirectory(RunTmChk)
|
||||
else()
|
||||
add_subdirectory(gcc-compat)
|
||||
endif()
|
||||
|
||||
add_subdirectory(delayimp)
|
||||
|
|
15
sdk/lib/gcc-compat/CMakeLists.txt
Normal file
15
sdk/lib/gcc-compat/CMakeLists.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
include_directories(
|
||||
${REACTOS_SOURCE_DIR}/sdk/lib/crt/include)
|
||||
|
||||
list(APPEND SOURCE
|
||||
__mingw_vsprintf.c
|
||||
__throw_out_of_range_fmt.cpp
|
||||
StringCchCopyNA.c)
|
||||
|
||||
add_library(stdc++compat ${SOURCE})
|
||||
set_target_cpp_properties(stdc++compat WITH_EXCEPTIONS)
|
||||
add_dependencies(stdc++compat xdk)
|
||||
target_link_libraries(stdc++compat libmsvcrt)
|
||||
remove_target_compile_option(stdc++compat "$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<IN_LIST:cppstl,$<TARGET_PROPERTY:LINK_LIBRARIES>>>>:-nostdinc>")
|
||||
target_compile_definitions(stdc++compat PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:PAL_STDCPP_COMPAT>")
|
23
sdk/lib/gcc-compat/StringCchCopyNA.c
Normal file
23
sdk/lib/gcc-compat/StringCchCopyNA.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* PROJECT: GCC c++ support library
|
||||
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||
* PURPOSE: StringCchCopyNA implementation
|
||||
* COPYRIGHT: Copyright 2024 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#define StringCchCopyNA _StringCchCopyNA
|
||||
#include <strsafe.h>
|
||||
|
||||
#undef StringCchCopyNA
|
||||
|
||||
HRESULT
|
||||
WINAPI
|
||||
StringCchCopyNA(
|
||||
_Out_writes_(cchDest) _Always_(_Post_z_) STRSAFE_LPSTR pszDest,
|
||||
_In_ size_t cchDest,
|
||||
_In_reads_or_z_(cchToCopy) STRSAFE_LPCSTR pszSrc,
|
||||
_In_ size_t cchToCopy)
|
||||
{
|
||||
return _StringCchCopyNA(pszDest, cchDest, pszSrc, cchToCopy);
|
||||
}
|
13
sdk/lib/gcc-compat/__mingw_vsprintf.c
Normal file
13
sdk/lib/gcc-compat/__mingw_vsprintf.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* PROJECT: GCC c++ support library
|
||||
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||
* PURPOSE: __mingw_vsprintf implementation
|
||||
* COPYRIGHT: Copyright 2024 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int __cdecl __mingw_vsprintf(char* dest, const char* format, va_list arglist)
|
||||
{
|
||||
return vsprintf(dest, format, arglist);
|
||||
}
|
42
sdk/lib/gcc-compat/__throw_out_of_range_fmt.cpp
Normal file
42
sdk/lib/gcc-compat/__throw_out_of_range_fmt.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* PROJECT: GCC c++ support library
|
||||
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||
* PURPOSE: __throw_out_of_range_fmt implementation
|
||||
* COPYRIGHT: Copyright 2024 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cstdarg>
|
||||
#include <cstring>
|
||||
#include <malloc.h>
|
||||
|
||||
namespace std {
|
||||
|
||||
class out_of_range_error : public exception
|
||||
{
|
||||
char* m_msg;
|
||||
public:
|
||||
explicit out_of_range_error(const char* msg) noexcept
|
||||
{
|
||||
size_t len = strlen(msg) + 1;
|
||||
m_msg = (char*)malloc(len);
|
||||
strcpy(m_msg, msg);
|
||||
}
|
||||
virtual ~out_of_range_error() { free(m_msg); };
|
||||
virtual const char* what() const noexcept { return m_msg; }
|
||||
};
|
||||
|
||||
void __throw_out_of_range_fmt(const char *format, ...)
|
||||
{
|
||||
char buffer[1024];
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, format);
|
||||
_vsnprintf(buffer, sizeof(buffer), format, argptr);
|
||||
buffer[sizeof(buffer) - 1] = 0;
|
||||
va_end(argptr);
|
||||
|
||||
throw out_of_range_error(buffer);
|
||||
}
|
||||
|
||||
} // namespace std
|
Loading…
Reference in a new issue