Mercurial > vim
comparison src/userfunc.c @ 30083:a542dfb1c1a2 v9.0.0379
patch 9.0.0379: cleaning up after writefile() is a hassle
Commit: https://github.com/vim/vim/commit/806a273f3c84ecd475913d901890bb1929be9a0a
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Sep 4 15:40:36 2022 +0100
patch 9.0.0379: cleaning up after writefile() is a hassle
Problem: Cleaning up after writefile() is a hassle.
Solution: Add the 'D' flag to defer deleting the written file. Very useful
in tests.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 04 Sep 2022 17:00:03 +0200 |
parents | 105f946422d1 |
children | 0352577f1ba5 |
comparison
equal
deleted
inserted
replaced
30082:3dc03a877e86 | 30083:a542dfb1c1a2 |
---|---|
1726 } | 1726 } |
1727 | 1727 |
1728 /* | 1728 /* |
1729 * Get function arguments at "*arg" and advance it. | 1729 * Get function arguments at "*arg" and advance it. |
1730 * Return them in "*argvars[MAX_FUNC_ARGS + 1]" and the count in "argcount". | 1730 * Return them in "*argvars[MAX_FUNC_ARGS + 1]" and the count in "argcount". |
1731 * On failure FAIL is returned but the "argvars[argcount]" are still set. | |
1731 */ | 1732 */ |
1732 static int | 1733 static int |
1733 get_func_arguments( | 1734 get_func_arguments( |
1734 char_u **arg, | 1735 char_u **arg, |
1735 evalarg_T *evalarg, | 1736 evalarg_T *evalarg, |
5568 static int | 5569 static int |
5569 ex_defer_inner(char_u *name, char_u **arg, evalarg_T *evalarg) | 5570 ex_defer_inner(char_u *name, char_u **arg, evalarg_T *evalarg) |
5570 { | 5571 { |
5571 typval_T argvars[MAX_FUNC_ARGS + 1]; // vars for arguments | 5572 typval_T argvars[MAX_FUNC_ARGS + 1]; // vars for arguments |
5572 int argcount = 0; // number of arguments found | 5573 int argcount = 0; // number of arguments found |
5574 | |
5575 if (current_funccal == NULL) | |
5576 { | |
5577 semsg(_(e_str_not_inside_function), "defer"); | |
5578 return FAIL; | |
5579 } | |
5580 if (get_func_arguments(arg, evalarg, FALSE, argvars, &argcount) == FAIL) | |
5581 { | |
5582 while (--argcount >= 0) | |
5583 clear_tv(&argvars[argcount]); | |
5584 return FAIL; | |
5585 } | |
5586 return add_defer(name, argcount, argvars); | |
5587 } | |
5588 | |
5589 /* | |
5590 * Add a deferred call for "name" with arguments "argvars[argcount]". | |
5591 * Consumes "argvars[]". | |
5592 * Caller must check that in_def_function() returns TRUE or current_funccal is | |
5593 * not NULL. | |
5594 * Returns OK or FAIL. | |
5595 */ | |
5596 int | |
5597 add_defer(char_u *name, int argcount_arg, typval_T *argvars) | |
5598 { | |
5599 char_u *saved_name = vim_strsave(name); | |
5600 int argcount = argcount_arg; | |
5573 defer_T *dr; | 5601 defer_T *dr; |
5574 int ret = FAIL; | 5602 int ret = FAIL; |
5575 char_u *saved_name; | 5603 |
5576 | |
5577 if (current_funccal == NULL) | |
5578 { | |
5579 semsg(_(e_str_not_inside_function), "defer"); | |
5580 return FAIL; | |
5581 } | |
5582 if (get_func_arguments(arg, evalarg, FALSE, argvars, &argcount) == FAIL) | |
5583 goto theend; | |
5584 saved_name = vim_strsave(name); | |
5585 if (saved_name == NULL) | 5604 if (saved_name == NULL) |
5586 goto theend; | 5605 goto theend; |
5587 | 5606 if (in_def_function()) |
5588 if (current_funccal->fc_defer.ga_itemsize == 0) | 5607 { |
5589 ga_init2(¤t_funccal->fc_defer, sizeof(defer_T), 10); | 5608 if (add_defer_function(saved_name, argcount, argvars) == OK) |
5590 if (ga_grow(¤t_funccal->fc_defer, 1) == FAIL) | 5609 argcount = 0; |
5591 goto theend; | 5610 } |
5592 dr = ((defer_T *)current_funccal->fc_defer.ga_data) | 5611 else |
5612 { | |
5613 if (current_funccal->fc_defer.ga_itemsize == 0) | |
5614 ga_init2(¤t_funccal->fc_defer, sizeof(defer_T), 10); | |
5615 if (ga_grow(¤t_funccal->fc_defer, 1) == FAIL) | |
5616 goto theend; | |
5617 dr = ((defer_T *)current_funccal->fc_defer.ga_data) | |
5593 + current_funccal->fc_defer.ga_len++; | 5618 + current_funccal->fc_defer.ga_len++; |
5594 dr->dr_name = saved_name; | 5619 dr->dr_name = saved_name; |
5595 dr->dr_argcount = argcount; | 5620 dr->dr_argcount = argcount; |
5596 while (argcount > 0) | 5621 while (argcount > 0) |
5597 { | 5622 { |
5598 --argcount; | 5623 --argcount; |
5599 dr->dr_argvars[argcount] = argvars[argcount]; | 5624 dr->dr_argvars[argcount] = argvars[argcount]; |
5625 } | |
5600 } | 5626 } |
5601 ret = OK; | 5627 ret = OK; |
5602 | 5628 |
5603 theend: | 5629 theend: |
5604 while (--argcount >= 0) | 5630 while (--argcount >= 0) |