Mercurial > vim
comparison src/userfunc.c @ 28047:b10fa9b17c85 v8.2.4548
patch 8.2.4548: script-local function is deleted when used in a funcref
Commit: https://github.com/vim/vim/commit/fb43cfc2c6a003b850343bfd27cb3059c734d7d4
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Mar 11 18:54:17 2022 +0000
patch 8.2.4548: script-local function is deleted when used in a funcref
Problem: Script-local function is deleted when used in a funcref.
Solution: Do not consider a function starting with "<SNR>" reference
counted. (closes #9916, closes #9820)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 11 Mar 2022 20:00:03 +0100 |
parents | cc7d54a134e4 |
children | e5fcd1256ee3 |
comparison
equal
deleted
inserted
replaced
28046:e0b5ccdea95f | 28047:b10fa9b17c85 |
---|---|
2213 || (name[0] == 'g' && name[1] == ':' && isdigit(name[2])); | 2213 || (name[0] == 'g' && name[1] == ':' && isdigit(name[2])); |
2214 } | 2214 } |
2215 | 2215 |
2216 /* | 2216 /* |
2217 * There are two kinds of function names: | 2217 * There are two kinds of function names: |
2218 * 1. ordinary names, function defined with :function or :def | 2218 * 1. ordinary names, function defined with :function or :def; |
2219 * 2. numbered functions and lambdas | 2219 * can start with "<SNR>123_" literally or with K_SPECIAL. |
2220 * 2. Numbered functions and lambdas: "<lambda>123" | |
2220 * For the first we only count the name stored in func_hashtab as a reference, | 2221 * For the first we only count the name stored in func_hashtab as a reference, |
2221 * using function() does not count as a reference, because the function is | 2222 * using function() does not count as a reference, because the function is |
2222 * looked up by name. | 2223 * looked up by name. |
2223 */ | 2224 */ |
2224 int | 2225 int |
2225 func_name_refcount(char_u *name) | 2226 func_name_refcount(char_u *name) |
2226 { | 2227 { |
2227 return numbered_function(name) || *name == '<'; | 2228 return numbered_function(name) || (name[0] == '<' && name[1] == 'l'); |
2228 } | 2229 } |
2229 | 2230 |
2230 /* | 2231 /* |
2231 * Unreference "fc": decrement the reference count and free it when it | 2232 * Unreference "fc": decrement the reference count and free it when it |
2232 * becomes zero. "fp" is detached from "fc". | 2233 * becomes zero. "fp" is detached from "fc". |