[bug-gnulib] Re: new modules for C# interoperability

2005-06-01 Thread Bruno Haible
There were no comments on csharpexec, no I committed this module.

Here comes the module for compiling a C# program.

= modules/csharpcomp =
Description:
Compile a C# program.

Files:
lib/csharpcomp.h
lib/csharpcomp.c
lib/csharpcomp.sh.in
m4/csharpcomp.m4
m4/csharp.m4

Depends-on:
stdbool
xallocsa
execute
pipe
wait-process
getline
sh-quote
safe-read
error
gettext

configure.ac:
gt_CSHARPCOMP

Makefile.am:
lib_SOURCES += csharpcomp.h csharpcomp.c
EXTRA_DIST += csharpcomp.sh.in

Include:
csharpcomp.h

License:
GPL

Maintainer:
Bruno Haible

 lib/csharpcomp.sh.in 
#!/bin/sh
# Compile a C# program.

# Copyright (C) 2003-2005 Free Software Foundation, Inc.
# Written by Bruno Haible [EMAIL PROTECTED], 2003.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# This uses the same choices as csharpcomp.c, but instead of relying on the
# environment settings at run time, it uses the environment variables
# present at configuration time.
#
# This is a separate shell script, because the various C# compilers have
# different command line options.
#
# Usage: /bin/sh csharpcomp.sh [OPTION] SOURCE.cs ... RES.resource ...
# Options:
#   -o PROGRAM.exe  or  -o LIBRARY.dll
# set the output assembly name
#   -L DIRECTORY  search for C# libraries also in DIRECTORY
#   -l LIBRARYreference the C# library LIBRARY.dll
#   -Ooptimize
#   -ggenerate debugging information

# func_tmpdir
# creates a temporary directory.
# Sets variable
# - tmp pathname of freshly created temporary directory
func_tmpdir ()
{
  # Use the environment variable TMPDIR, falling back to /tmp. This allows
  # users to specify a different temporary directory, for example, if their
  # /tmp is filled up or too small.
  : ${TMPDIR=/tmp}
  {
# Use the mktemp program if available. If not available, hide the error
# message.
tmp=`(umask 077  mktemp -d -q $TMPDIR/gtXX) 2/dev/null` 
test -n $tmp  test -d $tmp
  } ||
  {
# Use a simple mkdir command. It is guaranteed to fail if the directory
# already exists.  $RANDOM is bash specific and expands to empty in shells
# other than bash, ksh and zsh.  Its use does not increase security;
# rather, it minimizes the probability of failure in a very cluttered /tmp
# directory.
tmp=$TMPDIR/gt$$-$RANDOM
(umask 077  mkdir $tmp)
  } ||
  {
echo $0: cannot create a temporary directory in $TMPDIR 2
{ (exit 1); exit 1; }
  }
}

sed_quote_subst='s/\([|;()$`'''*?[#~=%\\]\)/\\\1/g'
options_cscc=
options_mcs=
options_csc=-nologo
sources=
while test $# != 0; do
  case $1 in
-o)
  case $2 in
*.dll)
  options_cscc=$options_cscc -shared
  options_mcs=$options_mcs -target:library
  options_csc=$options_csc -target:library
  ;;
*.exe)
  options_csc=$options_csc -target:exe
  ;;
  esac
  options_cscc=$options_cscc -o `echo $2 | sed -e $sed_quote_subst`
  options_mcs=$options_mcs -o `echo $2 | sed -e $sed_quote_subst`
  options_csc=$options_csc -out:`echo $2 | sed -e $sed_quote_subst`
  shift
  ;;
-L)
  options_cscc=$options_cscc -L `echo $2 | sed -e $sed_quote_subst`
  options_mcs=$options_mcs -L `echo $2 | sed -e $sed_quote_subst`
  options_csc=$options_csc -lib:`echo $2 | sed -e $sed_quote_subst`
  shift
  ;;
-l)
  options_cscc=$options_cscc -l `echo $2 | sed -e $sed_quote_subst`
  options_mcs=$options_mcs -r `echo $2 | sed -e $sed_quote_subst`
  options_csc=$options_csc -reference:`echo $2 | sed -e 
$sed_quote_subst`
  shift
  ;;
