guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Again on Windows support


From: carlo\.bramix
Subject: Re: Again on Windows support
Date: Fri, 20 Mar 2009 20:37:27 +0100

Hello!

> > LIBGUILE/GSUBR.C
> > ================
> > function alloca() is undefined because under Windows the intrinsic
> > function is called _alloca().
>
> Hm, I thought the Gnulib alloca thing should have fixed this. Does
> adding #include <alloca.h> in gsubr.c not fix this?
>

<alloca.h> does not exists here.
Unfortunately, we (Windows users) have no other choice than including malloc.h

> > LIBGUILE/OBJCODES.C
> > ===================
> > sys/mmap.h is absent.
>
> This is unfortunate. But I understand that windows has ways of mapping
> files to memory, and we should use those. Do you know what those calls
> are?
>

it can be done in this manner:
1) add presence check of windows.h into configure script.
2) on top of objcodes.c add:

#if HAVE_WINDOWS_H
#  define WIN32_LEAN_AND_MEAN
#  include <windows.h>
#endif

and:

#if HAVE_IO_H
#  include <io.h>
#endif

Hopefully, io.h is already tested by configure.

3) Now you can modify the function in this manner:

static SCM
make_objcode_by_mmap (int fd)
#define FUNC_NAME "make_objcode_by_mmap"
{
  int ret;
  char *addr;
  struct stat st;
  SCM sret = SCM_BOOL_F;
  struct scm_objcode *data;
#ifdef HAVE_WINSOCK2_H
  HANDLE hFile, hMapFile;
#endif

  ret = fstat (fd, &st);
  if (ret < 0)
    SCM_SYSERROR;

  if (st.st_size <= sizeof (struct scm_objcode) + strlen (OBJCODE_COOKIE))
    scm_misc_error (FUNC_NAME, "object file too small (~a bytes)",
                    SCM_LIST1 (SCM_I_MAKINUM (st.st_size)));

#ifdef HAVE_WINSOCK2_H
  /* Retrieve system handle from fd */
  hFile = (HANDLE)_get_osfhandle(fd);
  if (hFile == INVALID_HANDLE_VALUE)
    SCM_SYSERROR;

  /* Create mapping object */
  hMapFile = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
  if (hMapFile == INVALID_HANDLE_VALUE)
    SCM_SYSERROR;

  /* Select which portions of the file we need (entire file) */
  addr = (char *)MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
  if (addr == NULL) {
    /* Free the mapping object */
    CloseHandle(hMapFile);
    SCM_SYSERROR;
  }
#else
  addr = mmap (0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
  if (addr == MAP_FAILED)
    SCM_SYSERROR;
#endif

  if (memcmp (addr, OBJCODE_COOKIE, strlen (OBJCODE_COOKIE)))
    SCM_SYSERROR;
....

Everything else is the same.
I'm wondering: who frees the mapper object?
If we want to free it on Windows too, we must preserve "hMapFile" handle 
somewhere for closing it.

> > compilation of function make_objcode_by_mmap() fails because function
> > mmap() does not exist.
>
> I would rather implement this properly on windows than make a new, hacky
> function. This is a very important function, actually.
>

I did the change described above, it compiles fine.
Although it is very simple, I verified that the Win32 code works fine 
separately with a simple test programme.

> > LIBGUILE/VM.C
> > =============
> > I have not really understood this error:
> >
> > ../../guile-git/libguile/vm-engine.c: In function `vm_regular_engine':
> > ../../guile-git/libguile/vm-engine.c:277: error: unable to find a register 
> > to spill in class `SIREG'
>
> This is because in the VM we declare some variables to be in registers,
> but this confuses some gccs, especially on win32. I don't know what the
> real answer is -- perhaps we shouldn't force register allocation for
> these variables.
>

Ah, I understood.
I removed hardwired registers and now it compiles even with old GCC3.4.5
Instead of manually patching every GCC release, perhaps it's better to leave 
that choice to the user.
For example if, at configure time, the user adds something like 
"--disable-vm-hardregs" or "--enable-vm-hardregs" then it will be possible to 
recover a working build (normally, those register variables will be always 
enabled).
And it will be available for all architectures and all cpus, not only i386 
and/or mingw32.

Now I advanced my compilation but, sigh, it seems I have not big luck...
After a while this is the error I'm getting:

make[4]: Entering directory `/home/Carlo/guile/doc/ref'
restore=: && backupdir=".am$$" && \
am__cwd=`pwd` && cd ../../../guile-git/doc/ref && \
rm -rf $backupdir && mkdir $backupdir && \
if (/bin/sh /home/Carlo/guile-git/build-aux/missing --run makeinfo --version) 
>/dev/null 2>&1; then \
  for f in ../../../guile-git/doc/ref/guile.info 
../../../guile-git/doc/ref/guile.info-[0-9] 
../../../guile-git/doc/ref/guile.info-[0-9][0-9] 
../../../guile-git/doc/ref/guile.i[0-9] 
../../../guile-git/doc/ref/guile.i[0-9][0-9]; do \
    if test -f $f; then mv $f $backupdir; restore=mv; else :; fi; \
  done; \
else :; fi && \
cd "$am__cwd"; \
if /bin/sh /home/Carlo/guile-git/build-aux/missing --run makeinfo   -I 
../../../guile-git/doc/ref \
 -o ../../../guile-git/doc/ref/guile.info 
../../../guile-git/doc/ref/guile.texi; \
then \
  rc=0; \
  cd ../../../guile-git/doc/ref; \
else \
  rc=$?; \
  cd ../../../guile-git/doc/ref && \
  $restore $backupdir/* `echo "./../../../guile-git/doc/ref/guile.info" | sed 
's|[^/]*$||'`; \
fi; \
rm -rf $backupdir; exit $rc
../../../guile-git/doc/ref/compiler.texi:54: Unknown command `'.
makeinfo: Removing output file `../../../guile-git/doc/ref/guile.info' due to 
errors; use --force to preserve.
make[4]: *** [../../../guile-git/doc/ref/guile.info] Error 1

Sincerely,

Carlo Bramini.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]