Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
G
GLib
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 936
    • Issues 936
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 59
    • Merge Requests 59
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • GNOME
  • GLib
  • Issues
  • #1486

Closed
Open
Opened Aug 08, 2018 by david@sanborn

g_hash_table_lookup/g_hash_table_lookup_node bug

Created custom hash (GHashFunc) and equal (GEqualFunc) functions for g_hash_table_new_full implementation. Problem occurs when calling g_hash_table_lookup. The custom GEqualFunc callback is never executed because g_hash_table_lookup_node compares hash values and will skip the execution path to make the GEqualFunc call. This completely negates the purpose of being able to define your own GEqualFunc implementation.

The comments say this is done to avoid calling the "full-blow key equality function in most cases," but in reality this is for all cases. There is not alternative logic flow to execute the equality function if the "node_hash == hash_value" condition fails.

See glib/ghash.c lines 388 - 407; specifically lines 394 and thereafter:

while (!HASH_IS_UNUSED (node_hash))
{
  /* We first check if our full hash values
   * are equal so we can avoid calling the full-blown
   * key equality function in most cases.
   */
  if (node_hash == hash_value)
    {
      gpointer node_key = hash_table->keys[node_index];

      if (hash_table->key_equal_func)
        {
          if (hash_table->key_equal_func (node_key, key))
            return node_index;
        }
      else if (node_key == key)
        {
          return node_index;
        }
    }
Edited Aug 08, 2018 by david
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: GNOME/glib#1486