-O)
  options_cscc=$options_cscc -O
  options_csc=$options_csc -optimize+
  ;;
-g)
  options_cscc=$options_cscc -g
  options_mcs=$options_mcs -g
  options_csc=$options_csc -debug+
  ;;
-*)
  echo csharpcomp: unknown option '$1' 12
  exit 1
  ;;
*.resource)
  options_cscc=$options_cscc -fresources=`echo $1 | sed -e 
$sed_quote_subst`
  options_mcs=$options_mcs -resource:`echo $1 | sed -e 
$sed_quote_subst`
  options_csc=$options_csc -resource:`echo $1 | sed -e 
$sed_quote_subst`
  ;;
*.cs)
  sources=$sources `echo $1 | sed 

[bug-gnulib] work around poll() bug in MacOS X 10.4

2005-06-01 Thread Bruno Haible
Hi,

It has been reported that MacOS X 10.4 has the poll() system call, but it
is completely broken: it does not work any files in /dev/*. This includes
/dev/tty, normal stdin and stdout, and even /dev/null. See
http://lists.apple.com/archives/darwin-dev/2005/May/msg00220.html
http://comments.gmane.org/gmane.os.apple.fink.gnome/1193
http://cvs.sourceforge.net/viewcvs.py/fink/dists/10.4-transitional/unstable/main/finkinfo/gnome/glib2.info?r1=1.3r2=1.4

This test program
=== polltest.c ===
#include stdio.h
#include errno.h
#include fcntl.h
#include poll.h

int main () {
  struct pollfd ufd;
  int result;
  {
ufd.fd = 0;
ufd.events = POLLIN;
ufd.revents = 0;
errno = 0;
result = poll(ufd,1,0);
printf(fd = %d: %d/%d %d - %d\n, ufd.fd, result, errno, ufd.events, 
ufd.revents);
  }
  {
ufd.fd = 1;
ufd.events = POLLOUT;
ufd.revents = 0;
errno = 0;
result = poll(ufd,1,0);
printf(fd = %d: %d/%d %d - %d\n, ufd.fd, result, errno, ufd.events, 
ufd.revents);
  }
  {
ufd.fd = open(/dev/tty, O_RDONLY);
ufd.events = POLLIN;
ufd.revents = 0;
errno = 0;
result = poll(ufd,1,0);
printf(fd = %d: %d/%d %d - %d\n, ufd.fd, result, errno, ufd.events, 
ufd.revents);
  }
  {
ufd.fd = open(/dev/tty, O_WRONLY);
ufd.events = POLLOUT;
ufd.revents = 0;
errno = 0;
result = poll(ufd,1,0);
printf(fd = %d: %d/%d %d - %d\n, ufd.fd, result, errno, ufd.events, 
ufd.revents);
  }
  {
ufd.fd = open(/dev/null, O_RDONLY);
ufd.events = POLLIN;
ufd.revents = 0;
errno = 0;
result = poll(ufd,1,0);
printf(fd = %d: %d/%d %d - %d\n, ufd.fd, result, errno, ufd.events, 
ufd.revents);
  }
  {
ufd.fd = open(/dev/null, O_WRONLY);
ufd.events = POLLOUT;
ufd.revents = 0;
errno = 0;
result = poll(ufd,1,0);
printf(fd = %d: %d/%d %d - %d\n, ufd.fd, result, errno, ufd.events, 
ufd.revents);
  }
  return 0;
}
==

yields this on Linux and Solaris:

fd = 0: 0/0 1 - 0
fd = 1: 1/0 4 - 4
fd = 3: 0/0 1 - 0
fd = 4: 1/0 4 - 4
fd = 5: 1/0 1 - 1
fd = 6: 1/0 4 - 4

but this on MacOS X 10.4.0:

fd = 0: 1/0 1 - 32
fd = 1: 1/0 4 - 32
fd = 3: 1/0 1 - 32
fd = 4: 1/0 4 - 32
fd = 5: 1/0 1 - 32
fd = 6: 1/0 4 - 32

Here is a proposed patch for gnulib.

2005-06-01  Bruno Haible  [EMAIL PROTECTED]

* poll.m4 (gl_FUNC_POLL): Check against MacOS X 10.4 poll() bug.
When using lib/poll.c, define poll as rpl_poll.

diff -c -3 -r1.3 poll.m4
*** m4/poll.m4  23 Jan 2005 08:06:57 -  1.3
--- m4/poll.m4  1 Jun 2005 11:44:30 -
***
*** 1,5 
! # poll.m4 serial 3
! dnl Copyright (c) 2003 Free Software Foundation, Inc.
  dnl This file is free software; the Free Software Foundation
  dnl gives unlimited permission to copy and/or distribute it,
  dnl with or without modifications, as long as this notice is preserved.
--- 1,5 
! # poll.m4 serial 4
! dnl Copyright (c) 2003, 2005 Free Software Foundation, Inc.
  dnl This file is free software; the Free Software Foundation
  dnl gives unlimited permission to copy and/or distribute it,
  dnl with or without modifications, as long as this notice is preserved.
***
*** 14,21 
fi
AC_SUBST([POLL_H])
  
!   AC_REPLACE_FUNCS(poll)
!   if test $ac_cv_func_poll = no; then
  gl_PREREQ_POLL
fi
  ])
--- 14,65 
fi
AC_SUBST([POLL_H])
  
!   AC_CHECK_FUNC(poll,
! [# Check whether poll() works on special files (like /dev/null) and
!  # and ttys (like /dev/tty). On MacOS X 10.4.0, it doesn't.
!  AC_TRY_RUN([
! #include fcntl.h
! #include poll.h
!int main()
!{
!  struct pollfd ufd;
!  /* Try /dev/null for reading.  */
!  ufd.fd = open (/dev/null, O_RDONLY);
!  if (ufd.fd  0) /* If /dev/null does not exist, it's not MacOS X. */
!return 0;
!  ufd.events = POLLIN;
!  ufd.revents = 0;
!  if (!(poll (ufd, 1, 0) == 1  ufd.revents == POLLIN))
!return 1;
!  /* Try /dev/null for writing.  */
!  ufd.fd = open (/dev/null, O_WRONLY);
!  if (ufd.fd  0) /* If /dev/null does not exist, it's not MacOS X. */
!return 0;
!  ufd.events = POLLOUT;
!  ufd.revents = 0;
!  if (!(poll (ufd, 1, 0) == 1  ufd.revents == POLLOUT))
!return 1;
!  /* Trying /dev/tty may be too environment dependent.  */
!  return 0;
!}],
![gl_cv_func_poll=yes],
![gl_cv_func_poll=no],
![# When cross-compiling, assume that poll() works everywhere except on
! # MacOS X, regardless of its version.
! AC_EGREP_CPP([MacOSX], [
! #if defined(__APPLE__)  defined(__MACH__)
! This is MacOSX
! #endif
! ], [gl_cv_func_poll=no], [gl_cv_func_poll=yes])])])
!   if test $gl_cv_func_poll = yes; then
! AC_DEFINE([HAVE_POLL], 1,
!   [Define to 

Re: [bug-gnulib] New GNULIB glob module?

2005-06-01 Thread Derek Price
Paul Eggert wrote:

Derek Price [EMAIL PROTECTED] writes:

  

   1. Corrects an incorrect check for a successful return from
  getlogin_r to assume only 0 means success, per the POSIX2 spec:
  
 http://www.opengroup.org/onlinepubs/009695399/functions/getlogin_r.html.
   2. Moves the check for GLOB_MARK directory status (and the append of
  `/') into glob_in_dir, where it is more efficient than performing
  a second pass and sometimes calling stat a second time on each
  file or directory.  All calls to stat are avoided when
  dirent-d_type is available.  No call to realloc of the directory
  name is ever necessary since room for the slash can be allocated
  in the first pass.



