Karsten Hopp 6a194d
To: vim_dev@googlegroups.com
Karsten Hopp 6a194d
Subject: Patch 7.3.1004
Karsten Hopp 6a194d
Fcc: outbox
Karsten Hopp 6a194d
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 6a194d
Mime-Version: 1.0
Karsten Hopp 6a194d
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 6a194d
Content-Transfer-Encoding: 8bit
Karsten Hopp 6a194d
------------
Karsten Hopp 6a194d
Karsten Hopp 6a194d
Patch 7.3.1004
Karsten Hopp 6a194d
Problem:    No error when option could not be set.
Karsten Hopp 6a194d
Solution:   Report an error. (ZyX)
Karsten Hopp 6a194d
Files:	    src/if_py_both.h, src/option.c, src/proto/option.pro,
Karsten Hopp 6a194d
	    src/testdir/test86.ok, src/testdir/test87.ok
Karsten Hopp 6a194d
Karsten Hopp 6a194d
Karsten Hopp 6a194d
*** ../vim-7.3.1003/src/if_py_both.h	2013-05-21 22:23:50.000000000 +0200
Karsten Hopp 6a194d
--- src/if_py_both.h	2013-05-21 22:34:04.000000000 +0200
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 1521,1526 ****
Karsten Hopp 6a194d
--- 1521,1545 ----
Karsten Hopp 6a194d
  }
Karsten Hopp 6a194d
  
Karsten Hopp 6a194d
      static int
Karsten Hopp 6a194d
+ set_option_value_err(key, numval, stringval, opt_flags)
Karsten Hopp 6a194d
+     char_u	*key;
Karsten Hopp 6a194d
+     int		numval;
Karsten Hopp 6a194d
+     char_u	*stringval;
Karsten Hopp 6a194d
+     int		opt_flags;
Karsten Hopp 6a194d
+ {
Karsten Hopp 6a194d
+     char_u	*errmsg;
Karsten Hopp 6a194d
+ 
Karsten Hopp 6a194d
+     if ((errmsg = set_option_value(key, numval, stringval, opt_flags)))
Karsten Hopp 6a194d
+     {
Karsten Hopp 6a194d
+ 	if (VimTryEnd())
Karsten Hopp 6a194d
+ 	    return FAIL;
Karsten Hopp 6a194d
+ 	PyErr_SetVim((char *)errmsg);
Karsten Hopp 6a194d
+ 	return FAIL;
Karsten Hopp 6a194d
+     }
Karsten Hopp 6a194d
+     return OK;
Karsten Hopp 6a194d
+ }
Karsten Hopp 6a194d
+ 
Karsten Hopp 6a194d
+     static int
Karsten Hopp 6a194d
  set_option_value_for(key, numval, stringval, opt_flags, opt_type, from)
Karsten Hopp 6a194d
      char_u	*key;
Karsten Hopp 6a194d
      int		numval;
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 1532,1537 ****
Karsten Hopp 6a194d
--- 1551,1557 ----
Karsten Hopp 6a194d
      win_T	*save_curwin = NULL;
Karsten Hopp 6a194d
      tabpage_T	*save_curtab = NULL;
Karsten Hopp 6a194d
      buf_T	*save_curbuf = NULL;
Karsten Hopp 6a194d
+     int		r = 0;
Karsten Hopp 6a194d
  
Karsten Hopp 6a194d
      VimTryStart();
Karsten Hopp 6a194d
      switch (opt_type)
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 1545,1560 ****
Karsten Hopp 6a194d
  		PyErr_SetVim("Problem while switching windows.");
Karsten Hopp 6a194d
  		return -1;
Karsten Hopp 6a194d
  	    }
Karsten Hopp 6a194d
! 	    set_option_value(key, numval, stringval, opt_flags);
Karsten Hopp 6a194d
  	    restore_win(save_curwin, save_curtab);
Karsten Hopp 6a194d
  	    break;
Karsten Hopp 6a194d
  	case SREQ_BUF:
Karsten Hopp 6a194d
  	    switch_buffer(&save_curbuf, (buf_T *)from);
Karsten Hopp 6a194d
! 	    set_option_value(key, numval, stringval, opt_flags);
Karsten Hopp 6a194d
  	    restore_buffer(save_curbuf);
Karsten Hopp 6a194d
  	    break;
Karsten Hopp 6a194d
  	case SREQ_GLOBAL:
Karsten Hopp 6a194d
! 	    set_option_value(key, numval, stringval, opt_flags);
Karsten Hopp 6a194d
  	    break;
