[depend] Quick fixes: nullptr guard, enum flags, context set macro, comment

Remove nullptr check in hb_depend_t constructor per HarfBuzz convention
(crashing on null is fine). Convert HB_DEPEND_EDGE_FLAG_* #defines to
an hb_depend_edge_flags_t enum with HB_MARK_AS_FLAG_T, updating all
flag fields and parameters to use the enum type. Add
HB_DEPEND_CONTEXT_SET_FLAG for the 0x80000000 sentinel that marks
set-index references in context element sets; replace all raw literals
across depend-data.hh, gsubgpos.hh, and ReverseChain. Remove stale line
number reference from a comment in ReverseChain.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Skef IterumandClaude Sonnet 4.6 committed 2026-06-05 15:09:12 -07:00
1 parent 7c716218d6
commit b5d2b4d5fb
4 files changed
+30 -26

No files matched your search

@@ -69,7 +69,7 @@ struct ReverseChainSingleSubstFormat1
#ifndef HB_NO_SUBSET_DEPEND
bool depend (hb_depend_context_t *c) const {
// Filter by intersects and parent_active_glyphs like closure does (lines 83-95)
// Filter by intersects and parent_active_glyphs like closure does
if (!intersects (c->glyphs)) return true;
const auto &lookahead = StructAfter<decltype (lookaheadX)> (backtrack);
@@ -91,7 +91,7 @@ struct ReverseChainSingleSubstFormat1
else if (back_glyphs.get_population () > 1)
{
hb_codepoint_t set_idx = c->depend_data->find_or_create_context_set (back_glyphs);
context_glyphs.add (0x80000000 | set_idx);
context_glyphs.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx);
}
}
@@ -106,7 +106,7 @@ struct ReverseChainSingleSubstFormat1
else if (look_glyphs.get_population () > 1)
{
hb_codepoint_t set_idx = c->depend_data->find_or_create_context_set (look_glyphs);
context_glyphs.add (0x80000000 | set_idx);
context_glyphs.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx);
}
}
+21 -13
View File
@@ -61,8 +61,16 @@
* context). The outer context's requirements are not preserved on this edge,
* so it may over-approximate.
*/
#define HB_DEPEND_EDGE_FLAG_FROM_CONTEXT_POSITION 0x01
#define HB_DEPEND_EDGE_FLAG_FROM_NESTED_CONTEXT 0x02
enum hb_depend_edge_flags_t {
HB_DEPEND_EDGE_FLAG_NONE = 0x00u,
HB_DEPEND_EDGE_FLAG_FROM_CONTEXT_POSITION = 0x01u,
HB_DEPEND_EDGE_FLAG_FROM_NESTED_CONTEXT = 0x02u,
};
HB_MARK_AS_FLAG_T (hb_depend_edge_flags_t);
/* High bit of a context-set element marks it as an index into the sets array
* rather than a raw glyph ID. */
#define HB_DEPEND_CONTEXT_SET_FLAG 0x80000000u
/**
* hb_depend_edge_t:
@@ -85,7 +93,7 @@ struct hb_depend_edge_t {
hb_tag_t layout_tag,
hb_codepoint_t ligature_set,
hb_codepoint_t context_set,
uint8_t flags = 0) : table_tag(table_tag),
hb_depend_edge_flags_t flags = HB_DEPEND_EDGE_FLAG_NONE) : table_tag(table_tag),
dependent(dependent), layout_tag(layout_tag),
ligature_set(ligature_set), context_set(context_set),
flags(flags)
@@ -127,7 +135,7 @@ struct hb_depend_edge_t {
hb_tag_t layout_tag;
hb_codepoint_t ligature_set;
hb_codepoint_t context_set;
uint8_t flags;
hb_depend_edge_flags_t flags;
};
/**
@@ -140,7 +148,7 @@ struct hb_depend_edge_key_t {
hb_codepoint_t source;
hb_depend_edge_t record;
hb_depend_edge_key_t () : source (0), record (0, 0, 0, HB_CODEPOINT_INVALID, HB_CODEPOINT_INVALID, 0) {}
hb_depend_edge_key_t () : source (0), record (0, 0, 0, HB_CODEPOINT_INVALID, HB_CODEPOINT_INVALID, HB_DEPEND_EDGE_FLAG_NONE) {}
hb_depend_edge_key_t (hb_codepoint_t source,
hb_tag_t table_tag,
@@ -149,7 +157,7 @@ struct hb_depend_edge_key_t {
hb_codepoint_t ligature_set,
hb_codepoint_t context_set)
: source (source),
record (table_tag, dependent, layout_tag, ligature_set, context_set, 0) {}
record (table_tag, dependent, layout_tag, ligature_set, context_set, HB_DEPEND_EDGE_FLAG_NONE) {}
bool operator == (const hb_depend_edge_key_t &o) const
{
@@ -287,7 +295,7 @@ struct hb_depend_data_builder_t
{
hb_depend_data_builder_t (hb_depend_data_t &data_)
: current_context_set_index (HB_CODEPOINT_INVALID),
current_edge_flags (0),
current_edge_flags (HB_DEPEND_EDGE_FLAG_NONE),
data (data_) {}
/* Forward to data for use during construction (e.g. from hb_depend_context_t) */
@@ -408,7 +416,7 @@ struct hb_depend_data_builder_t
if (!filtered_set.is_empty ())
{
hb_codepoint_t set_idx = find_or_create_context_set (filtered_set);
context_elements.add (0x80000000 | set_idx);
context_elements.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx);
}
}
}
@@ -427,7 +435,7 @@ struct hb_depend_data_builder_t
if (!filtered_set.is_empty ())
{
hb_codepoint_t set_idx = find_or_create_context_set (filtered_set);
context_elements.add (0x80000000 | set_idx);
context_elements.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx);
}
}
}
@@ -446,7 +454,7 @@ struct hb_depend_data_builder_t
hb_codepoint_t dependent,
hb_codepoint_t lig_set = HB_CODEPOINT_INVALID,
hb_codepoint_t context_set = HB_CODEPOINT_INVALID,
uint8_t flags = 0)
hb_depend_edge_flags_t flags = HB_DEPEND_EDGE_FLAG_NONE)
{
if (target >= data.glyph_dependencies.length) {
DEBUG_MSG (SUBSET, nullptr, "Dependency glyph %u for %c%c%c%c too large",
@@ -473,7 +481,7 @@ struct hb_depend_data_builder_t
{
if (context_set == HB_CODEPOINT_INVALID)
context_set = current_context_set_index;
uint8_t flags = current_edge_flags;
hb_depend_edge_flags_t flags = current_edge_flags;
bool any_added = false;
for (auto t : lookup_features[lookup_index]) {
@@ -487,7 +495,7 @@ struct hb_depend_data_builder_t
hb_codepoint_t dependent,
hb_codepoint_t lig_set = HB_CODEPOINT_INVALID,
hb_codepoint_t context_set = HB_CODEPOINT_INVALID,
uint8_t flags = 0)
hb_depend_edge_flags_t flags = HB_DEPEND_EDGE_FLAG_NONE)
{
add_depend_layout (target, table_tag, HB_CODEPOINT_INVALID, dependent, lig_set,
context_set, flags);
@@ -514,7 +522,7 @@ struct hb_depend_data_builder_t
hb_hashmap_t<const hb_set_t*, hb_codepoint_t> set_to_index;
hb_vector_t<hb_codepoint_t> free_set_list;
hb_codepoint_t current_context_set_index;
uint8_t current_edge_flags;
hb_depend_edge_flags_t current_edge_flags;
hb_depend_data_t &data;
};
-4
View File
@@ -64,10 +64,6 @@
hb_depend_t::hb_depend_t (hb_face_t *f)
{
if (unlikely (f == nullptr)) {
successful = false;
return;
}
face = hb_face_reference(f);
if (unlikely (!data.glyph_dependencies.resize_exact (face->get_num_glyphs ()))) {
successful = false;
+6 -6
View File
@@ -1932,7 +1932,7 @@ static void context_depend_recurse_lookups (hb_depend_context_t *c,
/* Process preliminary_context in one pass */
hb_codepoint_t elem = HB_SET_VALUE_INVALID;
while (preliminary_context.next (&elem)) {
if (elem < 0x80000000) {
if (!(elem & HB_DEPEND_CONTEXT_SET_FLAG)) {
/* Direct glyph */
position_context.add (elem);
} else {
@@ -1982,7 +1982,7 @@ static void context_depend_recurse_lookups (hb_depend_context_t *c,
if (filtered == (*input_position_glyphs)[j]) {
/* No overlap with position_context - add full requirement */
hb_codepoint_t idx = c->depend_data->find_or_create_context_set ((*input_position_glyphs)[j]);
filtered_disjunctive_indices.add (0x80000000 | idx);
filtered_disjunctive_indices.add (HB_DEPEND_CONTEXT_SET_FLAG | idx);
}
/* Otherwise: position_context intersects, requirement satisfied */
}
@@ -2000,7 +2000,7 @@ static void context_depend_recurse_lookups (hb_depend_context_t *c,
* calls another contextual lookup, we want each lookup in this rule to see
* the same outer context, not context from a sibling lookup. */
hb_codepoint_t saved_context_set_index = c->depend_data->current_context_set_index;
uint8_t saved_edge_flags = c->depend_data->current_edge_flags;
hb_depend_edge_flags_t saved_edge_flags = c->depend_data->current_edge_flags;
/* Detect nested contextual: if we already have a context set, we're inside
* an outer contextual rule that called this one. The outer context will be
@@ -2018,7 +2018,7 @@ static void context_depend_recurse_lookups (hb_depend_context_t *c,
* lookups at the same position may interact (one produces a glyph, another
* immediately consumes it as an "intermediate"). So a glyph matching the
* coverage might not persist at that position when closure traverses. */
c->depend_data->current_edge_flags = 0;
c->depend_data->current_edge_flags = HB_DEPEND_EDGE_FLAG_NONE;
if (inputCount > 1) {
c->depend_data->current_edge_flags |= HB_DEPEND_EDGE_FLAG_FROM_CONTEXT_POSITION;
}
@@ -3720,7 +3720,7 @@ static inline void chain_context_depend_lookup (hb_depend_context_t *c,
preliminary_context.add (back_set.get_min ()); // Direct glyph
} else if (back_set.get_population () > 1) {
hb_codepoint_t set_idx = c->depend_data->find_or_create_context_set (back_set);
preliminary_context.add (0x80000000 | set_idx); // Encoded set reference
preliminary_context.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx); // Encoded set reference
}
}
for (const auto &look_set : ctx_info.lookahead_sets)
@@ -3729,7 +3729,7 @@ static inline void chain_context_depend_lookup (hb_depend_context_t *c,
preliminary_context.add (look_set.get_min ()); // Direct glyph
} else if (look_set.get_population () > 1) {
hb_codepoint_t set_idx = c->depend_data->find_or_create_context_set (look_set);
preliminary_context.add (0x80000000 | set_idx); // Encoded set reference
preliminary_context.add (HB_DEPEND_CONTEXT_SET_FLAG | set_idx); // Encoded set reference
}
}