These changes sound reasonable, though we should submit them as
separate patches.
  


The attached  glibc-understand-getlogin_r.diff may come off as a little
fuzzy, but it should work for (1).  I've also reattached the patch for 2
 3 minus the above chunk, as glibc-glob-list-links2.diff.

Is (2) independent of (3)?  (Please see below for why this is important.)
  


(2) could be separated with a little more work, but lets finish the
discussion below before I provide a second patch.

   3. Ignores broken links only when GLOB_ONLYDIR is set.  With glibc
  versions 2.3.3 through 2.3.5, the following in an empty directory
  would return nothing:

  ln -s doesnt-exist linkname
  glob (*, ...)

  This fix syncs with the comments in the file, syncs with the
  POSIX2 spec, restores the pre-glibc-2.3.3 behavior, and simply
  makes more sense - why should `ls *' fail to list broken links?



This change sounds controversial to me.  glibc 2.3.5 behaves similarly
  


It may be.  It looks like the change was intentional
(http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/sysdeps/generic/glob.c?rev=1.52content-type=text/x-cvsweb-markupcvsroot=glibc),
but I still disagree.

to Solaris 8 and to Solaris 10 -- I just checked, with the following
program and with the working directory containing only a dangling
symlink:

  #include glob.h
  #include stdio.h

  int
  main (void)
  {
glob_t g;
int r = glob (*, 0, NULL, g);
int i;

if (r != 0)
  {
fprintf (stderr, glob failed (%s)\n,
 r == GLOB_NOMATCH ? GLOB_NOMATCH
 : r == GLOB_NOSPACE ? GLOB_NOSPACE
 : other glob failure);
return 1;
  }

for (i = 0; i  g.gl_pathc; i++)
  puts (g.gl_pathv[i]);
return 0;
  }

Solaris 8 and 10 both report glob failed (GLOB_NOMATCH).

Let's separate (3) into a separate patch and think about it more
carefully before submitting it.
  


This would involve creating at least one new function for (2) which
would just need to be removed again for (3), and the POSIX2 glob spec
states that glob returns GLOB_NOMATCH only when, the pattern does not
match any existing pathname, and GLOB_NOCHECK was not set in flags. 
(http://www.opengroup.org/onlinepubs/009695399/functions/glob.html)

Nowhere does the POSIX2 glob spec specify that a broken symlink should
not be considered an existing pathname.  After all, the link exists,
only its target does not.  Interpreted in this way, glob cannot be used
by a program which, for instance, wished to verify that all links
matching a pattern had valid targets since the broken links would not be
returned by glob.

If glob is only going to consider a link as if it is its target, then
what about the case where a matching link points to a file in the same
directory that also matches the pattern?  Should glob only return one or
the other?

Perhaps a GNU extension similar to GLOB_ONLYDIR is in order
(GLOB_VERIFY_SYMLINKS?), but I do not think glob should be making these
value judgements when the user did not request it.  It certainly does
not appear to be implied by the POSIX spec as I read it.

Have you investigated with FreeBSD glob does?  


No, but I ran your test program on NetBSD 1.6.1 and it does return the
broken symlink.

I copied and pasted most of my above commentary on why this should be
considered a bug into
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=126460, where I
found the discussion that apparently caused the original bug fix that
broke this.

Cheers,

Derek

--- ../glob-glibc2gnulib/lib/glob.c 2005-05-31 18:12:01.0 -0400
+++ lib/glob.c  2005-05-27 13:52:28.0 -0400
@@ -538,7 +539,7 @@ glob (const char *pattern, int flags,
buflen = 20;
  name = __alloca (buflen);
 
- success = getlogin_r (name, buflen) = 0;
+ success = getlogin_r (name, buflen) == 0;
  if (success)
{
  struct passwd *p;
--- ../glob-glibc2gnulib/lib/glob.c 2005-05-31 18:12:01.0 -0400
+++ lib/glob.c  2005-05-27 13:52:28.0 -0400
@@ -175,6 +175,7 @@
 # define __glob_pattern_p  glob_pattern_p
 #endif /* _LIBC */
 
+#include stdbool.h
 #include fnmatch.h