MinGW32 Build of Bigloo 4.0b

Joseph Donaldson <[email protected]>
Newsgroups gmane.lisp.scheme.bigloo
Message-ID <[email protected]>
Hello, Manuel,

I recently attempted to create a MinGW32 build of bigloo 4.0b. A few changes were required to get it to build. I have attached the patches. Most are very small, and I don't expect any problems. However, I did have to make a few changes to csocket.c that I am less sure of. The first was that the type of the socket option value variable is different on windows; it is a char* instead of void*. I introduced a define SOCKOPTVALTYPE that is set to the appropriate type depending on the platform and modified setsockopt and getsockopt calls to use it. I also  modified bgl_datagram_socket to use getaddrinfo when inet_pton is not available. For whatever reason, windows has had getaddrinfo for a long time but only recently added (I believe in VISTA) inet_pton. Unfortunately, mingw does not yet expose this function and using it would require VISTA or greater.

For those interested, a inno installer for bigloo4.0b can be found at http://jwd.sandjsite.net/projects/mingw-bigloo. Both the native and jvm backends are supported. You will, however, need to install Mingw and a jave runtime to use; it is not included in the install.

Best Regards,
Joseph Donaldson
csocket.patch (application/octet-stream, 6.5 KB)
--- bigloo4.0b/runtime/Clib/csocket.c	2013-08-01 02:50:44.000000000 -0400
+++ bigloo4.0bmod/runtime/Clib/csocket.c	2013-08-16 13:11:16.669042565 -0400
@@ -26,6 +26,7 @@
 #include <bigloo_config.h>
 #include <time.h>
 #ifndef _BGL_WIN32_VER
+#   define SOCKOPTVALTYPE void*
 #   include <sys/types.h> 
 #   include <sys/socket.h>
 #   include <netinet/in.h>
@@ -43,13 +44,18 @@
 #     include <unistd.h>
 #   endif
 #else
+#   define SOCKOPTVALTYPE char*
 #   if defined( _MINGW_VER )
+#      define WINVER  0x0501  /* minimum supported windows version XP */
 #      include "windows.h"
 #   endif
 #   include <winsock2.h>
 #   include <mswsock.h>
 #   include <ws2tcpip.h>
 #   include <io.h>
+#   ifndef AI_ADDRCONFIG
+#      define AI_ADDRCONFIG 0
+#   endif
 #endif
 #include <fcntl.h>
 #include <memory.h>
