Skip to content

Commit

Permalink
add patch from #5159
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyu1994 authored and jameslamb committed Oct 10, 2022
1 parent 4498a89 commit a0a617d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,18 @@ if(WIN32 AND MINGW)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++")
endif()

# Check if inet_pton is already available, to avoid conflicts with the implementation in LightGBM.
# As of 2022, MinGW started including a definition of inet_pton.
if(WIN32)
include(CheckSymbolExists)
list(APPEND CMAKE_REQUIRED_LIBRARIES "ws2_32")
check_symbol_exists(inet_pton "ws2tcpip.h" WIN_INET_PTON_FOUND)
if(WIN_INET_PTON_FOUND)
add_definitions(-DWIN_HAS_INET_PTON)
endif()
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "ws2_32")
endif()

if(MSVC)
SET(variables
CMAKE_C_FLAGS_DEBUG
Expand Down
8 changes: 2 additions & 6 deletions src/network/socket_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ const int INVALID_SOCKET = -1;
#endif

#ifdef _WIN32
#ifndef _UCRT
// Recent MinGW has inet_pton, which then causes compiler error in
// combination with this replacement.
#ifndef _MSC_VER
// not using visual studio in windows
// existence of inet_pton is checked in CMakeLists.txt and configure.win, then stored in WIN_HAS_INET_PTON
#ifndef WIN_HAS_INET_PTON
inline int inet_pton(int af, const char *src, void *dst) {
struct sockaddr_storage ss;
int size = sizeof(ss);
Expand All @@ -89,7 +86,6 @@ inline int inet_pton(int af, const char *src, void *dst) {
}
#endif
#endif
#endif

#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
Expand Down

0 comments on commit a0a617d

Please sign in to comment.