aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2020-08-15 10:48:36 -0700
committerPaul Eggert2020-08-15 11:19:51 -0700
commitf1b06fd5fc66377f85b420d3d40c666da9dca2a5 (patch)
tree588b05ababc36aaec1d28f6543aa35b180cba79c /src
parentd0145537fa511a44e2a4af01da3947e92f0b8331 (diff)
downloademacs-f1b06fd5fc66377f85b420d3d40c666da9dca2a5.tar.gz
emacs-f1b06fd5fc66377f85b420d3d40c666da9dca2a5.zip
Prefer Fvector to make_uninit_vector
Fvector is less error-prone than make_uninit_vector, as it avoids the possibility of a GC crash due to an uninitialized vector. So prefer Fvector to make_uninit_vector when this is easy (and when there's no significant performance difference). Inspired by a suggestion by Pip Cet in: https://lists.gnu.org/r/emacs-devel/2020-08/msg00313.html * src/ccl.c (Fregister_ccl_program): * src/ccl.c (Fregister_ccl_program): * src/charset.c (Fdefine_charset_internal): * src/font.c (Fquery_font, Ffont_info, syms_of_font): * src/fontset.c (font_def_new, Fset_fontset_font): * src/ftfont.c (ftfont_shape_by_flt): * src/hbfont.c (hbfont_shape): * src/macfont.m (macfont_shape): * src/search.c (Fnewline_cache_check): * src/xfaces.c (Fx_family_fonts): * src/xfns.c (Fx_window_property_attributes): Prefer Fvector to make_uninit_vector when either is easy. * src/fontset.c (font_def_new): Now a function with one less arg instead of a do-while macro, and renamed from FONT_DEF_NEW. All uses changed.
Diffstat (limited to 'src')
-rw-r--r--src/ccl.c11
-rw-r--r--src/charset.c9
-rw-r--r--src/font.c68
-rw-r--r--src/fontset.c27
-rw-r--r--src/ftfont.c12
-rw-r--r--src/hbfont.c11
-rw-r--r--src/macfont.m6
-rw-r--r--src/search.c4
-rw-r--r--src/xfaces.c28
-rw-r--r--src/xfns.c8
10 files changed, 73 insertions, 111 deletions
diff --git a/src/ccl.c b/src/ccl.c
index ef059ffff25..e85cfa6cdf2 100644
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -2219,15 +2219,8 @@ Return index number of the registered CCL program. */)
2219 /* Extend the table. */ 2219 /* Extend the table. */
2220 Vccl_program_table = larger_vector (Vccl_program_table, 1, -1); 2220 Vccl_program_table = larger_vector (Vccl_program_table, 1, -1);
2221 2221
2222 { 2222 ASET (Vccl_program_table, idx,
2223 Lisp_Object elt = make_uninit_vector (4); 2223 CALLN (Fvector, name, ccl_prog, resolved, Qt));
2224
2225 ASET (elt, 0, name);
2226 ASET (elt, 1, ccl_prog);
2227 ASET (elt, 2, resolved);
2228 ASET (elt, 3, Qt);
2229 ASET (Vccl_program_table, idx, elt);
2230 }
2231 2224
2232 Fput (name, Qccl_program_idx, make_fixnum (idx)); 2225 Fput (name, Qccl_program_idx, make_fixnum (idx));
2233 return make_fixnum (idx); 2226 return make_fixnum (idx);
diff --git a/src/charset.c b/src/charset.c
index 8635aad3ed6..520dd3a9605 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -1035,12 +1035,9 @@ usage: (define-charset-internal ...) */)
1035 CHECK_FIXNAT (parent_max_code); 1035 CHECK_FIXNAT (parent_max_code);
1036 parent_code_offset = Fnth (make_fixnum (3), val); 1036 parent_code_offset = Fnth (make_fixnum (3), val);
1037 CHECK_FIXNUM (parent_code_offset); 1037 CHECK_FIXNUM (parent_code_offset);
1038 val = make_uninit_vector (4); 1038 ASET (attrs, charset_subset,
1039 ASET (val, 0, make_fixnum (parent_charset->id)); 1039 CALLN (Fvector, make_fixnum (parent_charset->id),
1040 ASET (val, 1, parent_min_code); 1040 parent_min_code, parent_max_code, parent_code_offset));
1041 ASET (val, 2, parent_max_code);
1042 ASET (val, 3, parent_code_offset);
1043 ASET (attrs, charset_subset, val);
1044 1041
1045 charset.method = CHARSET_METHOD_SUBSET; 1042 charset.method = CHARSET_METHOD_SUBSET;
1046 /* Here, we just copy the parent's fast_map. It's not accurate, 1043 /* Here, we just copy the parent's fast_map. It's not accurate,
diff --git a/src/font.c b/src/font.c
index ccbd3fc9ce6..5c01c7ff796 100644
--- a/src/font.c
+++ b/src/font.c
@@ -4847,21 +4847,18 @@ If the font is not OpenType font, CAPABILITY is nil. */)
4847 (Lisp_Object font_object) 4847 (Lisp_Object font_object)
4848{ 4848{
4849 struct font *font = CHECK_FONT_GET_OBJECT (font_object); 4849 struct font *font = CHECK_FONT_GET_OBJECT (font_object);
4850 Lisp_Object val = make_uninit_vector (9); 4850 return CALLN (Fvector,
4851 4851 AREF (font_object, FONT_NAME_INDEX),
4852 ASET (val, 0, AREF (font_object, FONT_NAME_INDEX)); 4852 AREF (font_object, FONT_FILE_INDEX),
4853 ASET (val, 1, AREF (font_object, FONT_FILE_INDEX)); 4853 make_fixnum (font->pixel_size),
4854 ASET (val, 2, make_fixnum (font->pixel_size)); 4854 make_fixnum (font->max_width),
4855 ASET (val, 3, make_fixnum (font->max_width)); 4855 make_fixnum (font->ascent),
4856 ASET (val, 4, make_fixnum (font->ascent)); 4856 make_fixnum (font->descent),
4857 ASET (val, 5, make_fixnum (font->descent)); 4857 make_fixnum (font->space_width),
4858 ASET (val, 6, make_fixnum (font->space_width)); 4858 make_fixnum (font->average_width),
4859 ASET (val, 7, make_fixnum (font->average_width)); 4859 (font->driver->otf_capability
4860 if (font->driver->otf_capability) 4860 ? Fcons (Qopentype, font->driver->otf_capability (font))
4861 ASET (val, 8, Fcons (Qopentype, font->driver->otf_capability (font))); 4861 : Qnil));
4862 else
4863 ASET (val, 8, Qnil);
4864 return val;
4865} 4862}
4866 4863
4867DEFUN ("font-get-glyphs", Ffont_get_glyphs, Sfont_get_glyphs, 3, 4, 0, 4864DEFUN ("font-get-glyphs", Ffont_get_glyphs, Sfont_get_glyphs, 3, 4, 0,
@@ -5168,24 +5165,23 @@ If the named font cannot be opened and loaded, return nil. */)
5168 return Qnil; 5165 return Qnil;
5169 font = XFONT_OBJECT (font_object); 5166 font = XFONT_OBJECT (font_object);
5170 5167
5171 info = make_uninit_vector (14); 5168 info = CALLN (Fvector,
5172 ASET (info, 0, AREF (font_object, FONT_NAME_INDEX)); 5169 AREF (font_object, FONT_NAME_INDEX),
5173 ASET (info, 1, AREF (font_object, FONT_FULLNAME_INDEX)); 5170 AREF (font_object, FONT_FULLNAME_INDEX),
5174 ASET (info, 2, make_fixnum (font->pixel_size)); 5171 make_fixnum (font->pixel_size),
5175 ASET (info, 3, make_fixnum (font->height)); 5172 make_fixnum (font->height),
5176 ASET (info, 4, make_fixnum (font->baseline_offset)); 5173 make_fixnum (font->baseline_offset),
5177 ASET (info, 5, make_fixnum (font->relative_compose)); 5174 make_fixnum (font->relative_compose),
5178 ASET (info, 6, make_fixnum (font->default_ascent)); 5175 make_fixnum (font->default_ascent),
5179 ASET (info, 7, make_fixnum (font->max_width)); 5176 make_fixnum (font->max_width),
5180 ASET (info, 8, make_fixnum (font->ascent)); 5177 make_fixnum (font->ascent),
5181 ASET (info, 9, make_fixnum (font->descent)); 5178 make_fixnum (font->descent),
5182 ASET (info, 10, make_fixnum (font->space_width)); 5179 make_fixnum (font->space_width),
5183 ASET (info, 11, make_fixnum (font->average_width)); 5180 make_fixnum (font->average_width),
5184 ASET (info, 12, AREF (font_object, FONT_FILE_INDEX)); 5181 AREF (font_object, FONT_FILE_INDEX),
5185 if (font->driver->otf_capability) 5182 (font->driver->otf_capability
5186 ASET (info, 13, Fcons (Qopentype, font->driver->otf_capability (font))); 5183 ? Fcons (Qopentype, font->driver->otf_capability (font))
5187 else 5184 : Qnil));
5188 ASET (info, 13, Qnil);
5189 5185
5190#if 0 5186#if 0
5191 /* As font_object is still in FONT_OBJLIST of the entity, we can't 5187 /* As font_object is still in FONT_OBJLIST of the entity, we can't
@@ -5494,10 +5490,8 @@ This variable cannot be set; trying to do so will signal an error. */);
5494 make_symbol_constant (intern_c_string ("font-width-table")); 5490 make_symbol_constant (intern_c_string ("font-width-table"));
5495 5491
5496 staticpro (&font_style_table); 5492 staticpro (&font_style_table);
5497 font_style_table = make_uninit_vector (3); 5493 font_style_table = CALLN (Fvector, Vfont_weight_table, Vfont_slant_table,
5498 ASET (font_style_table, 0, Vfont_weight_table); 5494 Vfont_width_table);
5499 ASET (font_style_table, 1, Vfont_slant_table);
5500 ASET (font_style_table, 2, Vfont_width_table);
5501 5495
5502 DEFVAR_LISP ("font-log", Vfont_log, doc: /* 5496 DEFVAR_LISP ("font-log", Vfont_log, doc: /*
5503A list that logs font-related actions and results, for debugging. 5497A list that logs font-related actions and results, for debugging.
diff --git a/src/fontset.c b/src/fontset.c
index c2bb8b21f26..8c86075c07e 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -252,14 +252,13 @@ set_fontset_fallback (Lisp_Object fontset, Lisp_Object fallback)
252 252
253#define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset))) 253#define BASE_FONTSET_P(fontset) (NILP (FONTSET_BASE (fontset)))
254 254
255/* Macros for FONT-DEF and RFONT-DEF of fontset. */ 255/* Definitions for FONT-DEF and RFONT-DEF of fontset. */
256#define FONT_DEF_NEW(font_def, font_spec, encoding, repertory) \ 256static Lisp_Object
257 do { \ 257font_def_new (Lisp_Object font_spec, Lisp_Object encoding,
258 (font_def) = make_uninit_vector (3); \ 258 Lisp_Object repertory)
259 ASET ((font_def), 0, font_spec); \ 259{
260 ASET ((font_def), 1, encoding); \ 260 return CALLN (Fvector, font_spec, encoding, repertory);
261 ASET ((font_def), 2, repertory); \ 261}
262 } while (0)
263 262
264#define FONT_DEF_SPEC(font_def) AREF (font_def, 0) 263#define FONT_DEF_SPEC(font_def) AREF (font_def, 0)
265#define FONT_DEF_ENCODING(font_def) AREF (font_def, 1) 264#define FONT_DEF_ENCODING(font_def) AREF (font_def, 1)
@@ -1547,7 +1546,7 @@ appended. By default, FONT-SPEC overrides the previous settings. */)
1547 repertory = CHARSET_SYMBOL_ID (repertory); 1546 repertory = CHARSET_SYMBOL_ID (repertory);
1548 } 1547 }
1549 } 1548 }
1550 FONT_DEF_NEW (font_def, font_spec, encoding, repertory); 1549 font_def = font_def_new (font_spec, encoding, repertory);
1551 } 1550 }
1552 else 1551 else
1553 font_def = Qnil; 1552 font_def = Qnil;
@@ -1619,14 +1618,8 @@ appended. By default, FONT-SPEC overrides the previous settings. */)
1619 1618
1620 if (charset) 1619 if (charset)
1621 { 1620 {
1622 Lisp_Object arg; 1621 Lisp_Object arg = CALLN (Fvector, fontset, font_def, add,
1623 1622 ascii_changed ? Qt : Qnil, range_list);
1624 arg = make_uninit_vector (5);
1625 ASET (arg, 0, fontset);
1626 ASET (arg, 1, font_def);
1627 ASET (arg, 2, add);
1628 ASET (arg, 3, ascii_changed ? Qt : Qnil);
1629 ASET (arg, 4, range_list);
1630 1623
1631 map_charset_chars (set_fontset_font, Qnil, arg, charset, 1624 map_charset_chars (set_fontset_font, Qnil, arg, charset,
1632 CHARSET_MIN_CODE (charset), 1625 CHARSET_MIN_CODE (charset),
diff --git a/src/ftfont.c b/src/ftfont.c
index 696f5e65341..a904007a329 100644
--- a/src/ftfont.c
+++ b/src/ftfont.c
@@ -2826,14 +2826,10 @@ ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font,
2826 LGLYPH_SET_ASCENT (lglyph, g->g.ascent >> 6); 2826 LGLYPH_SET_ASCENT (lglyph, g->g.ascent >> 6);
2827 LGLYPH_SET_DESCENT (lglyph, g->g.descent >> 6); 2827 LGLYPH_SET_DESCENT (lglyph, g->g.descent >> 6);
2828 if (g->g.adjusted) 2828 if (g->g.adjusted)
2829 { 2829 LGLYPH_SET_ADJUSTMENT (lglyph, CALLN (Fvector,
2830 Lisp_Object vec = make_uninit_vector (3); 2830 make_fixnum (g->g.xoff >> 6),
2831 2831 make_fixnum (g->g.yoff >> 6),
2832 ASET (vec, 0, make_fixnum (g->g.xoff >> 6)); 2832 make_fixnum (g->g.xadv >> 6)));
2833 ASET (vec, 1, make_fixnum (g->g.yoff >> 6));
2834 ASET (vec, 2, make_fixnum (g->g.xadv >> 6));
2835 LGLYPH_SET_ADJUSTMENT (lglyph, vec);
2836 }
2837 } 2833 }
2838 return make_fixnum (i); 2834 return make_fixnum (i);
2839} 2835}
diff --git a/src/hbfont.c b/src/hbfont.c
index 4b3f64ef504..82b115e6868 100644
--- a/src/hbfont.c
+++ b/src/hbfont.c
@@ -594,13 +594,10 @@ hbfont_shape (Lisp_Object lgstring, Lisp_Object direction)
594 yoff = - lround (pos[i].y_offset * position_unit); 594 yoff = - lround (pos[i].y_offset * position_unit);
595 wadjust = lround (pos[i].x_advance * position_unit); 595 wadjust = lround (pos[i].x_advance * position_unit);
596 if (xoff || yoff || wadjust != metrics.width) 596 if (xoff || yoff || wadjust != metrics.width)
597 { 597 LGLYPH_SET_ADJUSTMENT (lglyph, CALLN (Fvector,
598 Lisp_Object vec = make_uninit_vector (3); 598 make_fixnum (xoff),
599 ASET (vec, 0, make_fixnum (xoff)); 599 make_fixnum (yoff),
600 ASET (vec, 1, make_fixnum (yoff)); 600 make_fixnum (wadjust)));
601 ASET (vec, 2, make_fixnum (wadjust));
602 LGLYPH_SET_ADJUSTMENT (lglyph, vec);
603 }
604 } 601 }
605 602
606 return make_fixnum (glyph_len); 603 return make_fixnum (glyph_len);
diff --git a/src/macfont.m b/src/macfont.m
index c7430d32772..904814647f9 100644
--- a/src/macfont.m
+++ b/src/macfont.m
@@ -3137,10 +3137,8 @@ macfont_shape (Lisp_Object lgstring, Lisp_Object direction)
3137 wadjust = lround (gl->advance); 3137 wadjust = lround (gl->advance);
3138 if (xoff != 0 || yoff != 0 || wadjust != metrics.width) 3138 if (xoff != 0 || yoff != 0 || wadjust != metrics.width)
3139 { 3139 {
3140 Lisp_Object vec = make_uninit_vector (3); 3140 Lisp_Object vec = CALLN (Fvector, make_fixnum (xoff),
3141 ASET (vec, 0, make_fixnum (xoff)); 3141 make_fixnum (yoff), make_fixnum (wadjust));
3142 ASET (vec, 1, make_fixnum (yoff));
3143 ASET (vec, 2, make_fixnum (wadjust));
3144 LGLYPH_SET_ADJUSTMENT (lglyph, vec); 3142 LGLYPH_SET_ADJUSTMENT (lglyph, vec);
3145 } 3143 }
3146 } 3144 }
diff --git a/src/search.c b/src/search.c
index 23b31d92810..6fb3716cd43 100644
--- a/src/search.c
+++ b/src/search.c
@@ -3306,9 +3306,7 @@ the buffer. If the buffer doesn't have a cache, the value is nil. */)
3306 } 3306 }
3307 3307
3308 /* Construct the value and return it. */ 3308 /* Construct the value and return it. */
3309 val = make_uninit_vector (2); 3309 val = CALLN (Fvector, cache_newlines, buf_newlines);
3310 ASET (val, 0, cache_newlines);
3311 ASET (val, 1, buf_newlines);
3312 3310
3313 if (old != NULL) 3311 if (old != NULL)
3314 set_buffer_internal_1 (old); 3312 set_buffer_internal_1 (old);
diff --git a/src/xfaces.c b/src/xfaces.c
index 2c6e593f631..06d2f994de6 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -1572,22 +1572,18 @@ the face font sort order. */)
1572 for (i = nfonts - 1; i >= 0; --i) 1572 for (i = nfonts - 1; i >= 0; --i)
1573 { 1573 {
1574 Lisp_Object font = AREF (vec, i); 1574 Lisp_Object font = AREF (vec, i);
1575 Lisp_Object v = make_uninit_vector (8); 1575 int point = PIXEL_TO_POINT (XFIXNUM (AREF (font, FONT_SIZE_INDEX)) * 10,
1576 int point; 1576 FRAME_RES_Y (f));
1577 Lisp_Object spacing; 1577 Lisp_Object spacing = Ffont_get (font, QCspacing);
1578 1578 Lisp_Object v = CALLN (Fvector,
1579 ASET (v, 0, AREF (font, FONT_FAMILY_INDEX)); 1579 AREF (font, FONT_FAMILY_INDEX),
1580 ASET (v, 1, FONT_WIDTH_SYMBOLIC (font)); 1580 FONT_WIDTH_SYMBOLIC (font),
1581 point = PIXEL_TO_POINT (XFIXNUM (AREF (font, FONT_SIZE_INDEX)) * 10, 1581 make_fixnum (point),
1582 FRAME_RES_Y (f)); 1582 FONT_WEIGHT_SYMBOLIC (font),
1583 ASET (v, 2, make_fixnum (point)); 1583 FONT_SLANT_SYMBOLIC (font),
1584 ASET (v, 3, FONT_WEIGHT_SYMBOLIC (font)); 1584 NILP (spacing) || EQ (spacing, Qp) ? Qnil : Qt,
1585 ASET (v, 4, FONT_SLANT_SYMBOLIC (font)); 1585 Ffont_xlfd_name (font, Qnil),
1586 spacing = Ffont_get (font, QCspacing); 1586 AREF (font, FONT_REGISTRY_INDEX));
1587 ASET (v, 5, (NILP (spacing) || EQ (spacing, Qp)) ? Qnil : Qt);
1588 ASET (v, 6, Ffont_xlfd_name (font, Qnil));
1589 ASET (v, 7, AREF (font, FONT_REGISTRY_INDEX));
1590
1591 result = Fcons (v, result); 1587 result = Fcons (v, result);
1592 } 1588 }
1593 1589
diff --git a/src/xfns.c b/src/xfns.c
index 09dcbbfb92d..07bba90eaf2 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -6196,10 +6196,10 @@ Otherwise, the return value is a vector with the following fields:
6196 { 6196 {
6197 XFree (tmp_data); 6197 XFree (tmp_data);
6198 6198
6199 prop_attr = make_uninit_vector (3); 6199 prop_attr = CALLN (Fvector,
6200 ASET (prop_attr, 0, make_fixnum (actual_type)); 6200 make_fixnum (actual_type),
6201 ASET (prop_attr, 1, make_fixnum (actual_format)); 6201 make_fixnum (actual_format),
6202 ASET (prop_attr, 2, make_fixnum (bytes_remaining / (actual_format >> 3))); 6202 make_fixnum (bytes_remaining / (actual_format >> 3)));
6203 } 6203 }
6204 6204
6205 unblock_input (); 6205 unblock_input ();