Karsten Hopp 6a194d
      }
Karsten Hopp 6a194d
      return VimTryEnd();
Karsten Hopp 6a194d
--- 1565,1586 ----
Karsten Hopp 6a194d
  		PyErr_SetVim("Problem while switching windows.");
Karsten Hopp 6a194d
  		return -1;
Karsten Hopp 6a194d
  	    }
Karsten Hopp 6a194d
! 	    r = set_option_value_err(key, numval, stringval, opt_flags);
Karsten Hopp 6a194d
  	    restore_win(save_curwin, save_curtab);
Karsten Hopp 6a194d
+ 	    if (r == FAIL)
Karsten Hopp 6a194d
+ 		return -1;
Karsten Hopp 6a194d
  	    break;
Karsten Hopp 6a194d
  	case SREQ_BUF:
Karsten Hopp 6a194d
  	    switch_buffer(&save_curbuf, (buf_T *)from);
Karsten Hopp 6a194d
! 	    r = set_option_value_err(key, numval, stringval, opt_flags);
Karsten Hopp 6a194d
  	    restore_buffer(save_curbuf);
Karsten Hopp 6a194d
+ 	    if (r == FAIL)
Karsten Hopp 6a194d
+ 		return -1;
Karsten Hopp 6a194d
  	    break;
Karsten Hopp 6a194d
  	case SREQ_GLOBAL:
Karsten Hopp 6a194d
! 	    r = set_option_value_err(key, numval, stringval, opt_flags);
Karsten Hopp 6a194d
! 	    if (r == FAIL)
Karsten Hopp 6a194d
! 		return -1;
Karsten Hopp 6a194d
  	    break;
Karsten Hopp 6a194d
      }
Karsten Hopp 6a194d
      return VimTryEnd();
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 1611,1616 ****
Karsten Hopp 6a194d
--- 1637,1643 ----
Karsten Hopp 6a194d
      if (flags & SOPT_BOOL)
Karsten Hopp 6a194d
      {
Karsten Hopp 6a194d
  	int	istrue = PyObject_IsTrue(valObject);
Karsten Hopp 6a194d
+ 
Karsten Hopp 6a194d
  	if (istrue == -1)
Karsten Hopp 6a194d
  	    return -1;
Karsten Hopp 6a194d
  	r = set_option_value_for(key, istrue, NULL,
Karsten Hopp 6a194d
*** ../vim-7.3.1003/src/option.c	2013-05-19 19:16:25.000000000 +0200
Karsten Hopp 6a194d
--- src/option.c	2013-05-21 22:34:41.000000000 +0200
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 3018,3024 ****
Karsten Hopp 6a194d
  # define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
Karsten Hopp 6a194d
  #endif
Karsten Hopp 6a194d
  static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Karsten Hopp 6a194d
! static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Karsten Hopp 6a194d
  static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags));
Karsten Hopp 6a194d
  static char_u *set_chars_option __ARGS((char_u **varp));
Karsten Hopp 6a194d
  #ifdef FEAT_SYN_HL
Karsten Hopp 6a194d
--- 3018,3024 ----
Karsten Hopp 6a194d
  # define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
Karsten Hopp 6a194d
  #endif
Karsten Hopp 6a194d
  static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Karsten Hopp 6a194d
! static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Karsten Hopp 6a194d
  static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags));
Karsten Hopp 6a194d
  static char_u *set_chars_option __ARGS((char_u **varp));
Karsten Hopp 6a194d
  #ifdef FEAT_SYN_HL
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 5600,5607 ****
Karsten Hopp 6a194d
  
Karsten Hopp 6a194d
  /*
Karsten Hopp 6a194d
   * Set a string option to a new value, and handle the effects.
Karsten Hopp 6a194d
   */
Karsten Hopp 6a194d
!     static void
Karsten Hopp 6a194d
  set_string_option(opt_idx, value, opt_flags)
Karsten Hopp 6a194d
      int		opt_idx;
Karsten Hopp 6a194d
      char_u	*value;
Karsten Hopp 6a194d
--- 5600,5609 ----
Karsten Hopp 6a194d
  
Karsten Hopp 6a194d
  /*
Karsten Hopp 6a194d
   * Set a string option to a new value, and handle the effects.
Karsten Hopp 6a194d
+  *
Karsten Hopp 6a194d
+  * Returns NULL on success or error message on error.
Karsten Hopp 6a194d
   */
Karsten Hopp 6a194d
!     static char_u *
Karsten Hopp 6a194d
  set_string_option(opt_idx, value, opt_flags)
