forked from aniani/vim
patch 9.1.1169: using global variable for get_insert()/get_lambda_name()
Problem: using global variable for get_insert()/get_lambda_name() (after v9.1.1151) Solution: let the functions return a string_T object instead (Yee Cheng Chin) In #16720, `get_insert()` was modified to store a string length in a global variable to be queried immediately by another `get_insert_len()` function, which is somewhat fragile. Instead, just have the function itself return a `string_T` object instead. Also do the same for `get_lambda_name()` which has similar issues. closes: #16775 Signed-off-by: Yee Cheng Chin <ychin.git@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
d2219d547d
commit
0b5fe42071
22
src/edit.c
22
src/edit.c
@@ -415,14 +415,10 @@ edit(
|
|||||||
* Get the current length of the redo buffer, those characters have to be
|
* Get the current length of the redo buffer, those characters have to be
|
||||||
* skipped if we want to get to the inserted characters.
|
* skipped if we want to get to the inserted characters.
|
||||||
*/
|
*/
|
||||||
ptr = get_inserted();
|
string_T inserted = get_inserted();
|
||||||
if (ptr == NULL)
|
new_insert_skip = (int)inserted.length;
|
||||||
new_insert_skip = 0;
|
if (inserted.string != NULL)
|
||||||
else
|
vim_free(inserted.string);
|
||||||
{
|
|
||||||
new_insert_skip = (int)get_inserted_len();
|
|
||||||
vim_free(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
old_indent = 0;
|
old_indent = 0;
|
||||||
|
|
||||||
@@ -2445,7 +2441,7 @@ stop_insert(
|
|||||||
int nomove) // <c-\><c-o>, don't move cursor
|
int nomove) // <c-\><c-o>, don't move cursor
|
||||||
{
|
{
|
||||||
int cc;
|
int cc;
|
||||||
char_u *ptr;
|
string_T inserted;
|
||||||
|
|
||||||
stop_redo_ins();
|
stop_redo_ins();
|
||||||
replace_flush(); // abandon replace stack
|
replace_flush(); // abandon replace stack
|
||||||
@@ -2455,16 +2451,16 @@ stop_insert(
|
|||||||
* Don't do it when "restart_edit" was set and nothing was inserted,
|
* Don't do it when "restart_edit" was set and nothing was inserted,
|
||||||
* otherwise CTRL-O w and then <Left> will clear "last_insert".
|
* otherwise CTRL-O w and then <Left> will clear "last_insert".
|
||||||
*/
|
*/
|
||||||
ptr = get_inserted();
|
inserted = get_inserted();
|
||||||
int added = ptr == NULL ? 0 : (int)get_inserted_len() - new_insert_skip;
|
int added = inserted.string == NULL ? 0 : (int)inserted.length - new_insert_skip;
|
||||||
if (did_restart_edit == 0 || added > 0)
|
if (did_restart_edit == 0 || added > 0)
|
||||||
{
|
{
|
||||||
vim_free(last_insert);
|
vim_free(last_insert);
|
||||||
last_insert = ptr;
|
last_insert = inserted.string;
|
||||||
last_insert_skip = added < 0 ? 0 : new_insert_skip;
|
last_insert_skip = added < 0 ? 0 : new_insert_skip;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
vim_free(ptr);
|
vim_free(inserted.string);
|
||||||
|
|
||||||
if (!arrow_used && end_insert_pos != NULL)
|
if (!arrow_used && end_insert_pos != NULL)
|
||||||
{
|
{
|
||||||
|
@@ -88,9 +88,6 @@ static char_u noremapbuf_init[TYPELEN_INIT]; // initial typebuf.tb_noremap
|
|||||||
|
|
||||||
static size_t last_recorded_len = 0; // number of last recorded chars
|
static size_t last_recorded_len = 0; // number of last recorded chars
|
||||||
|
|
||||||
static size_t last_get_inserted_len = 0; // length of the string returned from the
|
|
||||||
// last call to get_inserted()
|
|
||||||
|
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
mapblock_T *last_used_map = NULL;
|
mapblock_T *last_used_map = NULL;
|
||||||
int last_used_sid = -1;
|
int last_used_sid = -1;
|
||||||
@@ -203,19 +200,13 @@ get_recorded(void)
|
|||||||
* Return the contents of the redo buffer as a single string.
|
* Return the contents of the redo buffer as a single string.
|
||||||
* K_SPECIAL and CSI in the returned string are escaped.
|
* K_SPECIAL and CSI in the returned string are escaped.
|
||||||
*/
|
*/
|
||||||
char_u *
|
string_T
|
||||||
get_inserted(void)
|
get_inserted(void)
|
||||||
{
|
{
|
||||||
return get_buffcont(&redobuff, FALSE, &last_get_inserted_len);
|
size_t len = 0;
|
||||||
}
|
char_u* str = get_buffcont(&redobuff, FALSE, &len);
|
||||||
|
string_T ret = { str, len };
|
||||||
/*
|
return ret;
|
||||||
* Return the length of string returned from the last call of get_inserted().
|
|
||||||
*/
|
|
||||||
size_t
|
|
||||||
get_inserted_len(void)
|
|
||||||
{
|
|
||||||
return last_get_inserted_len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
/* getchar.c */
|
/* getchar.c */
|
||||||
char_u *get_recorded(void);
|
char_u *get_recorded(void);
|
||||||
char_u *get_inserted(void);
|
string_T get_inserted(void);
|
||||||
size_t get_inserted_len(void);
|
|
||||||
int stuff_empty(void);
|
int stuff_empty(void);
|
||||||
int readbuf1_empty(void);
|
int readbuf1_empty(void);
|
||||||
void typeahead_noflush(int c);
|
void typeahead_noflush(int c);
|
||||||
|
@@ -2,8 +2,7 @@
|
|||||||
void func_init(void);
|
void func_init(void);
|
||||||
hashtab_T *func_tbl_get(void);
|
hashtab_T *func_tbl_get(void);
|
||||||
char_u *make_ufunc_name_readable(char_u *name, char_u *buf, size_t bufsize);
|
char_u *make_ufunc_name_readable(char_u *name, char_u *buf, size_t bufsize);
|
||||||
char_u *get_lambda_name(void);
|
string_T get_lambda_name(void);
|
||||||
size_t get_lambda_name_len(void);
|
|
||||||
char_u *register_cfunc(cfunc_T cb, cfunc_free_T cb_free, void *state);
|
char_u *register_cfunc(cfunc_T cb, cfunc_free_T cb_free, void *state);
|
||||||
int get_lambda_tv(char_u **arg, typval_T *rettv, int types_optional, evalarg_T *evalarg);
|
int get_lambda_tv(char_u **arg, typval_T *rettv, int types_optional, evalarg_T *evalarg);
|
||||||
char_u *deref_func_name(char_u *name, int *lenp, partial_T **partialp, type_T **type, int no_autoload, int new_function, int *found_var);
|
char_u *deref_func_name(char_u *name, int *lenp, partial_T **partialp, type_T **type, int no_autoload, int new_function, int *found_var);
|
||||||
|
@@ -683,36 +683,28 @@ make_ufunc_name_readable(char_u *name, char_u *buf, size_t bufsize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char_u lambda_name[8 + NUMBUFLEN];
|
static char_u lambda_name[8 + NUMBUFLEN];
|
||||||
static size_t lambda_namelen = 0;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get a name for a lambda. Returned in static memory.
|
* Get a name for a lambda. Returned in static memory.
|
||||||
*/
|
*/
|
||||||
char_u *
|
string_T
|
||||||
get_lambda_name(void)
|
get_lambda_name(void)
|
||||||
{
|
{
|
||||||
static int lambda_no = 0;
|
static int lambda_no = 0;
|
||||||
int n;
|
int n;
|
||||||
|
string_T ret;
|
||||||
|
|
||||||
n = vim_snprintf((char *)lambda_name, sizeof(lambda_name), "<lambda>%d", ++lambda_no);
|
n = vim_snprintf((char *)lambda_name, sizeof(lambda_name), "<lambda>%d", ++lambda_no);
|
||||||
if (n < 1)
|
if (n < 1)
|
||||||
lambda_namelen = 0;
|
ret.length = 0;
|
||||||
else
|
else
|
||||||
if (n >= (int)sizeof(lambda_name))
|
if (n >= (int)sizeof(lambda_name))
|
||||||
lambda_namelen = sizeof(lambda_name) - 1;
|
ret.length = sizeof(lambda_name) - 1;
|
||||||
else
|
else
|
||||||
lambda_namelen = (size_t)n;
|
ret.length = (size_t)n;
|
||||||
|
|
||||||
return lambda_name;
|
ret.string = lambda_name;
|
||||||
}
|
return ret;
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the length of the last lambda name.
|
|
||||||
*/
|
|
||||||
size_t
|
|
||||||
get_lambda_name_len(void)
|
|
||||||
{
|
|
||||||
return lambda_namelen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -756,11 +748,10 @@ alloc_ufunc(char_u *name, size_t namelen)
|
|||||||
char_u *
|
char_u *
|
||||||
register_cfunc(cfunc_T cb, cfunc_free_T cb_free, void *state)
|
register_cfunc(cfunc_T cb, cfunc_free_T cb_free, void *state)
|
||||||
{
|
{
|
||||||
char_u *name = get_lambda_name();
|
string_T name = get_lambda_name();
|
||||||
size_t namelen = get_lambda_name_len();
|
|
||||||
ufunc_T *fp;
|
ufunc_T *fp;
|
||||||
|
|
||||||
fp = alloc_ufunc(name, namelen);
|
fp = alloc_ufunc(name.string, name.length);
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -776,7 +767,7 @@ register_cfunc(cfunc_T cb, cfunc_free_T cb_free, void *state)
|
|||||||
|
|
||||||
hash_add(&func_hashtab, UF2HIKEY(fp), "add C function");
|
hash_add(&func_hashtab, UF2HIKEY(fp), "add C function");
|
||||||
|
|
||||||
return name;
|
return name.string;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1477,8 +1468,7 @@ lambda_function_body(
|
|||||||
char_u *cmdline = NULL;
|
char_u *cmdline = NULL;
|
||||||
int ret = FAIL;
|
int ret = FAIL;
|
||||||
partial_T *pt;
|
partial_T *pt;
|
||||||
char_u *name;
|
string_T name;
|
||||||
size_t namelen;
|
|
||||||
int lnum_save = -1;
|
int lnum_save = -1;
|
||||||
linenr_T sourcing_lnum_top = SOURCING_LNUM;
|
linenr_T sourcing_lnum_top = SOURCING_LNUM;
|
||||||
char_u *line_arg = NULL;
|
char_u *line_arg = NULL;
|
||||||
@@ -1597,8 +1587,7 @@ lambda_function_body(
|
|||||||
}
|
}
|
||||||
|
|
||||||
name = get_lambda_name();
|
name = get_lambda_name();
|
||||||
namelen = get_lambda_name_len();
|
ufunc = alloc_ufunc(name.string, name.length);
|
||||||
ufunc = alloc_ufunc(name, namelen);
|
|
||||||
if (ufunc == NULL)
|
if (ufunc == NULL)
|
||||||
goto erret;
|
goto erret;
|
||||||
if (hash_add(&func_hashtab, UF2HIKEY(ufunc), "add function") == FAIL)
|
if (hash_add(&func_hashtab, UF2HIKEY(ufunc), "add function") == FAIL)
|
||||||
@@ -1805,10 +1794,9 @@ get_lambda_tv(
|
|||||||
int flags = FC_LAMBDA;
|
int flags = FC_LAMBDA;
|
||||||
char_u *p;
|
char_u *p;
|
||||||
char_u *line_end;
|
char_u *line_end;
|
||||||
char_u *name = get_lambda_name();
|
string_T name = get_lambda_name();
|
||||||
size_t namelen = get_lambda_name_len();
|
|
||||||
|
|
||||||
fp = alloc_ufunc(name, namelen);
|
fp = alloc_ufunc(name.string, name.length);
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
goto errret;
|
goto errret;
|
||||||
fp->uf_def_status = UF_NOT_COMPILED;
|
fp->uf_def_status = UF_NOT_COMPILED;
|
||||||
|
@@ -704,6 +704,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1169,
|
||||||
/**/
|
/**/
|
||||||
1168,
|
1168,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -1033,8 +1033,7 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx, garray_T *lines_to_free)
|
|||||||
char_u *name_end = to_name_end(eap->arg, TRUE);
|
char_u *name_end = to_name_end(eap->arg, TRUE);
|
||||||
int off;
|
int off;
|
||||||
char_u *func_name;
|
char_u *func_name;
|
||||||
char_u *lambda_name;
|
string_T lambda_name;
|
||||||
size_t lambda_namelen;
|
|
||||||
ufunc_T *ufunc;
|
ufunc_T *ufunc;
|
||||||
int r = FAIL;
|
int r = FAIL;
|
||||||
compiletype_T compile_type;
|
compiletype_T compile_type;
|
||||||
@@ -1094,9 +1093,8 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx, garray_T *lines_to_free)
|
|||||||
eap->forceit = FALSE;
|
eap->forceit = FALSE;
|
||||||
// We use the special <Lamba>99 name, but it's not really a lambda.
|
// We use the special <Lamba>99 name, but it's not really a lambda.
|
||||||
lambda_name = get_lambda_name();
|
lambda_name = get_lambda_name();
|
||||||
lambda_namelen = get_lambda_name_len();
|
lambda_name.string = vim_strnsave(lambda_name.string, lambda_name.length);
|
||||||
lambda_name = vim_strnsave(lambda_name, lambda_namelen);
|
if (lambda_name.string == NULL)
|
||||||
if (lambda_name == NULL)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// This may free the current line, make a copy of the name.
|
// This may free the current line, make a copy of the name.
|
||||||
@@ -1112,7 +1110,7 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx, garray_T *lines_to_free)
|
|||||||
int save_KeyTyped = KeyTyped;
|
int save_KeyTyped = KeyTyped;
|
||||||
KeyTyped = FALSE;
|
KeyTyped = FALSE;
|
||||||
|
|
||||||
ufunc = define_function(eap, lambda_name, lines_to_free, 0, NULL, 0);
|
ufunc = define_function(eap, lambda_name.string, lines_to_free, 0, NULL, 0);
|
||||||
|
|
||||||
KeyTyped = save_KeyTyped;
|
KeyTyped = save_KeyTyped;
|
||||||
|
|
||||||
@@ -1148,9 +1146,10 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx, garray_T *lines_to_free)
|
|||||||
// recursive call.
|
// recursive call.
|
||||||
if (is_global)
|
if (is_global)
|
||||||
{
|
{
|
||||||
r = generate_NEWFUNC(cctx, lambda_name, func_name);
|
r = generate_NEWFUNC(cctx, lambda_name.string, func_name);
|
||||||
func_name = NULL;
|
func_name = NULL;
|
||||||
lambda_name = NULL;
|
lambda_name.string = NULL;
|
||||||
|
lambda_name.length = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1197,7 +1196,7 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx, garray_T *lines_to_free)
|
|||||||
}
|
}
|
||||||
|
|
||||||
theend:
|
theend:
|
||||||
vim_free(lambda_name);
|
vim_free(lambda_name.string);
|
||||||
vim_free(func_name);
|
vim_free(func_name);
|
||||||
return r == FAIL ? NULL : (char_u *)"";
|
return r == FAIL ? NULL : (char_u *)"";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user