Re: [Vala] Using a C library



From: Justin Brown <justin brown fandingo org>
Cc: vala-list gnome org 
Sent: Wednesday, 22 April 2015, 7:05
Subject: Re: [Vala] Using a C library

I did have a question about the C sp_error enum. There are 36 values [0-35] in the C library, but there are 
some gaps such that the last value (SYSTEM_FAILURE) is 41, not 35. Every once in a while in the C enum a 
manual value is specified that jumps the integer a few places -- for example:

SP_ERROR_TRACK_NOT_PLAYABLE        = 3,
SP_ERROR_BAD_APPLICATION_KEY       = 5,

I've tried a variety of solutions. If I don't specify any integer values in Vala, then the codes don't 
respect the "jumps," meaning that SP_ERROR_BAD_APPLICATION_KEY == 4. If I specify the "jumps" or all the 
integers, then libspotify sp_error_message() complains about an invalid type in a string (not a segfault or 
compilation error). Why isn't Vala using the C values properly when not specified? Also, what's the 
possible >invalid type problem when specifying the integers? I don't feel like I'm understanding whether 
it's a >int-length (unsigned/long/etc.) issue or something else. Any idea why the Vala enum isn't pulling 
the values >specified in libspotfiy/api.h? 


This is because you are not using a VAPI for your binding, but a Vala program. 

As I understand it now, after some experimentation, a VAPI can be seen as a
translation file. It is used by the Vala compiler when it parses a Vala program
to validate the identifier exists, in this case the Vala enum you have created.

The second thing the Vala compiler uses the VAPI file for is to generate the C code
from the Vala program using the binding. So the cname CCode attribute will
translate the Vala program name for the enum to the C code name. The cprefix CCode
attribute will prepend SP_ERROR_ to all the enum values in the C code. What the
Vala compiler doesn't do is generate a C code translation of the enum in the VAPI
itself. This is because the C code is already there in the C header file of your
library. By placing the Vala enum in a VAPI you stop two versions of the enum
being generated in C code.

Hope that helps,

Al


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