Add support for value labels on long string variables.
[pspp-builds.git] / perl-module / PSPP.xs
index 13386588b62c9738a6346a758717da61937cdb82..8179d29a3721aa27b0b0e7417085a515eb65c591 100644 (file)
@@ -404,26 +404,27 @@ INIT:
  sv_setpv (errstr, "");
 CODE:
  union value the_value;
+ int width = var_get_width (var);
+ int ok;
 
+ value_init (&the_value, width);
  if ( var_is_numeric (var))
  {
   if ( ! looks_like_number (key))
     {
       sv_setpv (errstr, "Cannot add label with string key to a numeric variable");
+      value_destroy (&the_value, width);
       XSRETURN_IV (0);
     }
   the_value.f = SvNV (key);
  }
  else
  {
-   if ( var_is_long_string (var) )
-     {
-      sv_setpv (errstr, "Cannot add label to a long string variable");
-      XSRETURN_IV (0);
-     }
-  strncpy (the_value.short_string, SvPV_nolen(key), MAX_SHORT_STRING);
+  value_copy_str_rpad (&the_value, width, SvPV_nolen(key), ' ');
  }
- if (! var_add_value_label (var, &the_value, label) )
+ ok = var_add_value_label (var, &the_value, label);
+ value_destroy (&the_value, width);
+ if (!ok)
  {
    sv_setpv (errstr, "Something went wrong");
    XSRETURN_IV (0);