Re: [Vala] Interesting bug...



On Sat, Oct 17, 2009 at 3:31 PM, Magnus Therning <magnus therning org> wrote:
Here's a piece of code I'm having some problems with:

 int main( string[] args ) {
     var res = store_password_sync( NETWORK_PASSWORD, DEFAULT,
                                    "Vala Test key", "the password", 0 );

     return( 0 );
 }

When compiled to C it results in the following:

 gint _main (char** args, int args_length1) {
       gint result;
       GnomeKeyringResult res;
       res = gnome_keyring_store_password_sync
(gnome_keyring_NETWORK_PASSWORD, GNOME_KEYRING_DEFAULT, "Vala Test key",
"the password", 0, NULL);
       result = 0;
       return result;
 }

The problem is of course that "gnome_keyring_NETWORK_PASSWORD" isn't
declared
in the gnome-keyring.h header file, "GNOME_KEYRING_NETWORK_PASSWORD" is!

Looking at the relevant part of the vapi file I can't see why
NETWORK_PASSWORD
doesn't get expanded correctly, while DEFAULT does:

 [CCode (cheader_filename = "gnome-keyring.h")]
 public static GnomeKeyring.PasswordSchema NETWORK_PASSWORD;
 [CCode (cheader_filename = "gnome-keyring.h")]
 public const string DEFAULT;

is it due to one being declared 'const' and the other not?

Yes, constants are uppercase by convention. Variables are not, so Vala
prefixes them with the namespace in lower case. You can always force
the cname:

diff --git a/vapi/gnome-keyring-1.vapi b/vapi/gnome-keyring-1.vapi
index 7f34fc9..9e21a57 100644
--- a/vapi/gnome-keyring-1.vapi
+++ b/vapi/gnome-keyring-1.vapi
@@ -153,7 +153,7 @@ namespace GnomeKeyring {
        public delegate void OperationGetListCallback
(GnomeKeyring.Result result, GLib.List list);
        [CCode (cheader_filename = "gnome-keyring.h")]
        public delegate void OperationGetStringCallback
(GnomeKeyring.Result result, string str);
-       [CCode (cheader_filename = "gnome-keyring.h")]
+       [CCode (cname = "GNOME_KEYRING_NETWORK_PASSWORD",
cheader_filename = "gnome-keyring.h")]
        public static GnomeKeyring.PasswordSchema NETWORK_PASSWORD;
        [CCode (cheader_filename = "gnome-keyring.h")]
        public const string DEFAULT;

I also tried to use [CCode (lower_case_prefix = "GNOME_KEYRING_")] in
front of NETWORK_PASSWORD, but that didn't work.

regards
Philipp



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