Rename misc uses of "free"

In preparation for fixing https://github.com/harfbuzz/harfbuzz/issues/3044
This commit is contained in:
Behdad Esfahbod 2021-07-08 10:53:45 -06:00
parent 7416faceeb
commit bb48bf52a4
14 changed files with 24 additions and 25 deletions

View File

@ -232,8 +232,8 @@ struct hb_array_t : hb_iter_with_fallback_t<hb_array_t<Type>, Type&>
} }
/* Only call if you allocated the underlying array using malloc() or similar. */ /* Only call if you allocated the underlying array using malloc() or similar. */
void free () void fini ()
{ ::free ((void *) arrayZ); arrayZ = nullptr; length = 0; } { free ((void *) arrayZ); arrayZ = nullptr; length = 0; }
template <typename hb_serialize_context_t> template <typename hb_serialize_context_t>
hb_array_t copy (hb_serialize_context_t *c) const hb_array_t copy (hb_serialize_context_t *c) const

View File

@ -30,7 +30,7 @@
#include "hb.hh" #include "hb.hh"
/* Implements a lock-free cache for int->int functions. */ /* Implements a lockfree cache for int->int functions. */
template <unsigned int key_bits, unsigned int value_bits, unsigned int cache_bits> template <unsigned int key_bits, unsigned int value_bits, unsigned int cache_bits>
struct hb_cache_t struct hb_cache_t

View File

@ -257,11 +257,9 @@ struct hb_language_item_t {
bool operator == (const char *s) const bool operator == (const char *s) const
{ return lang_equal (lang, s); } { return lang_equal (lang, s); }
hb_language_item_t & operator = (const char *s) { hb_language_item_t & operator = (const char *s)
/* If a custom allocated is used calling strdup() pairs {
badly with a call to the custom free() in fini() below. /* We can't call strdup(), because we allow custom allocators. */
Therefore don't call strdup(), implement its behavior.
*/
size_t len = strlen(s) + 1; size_t len = strlen(s) + 1;
lang = (hb_language_t) malloc(len); lang = (hb_language_t) malloc(len);
if (likely (lang)) if (likely (lang))
@ -278,7 +276,7 @@ struct hb_language_item_t {
}; };
/* Thread-safe lock-free language list */ /* Thread-safe lockfree language list */
static hb_atomic_ptr_t <hb_language_item_t> langs; static hb_atomic_ptr_t <hb_language_item_t> langs;

View File

@ -46,7 +46,7 @@
* TODO Document more. * TODO Document more.
* *
* If iterator implementation implements operator!=, then can be * If iterator implementation implements operator!=, then can be
* used in range-based for loop. That comes free if the iterator * used in range-based for loop. That already happens if the iterator
* is random-access. Otherwise, the range-based for loop incurs * is random-access. Otherwise, the range-based for loop incurs
* one traversal to find end(), which can be avoided if written * one traversal to find end(), which can be avoided if written
* as a while-style for loop, or if iterator implements a faster * as a while-style for loop, or if iterator implements a faster

View File

@ -40,7 +40,7 @@
/* This lists font tables that the hb_face_t will contain and lazily /* This lists font tables that the hb_face_t will contain and lazily
* load. Don't add a table unless it's used though. This is not * load. Don't add a table unless it's used though. This is not
* exactly free. */ * exactly zero-cost. */
/* v--- Add new tables in the right place here. */ /* v--- Add new tables in the right place here. */

View File

@ -920,7 +920,7 @@ struct glyf
{ {
if (gid >= num_glyphs) return false; if (gid >= num_glyphs) return false;
/* Making this alloc free is not that easy /* Making this allocfree is not that easy
https://github.com/harfbuzz/harfbuzz/issues/2095 https://github.com/harfbuzz/harfbuzz/issues/2095
mostly because of gvar handling in VF fonts, mostly because of gvar handling in VF fonts,
perhaps a separate path for non-VF fonts can be considered */ perhaps a separate path for non-VF fonts can be considered */

View File

@ -1880,7 +1880,7 @@ struct CursivePosFormat1
else else
pos[child].x_offset = x_offset; pos[child].x_offset = x_offset;
/* If parent was attached to child, break them free. /* If parent was attached to child, separate them.
* https://github.com/harfbuzz/harfbuzz/issues/2469 * https://github.com/harfbuzz/harfbuzz/issues/2469
*/ */
if (unlikely (pos[parent].attach_chain() == -pos[child].attach_chain())) if (unlikely (pos[parent].attach_chain() == -pos[child].attach_chain()))

View File

@ -1388,7 +1388,8 @@ hb_ot_layout_has_substitution (hb_face_t *face)
* @lookup_index: The index of the lookup to query * @lookup_index: The index of the lookup to query
* @glyphs: The sequence of glyphs to query for substitution * @glyphs: The sequence of glyphs to query for substitution
* @glyphs_length: The length of the glyph sequence * @glyphs_length: The length of the glyph sequence
* @zero_context: #hb_bool_t indicating whether substitutions should be context-free * @zero_context: #hb_bool_t indicating whether pre-/post-context are disallowed
* in substitutions
* *
* Tests whether a specified lookup in the specified face would * Tests whether a specified lookup in the specified face would
* trigger a substitution on the given glyph sequence. * trigger a substitution on the given glyph sequence.

View File

@ -41,7 +41,7 @@ struct hb_pool_t
{ {
next = nullptr; next = nullptr;
for (chunk_t *_ : chunks) ::free (_); for (chunk_t *_ : chunks) free (_);
chunks.fini (); chunks.fini ();
} }
@ -65,7 +65,7 @@ struct hb_pool_t
return obj; return obj;
} }
void free (T* obj) void release (T* obj)
{ {
* (T**) obj = next; * (T**) obj = next;
next = obj; next = obj;

View File

@ -254,7 +254,7 @@ struct hb_serialize_context_t
current = current->next; current = current->next;
revert (obj->head, obj->tail); revert (obj->head, obj->tail);
obj->fini (); obj->fini ();
object_pool.free (obj); object_pool.release (obj);
} }
/* Set share to false when an object is unlikely sharable with others /* Set share to false when an object is unlikely sharable with others

View File

@ -35,7 +35,7 @@
* hb_set_t * hb_set_t
*/ */
/* TODO Keep a free-list so we can free pages that are completely zeroed. At that /* TODO Keep a freelist so we can release pages that are completely zeroed. At that
* point maybe also use a sentinel value for "all-1" pages? */ * point maybe also use a sentinel value for "all-1" pages? */
struct hb_set_t struct hb_set_t

View File

@ -264,7 +264,7 @@ hb_shape_plan_create2 (hb_face_t *face,
#ifndef HB_NO_OT_SHAPE #ifndef HB_NO_OT_SHAPE
bail3: bail3:
#endif #endif
shape_plan->key.free (); shape_plan->key.fini ();
bail2: bail2:
free (shape_plan); free (shape_plan);
bail: bail:
@ -320,7 +320,7 @@ hb_shape_plan_destroy (hb_shape_plan_t *shape_plan)
#ifndef HB_NO_OT_SHAPE #ifndef HB_NO_OT_SHAPE
shape_plan->ot.fini (); shape_plan->ot.fini ();
#endif #endif
shape_plan->key.free (); shape_plan->key.fini ();
free (shape_plan); free (shape_plan);
} }

