X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fattributes.c;h=d7b45ff59571dd65567349d937f35ee4e038fa1d;hb=62b5101a28fc2c4a9b8b26a998fb6c4ec12d84c7;hp=f516dc61a172f72afb792f27026a109447b5c903;hpb=7bf210c4fd179a22dd8c6a071f0b23f7ae4e14c2;p=pspp diff --git a/src/data/attributes.c b/src/data/attributes.c index f516dc61a1..d7b45ff595 100644 --- a/src/data/attributes.c +++ b/src/data/attributes.c @@ -22,6 +22,7 @@ #include #include "libpspp/array.h" +#include "libpspp/compiler.h" #include "libpspp/hash-functions.h" #include "libpspp/i18n.h" @@ -230,15 +231,28 @@ attrset_lookup (const struct attrset *set, const char *name) return CONST_CAST (struct attribute *, attr); } +/* Adds ATTR to SET. Succeeds and returns true if SET does not already contain + an attribute with the same name (matched case insensitively); otherwise + fails and returns false. On success only, ownership of ATTR is transferred + to SET. */ +bool +attrset_try_add (struct attrset *set, struct attribute *attr) +{ + const char *name = attribute_get_name (attr); + if (attrset_lookup (set, name)) + return false; + hmap_insert (&set->map, &attr->node, utf8_hash_case_string (name, 0)); + return true; +} + /* Adds ATTR to SET, which must not already contain an attribute with the same name (matched case insensitively). Ownership of ATTR is transferred to SET. */ void attrset_add (struct attrset *set, struct attribute *attr) { - const char *name = attribute_get_name (attr); - assert (attrset_lookup (set, name) == NULL); - hmap_insert (&set->map, &attr->node, utf8_hash_case_string (name, 0)); + bool ok UNUSED = attrset_try_add (set, attr); + assert (ok); } /* Deletes any attribute from SET that matches NAME