g-wrap-dev
[Top][All Lists]
Advanced

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

Re: functions which return enumerate types


From: Andreas Rottmann
Subject: Re: functions which return enumerate types
Date: Sun, 17 Sep 2006 12:51:15 +0200
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux)

John Steele Scott <address@hidden> writes:

> I have used g-wrap to wrap a function which returns an enumerate type. I
> wanted to test the return value like so:
>
>    (let ((status (cairo-status cr)))
>      (if (not (eqv?  status 'success))
>          (print-cairo-error status)
>          (display "OK\n")))
>
> This does not work correctly, because cairo-status is returning the
> integer value (i.e. 0), rather than the symbol (i.e. 'success).
>
> Is this a bug?
>
It's a "feature"; I agree that returning a symbol would be preferable,
but changing the behaviour might break code.

>>From looking at the C code generated by g-wrap, I discovered that there
> is a generated function which will convert from the integer
> value to the enumeration symbol, which allows a simple workaround:
>
>    (let ((status (enum-cairo-status-val->sym (cairo-status cr) #f)))
>      (if (not (eqv?  status 'success))
>          (print-cairo-error status)
>          (display "OK\n")))
>
> So that's doable, but it means I need to add an extra layer of wrapping to
> cairo-status to get the effect I want.
>
> By the way, what is the second argument to enum-*-val->sym for? I first
> assumed that it was for decoding bitset enums, but after some basic
> experimentation, this doesn't seem to be the case.
>
If there are more than one enum identifier with the same values, a
list of symbols is returned; e.g.:

enum { FOO = 1, BAR = 2, BAZ = 1};

would cause '(foo baz) to be returned for the value 2.

Regards, Rotty
-- 
Andreas Rottmann         | address@hidden      | address@hidden | address@hidden
http://yi.org/rotty      | GnuPG Key: http://yi.org/rotty/gpg.asc
Fingerprint              | C38A 39C5 16D7 B69F 33A3  6993 22C8 27F7 35A9 92E7
v2sw7MYChw5pr5OFma7u7Lw2m5g/l7Di6e6t5BSb7en6g3/5HZa2Xs6MSr1/2p7 hackerkey.com

Software Patents: Where do you want to stifle innovation today?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]