[PATCH] check if LEX is available before use it

2009-06-23 Thread Giuseppe Scrivano
Hello,

At the moment configure doesn't check if lex is installed before use it,
is is safe to assume it?

In case, this short patch adds the check in the configure.in file and
use the found LEX instead of `flex'.

Cheers,
Giuseppe



>From 43c2daa582df1a0e88d928d49934c984396c4d77 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano 
Date: Tue, 23 Jun 2009 17:28:40 +0200
Subject: [PATCH] Check if LEX is present before use it

 * configure.in: Check if LEX is present.
 * libguile/Makefile.am: Use LEX instead of `flex'.
---
 configure.in |7 +++
 libguile/Makefile.am |2 +-
 2 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/configure.in b/configure.in
index 1c4cf5f..35a963d 100644
--- a/configure.in
+++ b/configure.in
@@ -73,6 +73,13 @@ AC_PROG_CC
 gl_EARLY
 AC_PROG_CPP
 AC_PROG_AWK
+AC_PROG_LEX
+
+if test "$LEX" = ":"; then
+  AC_MSG_ERROR([lex not found.])
+fi
+
+AC_SUBST([LEX])
 
 dnl Gnulib.
 gl_INIT
diff --git a/libguile/Makefile.am b/libguile/Makefile.am
index 8c9c598..53f1c63 100644
--- a/libguile/Makefile.am
+++ b/libguile/Makefile.am
@@ -361,7 +361,7 @@ guile-procedures.txt: guile-procedures.texi
 endif
 
 c-tokenize.c: c-tokenize.lex
-   flex -t $(srcdir)/c-tokenize.lex > $@ || { rm $@; false; }
+   $(LEX) -t $(srcdir)/c-tokenize.lex > $@ || { rm $@; false; }
 
 schemelibdir = $(pkgdatadir)/$(GUILE_EFFECTIVE_VERSION)
 schemelib_DATA = guile-procedures.txt
-- 
1.6.3.1





Re: guile 1.9.0 scm_read_hash_extend gc trouble

2009-06-23 Thread Ludovic Courtès
Hello,

"Bill Schottstaedt"  writes:

> This is trickier than I thought -- it's not the GC after all.  In my configure
> script for Snd, autoconf defines _FILE_OFFSET_BITS to 64 if large files are 
> implemented.
> The config.h "include" precedes everything else.  When scm_getc is called
> within guile, it thinks sizeof(scm_t_port) is 92.  Everything is fine until
> my skip comment procedure is called (with this 92 byte struct) -- it
> thinks the scm_t_port size is 104, and fields like rw_active (in scm_getc
> which is apparently expanded inline) are not where it expects them to be!
> If I undef _FILE_OFFSET_BITS, both agree on the struct size, and there
> is no problem.  

Ouch!  That's a good illustration of the harm that can be done by
exposing data structures.

The attached patch adds a new `scm_t_off' type, whose definition does
not depend on the application's `_FILE_OFFSET_BITS' value.  Can you
confirm that it allows you to build Guile with 32-bit offsets and Snd
with 64-bit offsets (or vice versa)?

Neil: Does this sound like the right approach?

Thanks,
Ludo'.

diff --git a/libguile/fports.c b/libguile/fports.c
index de788c9..53d1140 100644
--- a/libguile/fports.c
+++ b/libguile/fports.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -671,8 +671,8 @@ fport_seek_or_seek64 (SCM port, off_t_or_off64_t offset, int whence)
fport_seek already.  */
 
 #if GUILE_USE_64_CALLS && HAVE_STAT64 && SIZEOF_OFF_T != SIZEOF_OFF64_T
-static off_t
-fport_seek (SCM port, off_t offset, int whence)
+static scm_t_off
+fport_seek (SCM port, scm_t_off offset, int whence)
 {
   off64_t rv = fport_seek_or_seek64 (port, (off64_t) offset, whence);
   if (rv > OFF_T_MAX || rv < OFF_T_MIN)
@@ -696,7 +696,7 @@ scm_i_fport_seek (SCM port, SCM offset, int how)
 }
 
 static void
