pxd: initial work
[pspp] / src / libpspp / intern.c
index fe0e784cda6b02db4e28e54a7fdce3eb04e08cd3..101a14d3c3a829df3d6ce38989339069b260cf71 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -59,7 +59,12 @@ intern_lookup__ (const char *s, size_t length, unsigned int hash)
 const char *
 intern_new (const char *s)
 {
-  size_t length = strlen (s);
+  return intern_buffer (s, strlen (s));
+}
+
+const char *
+intern_buffer (const char *s, size_t length)
+{
   unsigned int hash = hash_bytes (s, length, 0);
   struct interned_string *is;
 
@@ -78,8 +83,9 @@ intern_new (const char *s)
 }
 
 static struct interned_string *
-interned_string_from_string (const char *s)
+interned_string_from_string (const char *s_)
 {
+  char (*s)[1] = (char (*)[1]) s_;
   struct interned_string *is = UP_CAST (s, struct interned_string, string);
   assert (is->ref_cnt > 0);
   return is;
@@ -109,6 +115,13 @@ intern_unref (const char *s)
     }
 }
 
+/* Returns the length of interned string S. */
+size_t
+intern_strlen (const char *s)
+{
+  return interned_string_from_string (s)->length;
+}
+
 /* Given null-terminated string S, returns true if S is an interned string
    returned by intern_string_new(), false otherwise.
 
@@ -122,11 +135,3 @@ is_interned_string (const char *s)
   unsigned int hash = hash_bytes (s, length, 0);
   return intern_lookup__ (s, length, hash) != NULL;
 }
-
-/* Returns the length of S, which must be an interned string returned by
-   intern_new(). */
-size_t
-intern_strlen (const char *s)
-{
-  return interned_string_from_string (s)->length;
-}