Karsten Hopp 6a194d
      int		opt_idx;
Karsten Hopp 6a194d
      char_u	*value;
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 5610,5618 ****
Karsten Hopp 6a194d
      char_u	*s;
Karsten Hopp 6a194d
      char_u	**varp;
Karsten Hopp 6a194d
      char_u	*oldval;
Karsten Hopp 6a194d
  
Karsten Hopp 6a194d
      if (options[opt_idx].var == NULL)	/* don't set hidden option */
Karsten Hopp 6a194d
! 	return;
Karsten Hopp 6a194d
  
Karsten Hopp 6a194d
      s = vim_strsave(value);
Karsten Hopp 6a194d
      if (s != NULL)
Karsten Hopp 6a194d
--- 5612,5621 ----
Karsten Hopp 6a194d
      char_u	*s;
Karsten Hopp 6a194d
      char_u	**varp;
Karsten Hopp 6a194d
      char_u	*oldval;
Karsten Hopp 6a194d
+     char_u	*r = NULL;
Karsten Hopp 6a194d
  
Karsten Hopp 6a194d
      if (options[opt_idx].var == NULL)	/* don't set hidden option */
Karsten Hopp 6a194d
! 	return NULL;
Karsten Hopp 6a194d
  
Karsten Hopp 6a194d
      s = vim_strsave(value);
Karsten Hopp 6a194d
      if (s != NULL)
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 5624,5633 ****
Karsten Hopp 6a194d
  		    : opt_flags);
Karsten Hopp 6a194d
  	oldval = *varp;
Karsten Hopp 6a194d
  	*varp = s;
Karsten Hopp 6a194d
! 	if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Karsten Hopp 6a194d
! 							   opt_flags) == NULL)
Karsten Hopp 6a194d
  	    did_set_option(opt_idx, opt_flags, TRUE);
Karsten Hopp 6a194d
      }
Karsten Hopp 6a194d
  }
Karsten Hopp 6a194d
  
Karsten Hopp 6a194d
  /*
Karsten Hopp 6a194d
--- 5627,5637 ----
Karsten Hopp 6a194d
  		    : opt_flags);
Karsten Hopp 6a194d
  	oldval = *varp;
Karsten Hopp 6a194d
  	*varp = s;
Karsten Hopp 6a194d
! 	if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Karsten Hopp 6a194d
! 							   opt_flags)) == NULL)
Karsten Hopp 6a194d
  	    did_set_option(opt_idx, opt_flags, TRUE);
Karsten Hopp 6a194d
      }
Karsten Hopp 6a194d
+     return r;
Karsten Hopp 6a194d
  }
Karsten Hopp 6a194d
  
Karsten Hopp 6a194d
  /*
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 8969,8976 ****
Karsten Hopp 6a194d
  /*
Karsten Hopp 6a194d
   * Set the value of option "name".
Karsten Hopp 6a194d
   * Use "string" for string options, use "number" for other options.
Karsten Hopp 6a194d
   */
Karsten Hopp 6a194d
!     void
Karsten Hopp 6a194d
  set_option_value(name, number, string, opt_flags)
Karsten Hopp 6a194d
      char_u	*name;
Karsten Hopp 6a194d
      long	number;
Karsten Hopp 6a194d
--- 8973,8982 ----
Karsten Hopp 6a194d
  /*
Karsten Hopp 6a194d
   * Set the value of option "name".
Karsten Hopp 6a194d
   * Use "string" for string options, use "number" for other options.
Karsten Hopp 6a194d
+  *
Karsten Hopp 6a194d
+  * Returns NULL on success or error message on error.
Karsten Hopp 6a194d
   */
Karsten Hopp 6a194d
!     char_u *
Karsten Hopp 6a194d
  set_option_value(name, number, string, opt_flags)
Karsten Hopp 6a194d
      char_u	*name;
Karsten Hopp 6a194d
      long	number;
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 8992,9002 ****
Karsten Hopp 6a194d
  	if (sandbox > 0 && (flags & P_SECURE))
Karsten Hopp 6a194d
  	{
Karsten Hopp 6a194d
  	    EMSG(_(e_sandbox));
Karsten Hopp 6a194d
! 	    return;
Karsten Hopp 6a194d
  	}
Karsten Hopp 6a194d
  #endif
Karsten Hopp 6a194d
  	if (flags & P_STRING)
Karsten Hopp 6a194d
! 	    set_string_option(opt_idx, string, opt_flags);
Karsten Hopp 6a194d
  	else