-fport_truncate (SCM port, off_t length)
+fport_truncate (SCM port, scm_t_off length)
 {
   scm_t_fport *fp = SCM_FSTREAM (port);
 
diff --git a/libguile/gen-scmconfig.c b/libguile/gen-scmconfig.c
index 85ebfae..9715973 100644
--- a/libguile/gen-scmconfig.c
+++ b/libguile/gen-scmconfig.c
@@ -400,6 +400,22 @@ main (int argc, char *argv[])
   pf ("#define SCM_HAVE_READDIR64_R 0 /* 0 or 1 */\n");
 #endif
 
+  /* Arrange so that we have a file offset type that reflects the one
+ used when compiling Guile, regardless of the application's
+ `_FILE_OFFSET_BITS' says.
+
+ Note that we can't define `scm_t_off' in terms of `off_t' or
+ `off64_t' because they may or may not be available depending on
+ how the application that uses Guile is compiled.  */
+
+#if defined GUILE_USE_64_CALLS && defined HAVE_STAT64
+  pf ("typedef scm_t_int64 scm_t_off;\n");
+#elif SIZEOF_OFF_T == SIZEOF_INT
+  pf ("typedef int scm_t_off;\n");
+#else
+  pf ("typedef long int scm_t_off;\n");
+#endif
+
 #if USE_DLL_IMPORT
   pf ("\n");
   pf ("/* Define some additional CPP macros on Win32 platforms. */\n");
diff --git a/libguile/ports.c b/libguile/ports.c
index 248e0a4..1b7c9a5 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -222,15 +222,14 @@ scm_set_port_close (scm_t_bits tc, int (*close) (SCM))
 }
 
 void
-scm_set_port_seek (scm_t_bits tc, off_t (*seek) (SCM port,
-	   off_t OFFSET,
-	   int WHENCE))
+scm_set_port_seek (scm_t_bits tc,
+		   scm_t_off (*seek) (SCM, scm_t_off, int))
 {
   scm_ptobs[SCM_TC2PTOBNUM (tc)].seek = seek;
 }
 
 void
-scm_set_port_truncate (scm_t_bits tc, void (*truncate) (SCM port, off_t length))
+scm_set_port_truncate (scm_t_bits tc, void (*truncate) (SCM, scm_t_off))
 {
   scm_ptobs[SCM_TC2PTOBNUM (tc)].truncate = truncate;
 }
diff --git a/libguile/ports.h b/libguile/ports.h
index 64a0a89..48ed770 100644
--- a/libguile/ports.h
+++ b/libguile/ports.h
@@ -29,8 +29,6 @@
 #include "libguile/struct.h"
 #include "libguile/threads.h"
 
-/* Not sure if this is a good idea.  We need it for off_t.  */
-#include 
 
 
 
@@ -70,7 +68,7 @@ typedef struct
   unsigned char *read_buf;	/* buffer start.  */
   const unsigned char *read_pos;/* the next unread char.  */
   unsigned char *read_end;  /* pointer to last buffered char + 1.  */
