To: vim_dev@googlegroups.com Subject: Patch 9.0.1149 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1149 Problem: Class members may be garbage collected. Solution: Mark class members as being in use. Files: src/structs.h, src/eval.c, src/testdir/test_vim9_class.vim *** ../vim-9.0.1148/src/structs.h 2023-01-03 19:08:46.005020599 +0000 --- src/structs.h 2023-01-05 12:47:06.846955677 +0000 *************** *** 1487,1492 **** --- 1487,1493 ---- { char_u *class_name; // allocated int class_refcount; + int class_copyID; // used by garbage collection // class members: "static varname" int class_class_member_count; *** ../vim-9.0.1148/src/eval.c 2023-01-04 17:17:49.121005598 +0000 --- src/eval.c 2023-01-05 13:11:11.375333880 +0000 *************** *** 5674,5682 **** } case VAR_CLASS: ! // TODO: Mark methods in class_obj_methods ? ! // Mark initializer expressions? ! break; case VAR_OBJECT: { --- 5674,5705 ---- } case VAR_CLASS: ! { ! class_T *cl = tv->vval.v_class; ! 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: { *** ../vim-9.0.1148/src/testdir/test_vim9_class.vim 2023-01-04 18:54:05.320172637 +0000 --- src/testdir/test_vim9_class.vim 2023-01-05 12:54:17.094239479 +0000 *************** *** 493,498 **** --- 493,515 ---- v9.CheckScriptFailure(lines, 'E1341: Variable already declared in the class: count') 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() var lines =<< trim END vim9script *** ../vim-9.0.1148/src/version.c 2023-01-04 18:59:53.457710839 +0000 --- src/version.c 2023-01-05 13:15:14.815939665 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1149, /**/ -- SECOND SOLDIER: It could be carried by an African swallow! FIRST SOLDIER: Oh yes! An African swallow maybe ... but not a European swallow. that's my point. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///