Gauche > Archives > 2018/10/11

2018/10/11 06:18:38 UTC齊藤
#
MSYS2 上で各種パッケージを更新してから Gauche をビルドしようとしたらエラーになる……と思ったら inet_pton と inet_ntop の定義が MinGW 側で用意されるようになったので Gauche 内の定義とぶつかってました。
2018/10/11 06:26:01 UTCshiro
#
#ifdefで判断する方法あるかな? MINGW64_VERSION_MAJOR とか見ればいいんかな。
2018/10/11 06:33:53 UTC齊藤
#
inet_ntop と inet_pton はマクロとして定義されているのでそれを直接使えます。 それぞれ InetPtonA (または InetPtonW) と InetNtopA (または InetNtopW) の別名として定義されています。
2018/10/11 06:43:16 UTCshiro
#
diff --git a/ext/net/gauche-net.h b/ext/net/gauche-net.h
index 91e15ca..f70004b 100644
--- a/ext/net/gauche-net.h
+++ b/ext/net/gauche-net.h
@@ -82,8 +82,12 @@ struct sockaddr_un {
     unsigned short sun_family;
     char sun_path[108];
 };
+
+#if !defined(inet_pton)
 int inet_pton(int af, const char *src, void *dst);
 const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
+#endif
+
 #define MSG_WAITALL   0x8
 #ifdef HAVE_IPV6
 #define IPV6_V6ONLY   27
diff --git a/ext/net/net.c b/ext/net/net.c
index c41fe6e..6025d80 100644
--- a/ext/net/net.c
+++ b/ext/net/net.c
@@ -746,7 +746,7 @@ ScmObj Scm_SocketIoctl(ScmSocket *s, u_long request, ScmObj data)
 /*==================================================================
  * Windows/MinGW compatibility layer
  */
-#if defined(GAUCHE_WINDOWS)
+#if defined(GAUCHE_WINDOWS) && !defined(inet_pton)
 
 int inet_pton(int af, const char *src, void *dst)
 {
#
試してないけどこんな感じでどう?
2018/10/11 06:54:47 UTC齊藤
#
すいません、勘違いです。 InetNtopA が inet_ntop の別名として定義されてました。
#
(提示して頂いたパッチの inet_pton のところを InetPtonA に置き換えればコンパイルできました。)
2018/10/11 06:58:23 UTCshiro
#
InetNtopAはUNICODEの設定が何であれ定義されますか?
#
diff --git a/ext/net/gauche-net.h b/ext/net/gauche-net.h
index 91e15ca..c6952af 100644
--- a/ext/net/gauche-net.h
+++ b/ext/net/gauche-net.h
@@ -82,8 +82,13 @@ struct sockaddr_un {
     unsigned short sun_family;
     char sun_path[108];
 };
+
+#if !defined(InetNtopA)
+/* This is for older MinGW */
 int inet_pton(int af, const char *src, void *dst);
 const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
+#endif /* !defined(InetNtopA) */
+
 #define MSG_WAITALL   0x8
 #ifdef HAVE_IPV6
 #define IPV6_V6ONLY   27
diff --git a/ext/net/net.c b/ext/net/net.c
index c41fe6e..cd43737 100644
--- a/ext/net/net.c
+++ b/ext/net/net.c
@@ -745,8 +745,9 @@ ScmObj Scm_SocketIoctl(ScmSocket *s, u_long request, ScmObj data)
 
 /*==================================================================
  * Windows/MinGW compatibility layer
+ * Older MinGW lacks inet_pton/ntop.  
  */
-#if defined(GAUCHE_WINDOWS)
+#if defined(GAUCHE_WINDOWS) && !defined(InetNtopA)
 
 int inet_pton(int af, const char *src, void *dst)
 {
@@ -813,7 +814,7 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size)
     return dst;
 #undef ADDR_MAXLEN
 }
-#endif /*GAUCHE_WINDOWS*/
+#endif /*defined(GAUCHE_WINDOWS) && !defined(InetNtopA)*/
 
 /*==================================================================
  * Initialization
#
これでいけたらcommitします
2018/10/11 07:06:19 UTC齊藤
#
はい。 UNICODE の設定に影響されません。 そのパッチで通りました。
2018/10/11 07:19:02 UTCshiro
#
https://github.com/shirok/Gauche/commit/5addf688f1ddd7a5a78956e6e9186478266ec8ab
2018/10/11 07:47:31 UTC齊藤
#
ありがとうございます。 念のため ./DIST gen からビルドしなおしてテストもやってみましたがパスしました。