changeset 29224:ca46658481cf v8.2.5131

patch 8.2.5131: timeout implementation is not optimal Commit: https://github.com/vim/vim/commit/e530395c2cd261d598094dc9ea785e90a753c5f1 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 19 17:05:47 2022 +0100 patch 8.2.5131: timeout implementation is not optimal Problem: Timeout implementation is not optimal. Solution: Further improvements for timeouts. Add a test for searchpair() timeout. (partly by Paul Ollis)
author Bram Moolenaar <Bram@vim.org>
date Sun, 19 Jun 2022 18:15:03 +0200
parents 18ff9d5a73ed
children 80258dfb5657
files src/auto/configure src/configure.ac src/testdir/test_hlsearch.vim src/testdir/test_search.vim src/version.c
diffstat 5 files changed, 60 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/auto/configure
+++ b/src/auto/configure
@@ -4769,6 +4769,8 @@ rm -f core conftest.err conftest.$ac_obj
     MACOS_X_DARWIN=yes
     OS_EXTRA_SRC="os_macosx.m os_mac_conv.c";
     OS_EXTRA_OBJ="objects/os_macosx.o objects/os_mac_conv.o"
+        $as_echo "#define HAVE_TIMER_CREATE 1" >>confdefs.h
+
             CPPFLAGS="$CPPFLAGS -DMACOS_X_DARWIN"
 
                if test -z "$with_x" -a "X$enable_gui" != Xmotif -a "X$enable_gui" != Xgtk2 -a "X$enable_gui" != Xgtk3; then
@@ -13044,7 +13046,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_
 
 #include<signal.h>
 #include<time.h>
-static void set_flag(union sigval) {}
+static void set_flag(union sigval sv) {}
 
 int
 main ()
@@ -13073,7 +13075,7 @@ else
 
 #include<signal.h>
 #include<time.h>
-static void set_flag(union sigval) {}
+static void set_flag(union sigval sv) {}
 
 int
 main ()
--- a/src/configure.ac
+++ b/src/configure.ac
@@ -80,7 +80,7 @@ dnl Check for the flag that fails if stu
 AC_MSG_CHECKING(--enable-fail-if-missing argument)
 AC_ARG_ENABLE(fail_if_missing,
 	[  --enable-fail-if-missing    Fail if dependencies on additional features
-     specified on the command line are missing.], 
+     specified on the command line are missing.],
 	[fail_if_missing="yes"],
 	[fail_if_missing="no"])
 AC_MSG_RESULT($fail_if_missing)
@@ -237,7 +237,7 @@ if test "$vim_cv_uname_output" = Darwin;
   AC_ARG_WITH(developer-dir, [  --with-developer-dir=PATH    use PATH as location for Xcode developer tools],
 	DEVELOPER_DIR="$withval"; AC_MSG_RESULT($DEVELOPER_DIR),
         AC_MSG_RESULT(not present))
-  
+
   if test "x$DEVELOPER_DIR" = "x"; then
     AC_PATH_PROG(XCODE_SELECT, xcode-select)
     if test "x$XCODE_SELECT" != "x"; then
@@ -287,6 +287,8 @@ if test "$vim_cv_uname_output" = Darwin;
     MACOS_X_DARWIN=yes
     OS_EXTRA_SRC="os_macosx.m os_mac_conv.c";
     OS_EXTRA_OBJ="objects/os_macosx.o objects/os_mac_conv.o"
+    dnl os_macosx.m implements timer_create() and friends
+    AC_DEFINE(HAVE_TIMER_CREATE)
     dnl TODO: use -arch i386 on Intel machines
     dnl Removed -no-cpp-precomp, only for very old compilers.
     CPPFLAGS="$CPPFLAGS -DMACOS_X_DARWIN"
@@ -1499,36 +1501,36 @@ if test "$enable_python3interp" = "yes" 
        if ${vi_cv_path_python3} -c \
            "import sys; sys.exit(${vi_cv_var_python3_version} < 3.2)"
        then