-  off_t read_buf_size;		/* size of the buffer.  */
+  scm_t_off read_buf_size;		/* size of the buffer.  */
 
   /* when chars are put back into the buffer, e.g., using peek-char or
  unread-string, the read-buffer pointers are switched to cbuf.
@@ -79,7 +77,7 @@ typedef struct
   unsigned char *saved_read_buf;
   const unsigned char *saved_read_pos;
   unsigned char *saved_read_end;
-  off_t saved_read_buf_size;
+  scm_t_off saved_read_buf_size;
 
   /* write requests are saved into this buffer at write_pos until it
  reaches write_buf + write

Re: guile 1.9.0 scm_read_hash_extend gc trouble

2009-06-23 Thread Bill Schottstaedt
This is trickier than I thought -- it's not the GC after all.  In my configure
script for Snd, autoconf defines _FILE_OFFSET_BITS to 64 if large files are 
implemented.
The config.h "include" precedes everything else.  When scm_getc is called
within guile, it thinks sizeof(scm_t_port) is 92.  Everything is fine until
my skip comment procedure is called (with this 92 byte struct) -- it
thinks the scm_t_port size is 104, and fields like rw_active (in scm_getc
which is apparently expanded inline) are not where it expects them to be!
If I undef _FILE_OFFSET_BITS, both agree on the struct size, and there
is no problem.  





Re: undefined __rl_init_argument on Mac OS 10.4

2009-06-23 Thread Ludovic Courtès
Hi,

Abdulaziz Ghuloum  writes:

> I tried building guile 1.9 today and the build fails due to undefined
> "__rl_init_argument".  This appears to be defined in line 96 of guile- 
> readline/readline.c and used only once in like 125 of the same file.
> Commenting out both lines makes the build proceed, but I don't know
> how bad this is.  There are also a bunch of warnings about redefined
> bindings.  A summary of the failed build log is below.

Can you please make sure you use GNU Readline and not BSD Editline's
broken compatibility layer?  The `FAQ' file contains an entry on this
topic.

Thanks,
Ludo'.





Re: undefined __rl_init_argument on Mac OS 10.4

2009-06-23 Thread dsmich
Howdy Aziz,

 Abdulaziz Ghuloum  wrote: 
> Hello,
> 
> I tried building guile 1.9 today and the build fails due to undefined  
> "__rl_init_argument".  This appears to be defined in line 96 of guile- 
> readline/readline.c and used only once in like 125 of the same file.   
> Commenting out both lines makes the build proceed, but I don't know  
> how bad this is.  There are also a bunch of warnings about redefined  
> bindings.  A summary of the failed build log is below.

That's because the Apple reimplementation of readline is incomplete.  The 
preferred solution is to install gnu readline.

On the other hand, I did basically the same as you when I built Guile on my mac 
mini.  Never had a problem with it.

-Dale





undefined __rl_init_argument on Mac OS 10.4

2009-06-23 Thread Abdulaziz Ghuloum

Hello,

I tried building guile 1.9 today and the build fails due to undefined  
"__rl_init_argument".  This appears to be defined in line 96 of guile- 
readline/readline.c and used only once in like 125 of the same file.   
Commenting out both lines makes the build proceed, but I don't know  
how bad this is.  There are also a bunch of warnings about redefined  
bindings.  A summary of the failed build log is below.


Thanks!

Aziz,,,

$ make
make  all-recursive
make[1]: Entering directory `/private/tmp/guile-1.9.0'
Making all in lib
make[2]: Entering directory `/private/tmp/guile-1.9.0/lib'
make  all-recursive
make[3]: Entering directory `/private/tmp/guile-1.9.0/lib'
make[4]: Entering directory `/private/tmp/guile-1.9.0/lib'
make[4]: Nothing to be done for `all-am'.
make[4]: Leaving directory `/private/tmp/guile-1.9.0/lib'
make[3]: Leaving directory `/private/tmp/guile-1.9.0/lib'
make[2]: Leaving directory `/private/tmp/guile-1.9.0/lib'
Making all in meta
make[2]: Entering directory `/private/tmp/guile-1.9.0/meta'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/private/tmp/guile-1.9.0/meta'
Making all in libguile
make[2]: Entering directory `/private/tmp/guile-1.9.0/libguile'
make  all-am
make[3]: Entering directory `/private/tmp/guile-1.9.0/libguile'
make[3]: Nothing to be done for `all-am'.
make[3]: Leaving directory `/private/tmp/guile-1.9.0/libguile'
make[2]: Leaving directory `/private/tmp/guile-1.9.0/libguile'
Making all in guile-readline
make[2]: Entering directory `/private/tmp/guile-1.9.0/guile-readline'
../libguile/guile-snarf -o readline.x readline.c -DHAVE_CONFIG_H  -I.  
-I.. -I./.. -I./lib -I./lib -I/Users/ikarus/.opt/include -g -O2

make  all-recursive
make[3]: Entering directory `/private/tmp/guile-1.9.0/guile-readline'
Making all in ice-9
make[4]: Entering directory `/private/tmp/guile-1.9.0/guile-readline/ 
ice-9'

make[4]: Nothing to be done for `all'.
make[4]: Leaving directory `/private/tmp/guile-1.9.0/guile-readline/ 
ice-9'

make[4]: Entering directory `/private/tmp/guile-1.9.0/guile-readline'
/bin/sh ./libtool --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H  -I. - 
I. -I.. -I./.. -I./lib -I./lib  -I/Users/ikarus/.opt/include  -g -O2 - 
MT readline.lo -MD -MP -MF .deps/readline.Tpo -c -o readline.lo  
readline.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -I.. -I./.. -I./lib - 
I./lib -I/Users/ikarus/.opt/include -g -O2 -MT readline.lo -MD -MP - 
MF .deps/readline.Tpo -c readline.c  -fno-common -DPIC -o .libs/ 
readline.o

readline.c: In function 'scm_filename_completion_function':
readline.c:392: warning: assignment makes pointer from integer  
without a cast
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I. -I.. -I./.. -I./lib - 
I./lib -I/Users/ikarus/.opt/include -g -O2 -MT readline.lo -MD -MP - 
MF .deps/readline.Tpo -c readline.c -o readline.o >/dev/null 2>&1

mv -f .deps/readline.Tpo .deps/readline.Plo
/bin/sh ./libtool --tag=CC   --mode=link gcc  -g -O2 -version-info  
18:0:0 -export-dynamic -no-undefined  -o libguilereadline-v-18.la - 
rpath /Users/ikarus/.opt/lib readline.lo ../libguile/libguile.la ../ 
lib/libgnu.la -lreadline -lncurses
libtool: link: rm -fr  .libs/libguilereadline-v-18.18.dylib .libs/ 
libguilereadline-v-18.a .libs/libguilereadline-v-18.dylib .libs/ 
libguilereadline-v-18.la .libs/libguilereadline-v-18.lai
libtool: link: (cd .libs/libguilereadline-v-18.lax/libgnu.a && ar x "/ 
tmp/guile-1.9.0/guile-readline/../lib/.libs/libgnu.a")
libtool: link: gcc -dynamiclib  -o .libs/libguilereadline- 
v-18.18.dylib  .libs/readline.o   .libs/libguilereadline-v-18.lax/ 
libgnu.a/c-ctype.o .libs/libguilereadline-v-18.lax/libgnu.a/c- 
strcasecmp.o .libs/libguilereadline-v-18.lax/libgnu.a/c- 
strncasecmp.o .libs/libguilereadline-v-18.lax/libgnu.a/canonicalize- 
lgpl.o .libs/libguilereadline-v-18.lax/libgnu.a/full-read.o .libs/ 
libguilereadline-v-18.lax/libgnu.a/full-write.o .libs/ 
libguilereadline-v-18.lax/libgnu.a/localcharset.o .libs/ 
libguilereadline-v-18.lax/libgnu.a/malloca.o .libs/libguilereadline- 
v-18.lax/libgnu.a/putenv.o .libs/libguilereadline-v-18.lax/libgnu.a/ 
safe-read.o .libs/libguilereadline-v-18.lax/libgnu.a/safe- 
write.o .libs/libguilereadline-v-18.lax/libgnu.a/strftime.o .libs/ 
libguilereadline-v-18.lax/libgnu.a/striconveh.o .libs/ 
libguilereadline-v-18.lax/libgnu.a/u8-mbtouc-aux.o .libs/ 
libguilereadline-v-18.lax/libgnu.a/u8-mbtouc-unsafe-aux.o .libs/ 
libguilereadline-v-18.lax/libgnu.a/u8-mbtouc-unsafe.o .libs/ 
libguilereadline-v-18.lax/libgnu.a/u8-mbtouc.o .libs/libguilereadline- 
v-18.lax/libgnu.a/u8-mbtoucr.o .libs/libguilereadline-v-18.lax/ 
libgnu.a/u8-prev.o .libs/libguilereadline-v-18.lax/libgnu.a/u8-uctomb- 
aux.o .libs/libguilereadline-v-18.lax/libgnu.a/u8-uctomb.o   ../ 
libguile/.libs/libguile.dylib -L/usr/local/lib -L/usr/lib -L/Users/ 
ikarus/.opt/lib /Users/ikarus/.opt/lib/libunistring.dylib /Users/ 
ikarus/.opt/lib/libiconv.dylib /usr/local/lib/libgmp.dylib -lm /Users/ 
ikarus/.opt/lib/libltdl.dylib -lreadl

Re: guile 1.9.0 scm_read_hash_extend gc trouble

2009-06-23 Thread Thien-Thi Nguyen
() "Bill Schottstaedt" 
() Sun, 21 Jun 2009 05:10:09 -0700

   code to implement #|..|# block comment processing triggers either a
   glibc memory complaint or a segfault.

FWIW, below is the implementation from Guile 1.4.1.118 (not yet released).
It handles nesting (per R6RS, i believe) and a weird lookahead case.

thi

_
/* Skip #|...|# block comments.  */

static void
skip_hashpipe_block_comment (SCM port)
{
#define FUNC_NAME s_scm_read
  int c;
  bool pipep = false;
  int oline = SCM_LINUM (port);
  int ocol = SCM_COL (port);

  for (;;)
{
  if (EOF == (c = GETC ()))
  toosoon:
{
  char buf[149];

  snprintf (buf, 149, "%s\n%s:%d:%d: (starting here)",
"unterminated `#| ... |#' comment",
c_port_filename (port),
1 + oline, ocol - 1);
  BADNESS (0, buf);
}

  if (pipep && '#' == c)
return;

  /* Handle nested comments.  */
retry:
  if ('#' == c)
{
  if (EOF == (c = GETC ()))
goto toosoon;
  if ('|' == c)
{
  skip_hashpipe_block_comment (port);
  pipep = false;
}
  else
/* Don't get fooled by ##|...|# (ugh).  */
goto retry;
}

  pipep = ('|' == c);
}
#undef FUNC_NAME
}