mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 9.0.1149: class members may be garbage collected
Problem: Class members may be garbage collected. Solution: Mark class members as being in use.
This commit is contained in:
parent
2468add0b8
commit
cf760d50dc
29
src/eval.c
29
src/eval.c
@ -5674,9 +5674,32 @@ set_ref_in_item(
|
|||||||
}
|
}
|
||||||
|
|
||||||
case VAR_CLASS:
|
case VAR_CLASS:
|
||||||
// TODO: Mark methods in class_obj_methods ?
|
{
|
||||||
// Mark initializer expressions?
|
class_T *cl = tv->vval.v_class;
|
||||||
break;
|
if (cl != NULL && cl->class_copyID != copyID)
|
||||||
|
{
|
||||||
|
cl->class_copyID = copyID;
|
||||||
|
for (int i = 0; !abort
|
||||||
|
&& i < cl->class_class_member_count; ++i)
|
||||||
|
abort = abort || set_ref_in_item(
|
||||||
|
&cl->class_members_tv[i],
|
||||||
|
copyID, ht_stack, list_stack);
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; !abort
|
||||||
|
&& i < cl->class_class_function_count; ++i)
|
||||||
|
abort = abort || set_ref_in_func(NULL,
|
||||||
|
cl->class_class_functions[i], copyID);
|
||||||
|
|
||||||
|
for (int i = 0; !abort
|
||||||
|
&& i < cl->class_obj_method_count; ++i)
|
||||||
|
abort = abort || set_ref_in_func(NULL,
|
||||||
|
cl->class_obj_methods[i], copyID);
|
||||||
|
|
||||||
|
// Mark initializer expressions?
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case VAR_OBJECT:
|
case VAR_OBJECT:
|
||||||
{
|
{
|
||||||
|
@ -1487,6 +1487,7 @@ struct class_S
|
|||||||
{
|
{
|
||||||
char_u *class_name; // allocated
|
char_u *class_name; // allocated
|
||||||
int class_refcount;
|
int class_refcount;
|
||||||
|
int class_copyID; // used by garbage collection
|
||||||
|
|
||||||
// class members: "static varname"
|
// class members: "static varname"
|
||||||
int class_class_member_count;
|
int class_class_member_count;
|
||||||
|
@ -493,6 +493,23 @@ def Test_class_member()
|
|||||||
v9.CheckScriptFailure(lines, 'E1341: Variable already declared in the class: count')
|
v9.CheckScriptFailure(lines, 'E1341: Variable already declared in the class: count')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
func Test_class_garbagecollect()
|
||||||
|
let lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
|
||||||
|
class Point
|
||||||
|
this.p = [2, 3]
|
||||||
|
static pl = ['a', 'b']
|
||||||
|
static pd = {a: 'a', b: 'b'}
|
||||||
|
endclass
|
||||||
|
|
||||||
|
echo Point.pl Point.pd
|
||||||
|
call test_garbagecollect_now()
|
||||||
|
echo Point.pl Point.pd
|
||||||
|
END
|
||||||
|
call v9.CheckScriptSuccess(lines)
|
||||||
|
endfunc
|
||||||
|
|
||||||
def Test_class_function()
|
def Test_class_function()
|
||||||
var lines =<< trim END
|
var lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
@ -695,6 +695,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 */
|
||||||
|
/**/
|
||||||
|
1149,
|
||||||
/**/
|
/**/
|
||||||
1148,
|
1148,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user