Re: [PATCH 5/5] vala: new vapi generation machinery



On Mon, 2010-07-19 at 22:41 +0200, Víctor M. Jáquez L. wrote:
> The use of defines to keep some sort of API compatibility, but it
> breaks all
> the automatic introspection. And then the use of global variables as
> part of
> the API, it is not usual neither desirable, I reckon. Why not a
> factory
> function?
> 

Yesterday I've been talking with Simon, the guy who is hardly working on
improving introspection, about those issues.

One of the issue we talked about is replacing the #defines by functions.
At first I wasn't very up to do it, but I think it is better to do it
than loosing introspection, which could bring new developers.

Moreover, after googling for a while, I found a suggestion in linux
kernel development about using inline functions instead of defines: they
provide type-safety, and they are almost as efficient as defines (except
in some veeery rare cases).


Regarding the use of global variables, to be honest, when I designing
the new metadata key system, I didn't consider them. Instead, my
suggestion for plugin developers was going to declare you handled keys
as global, and then using get_metadata_key() function to initialize
them. Thus, we only need to call once that function, and then you can
use the keys along the code. A skeleton would be:

GrlKeyId GRL_METADATA_KEY_ARTIST;
GrlKeyId GRL_METADATA_KEY_ALBUM;

void f1 ()
{
 [...]
 // Use GRL_METADATA_KEY_ARTIST;
 [...]
}

void plugin_init()
{
   GRL_METADATA_KEY_ARTIST = get_metadata_key ("artist");
   GRL_METADATA_KEY_ALBUM = get_metadata_key ("album");
}


But then I found a way to have those variables already defined, so
sources can mostly remain unmodified. And that was I kept those
variables.

So if they're causing problems with introspection, my suggestion would
be removing them, and instead using the above approach. Note that it
requires a minimum change in sources: just defining global variables +
initializing them. If you choose the same names as current ones, no
other modification is required.


	J.A.




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