X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fvalue-variant.c;h=f332ccff11045ede52f5d274cb3ac0ff3c2df9cf;hb=d90a738745006b2696994bec344c160fca1f755b;hp=e8c342b7bb33ecc19089888342786fbde1b90b41;hpb=f062823782af5f98fecb1808136df3d565194698;p=pspp diff --git a/src/ui/gui/value-variant.c b/src/ui/gui/value-variant.c index e8c342b7bb..f332ccff11 100644 --- a/src/ui/gui/value-variant.c +++ b/src/ui/gui/value-variant.c @@ -28,7 +28,10 @@ enum IDX_DATA }; - +/* Returns a GVariant containing the data contained + in IN and WIDTH. The returned GVariant has a floating + reference. + */ GVariant * value_variant_new (const union value *in, int width) { @@ -37,35 +40,32 @@ value_variant_new (const union value *in, int width) if (width == 0) vv[IDX_DATA] = g_variant_new_double (in->f); - else if (width <= MAX_SHORT_STRING) - { - char xx[MAX_SHORT_STRING + 1]; - memset (xx, '\0', MAX_SHORT_STRING + 1); - memcpy (xx, in->short_string, width); - vv[IDX_DATA] = g_variant_new_bytestring (xx); - } else { gchar *q = xmalloc (width + 1); - memcpy (q, in->long_string, width); + memcpy (q, in->s, width); q[width] = '\0'; vv[IDX_DATA] = g_variant_new_from_data (G_VARIANT_TYPE_BYTESTRING, q, width + 1, FALSE, NULL, NULL); } - + return g_variant_new_tuple (vv, 2); } +/* Destroy the contents of VAL. Also unref V */ void value_destroy_from_variant (union value *val, GVariant *v) { GVariant *vwidth = g_variant_get_child_value (v, IDX_WIDTH); - gint32 width = g_variant_get_int32 (vwidth); + gint32 width = g_variant_get_int32 (vwidth); /* v is unreffed here */ g_variant_unref (vwidth); value_destroy (val, width); } +/* Fills VAL with the value data held in V. + When VAL is no longer required it must be destroyed using + value_destroy_from_variant. */ void value_variant_get (union value *val, GVariant *v) { @@ -80,12 +80,8 @@ value_variant_get (union value *val, GVariant *v) else { const gchar *data = g_variant_get_bytestring (vdata); - if (width <= MAX_SHORT_STRING) - memcpy (val->short_string, data, MAX_SHORT_STRING); - else - { - val->long_string = xmemdup (data, width); - } + size_t len = strlen (data); + val->s = xmemdup (data, MIN (width, len)); } g_variant_unref (vdata);