-         vi_cv_var_python3_abiflags=`${vi_cv_path_python3} -c \    
+         vi_cv_var_python3_abiflags=`${vi_cv_path_python3} -c \
            "import sys; print(sys.abiflags)"`
        fi ])
-  
+
       dnl -- find where python3 thinks it was installed
       AC_CACHE_CHECK(Python's install prefix,vi_cv_path_python3_pfx,
       [ vi_cv_path_python3_pfx=`
        ${vi_cv_path_python3} -c \
        "import sys; print(sys.prefix)"` ])
-  
+
       dnl -- and where it thinks it runs
       AC_CACHE_CHECK(Python's execution prefix,vi_cv_path_python3_epfx,
       [ vi_cv_path_python3_epfx=`
        ${vi_cv_path_python3} -c \
        "import sys; print(sys.exec_prefix)"` ])
-  
+
       dnl -- python3's internal library path
-  
+
       AC_CACHE_VAL(vi_cv_path_python3path,
       [ vi_cv_path_python3path=`
        unset PYTHONPATH;
        ${vi_cv_path_python3} -c \
        "import sys, string; print(':'.join(sys.path))"` ])
-  
+
       dnl -- where the Python implementation library archives are
-  
+
       AC_ARG_WITH(python3-config-dir,
        [  --with-python3-config-dir=PATH  Python's config directory (deprecated)],
        [ vi_cv_path_python3_conf="${withval}"; have_python3_config_dir=1 ] )
-  
+
       AC_CACHE_CHECK(Python's configuration directory,vi_cv_path_python3_conf,
       [
        vi_cv_path_python3_conf=
@@ -1550,13 +1552,13 @@ if test "$enable_python3interp" = "yes" 
          done
        fi
       ])
-  
+
       PYTHON3_CONFDIR="${vi_cv_path_python3_conf}"
-  
+
       if test "X$PYTHON3_CONFDIR" = "X"; then
         AC_MSG_RESULT([can't find it!])
       else
-  
+
         dnl -- we need to examine Python's config/Makefile too
         dnl    see what the interpreter is built from
         AC_CACHE_VAL(vi_cv_path_python3_plibs,
@@ -1601,7 +1603,7 @@ eof
 	fi
         PYTHON3_SRC="if_python3.c"
         PYTHON3_OBJ="objects/if_python3.o"
-  
+
         dnl On FreeBSD linking with "-pthread" is required to use threads.
         dnl _THREAD_SAFE must be used for compiling then.
         dnl The "-pthread" is added to $LIBS, so that the following check for
@@ -1636,7 +1638,7 @@ eof
         else
           AC_MSG_RESULT(no)
         fi
-  
+
         dnl check that compiling a simple program still works with the flags
         dnl added for Python.
         AC_MSG_CHECKING([if compile and link flags for Python 3 are sane])
@@ -1675,7 +1677,7 @@ AC_SUBST(PYTHON3_SRC)
 AC_SUBST(PYTHON3_OBJ)
 
 dnl if python2.x and python3.x are enabled one can only link in code
-dnl with dlopen(), dlsym(), dlclose() 
+dnl with dlopen(), dlsym(), dlclose()
 if test "$python_ok" = yes && test "$python3_ok" = yes; then
   AC_DEFINE(DYNAMIC_PYTHON)
   AC_DEFINE(DYNAMIC_PYTHON3)
@@ -3113,7 +3115,7 @@ if test -z "$SKIP_MOTIF"; then
 	AC_CHECK_HEADERS(Xm/Xm.h)
   else
 	AC_CHECK_HEADERS(Xm/Xm.h Xm/XpmP.h Xm/JoinSideT.h Xm/TraitP.h Xm/Manager.h Xm/UnhighlightT.h Xm/Notebook.h)
-  fi    
+  fi
 
   if test "x$ac_cv_header_Xm_XpmP_h" = "xyes"; then
     dnl Solaris uses XpmAttributes_21, very annoying.
@@ -3809,7 +3811,7 @@ LIBS="$LIBS -lrt"
 AC_LINK_IFELSE([AC_LANG_PROGRAM([
 #include<signal.h>
 #include<time.h>
-static void set_flag(union sigval) {}
+static void set_flag(union sigval sv) {}
 ], [
   struct timespec ts;
   struct sigevent action = {0};
@@ -3824,7 +3826,7 @@ static void set_flag(union sigval) {}
   AC_LINK_IFELSE([AC_LANG_PROGRAM([
 #include<signal.h>
 #include<time.h>
-static void set_flag(union sigval) {}
+static void set_flag(union sigval sv) {}
     ], [
     struct timespec ts;
     struct sigevent action = {0};
@@ -3885,7 +3887,7 @@ if test $ac_cv_struct_st_mtim_nsec != no
   AC_DEFINE_UNQUOTED([ST_MTIM_NSEC], [$ac_cv_struct_st_mtim_nsec],
   [Define if struct stat contains a nanoseconds field])
 fi
-  
+
 dnl Link with iconv for charset translation, if not found without library.
 dnl check for iconv() requires including iconv.h
 dnl Add "-liconv" when possible; Solaris has iconv but use GNU iconv when it
--- a/src/testdir/test_hlsearch.vim
+++ b/src/testdir/test_hlsearch.vim
@@ -37,7 +37,7 @@ endfunc
 func Test_hlsearch_hangs()
   CheckFunction reltimefloat
 
-  " So, it turns out the Windows 7 implements TimerQueue timers differently
+  " So, it turns out that Windows 7 implements TimerQueue timers differently
   " and they can expire *before* the requested time has elapsed. So allow for
   " the timeout occurring after 80 ms (5 * 16 (the typical clock tick)).
   if has("win32")
--- a/src/testdir/test_search.vim
+++ b/src/testdir/test_search.vim
@@ -355,6 +355,37 @@ func Test_searchpair_timeout()
   bwipe!
 endfunc
 
+func SearchpairSkip()
+  let id = synID(line('.'), col('.'), 0)
+  let attr = synIDattr(id, 'name')
+  return attr !~ 'comment'
+endfunc
+
+func Test_searchpair_timeout_with_skip()
+  let g:test_is_flaky = 1
+
+  edit ../evalfunc.c
+  if has('win32')
+    " Windows timeouts are rather coarse grained, about 16ms.
+    let ms = 20
+    let min_time = 0.016
+    let max_time = min_time * 10.0
+  else
+    let ms = 1
+    let min_time = 0.001
+    let max_time = min_time * 10.0
+    if GetVimCommand() =~ 'valgrind.*--log-file='
+      let max_time += 0.04  " this can be slow with valgrind
+    endif
+  endif
+  let start = reltime()
+  let found = searchpair('(', '', ')', 'crnm', 'SearchpairSkip()', 0, ms)
+  let elapsed = reltimefloat(reltime(start))
+  call assert_inrange(min_time, max_time, elapsed)
+
+  bwipe!
+endfunc
+
 func Test_searchpairpos()
   new
   call setline(1, ['other code', 'here [', ' [', ' " cursor here', ' ]]'])
--- a/src/version.c
+++ b/src/version.c
@@ -735,6 +735,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    5131,
+/**/
     5130,
 /**/
     5129,