@@ -1112,7 +1118,7 @@
 
    result = setsockopt( INVALID_SOCKET,
 			SOL_SOCKET, SO_OPENTYPE,
-			(const char *)&val,
+			(SOCKOPTVALTYPE)&val,
 			sizeof( val ) );
    if( 0 != result ) {
       socket_error( "make_server_socket",
@@ -1367,7 +1373,7 @@
 	       tcp_client_socket_error( hostname, port, "Connection failed", errno );
 	    } else {
 	       int len = sizeof( int );
-	       int r = getsockopt( s, SOL_SOCKET, SO_ERROR, (void *)&err, (socklen_t *)&len );
+	       int r = getsockopt( s, SOL_SOCKET, SO_ERROR, (SOCKOPTVALTYPE)&err, (socklen_t *)&len );
 
 	       if( (r < 0) || (err != 0) ) {
 		  /* we have experienced a failure so we */
@@ -1514,7 +1520,7 @@
 
    /* set the reuse flag */
    if( setsockopt( s, SOL_SOCKET, SO_REUSEADDR,
-		   &sock_opt, sizeof( sock_opt ) ) < 0 ) {
+		   (SOCKOPTVALTYPE)&sock_opt, sizeof( sock_opt ) ) < 0 ) {
 	 system_error( msg, BINT( portnum ) );
    }
 
@@ -1792,13 +1798,13 @@
    struct hostent *host = 0;
    char *hip = BSTRING_TO_STRING( hostip );
 
-#if( BGL_HAVE_INET_ATON || BGL_HAVE_INET_PTON )
+#if( BGL_HAVE_INET_ATON || BGL_HAVE_INET_PTON)
    struct sockaddr_in sin;
 #else
    struct sockaddr_in *sin;
 #endif      
       
-#if( BGL_HAVE_GETADDRINFO )
+#if( BGL_HAVE_INET_ATON || BGL_HAVE_INET_PTON)
    socklen_t len = sizeof( sin );
 
    /* cannot fail because we have created the socket */
@@ -1808,12 +1814,15 @@
       sin.sin_family = AF_INET;
    }
 #endif
+
+
       
 #if( BGL_HAVE_INET_ATON )
    /* For IPv4 prefer inet_aton when available because it */
    /* supports more IP format than inet_pton.             */
    if( inet_aton( BSTRING_TO_STRING( hostip ), &(sin.sin_addr) ) )
       host = bglhostbyaddr( &sin );
+   
 #else
 #  if( BGL_HAVE_INET_PTON )	 
    if( inet_pton( AF_INET, BSTRING_TO_STRING( hostip ), &sin.sin_addr ) )
@@ -1994,7 +2003,7 @@
       type _v;								\
       socklen_t _l = sizeof( type );					\
       									\
-      if( getsockopt( SOCKET( s ).fd, level, optname, &_v, &_l ) ) {	\
+      if( getsockopt( SOCKET( s ).fd, level, optname, (SOCKOPTVALTYPE)&_v, &_l ) ) { \
 	 return BUNSPEC;						\
       } else {								\
 	 return conv( _v );						\
@@ -2009,7 +2018,7 @@
       type _v = val;							\
       socklen_t _l = sizeof( type );					\
       									\
-      if( setsockopt( SOCKET( s ).fd, level, optname, &_v, _l ) ) {	\
+      if( setsockopt( SOCKET( s ).fd, level, optname, (SOCKOPTVALTYPE)&_v, _l ) ) { \
 	 return BFALSE;							\
       } else {								\
 	 return s;							\
@@ -2269,7 +2278,7 @@
       mreq.imr_interface.s_addr = htonl( INADDR_ANY );
       
       if( setsockopt( SOCKET( socket ).fd, IPPROTO_IP,
-	 IP_ADD_MEMBERSHIP, &mreq, sizeof( struct ip_mreq ) ) )
+		      IP_ADD_MEMBERSHIP, (SOCKOPTVALTYPE)&mreq, sizeof( struct ip_mreq ) ) )
 	 return BFALSE;
       else
 	 return socket;
@@ -2286,7 +2295,7 @@
       mreq.imr_multiaddr.s_addr = inet_addr( BSTRING_TO_STRING( val ) );
       mreq.imr_interface.s_addr = htonl( INADDR_ANY );
       if( setsockopt( SOCKET( socket ).fd, IPPROTO_IP,
-	 IP_DROP_MEMBERSHIP, &mreq, sizeof( struct ip_mreq ) ) )
+		      IP_DROP_MEMBERSHIP, (SOCKOPTVALTYPE)&mreq, sizeof( struct ip_mreq ) ) )
 	 return BFALSE;
       else
 	 return socket;
@@ -2374,7 +2383,7 @@
    // configure the socket
    if( broadcast ) {
       int bcast = 1;
-      if( setsockopt( s, SOL_SOCKET, SO_BROADCAST, &bcast, sizeof( bcast ) ) == -1) {
+      if( setsockopt( s, SOL_SOCKET, SO_BROADCAST, (SOCKOPTVALTYPE)&bcast, sizeof( bcast ) ) == -1) {
 	 datagram_client_socket_error( hostname, port,
 				       "cannot configure socket for broadcast",
 				       errno );
@@ -2468,7 +2477,7 @@
 
       /* set the reuse flag */
       if( setsockopt( s, SOL_SOCKET, SO_REUSEADDR,
-		      &sock_opt, sizeof( sock_opt ) ) < 0 ) {
+		      (SOCKOPTVALTYPE)&sock_opt, sizeof( sock_opt ) ) < 0 ) {
 	 system_error( msg, BINT( portnum ) );
       }
 
@@ -2710,6 +2719,7 @@
 			sock );
    }
 
+#if BGL_HAVE_INET_PTON 
    /* FIXME: No support for AF_UNIX, etc.  */
    if( !inet_pton( AF_INET, BSTRING_TO_STRING( host ),
 		   &((struct sockaddr_in *)&their_addr)->sin_addr ) ) {
@@ -2728,6 +2738,58 @@
       slen = sizeof( struct sockaddr_in );
    }
 
+#elif BGL_HAVE_GETADDRINFO
+   {
+     struct addrinfo hints;
+     struct addrinfo *results = NULL;
+     int ret = 0;
+     
+     memset(&hints, 0, sizeof(struct addrinfo));
+     hints.ai_family = AF_UNSPEC;
+     hints.ai_socktype = SOCK_DGRAM;
+     hints.ai_flags = 0;
+     hints.ai_protocol = 0;
+     
+     ret = getaddrinfo(BSTRING_TO_STRING( host ),
+		       NULL,
+		       &hints,
+		       &results);
+     
+     if(0 != ret || NULL == results){
+       socket_error( "datagram-socket-send",
+		     "cannot convert destination address", sock );
+     } else {
+       /* only use the first result */
+       if(AF_INET6 == results->ai_family){
+	 
+	 ((struct sockaddr_in6 *)&their_addr)->sin6_addr = ((struct sockaddr_in6*)&(results->ai_addr))->sin6_addr;
+	 ((struct sockaddr_in6 *)&their_addr)->sin6_port = htons( port );
+	 ((struct sockaddr *)&their_addr)->sa_family = AF_INET6;
+	 slen = sizeof( struct sockaddr_in6 );
+       
+       } else if (AF_INET == results->ai_family){
+	 
+	 ((struct sockaddr_in *)&their_addr)->sin_addr = ((struct sockaddr_in*)&(results->ai_addr))->sin_addr;
+	 ((struct sockaddr_in *)&their_addr)->sin_port = htons( port );
+	 ((struct sockaddr *)&their_addr)->sa_family = AF_INET;
+	 slen = sizeof( struct sockaddr_in );
+	 
+       }
+       
+     }
+
+     if(NULL != results){
+       freeaddrinfo(results);
+     }
+   }
+#else
+
+#error "inet_pton or getaddrinfo needed for bgl_datagram_socket_send"
+
+#endif /* BGL_HAVE_INET_PTON */
+
+
+
    sent = sendto( fd, BSTRING_TO_STRING( str ), STRING_LENGTH( str ), 0,
 		  (struct sockaddr *) &their_addr, slen );
    if( sent < 0 ) {
csystem.patch (application/octet-stream, 319 B)
--- bigloo4.0b/runtime/Clib/csystem.c	2013-08-01 02:50:44.000000000 -0400
+++ bigloo4.0bmod/runtime/Clib/csystem.c	2013-08-10 09:19:56.000000000 -0400
@@ -39,6 +39,7 @@
 #  include <pwd.h>
 #else
 #define uid_t int
+#define gid_t int
 #endif
 
 /*---------------------------------------------------------------------*/
getaddrinfo.patch (application/octet-stream, 442 B)
--- bigloo4.0b/autoconf/getaddrinfo	2013-08-01 02:50:44.000000000 -0400
+++ bigloo4.0bmod/autoconf/getaddrinfo	2013-08-16 11:13:35.348797898 -0400
@@ -43,7 +43,7 @@
 #*    mingw is super clear                                             */
 #*---------------------------------------------------------------------*/
 if [ "$HOSTOS " = "mingw " ]; then
-  echo "-lws2_32" # -lwsock32 -lmswsock"
+  echo 1 # -lwsock32 -lmswsock"
   exit 0
 fi
inet_aton.patch (application/octet-stream, 438 B)
--- bigloo4.0b/autoconf/inet_aton	2013-08-01 02:50:44.000000000 -0400
+++ bigloo4.0bmod/autoconf/inet_aton	2013-08-16 11:14:49.965467150 -0400
@@ -43,7 +43,7 @@
 #*    mingw is super clear                                             */
 #*---------------------------------------------------------------------*/
 if [ "$HOSTOS " = "mingw " ]; then
-  echo "-lws2_32" # -lwsock32 -lmswsock"
+  echo 0 # -lwsock32 -lmswsock"
   exit 0
 fi
inet_pton.patch (application/octet-stream, 439 B)
--- bigloo4.0b/autoconf/inet_pton	2013-08-01 02:50:43.000000000 -0400
+++ bigloo4.0bmod/autoconf/inet_pton	2013-08-16 11:14:11.558799154 -0400
@@ -52,7 +52,7 @@
 #*    mingw is super clear                                             */
 #*---------------------------------------------------------------------*/
 if [ "$HOSTOS " = "mingw " ]; then
-  echo "-lws2_32" # -lwsock32 -lmswsock"
+  echo 0  # -lwsock32 -lmswsock"
   exit 0
 fi
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.