Mercurial > vim
comparison src/textprop.c @ 15144:7960bf50d345 v8.1.0582
patch 8.1.0582: text properties are not enabled
commit https://github.com/vim/vim/commit/fb95e212a2696e5b1c8b5e6b2984af59fa7ead6f
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Dec 14 12:18:11 2018 +0100
patch 8.1.0582: text properties are not enabled
Problem: Text properties are not enabled.
Solution: Fix sizeof argument and re-enable the text properties feature.
Fix memory leak.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 14 Dec 2018 12:30:08 +0100 |
parents | 9df130fd5e0d |
children | 7903dce131d4 |
comparison
equal
deleted
inserted
replaced
15143:d04c4ce36c2a | 15144:7960bf50d345 |
---|---|
149 char_u *newtext; | 149 char_u *newtext; |
150 int proplen; | 150 int proplen; |
151 size_t textlen; | 151 size_t textlen; |
152 char_u *props; | 152 char_u *props; |
153 char_u *newprops; | 153 char_u *newprops; |
154 static textprop_T tmp_prop; // static to get it aligned. | 154 textprop_T tmp_prop; |
155 int i; | 155 int i; |
156 | 156 |
157 lnum = get_tv_number(&argvars[0]); | 157 lnum = get_tv_number(&argvars[0]); |
158 col = get_tv_number(&argvars[1]); | 158 col = get_tv_number(&argvars[1]); |
159 if (col < 1) | 159 if (col < 1) |
210 return; | 210 return; |
211 } | 211 } |
212 | 212 |
213 // Fetch the line to get the ml_line_len field updated. | 213 // Fetch the line to get the ml_line_len field updated. |
214 proplen = get_text_props(buf, lnum, &props, TRUE); | 214 proplen = get_text_props(buf, lnum, &props, TRUE); |
215 | 215 textlen = buf->b_ml.ml_line_len - proplen * sizeof(textprop_T); |
216 if (col >= (colnr_T)STRLEN(buf->b_ml.ml_line_ptr)) | 216 |
217 if (col >= (colnr_T)textlen - 1) | |
217 { | 218 { |
218 EMSGN(_(e_invalid_col), (long)col); | 219 EMSGN(_(e_invalid_col), (long)col); |
219 return; | 220 return; |
220 } | 221 } |
221 | 222 |
222 // Allocate the new line with space for the new proprety. | 223 // Allocate the new line with space for the new proprety. |
223 newtext = alloc(buf->b_ml.ml_line_len + sizeof(textprop_T)); | 224 newtext = alloc(buf->b_ml.ml_line_len + sizeof(textprop_T)); |
224 if (newtext == NULL) | 225 if (newtext == NULL) |
225 return; | 226 return; |
226 // Copy the text, including terminating NUL. | 227 // Copy the text, including terminating NUL. |
227 textlen = buf->b_ml.ml_line_len - proplen * sizeof(textprop_T); | |
228 mch_memmove(newtext, buf->b_ml.ml_line_ptr, textlen); | 228 mch_memmove(newtext, buf->b_ml.ml_line_ptr, textlen); |
229 | 229 |
230 // Find the index where to insert the new property. | 230 // Find the index where to insert the new property. |
231 // Since the text properties are not aligned properly when stored with the | 231 // Since the text properties are not aligned properly when stored with the |
232 // text, we need to copy them as bytes before using it as a struct. | 232 // text, we need to copy them as bytes before using it as a struct. |
233 for (i = 0; i < proplen; ++i) | 233 for (i = 0; i < proplen; ++i) |
234 { | 234 { |
235 mch_memmove(&tmp_prop, props + i * sizeof(proptype_T), | 235 mch_memmove(&tmp_prop, props + i * sizeof(textprop_T), |
236 sizeof(proptype_T)); | 236 sizeof(textprop_T)); |
237 if (tmp_prop.tp_col >= col) | 237 if (tmp_prop.tp_col >= col) |
238 break; | 238 break; |
239 } | 239 } |
240 newprops = newtext + textlen; | 240 newprops = newtext + textlen; |
241 if (i > 0) | 241 if (i > 0) |
272 { | 272 { |
273 return buf->b_proptypes != NULL || global_proptypes != NULL; | 273 return buf->b_proptypes != NULL || global_proptypes != NULL; |
274 } | 274 } |
275 | 275 |
276 /* | 276 /* |
277 * Fetch the text properties for line "lnum" in buffer 'buf". | 277 * Fetch the text properties for line "lnum" in buffer "buf". |
278 * Returns the number of text properties and, when non-zero, a pointer to the | 278 * Returns the number of text properties and, when non-zero, a pointer to the |
279 * first one in "props" (note that it is not aligned, therefore the char_u | 279 * first one in "props" (note that it is not aligned, therefore the char_u |
280 * pointer). | 280 * pointer). |
281 */ | 281 */ |
282 int | 282 int |
615 htp = buf == NULL ? &global_proptypes : &buf->b_proptypes; | 615 htp = buf == NULL ? &global_proptypes : &buf->b_proptypes; |
616 if (*htp == NULL) | 616 if (*htp == NULL) |
617 { | 617 { |
618 *htp = (hashtab_T *)alloc(sizeof(hashtab_T)); | 618 *htp = (hashtab_T *)alloc(sizeof(hashtab_T)); |
619 if (*htp == NULL) | 619 if (*htp == NULL) |
620 { | |
621 vim_free(prop); | |
620 return; | 622 return; |
623 } | |
621 hash_init(*htp); | 624 hash_init(*htp); |
622 } | 625 } |
623 hash_add(buf == NULL ? global_proptypes : buf->b_proptypes, | 626 hash_add(*htp, PT2HIKEY(prop)); |
624 PT2HIKEY(prop)); | |
625 } | 627 } |
626 else | 628 else |
627 { | 629 { |
628 if (prop == NULL) | 630 if (prop == NULL) |
629 { | 631 { |
638 if (di != NULL) | 640 if (di != NULL) |
639 { | 641 { |
640 char_u *highlight; | 642 char_u *highlight; |
641 int hl_id = 0; | 643 int hl_id = 0; |
642 | 644 |
643 highlight = get_dict_string(dict, (char_u *)"highlight", TRUE); | 645 highlight = get_dict_string(dict, (char_u *)"highlight", FALSE); |
644 if (highlight != NULL && *highlight != NUL) | 646 if (highlight != NULL && *highlight != NUL) |
645 hl_id = syn_name2id(highlight); | 647 hl_id = syn_name2id(highlight); |
646 if (hl_id <= 0) | 648 if (hl_id <= 0) |
647 { | 649 { |
648 EMSG2(_("E970: Unknown highlight group name: '%s'"), | 650 EMSG2(_("E970: Unknown highlight group name: '%s'"), |
719 | 721 |
720 hi = find_prop_hi(name, buf); | 722 hi = find_prop_hi(name, buf); |
721 if (hi != NULL) | 723 if (hi != NULL) |
722 { | 724 { |
723 hashtab_T *ht; | 725 hashtab_T *ht; |
726 proptype_T *prop = HI2PT(hi); | |
724 | 727 |
725 if (buf == NULL) | 728 if (buf == NULL) |
726 ht = global_proptypes; | 729 ht = global_proptypes; |
727 else | 730 else |
728 ht = buf->b_proptypes; | 731 ht = buf->b_proptypes; |
729 hash_remove(ht, hi); | 732 hash_remove(ht, hi); |
733 vim_free(prop); | |
730 } | 734 } |
731 } | 735 } |
732 | 736 |
733 /* | 737 /* |
734 * prop_type_get({name} [, {bufnr}]) | 738 * prop_type_get({name} [, {bufnr}]) |
844 vim_free(ht); | 848 vim_free(ht); |
845 } | 849 } |
846 | 850 |
847 #if defined(EXITFREE) || defined(PROTO) | 851 #if defined(EXITFREE) || defined(PROTO) |
848 /* | 852 /* |
849 * Free all property types for "buf". | 853 * Free all global property types. |
850 */ | 854 */ |
851 void | 855 void |
852 clear_global_prop_types(void) | 856 clear_global_prop_types(void) |
853 { | 857 { |
854 clear_ht_prop_types(global_proptypes); | 858 clear_ht_prop_types(global_proptypes); |