Karsten Hopp 6a194d
  	{
Karsten Hopp 6a194d
  	    varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Karsten Hopp 6a194d
--- 8998,9008 ----
Karsten Hopp 6a194d
  	if (sandbox > 0 && (flags & P_SECURE))
Karsten Hopp 6a194d
  	{
Karsten Hopp 6a194d
  	    EMSG(_(e_sandbox));
Karsten Hopp 6a194d
! 	    return NULL;
Karsten Hopp 6a194d
  	}
Karsten Hopp 6a194d
  #endif
Karsten Hopp 6a194d
  	if (flags & P_STRING)
Karsten Hopp 6a194d
! 	    return set_string_option(opt_idx, string, opt_flags);
Karsten Hopp 6a194d
  	else
Karsten Hopp 6a194d
  	{
Karsten Hopp 6a194d
  	    varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 9017,9035 ****
Karsten Hopp 6a194d
  			 * num option using a string. */
Karsten Hopp 6a194d
  			EMSG3(_("E521: Number required: &%s = '%s'"),
Karsten Hopp 6a194d
  								name, string);
Karsten Hopp 6a194d
! 			return;     /* do nothing as we hit an error */
Karsten Hopp 6a194d
  
Karsten Hopp 6a194d
  		    }
Karsten Hopp 6a194d
  		}
Karsten Hopp 6a194d
  		if (flags & P_NUM)
Karsten Hopp 6a194d
! 		    (void)set_num_option(opt_idx, varp, number,
Karsten Hopp 6a194d
  							  NULL, 0, opt_flags);
Karsten Hopp 6a194d
  		else
Karsten Hopp 6a194d
! 		    (void)set_bool_option(opt_idx, varp, (int)number,
Karsten Hopp 6a194d
  								   opt_flags);
Karsten Hopp 6a194d
  	    }
Karsten Hopp 6a194d
  	}
Karsten Hopp 6a194d
      }
Karsten Hopp 6a194d
  }
Karsten Hopp 6a194d
  
Karsten Hopp 6a194d
  /*
Karsten Hopp 6a194d
--- 9023,9042 ----
Karsten Hopp 6a194d
  			 * num option using a string. */
Karsten Hopp 6a194d
  			EMSG3(_("E521: Number required: &%s = '%s'"),
Karsten Hopp 6a194d
  								name, string);
Karsten Hopp 6a194d
! 			return NULL;     /* do nothing as we hit an error */
Karsten Hopp 6a194d
  
Karsten Hopp 6a194d
  		    }
Karsten Hopp 6a194d
  		}
Karsten Hopp 6a194d
  		if (flags & P_NUM)
Karsten Hopp 6a194d
! 		    return set_num_option(opt_idx, varp, number,
Karsten Hopp 6a194d
  							  NULL, 0, opt_flags);
Karsten Hopp 6a194d
  		else
Karsten Hopp 6a194d
! 		    return set_bool_option(opt_idx, varp, (int)number,
Karsten Hopp 6a194d
  								   opt_flags);
Karsten Hopp 6a194d
  	    }
Karsten Hopp 6a194d
  	}
Karsten Hopp 6a194d
      }
Karsten Hopp 6a194d
+     return NULL;
Karsten Hopp 6a194d
  }
Karsten Hopp 6a194d
  
