Added a base parameter to the interaction_case_hash function
[pspp] / src / data / dictionary.c
index c00bd4face382c363990b6185741bdf1d62080c5..2d99f6d72cfe2a7e6dc442102f16a4dc687cbe32 100644 (file)
@@ -87,16 +87,8 @@ struct dictionary
 static void dict_unset_split_var (struct dictionary *, struct variable *);
 static void dict_unset_mrset_var (struct dictionary *, struct variable *);
 
 static void dict_unset_split_var (struct dictionary *, struct variable *);
 static void dict_unset_mrset_var (struct dictionary *, struct variable *);
 
-void
-dict_set_encoding (struct dictionary *d, const char *enc)
-{
-  if (enc)
-    {
-      free (d->encoding);
-      d->encoding = xstrdup (enc);
-    }
-}
-
+/* Returns the encoding for data in dictionary D.  The return value is a
+   nonnull string that contains an IANA character set name. */
 const char *
 dict_get_encoding (const struct dictionary *d)
 {
 const char *
 dict_get_encoding (const struct dictionary *d)
 {
@@ -171,14 +163,16 @@ dict_copy_callbacks (struct dictionary *dest,
   dest->cb_data = src->cb_data;
 }
 
   dest->cb_data = src->cb_data;
 }
 
-/* Creates and returns a new dictionary. */
+/* Creates and returns a new dictionary with the specified ENCODING. */
 struct dictionary *
 struct dictionary *
-dict_create (void)
+dict_create (const char *encoding)
 {
   struct dictionary *d = xzalloc (sizeof *d);
 
 {
   struct dictionary *d = xzalloc (sizeof *d);
 
+  d->encoding = xstrdup (encoding);
   hmap_init (&d->name_map);
   attrset_init (&d->attributes);
   hmap_init (&d->name_map);
   attrset_init (&d->attributes);
+
   return d;
 }
 
   return d;
 }
 
@@ -189,14 +183,20 @@ dict_create (void)
    dictionary.  If the new dictionary won't be used to access
    cases produced with the old dictionary, then the new
    dictionary's case indexes should be compacted with
    dictionary.  If the new dictionary won't be used to access
    cases produced with the old dictionary, then the new
    dictionary's case indexes should be compacted with
-   dict_compact_values to save space. */
+   dict_compact_values to save space.
+
+   Callbacks are not cloned. */
 struct dictionary *
 dict_clone (const struct dictionary *s)
 {
   struct dictionary *d;
   size_t i;
 
 struct dictionary *
 dict_clone (const struct dictionary *s)
 {
   struct dictionary *d;
   size_t i;
 
-  d = dict_create ();
+  d = dict_create (s->encoding);
+
+  /* Set the new dictionary's encoding early so that string length limitations
+     are interpreted correctly. */
+  d->encoding = xstrdup (s->encoding);
 
   for (i = 0; i < s->var_cnt; i++)
     {
 
   for (i = 0; i < s->var_cnt; i++)
     {
@@ -235,9 +235,6 @@ dict_clone (const struct dictionary *s)
   for (i = 0; i < s->vector_cnt; i++)
     d->vector[i] = vector_clone (s->vector[i], s, d);
 
   for (i = 0; i < s->vector_cnt; i++)
     d->vector[i] = vector_clone (s->vector[i], s, d);
 
-  if ( s->encoding)
-    d->encoding = xstrdup (s->encoding);
-
   dict_set_attributes (d, dict_get_attributes (s));
 
   for (i = 0; i < s->n_mrsets; i++)
   dict_set_attributes (d, dict_get_attributes (s));
 
   for (i = 0; i < s->n_mrsets; i++)
@@ -1658,7 +1655,7 @@ struct variable *
 dict_create_internal_var (int case_idx, int width)
 {
   if (internal_dict == NULL)
 dict_create_internal_var (int case_idx, int width)
 {
   if (internal_dict == NULL)
-    internal_dict = dict_create ();
+    internal_dict = dict_create ("UTF-8");
 
   for (;;)
     {
 
   for (;;)
     {