View File

@ -55,7 +55,7 @@ struct hb_shape_plan_key_t
unsigned int num_coords, unsigned int num_coords,
const char * const *shaper_list); const char * const *shaper_list);
HB_INTERNAL void free () { ::free ((void *) user_features); } HB_INTERNAL void fini () { free ((void *) user_features); }
HB_INTERNAL bool user_features_match (const hb_shape_plan_key_t *other); HB_INTERNAL bool user_features_match (const hb_shape_plan_key_t *other);

View File

@ -377,8 +377,8 @@ test_serialize ()
assert (actual == expected); assert (actual == expected);
actual.free (); actual.fini ();
expected.free (); expected.fini ();
free (buffer_1); free (buffer_1);
free (buffer_2); free (buffer_2);
} }
@ -438,7 +438,7 @@ static void test_resolve_overflows_via_sort ()
hb_bytes_t result = out.copy_bytes (); hb_bytes_t result = out.copy_bytes ();
assert (result.length == (80000 + 3 + 3 * 2)); assert (result.length == (80000 + 3 + 3 * 2));
result.free (); result.fini ();
free (buffer); free (buffer);
free (out_buffer); free (out_buffer);
} }
@ -459,7 +459,7 @@ static void test_resolve_overflows_via_duplication ()
hb_bytes_t result = out.copy_bytes (); hb_bytes_t result = out.copy_bytes ();
assert (result.length == (10000 + 2 * 2 + 60000 + 2 + 3 * 2)); assert (result.length == (10000 + 2 * 2 + 60000 + 2 + 3 * 2));
result.free (); result.fini ();
free (buffer); free (buffer);
free (out_buffer); free (out_buffer);
} }