Re: Variant tests failing on big endian machines



Hi;

On 28 June 2015 at 22:09, Torsten Schoenfeld <kaffeetisch gmx de> wrote:
On 26.06.2015 17:54, Rafael dos Santos wrote:
const char * g_variant_classify (GVariant *value);
    PREINIT:
        GVariantClass vclass;
    CODE:
        vclass = g_variant_classify (value);
        RETVAL = (const char *) &((char) vclass);

GVariant.xs: In function ‘XS_Glib__Variant_classify’:
GVariant.xs:285:26: error: lvalue required as unary ‘&’ operand
  RETVAL = (const char *) &((char) vclass);
                          ^

Right.  How about this patch then?  Works on my (little-endian) machine.

(The "const char *" typemap copies the string, so it's OK to return
references to local variables.)

Can't we just return a char? The GVariantClass enumeration type only
contains the ASCII value of the *first* element of the type string.
You're supposed to switch on the value, and recurse if the type is a
complex one.

It's literally the equivalent of:

  return g_variant_get_type_string(variant)[0];

We can either do:

char g_variant_classify (GVariant *value)
    PREINIT:
        GVariantClass vclass;
    CODE:
        RETVAL = (char) g_variant_classify (value);
    OUTPUT:
        RETVAL

Or we could return a copy of the type string, limited to the first character:

char * g_variant_classify (GVariant *value)
    PREINIT:
        char *res;
    CODE:
         RETVAL = g_strndup (g_variant_type_string (variant), 1);
    OUTPUT
         RETVAL

If we still want to return a string.

Ciao,
 Emmanuele.

-- 
https://www.bassi.io
[ ] ebassi [ gmail com]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]