From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "carlo\.bramix" Newsgroups: gmane.lisp.guile.devel Subject: Mingw support. Date: Wed, 24 Feb 2010 21:56:41 +0100 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="_=__=_XaM3_.1267045001.2A.533193.42.7939.52.42.007.660710603" X-Trace: dough.gmane.org 1267045021 22201 80.91.229.12 (24 Feb 2010 20:57:01 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 24 Feb 2010 20:57:01 +0000 (UTC) To: "guile-devel" Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Feb 24 21:56:57 2010 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1NkOHw-0006pI-4Q for guile-devel@m.gmane.org; Wed, 24 Feb 2010 21:56:56 +0100 Original-Received: from localhost ([127.0.0.1]:50858 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NkOHv-000538-II for guile-devel@m.gmane.org; Wed, 24 Feb 2010 15:56:55 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NkOHq-000533-7p for guile-devel@gnu.org; Wed, 24 Feb 2010 15:56:50 -0500 Original-Received: from [140.186.70.92] (port=40745 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NkOHo-00052v-1o for guile-devel@gnu.org; Wed, 24 Feb 2010 15:56:48 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NkOHl-0007se-CZ for guile-devel@gnu.org; Wed, 24 Feb 2010 15:56:47 -0500 Original-Received: from cp-out1.libero.it ([212.52.84.101]:33376) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NkOHk-0007sQ-Rz for guile-devel@gnu.org; Wed, 24 Feb 2010 15:56:45 -0500 Original-Received: from libero.it (192.168.33.218) by cp-out1.libero.it (8.5.115) id 4AB2342308D54EBE for guile-devel@gnu.org; Wed, 24 Feb 2010 21:56:41 +0100 X-Sensitivity: 3 X-XaM3-API-Version: 4.3 (R1) (B3pl25) X-SenderIP: 213.203.169.135 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:9993 Archived-At: --_=__=_XaM3_.1267045001.2A.533193.42.7939.52.42.007.660710603 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hello, after an hard work I was able to get an almost working build of the most = recent guile. In the attached patch there are some little fixes and a bigger one, an al= most complete and working implementation of posix mmap()/munmap() for Win= dows: this will allow you a single source code to be easily modified for = both POSIX and WIN32 solutions. This code has been also tested separately and I have not found any proble= m. This patch corrects the most urgent problem but it is not enough for comp= iling guile completely working. I found some difficult problems that I corrected with some hacks into the= source and, obviously, not included in the attached patch. libguile/dynl.c and libguile/foreing.c generate an error like this one: ../../guile-1.9.8/libguile/dynl.c:304: error: for each function it appear= s in.) ../../guile-1.9.8/libguile/dynl.c: In function 'scm_dynamic_args_call': ../../guile-1.9.8/libguile/dynl.c:334: error: 'SCM_FOREIGN_TYPE_void' und= eclared (first use in this function) make[3]: *** [dynl.lo] Error 1 This problem happens because the Windows includes declare the VOID macro = to be an alias of void. One line of code explains it better: #define VOID void So, when combining with ## operator, SCM_FOREIGN_TYPE_ + VOID does not cr= eates SCM_FOREIGN_TYPE_VOID but SCM_FOREIGN_TYPE_void. There was no much that I could do to avoid this, except adding an "#undef= VOID" after all inclusions. After that, I got this error. libtool: link: gcc -std=3Dgnu99 -Wall -Wmissing-prototypes -Wdeclaration-= after-statement -Wundef -Wswitch-enum -fvisibility=3Dhidden -Ic:/mingw/in= clude -g -O2 -o .libs/guile_filter_doc_snarfage.exe c-tokenize.o -Lc:/mi= ngw/lib /mingw/lib/libgc.dll.a /mingw/lib/libatomic_ops.dll.a /mingw/lib/= libregex.dll.a /mingw/lib/libunistring.dll.a /mingw/lib/libiconv.dll.a -l= crypt -lws2_32 /mingw/lib/libltdl.dll.a -L/mingw/lib c-tokenize.o: In function `yyalloc': C:\msys\1.0\home\Carlo\guile\libguile/:2177: undefined reference = to `rpl_malloc' collect2: ld returned 1 exit status It seems to me that there is a missing libguile.la dependency. I'm not sure where it would be better to touch, so I hacked generated Mak= efile without touching Makefile.am yet. Anyways, adding libguile.la solved the trouble. Finally, when all things seemed to work correctly, I got this message whe= n compiling. make[2]: Entering directory `/home/Carlo/guile/module' GUILE_AUTO_COMPILE=3D0 \ ../meta/uninstalled-env \ guile-tools compile -Wunbound-variable -Warity-mismatch -o "ice-9= /eval.g o" "../../guile-1.9.8/module/ice-9/eval.scm" ERROR: In procedure delete-file: ERROR: Permission denied make[2]: *** [ice-9/eval.go] Error 1 Actually, this just means to me that there is at least one file descripto= r still open and valid when _unlink() function is called. It could be a plain file handle or a memory mapped object. Have you some suggestions to give me for testing this? I hope all this will be useful. Sincerely, Carlo Bramini. --_=__=_XaM3_.1267045001.2A.533193.42.7939.52.42.007.660710603 Content-Type: text/plain; name="=?iso-8859-1?Q?libguile-1.9.8.txt?=" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="=?iso-8859-1?Q?libguile-1.9.8.txt?=" diff -r -u guile-1.9.8-old/libguile/deprecated.c guile-1.9.8-new/libguile= /deprecated.c=0A--- guile-1.9.8-old/libguile/deprecated.c 2010-01-22 09:1= 6:50 +0000=0A+++ guile-1.9.8-new/libguile/deprecated.c 2010-02-22 17:12:2= 0 +0000=0A@@ -1640,7 +1640,7 @@=0A =0C=0A /* Networking. */=0A =0A-#ifde= f HAVE_NETWORKING=0A+#if defined HAVE_NETWORKING && defined HAVE_IPV6=0A = =0A SCM_DEFINE (scm_inet_aton, "inet-aton", 1, 0, 0,=0A (SCM = address),=0Adiff -r -u guile-1.9.8-old/libguile/filesys.c guile-1.9.8-new= /libguile/filesys.c=0A--- guile-1.9.8-old/libguile/filesys.c 2010-01-22 0= 9:16:50 +0000=0A+++ guile-1.9.8-new/libguile/filesys.c 2010-02-24 20:06:4= 7 +0000=0A@@ -117,7 +117,8 @@=0A =0A /* Some more definitions for the nat= ive Windows port. */=0A #ifdef __MINGW32__=0A-# define mkdir(path, mode) = mkdir (path)=0A+# undef mkdir=0A+# define mkdir(path, mode) _mkdir (path)= =0A # define fsync(fd) _commit (fd)=0A # define fchmod(fd, mode) (-1)=0A = #endif /* __MINGW32__ */=0A@@ -515,6 +516,11 @@=0A * under Windows. It d= ifferentiates between file, pipe and socket =0A * descriptors.=0A */=0A= +=0A+#ifndef _S_IFSOCK=0A+#define _S_IFSOCK 0140000=0A+#endif=0A+=0A st= atic int fstat_Win32 (int fdes, struct stat *buf)=0A {=0A int error, op= tlen =3D sizeof (int);=0Adiff -r -u guile-1.9.8-old/libguile/objcodes.c g= uile-1.9.8-new/libguile/objcodes.c=0A--- guile-1.9.8-old/libguile/objcode= s.c 2010-01-11 22:21:17 +0000=0A+++ guile-1.9.8-new/libguile/objcodes.c 2= 010-02-22 17:16:59 +0000=0A@@ -22,8 +22,10 @@=0A =0A #include =0A= #include =0A-#include =0A-#include =0A+#i= nclude +#if HAVE_SYS_MMAN_H=0A+# include +#endif=0A #include =0A #include =0A #include =0A@@ -38,6 +40,156 @@=0A verify (((sizeof (SCM_OBJCODE_COOKIE) -= 1) & 7) =3D=3D 0);=0A =0A =0C=0A+ +#ifdef _WIN32 + +/* + * Implementation of mmap()/munmap() replacement for Windows. + */ + +#define WIN32_LEAN_AND_MEAN +#include + +#define PROT_READ 0x0001 +#define PROT_WRITE 0x0002 +#define PROT_EXEC 0x0004 +#define PROT_NONE 0x0008 + +#define MAP_SHARED 0x0001 +#define MAP_PRIVATE 0x0002 +#define MAP_FIXED 0x0004 + +#define MAP_FAILED ((void *)-1) + +typedef struct { + unsigned int prot_flag; + DWORD win_flag; +} Protection_Scheme_t; + +typedef struct _MapList_t { + HANDLE hMap; + void *Base; + struct _MapList_t *Next; +} MapList_t; + +static const Protection_Scheme_t Protection_Scheme[] =3D { + { PROT_READ, PAGE_READONLY }, + { PROT_READ|PROT_WRITE, PAGE_READWRITE }, + { PROT_READ|PROT_WRITE|PROT_EXEC, PAGE_EXECUTE_READWRITE }, + { PROT_EXEC, PAGE_EXECUTE }, + { PROT_READ|PROT_EXEC, PAGE_EXECUTE_READ }, +}; + +static MapList_t *MapList =3D NULL; + +static void *mmap(unsigned int address, + unsigned int size, + unsigned int protection, + unsigned int flags, + int fd, + int offset) +{ + HANDLE hFile, hMapFile; + DWORD dwProtect, dwAccess; + void *Base; + MapList_t *Item; + unsigned int x; + + /* Check if fd is valid */ + if (fd =3D=3D -1) + return MAP_FAILED; + + /* Retrieve system handle from fd */ + hFile =3D (HANDLE)_get_osfhandle(fd); + if (hFile =3D=3D INVALID_HANDLE_VALUE) + return MAP_FAILED; + + /* Search protection schemes */ + for (dwProtect=3DPAGE_NOACCESS, x=3D0; + x < (sizeof(Protection_Scheme)/sizeof(Protection_Scheme_t)); + x++) + { + if (Protection_Scheme[x].prot_flag =3D=3D protection) + { + dwProtect =3D Protection_Scheme[x].win_flag; + break; + } + } + + if (flags & MAP_PRIVATE) { + dwAccess =3D FILE_MAP_COPY; + dwProtect =3D PAGE_WRITECOPY; + } else + if ((protection & PROT_WRITE)) + dwAccess =3D FILE_MAP_WRITE; + else + dwAccess =3D FILE_MAP_READ; + + /* Create mapping object */ + hMapFile =3D CreateFileMapping(hFile, NULL, dwProtect, 0, size, NULL);= + if (hMapFile =3D=3D INVALID_HANDLE_VALUE) + return MAP_FAILED; + + /* Select which portions of the file we need (entire file) */ + Base =3D MapViewOfFile(hMapFile, dwAccess, 0, offset, size); + + if (Base =3D=3D NULL) { + /* Free the mapping object */ + CloseHandle(hMapFile); + return MAP_FAILED; + } + + /* Allocate item for list mmaps... */ + Item =3D (MapList_t *)malloc(sizeof(MapList_t)); + if (Item =3D=3D NULL) { + UnmapViewOfFile(Base); + CloseHandle(hMapFile); + + return MAP_FAILED; + } + + Item->hMap =3D hMapFile; + Item->Base =3D Base; + Item->Next =3D MapList; + + if (MapList =3D=3D NULL) + MapList =3D Item; + + return Base; +} + +static int munmap(void *addr, unsigned int size) +{ + MapList_t *Item, *Prev; + + Prev =3D NULL; + Item =3D MapList; + + while (Item !=3D NULL) { + if (Item->Base =3D=3D addr) { + UnmapViewOfFile(Item->Base); + CloseHandle(Item->hMap); + + /* Delete this item from linked list */ + if (Prev !=3D NULL) + Prev->Next =3D Item->Next; + else + MapList =3D Item->Next; + + free(Item); + + return 0; + } + Prev =3D Item; + Item =3D Item->Next; + } + + return -1; +} + +#endif /* _WIN32 */ + + /*=0A * Objcode type=0A */=0Adiff -r -u guile-1.9.8-old/libguile/socke= t.c guile-1.9.8-new/libguile/socket.c=0A--- guile-1.9.8-old/libguile/sock= et.c 2009-11-26 09:18:09 +0000=0A+++ guile-1.9.8-new/libguile/socket.c 20= 10-02-22 17:17:50 +0000=0A@@ -56,6 +56,7 @@=0A #include =0A = #ifdef HAVE_WINSOCK2_H=0A #include =0A+#include #else=0A #include =0A #ifdef HAVE_UNIX_DOMAIN_SOCKETS=0A --_=__=_XaM3_.1267045001.2A.533193.42.7939.52.42.007.660710603--