Karsten Hopp 6a194d
  /*
Karsten Hopp 6a194d
*** ../vim-7.3.1003/src/proto/option.pro	2013-05-06 03:52:44.000000000 +0200
Karsten Hopp 6a194d
--- src/proto/option.pro	2013-05-21 22:27:50.000000000 +0200
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 23,29 ****
Karsten Hopp 6a194d
  char_u *check_stl_option __ARGS((char_u *s));
Karsten Hopp 6a194d
  int get_option_value __ARGS((char_u *name, long *numval, char_u **stringval, int opt_flags));
Karsten Hopp 6a194d
  int get_option_value_strict __ARGS((char_u *name, long *numval, char_u **stringval, int opt_type, void *from));
Karsten Hopp 6a194d
! void set_option_value __ARGS((char_u *name, long number, char_u *string, int opt_flags));
Karsten Hopp 6a194d
  char_u *get_term_code __ARGS((char_u *tname));
Karsten Hopp 6a194d
  char_u *get_highlight_default __ARGS((void));
Karsten Hopp 6a194d
  char_u *get_encoding_default __ARGS((void));
Karsten Hopp 6a194d
--- 23,29 ----
Karsten Hopp 6a194d
  char_u *check_stl_option __ARGS((char_u *s));
Karsten Hopp 6a194d
  int get_option_value __ARGS((char_u *name, long *numval, char_u **stringval, int opt_flags));
Karsten Hopp 6a194d
  int get_option_value_strict __ARGS((char_u *name, long *numval, char_u **stringval, int opt_type, void *from));
Karsten Hopp 6a194d
! char_u *set_option_value __ARGS((char_u *name, long number, char_u *string, int opt_flags));
Karsten Hopp 6a194d
  char_u *get_term_code __ARGS((char_u *tname));
Karsten Hopp 6a194d
  char_u *get_highlight_default __ARGS((void));
Karsten Hopp 6a194d
  char_u *get_encoding_default __ARGS((void));
Karsten Hopp 6a194d
*** ../vim-7.3.1003/src/testdir/test86.ok	2013-05-21 22:23:51.000000000 +0200
Karsten Hopp 6a194d
--- src/testdir/test86.ok	2013-05-21 22:27:50.000000000 +0200
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 166,171 ****
Karsten Hopp 6a194d
--- 166,172 ----
Karsten Hopp 6a194d
    inv: -100! KeyError
Karsten Hopp 6a194d
    gopts1! KeyError
Karsten Hopp 6a194d
    p/wopts1: 8
Karsten Hopp 6a194d
+   inv: -100! error
Karsten Hopp 6a194d
    p/bopts1! KeyError
Karsten Hopp 6a194d
    inv: -100! KeyError
Karsten Hopp 6a194d
    bopts1! KeyError
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 184,189 ****
Karsten Hopp 6a194d
--- 185,191 ----
Karsten Hopp 6a194d
    inv: 'abc'! KeyError
Karsten Hopp 6a194d
    gopts1! KeyError
Karsten Hopp 6a194d
    p/wopts1: ''
Karsten Hopp 6a194d
+   inv: 'abc'! error
Karsten Hopp 6a194d
    p/bopts1! KeyError
Karsten Hopp 6a194d
    inv: 'abc'! KeyError
Karsten Hopp 6a194d
    bopts1! KeyError
Karsten Hopp 6a194d
*** ../vim-7.3.1003/src/testdir/test87.ok	2013-05-21 22:23:51.000000000 +0200
Karsten Hopp 6a194d
--- src/testdir/test87.ok	2013-05-21 22:27:50.000000000 +0200
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 155,160 ****
Karsten Hopp 6a194d
--- 155,161 ----
Karsten Hopp 6a194d
    inv: -100! KeyError
Karsten Hopp 6a194d
    gopts1! KeyError
Karsten Hopp 6a194d
    p/wopts1: 8
Karsten Hopp 6a194d
+   inv: -100! error
Karsten Hopp 6a194d
    p/bopts1! KeyError
Karsten Hopp 6a194d
    inv: -100! KeyError
Karsten Hopp 6a194d
    bopts1! KeyError
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 173,178 ****
Karsten Hopp 6a194d
--- 174,180 ----
Karsten Hopp 6a194d
    inv: 'abc'! KeyError
Karsten Hopp 6a194d
    gopts1! KeyError
Karsten Hopp 6a194d
    p/wopts1: b''
Karsten Hopp 6a194d
+   inv: 'abc'! error
Karsten Hopp 6a194d
    p/bopts1! KeyError
Karsten Hopp 6a194d
    inv: 'abc'! KeyError
Karsten Hopp 6a194d
    bopts1! KeyError
Karsten Hopp 6a194d
*** ../vim-7.3.1003/src/version.c	2013-05-21 22:23:51.000000000 +0200
Karsten Hopp 6a194d
--- src/version.c	2013-05-21 22:37:33.000000000 +0200
Karsten Hopp 6a194d
***************
Karsten Hopp 6a194d
*** 730,731 ****
Karsten Hopp 6a194d
--- 730,733 ----
Karsten Hopp 6a194d
  {   /* Add new patch number below this line */
Karsten Hopp 6a194d
+ /**/
Karsten Hopp 6a194d
+     1004,
Karsten Hopp 6a194d
  /**/
Karsten Hopp 6a194d
Karsten Hopp 6a194d
-- 
Karsten Hopp 6a194d
FIRST SOLDIER:  So they wouldn't be able to bring a coconut back anyway.
Karsten Hopp 6a194d
SECOND SOLDIER: Wait a minute! Suppose two swallows carried it together?
Karsten Hopp 6a194d
FIRST SOLDIER:  No, they'd have to have it on a line.
Karsten Hopp 6a194d
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
Karsten Hopp 6a194d
Karsten Hopp 6a194d
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 6a194d
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 6a194d
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 6a194d
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///