X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fintern.c;fp=src%2Flibpspp%2Fintern.c;h=b8eb5198b4d9ac902ef2ce67c2fd1c994b5f0de2;hb=4ae5f1b099bc4de1f59898bc609e34dcb722b39c;hp=fc31acf0b439fec19c339296abe3e5fe8f5ce314;hpb=44c7a157afd05dace564c39e73a257c2758263b0;p=pspp diff --git a/src/libpspp/intern.c b/src/libpspp/intern.c index fc31acf0b4..b8eb5198b4 100644 --- a/src/libpspp/intern.c +++ b/src/libpspp/intern.c @@ -77,6 +77,13 @@ intern_new (const char *s) return is->string; } +const char * +intern_new_if_nonnull (const char *s) +{ + return s ? intern_new (s) : NULL; +} + + static struct interned_string * interned_string_from_string (const char *s_) { @@ -96,17 +103,26 @@ intern_ref (const char *s) return s; } +const char * +intern_ref_if_nonnull (const char *s) +{ + return s ? intern_ref (s) : NULL; +} + /* Decreases the reference count on S, which must be an interned string returned by intern_new(). If the reference count reaches 0, frees the interned string. */ void intern_unref (const char *s) { - struct interned_string *is = interned_string_from_string (s); - if (--is->ref_cnt == 0) + if (s) { - hmap_delete (&interns, &is->node); - free (is); + struct interned_string *is = interned_string_from_string (s); + if (--is->ref_cnt == 0) + { + hmap_delete (&interns, &is->node); + free (is); + } } }