Hi,

vim compiles but is unusable on NetBSD/sparc64 (extreme lag, high cpu).

Martin Husemann figured this is due to the wrong select() being called,
and provided a workaround here:
http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=53296

It works, but looking at this mess I couldn't resist to make it a
little more universal and remove some of those hacks from os_unix.c.

Your choice :)


(src/auto/configure can be regenerated)
--8<--
Replace select() redeclaration with less fragile method.

Vim should build on systems where the select() prototype takes either
int * or fd_set * as argument. Previously this was achieved by
providing its own prototype.

This approach fails on NetBSD, who do syscall versioning by symbol
renaming in their system headers (the real name is __select50).

In particular, on sparc64 the wrong select version is called and
random garbage is passed to the timeval argument, making vim unusable.

Instead of adding yet another set of workarounds for NetBSD, use the
prototype provided by system headers and cast the fd_set * arguments to
a suitable type.

diff --git a/src/auto/configure b/src/auto/configure
index 0ab7e2302..74d3e7219 100755
--- a/src/auto/configure
+++ b/src/auto/configure
@@ -12630,6 +12630,81 @@ _ACEOF
 fi
 done
 
+for ac_header in sys/select.h sys/socket.h
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" 
"$ac_includes_default"
+if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking types of arguments for 
select" >&5
+$as_echo_n "checking types of arguments for select... " >&6; }
+if ${ac_cv_func_select_args+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  for ac_arg234 in 'fd_set *' 'int *' 'void *'; do
+ for ac_arg1 in 'int' 'size_t' 'unsigned long int' 'unsigned int'; do
+  for ac_arg5 in 'struct timeval *' 'const struct timeval *'; do
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$ac_includes_default
+#ifdef HAVE_SYS_SELECT_H
+# include <sys/select.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+
+int
+main ()
+{
+extern int select ($ac_arg1,
+                                           $ac_arg234, $ac_arg234, $ac_arg234,
+                                           $ac_arg5);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_func_select_args="$ac_arg1,$ac_arg234,$ac_arg5"; break 3
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  done
+ done
+done
+# Provide a safe default value.
+: "${ac_cv_func_select_args=int,int *,struct timeval *}"
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_select_args" >&5
+$as_echo "$ac_cv_func_select_args" >&6; }
+ac_save_IFS=$IFS; IFS=','
+set dummy `echo "$ac_cv_func_select_args" | sed 's/\*/\*/g'`
+IFS=$ac_save_IFS
+shift
+
+cat >>confdefs.h <<_ACEOF
+#define SELECT_TYPE_ARG1 $1
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define SELECT_TYPE_ARG234 ($2)
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define SELECT_TYPE_ARG5 ($3)
+_ACEOF
+
+rm -f conftest*
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _LARGEFILE_SOURCE value 
needed for large files" >&5
 $as_echo_n "checking for _LARGEFILE_SOURCE value needed for large files... " 
>&6; }
 if ${ac_cv_sys_largefile_source+:} false; then :
diff --git a/src/config.h.in b/src/config.h.in
index 00117cf8c..b3066c7ba 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -113,6 +113,9 @@
 /* Define if you can safely include both <sys/time.h> and <sys/select.h>.  */
 #undef SYS_SELECT_WITH_SYS_TIME
 
+/* Define to the type of args 2, 3 and 4 for select. */
+#undef SELECT_TYPE_ARG234
+
 /* Define if you have /dev/ptc */
 #undef HAVE_DEV_PTC
 
diff --git a/src/configure.ac b/src/configure.ac
index 8994f3c90..9f17b9c70 100644
--- a/src/configure.ac
+++ b/src/configure.ac
@@ -3721,6 +3721,7 @@ AC_CHECK_FUNCS(fchdir fchown fchmod fsync getcwd 
getpseudotty \
        sigprocmask sigvec strcasecmp strerror strftime stricmp strncasecmp \
        strnicmp strpbrk strtol tgetent towlower towupper iswupper \
        usleep utime utimes mblen ftruncate unsetenv)
+AC_FUNC_SELECT_ARGTYPES
 AC_FUNC_FSEEKO
 
 dnl define _LARGE_FILES, _FILE_OFFSET_BITS and _LARGEFILE_SOURCE when
diff --git a/src/os_unix.c b/src/os_unix.c
index f33042675..1e41a138d 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -18,17 +18,6 @@
  * changed beyond recognition.
  */
 
-/*
- * Some systems have a prototype for select() that has (int *) instead of
- * (fd_set *), which is wrong. This define removes that prototype. We define
- * our own prototype below.
- * Don't use it for the Mac, it causes a warning for precompiled headers.
- * TODO: use a configure check for precompiled headers?
- */
-#if !defined(__APPLE__) && !defined(__TANDEM)
-# define select select_declared_wrong
-#endif
-
 #include "vim.h"
 
 #ifdef FEAT_MZSCHEME
@@ -54,14 +43,9 @@ static int selinux_enabled = -1;
 # endif
 #endif
 
-/*
- * Use this prototype for select, some include files have a wrong prototype
- */
-#ifndef __TANDEM
+#ifdef __BEOS__
 # undef select
-# ifdef __BEOS__
-#  define select       beos_select
-# endif
+# define select        beos_select
 #endif
 
 #ifdef __CYGWIN__
@@ -77,10 +61,6 @@ static int selinux_enabled = -1;
 # endif
 #endif
 
-#if defined(HAVE_SELECT)
-extern int   select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
-#endif
-
 #ifdef FEAT_MOUSE_GPM
 # include <gpm.h>
 /* <linux/keyboard.h> contains defines conflicting with "keymap.h",
@@ -6316,7 +6296,8 @@ select_eintr:
        if (interrupted != NULL)
            *interrupted = FALSE;
 
-       ret = select(maxfd + 1, &rfds, &wfds, &efds, tvp);
+       ret = select(maxfd + 1, SELECT_TYPE_ARG234 &rfds,
+           SELECT_TYPE_ARG234 &wfds, SELECT_TYPE_ARG234 &efds, tvp);
        result = ret > 0 && FD_ISSET(fd, &rfds);
        if (result)
            --ret;
-- 
2.18.0

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui