Skip to content

Commit

Permalink
[buffer] Clean up internal state bookkeeping
Browse files Browse the repository at this point in the history
hb_buffer_reset() was NOT resetting cluster_level. Ouch! Fix that.

Part of harfbuzz#1555
  • Loading branch information
behdad authored and Matthias Clasen committed Jan 7, 2022
1 parent 7b977cd commit edcd13e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
15 changes: 8 additions & 7 deletions src/hb-buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ hb_buffer_t::reset ()
hb_unicode_funcs_destroy (unicode);
unicode = hb_unicode_funcs_reference (hb_unicode_funcs_get_default ());
flags = HB_BUFFER_FLAG_DEFAULT;
cluster_level = HB_BUFFER_CLUSTER_LEVEL_DEFAULT;
replacement = HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT;
invisible = 0;
not_found = 0;
Expand All @@ -271,25 +272,26 @@ hb_buffer_t::reset ()
void
hb_buffer_t::clear ()
{
content_type = HB_BUFFER_CONTENT_TYPE_INVALID;
hb_segment_properties_t default_props = HB_SEGMENT_PROPERTIES_DEFAULT;
props = default_props;
scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT;

content_type = HB_BUFFER_CONTENT_TYPE_INVALID;
successful = true;
have_output = false;
have_positions = false;

idx = 0;
len = 0;
out_len = 0;
out_info = info;

serial = 0;
out_info = info;

memset (context, 0, sizeof context);
memset (context_len, 0, sizeof context_len);

scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT;
serial = 0;

deallocate_var_all ();
}

Expand Down Expand Up @@ -604,12 +606,11 @@ DEFINE_NULL_INSTANCE (hb_buffer_t) =
HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT,
0, /* invisible */
0, /* not_found */
HB_BUFFER_SCRATCH_FLAG_DEFAULT,
HB_BUFFER_MAX_LEN_DEFAULT,
HB_BUFFER_MAX_OPS_DEFAULT,


HB_BUFFER_CONTENT_TYPE_INVALID,
HB_SEGMENT_PROPERTIES_DEFAULT,

false, /* successful */
false, /* have_output */
true /* have_positions */
Expand Down
25 changes: 18 additions & 7 deletions src/hb-buffer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,21 @@ struct hb_buffer_t
{
hb_object_header_t header;

/* Information about how the text in the buffer should be treated */
/*
* Information about how the text in the buffer should be treated.
*/

hb_unicode_funcs_t *unicode; /* Unicode functions */
hb_buffer_flags_t flags; /* BOT / EOT / etc. */
hb_buffer_cluster_level_t cluster_level;
hb_codepoint_t replacement; /* U+FFFD or something else. */
hb_codepoint_t invisible; /* 0 or something else. */
hb_codepoint_t not_found; /* 0 or something else. */
hb_buffer_scratch_flags_t scratch_flags; /* Have space-fallback, etc. */
unsigned int max_len; /* Maximum allowed len. */
int max_ops; /* Maximum allowed operations. */

/* Buffer contents */
/*
* Buffer contents
*/

hb_buffer_content_type_t content_type;
hb_segment_properties_t props; /* Script, language, direction */

Expand All @@ -115,15 +118,23 @@ struct hb_buffer_t
hb_glyph_info_t *out_info;
hb_glyph_position_t *pos;

unsigned int serial;

/* Text before / after the main buffer contents.
* Always in Unicode, and ordered outward.
* Index 0 is for "pre-context", 1 for "post-context". */
static constexpr unsigned CONTEXT_LENGTH = 5u;
hb_codepoint_t context[2][CONTEXT_LENGTH];
unsigned int context_len[2];

/*
* Not part of content.
*/

hb_buffer_scratch_flags_t scratch_flags; /* Have space-fallback, etc. */
unsigned int serial;

unsigned int max_len; /* Maximum allowed len. */
int max_ops; /* Maximum allowed operations. */

/* Debugging API */
#ifndef HB_NO_BUFFER_MESSAGE
hb_buffer_message_func_t message_func;
Expand Down

0 comments on commit edcd13e

Please sign in to comment.