Re: [Vala] Unregister a GType

2013-05-04 Thread PCMan
On Sun, May 5, 2013 at 2:15 AM, Igor Azevedo igor.azev...@neticle.pt wrote:
 2013/5/4 Luca Bruno lethalma...@gmail.com

 On Sat, May 4, 2013 at 6:29 PM, Igor Azevedo igor.azev...@neticle.ptwrote:

 Hello,

 I'm developing an application that dynamically loads plugins using
 GModule.
 Each of the plugins registers it's own GTypes but if I load, unload, and
 finally reload them I get some errors and the modules don't load properly.

 Errors are:

 (process:21259): GLib-GObject-WARNING **: cannot register existing type
 `NeticleInfinityModulesBaseBaseModule'

 I understand why this happens, I'm registering a GType that was already
 registered previously when I first loaded the plugin and even after
 unloading the module, the types remained registered, so it obviously
 fails.

 My question is if there is any way to unregister a GType so I can reload
 the plugin successfully?


 Are you doing this way?
 https://live.gnome.org/Vala/TypeModules
 https://live.gnome.org/Vala/TypeModuleSample


 My implementation was based on the first example you mentioned. Should I
 use TypeModule (like in the second example)?

 Thanks,
 Igor Azevedo

You're not able to unregister a GType no matter it's a dynamic one or not.
Once registered, it should persist until the program terminates.
If you use type module, the type module objects and the types they
registered should not be freed until program termination.

The underlying modules used inside your type module implementation can
be unloaded when they're not needed, but the GType registered persist.
When someone referenced that GType again and GObject type system finds
that the module is not loaded, it tries to load your type module.
So the module can be unloaded, but the GType it registered cannot.

Unfortunately, this is hard to do correctly, and GTypeModule will be
deprecated later.
I talked with a gtk+ developer in #gtk+ channel last time and I'm
informed that GTypeModule will be moved.

So, don't waste your time trying to do that. Once you register a new
GType inside the module, you'd better make it persist and never unload
it.
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Generated vapi file for a library not compilable.

2012-11-29 Thread PCMan
OK, I use a workaround and run a sed command to fix the incorrect generated
vapi file.
I use sed to prepend global:: to all wrong namespaced classes then it works.
Before the bug of vala gets handled, I have to use the workaround for now.
The problem is, how to integrate this fix with automake?
I need to run the command everytime after the vapi file is generated.
However, I cannot find a proper automake mechanism to do it automatically.
Any suggestions?


On Thu, Nov 29, 2012 at 1:40 PM, Axel FILMORE axel.film...@gmail.comwrote:

 On Thu, 29 Nov 2012 13:09:53 +0800
 PCMan pcman...@gmail.com wrote:

  Thanks for sharing.
  Manually editing the vapi file works for me too, but this is only a
  workaround.
  After regeneration of vapi files, the changes are gone and need to be
  done again.
  There must be something wrong in valac or my compiler settings.
  We need a way to generate correct vapi files from vala code directly.
  So, it seems that it's a bug in valac?

 I done like this in the library :

 http://bazaar.launchpad.net/~axel-filmore/valadesktop/spanel-lib/view/head:/src/PanelApplet.vala

 http://bazaar.launchpad.net/~axel-filmore/valadesktop/spanel-lib/view/head:/vapi/libspanel.vapi

 And like this in the application :

 http://bazaar.launchpad.net/~axel-filmore/valadesktop/spanel/view/head:/src/Applets/Weather/WeatherApplet.vala

 I don't use any namespace for Applets :)

 I don't have the technical explanation however.

 :P

___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Generated vapi file for a library not compilable.

2012-11-29 Thread PCMan
Thank you for the prompt reply.
I just fixed it with using a sed command to add the global:: prefix in a
all-local target of Makefile.am, which is very dirty!
I'll try what you said. I did not noticed that it can be the cause of the
problem.
Thank you very much!!!


On Thu, Nov 29, 2012 at 5:11 PM, Jürg Billeter j...@bitron.ch wrote:

 On Thu, 2012-11-29 at 10:13 +0800, PCMan wrote:
  All of the errors I got are like these:
VALAC  lxpanel2_vala.stamp
  lxpanel-applet.vapi:10.27-10.49: error: The type name
 `Lxpanel.AppletInfo'
  could not be found

 In lxpanel2.vala you have a class `Lxpanel' in the namespace `Lxpanel'.
 This means that the symbol `Lxpanel' will be resolved to the class
 `Lxpanel.Lxpanel' instead of the global namespace `Lxpanel' - when
 referenced from within the namespace `Lxpanel'.

 valac typically detects such conflicts and prefixes the name with
 `global::' in the generated .vapi file. However, as the conflict is not
 in the lxpanel-applet library, it's impossible for valac to detect that
 conflict when generating the .vapi file.

 I recommend you to rename the class `Lxpanel.Lxpanel' to something else
 such as `Lxpanel.Panel'.

 Regards,
 Jürg


___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Generated vapi file for a library not compilable.

2012-11-29 Thread PCMan
Really thank you , Jürg Billeter.
My problem is solved by renaming that class to avoid conflicts.
Mailing list is good.
I spent hours and hours trying to workaround this and did not find any clue.
I should have came here earlier.
Thanks!


On Thu, Nov 29, 2012 at 5:26 PM, PCMan pcman...@gmail.com wrote:

 Thank you for the prompt reply.
 I just fixed it with using a sed command to add the global:: prefix in a 
 all-local target of Makefile.am, which is very dirty!
 I'll try what you said. I did not noticed that it can be the cause of the 
 problem.
 Thank you very much!!!


 On Thu, Nov 29, 2012 at 5:11 PM, Jürg Billeter j...@bitron.ch wrote:

 On Thu, 2012-11-29 at 10:13 +0800, PCMan wrote:
  All of the errors I got are like these:
VALAC  lxpanel2_vala.stamp
  lxpanel-applet.vapi:10.27-10.49: error: The type name `Lxpanel.AppletInfo'
  could not be found

 In lxpanel2.vala you have a class `Lxpanel' in the namespace `Lxpanel'.
 This means that the symbol `Lxpanel' will be resolved to the class
 `Lxpanel.Lxpanel' instead of the global namespace `Lxpanel' - when
 referenced from within the namespace `Lxpanel'.

 valac typically detects such conflicts and prefixes the name with
 `global::' in the generated .vapi file. However, as the conflict is not
 in the lxpanel-applet library, it's impossible for valac to detect that
 conflict when generating the .vapi file.

 I recommend you to rename the class `Lxpanel.Lxpanel' to something else
 such as `Lxpanel.Panel'.

 Regards,
 Jürg


___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Is creating dbus interfaces in type modules (plugins) broken?

2012-11-29 Thread PCMan
Thank you for the info.
I'll remove dynamic type modules from my program.
It's a pity that the feature is going to be removed.
I think it's a wrong decision.
Without this features, we cannot unload large and unused modules and
its dependencies to save resources once it's no longer needed.
In C++, it's perfectly legal to unload a lib at runtime.
In C/GObject, it's no longer possible. This is the price we pay for
fake OOP support in C.
Really disappointed to hear that news.
Thanks anyway.

On Thu, Nov 29, 2012 at 5:39 PM, Jürg Billeter j...@bitron.ch wrote:
 On Thu, 2012-11-29 at 10:06 +0800, PCMan wrote:
 I tried to develop some type modules for my program.
 Everything works fine initially and [ModuleInit] registered GObject dynamic
 classes automagically as expected.
 However, after I move a previously working dbus interface to that type
 module, I got crashes.

 Support for dynamic types will likely be removed from a future GLib
 version¹, i.e., you will no longer be able to unload modules. Can you
 try whether you can fix the crashes by simply removing the [ModuleInit]
 attribute? Module loading should still work the same way, you just won't
 be able to unload it without restarting the process.

 If you want to keep using dynamic types and help finding the solution
 for this bug, can you please try the following?
   * Replace G_DEFINE_TYPE_EXTENDED in the generated .c file by
 G_DEFINE_DYNAMIC_TYPE_EXTENDED (for the UPower proxy)
   * Add upower_upower_proxy_register_type(type_module) to your
 plugin_init function right after the call to
 upower_upower_register_type

 Regards,
 Jürg

 ¹ http://blogs.gnome.org/mclasen/2012/10/08/gnome-summit-sunday/

___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Is creating dbus interfaces in type modules (plugins) broken?

2012-11-28 Thread PCMan
Hello,
I tried to develop some type modules for my program.
Everything works fine initially and [ModuleInit] registered GObject dynamic
classes automagically as expected.
However, after I move a previously working dbus interface to that type
module, I got crashes.

My source code is here:
http://lxde.git.sourceforge.net/git/gitweb.cgi?p=lxde/lxpanel2;a=summary

A google search lead me to a similar report from others:
https://mail.gnome.org/archives/vala-list/2012-September/msg00125.html

Is this a known bug? Or is there anyway to overcome this?
I like vala a lot and I don't want to rewrite the whole program in C again
just because some little problems.

Thanks in advance.
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Generated vapi file for a library not compilable.

2012-11-28 Thread PCMan
Hello,
I got another issue with vala.
I moved the core part of my program to a separate library, and let the main
program call that library.
The library itself compiles correctly.
However, the genrated vapi file is not usable by the main program.
Both parts are written in vala.
The generated vapi file looks like this.

When compiling the main program with --pkg my_vapi_file, I got errors.
The generated vapi file seems to have duplicated nested namespace for
static methods like this.

namespace Lxpanel {

class Applet : Object {
static Lxpanel.Applet? from_file(string...);
}
}

If I remove Lxpanel.Applet manually and just use Applet, it works.
I like vala a lot and want to continue use it for my project, so I hope
that someone knows how to fix it. Otherwise I may have to rewrite the
program in plain C/GObject, which is a pain. :-(

All of the errors I got are like these:
  VALAC  lxpanel2_vala.stamp
lxpanel-applet.vapi:10.27-10.49: error: The type name `Lxpanel.AppletInfo'
could not be found
public static GLib.Listweak Lxpanel.AppletInfo get_all_types ();
^^^
lxpanel-applet.vapi:13.10-13.35: error: The type name `Lxpanel.AppletInfo'
could not be found
public unowned Lxpanel.AppletInfo get_info ();
   ^^
lxpanel-applet.vapi:18.17-18.30: error: The type name `Lxpanel.Applet'
could not be found
public static Lxpanel.Applet? new_from_type_name (string type_name);
  ^^
lxpanel-applet.vapi:19.44-19.61: error: The type name `Lxpanel.AppletInfo'
could not be found
public static void register_applet_info (Lxpanel.AppletInfo info);
 ^^
lxpanel-applet.vapi:34.10-34.29: error: The type name
`Lxpanel.AppletModule' could not be found
public Lxpanel.AppletModule? module;
   
lxpanel-applet.vapi:40.10-40.23: error: The type name `Lxpanel.Applet'
could not be found
public Lxpanel.Applet? create_new ();
   ^^
lxpanel-applet.vapi:41.17-41.34: error: The type name `Lxpanel.AppletInfo'
could not be found
public static Lxpanel.AppletInfo? from_file (string applet_id, string
info_path);
  ^^
lxpanel-applet.vapi:74.24-74.37: error: The type name `Lxpanel.Button'
could not be found
public class Drawer : Lxpanel.Button {
  ^^
lxpanel-applet.vapi:75.13-75.25: error: The type name `Lxpanel.Popup' could
not be found
protected Lxpanel.Popup? popup;
  ^
lxpanel-applet.vapi:80.28-80.41: error: The type name `Lxpanel.Button'
could not be found
public class MenuButton : Lxpanel.Button {
  ^^
Compilation failed: 10 error(s), 0 warning(s)

Thank you guys!
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Generated vapi file for a library not compilable.

2012-11-28 Thread PCMan
Sorry that I forgot to paste the complete vapi file generated
It's here:
http://pastebin.com/v2j6CnXq

Thanks a lot!

On Thu, Nov 29, 2012 at 10:13 AM, PCMan pcman...@gmail.com wrote:

 Hello,
 I got another issue with vala.
 I moved the core part of my program to a separate library, and let the
 main program call that library.
 The library itself compiles correctly.
 However, the genrated vapi file is not usable by the main program.
 Both parts are written in vala.
 The generated vapi file looks like this.

 When compiling the main program with --pkg my_vapi_file, I got errors.
 The generated vapi file seems to have duplicated nested namespace for
 static methods like this.

 namespace Lxpanel {

 class Applet : Object {
 static Lxpanel.Applet? from_file(string...);
 }
 }

 If I remove Lxpanel.Applet manually and just use Applet, it works.
 I like vala a lot and want to continue use it for my project, so I hope
 that someone knows how to fix it. Otherwise I may have to rewrite the
 program in plain C/GObject, which is a pain. :-(

 All of the errors I got are like these:
   VALAC  lxpanel2_vala.stamp
 lxpanel-applet.vapi:10.27-10.49: error: The type name `Lxpanel.AppletInfo'
 could not be found
 public static GLib.Listweak Lxpanel.AppletInfo get_all_types ();
 ^^^
 lxpanel-applet.vapi:13.10-13.35: error: The type name
 `Lxpanel.AppletInfo' could not be found
 public unowned Lxpanel.AppletInfo get_info ();
^^
 lxpanel-applet.vapi:18.17-18.30: error: The type name `Lxpanel.Applet'
 could not be found
 public static Lxpanel.Applet? new_from_type_name (string type_name);
   ^^
 lxpanel-applet.vapi:19.44-19.61: error: The type name `Lxpanel.AppletInfo'
 could not be found
 public static void register_applet_info (Lxpanel.AppletInfo info);
  ^^
 lxpanel-applet.vapi:34.10-34.29: error: The type name
 `Lxpanel.AppletModule' could not be found
  public Lxpanel.AppletModule? module;

 lxpanel-applet.vapi:40.10-40.23: error: The type name `Lxpanel.Applet'
 could not be found
  public Lxpanel.Applet? create_new ();
^^
 lxpanel-applet.vapi:41.17-41.34: error: The type name `Lxpanel.AppletInfo'
 could not be found
  public static Lxpanel.AppletInfo? from_file (string applet_id, string
 info_path);
   ^^
 lxpanel-applet.vapi:74.24-74.37: error: The type name `Lxpanel.Button'
 could not be found
 public class Drawer : Lxpanel.Button {
   ^^
 lxpanel-applet.vapi:75.13-75.25: error: The type name `Lxpanel.Popup'
 could not be found
 protected Lxpanel.Popup? popup;
   ^
 lxpanel-applet.vapi:80.28-80.41: error: The type name `Lxpanel.Button'
 could not be found
 public class MenuButton : Lxpanel.Button {
   ^^
 Compilation failed: 10 error(s), 0 warning(s)

 Thank you guys!


___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Generated vapi file for a library not compilable.

2012-11-28 Thread PCMan
Thanks for sharing.
Manually editing the vapi file works for me too, but this is only a
workaround.
After regeneration of vapi files, the changes are gone and need to be done
again.
There must be something wrong in valac or my compiler settings.
We need a way to generate correct vapi files from vala code directly.
So, it seems that it's a bug in valac?


On Thu, Nov 29, 2012 at 12:07 PM, Axel FILMORE axel.film...@gmail.comwrote:

 On Thu, 29 Nov 2012 10:13:40 +0800
 PCMan pcman...@gmail.com wrote:

  Hello,
  I got another issue with vala.
  I moved the core part of my program to a separate library, and let
  the main program call that library.
  The library itself compiles correctly.
  However, the genrated vapi file is not usable by the main program.
  Both parts are written in vala.
  The generated vapi file looks like this.
 
  When compiling the main program with --pkg my_vapi_file, I got
  errors. The generated vapi file seems to have duplicated nested
  namespace for static methods like this.

 I had a similar problem doing this :

 namespace Panel {
 public class MenuApplet {
 }
 }

 public static AppletType register () {

 applet_type.id = typeof (MenuApplet); //  it's PanelMenuApplet
 return applet_type;
 }

 I found that the type *is not* MenuApplet but PanelMenuApplet,
 I just removed the namespaces for Panel Applet that fixed the problem :

 public class MenuApplet {
 }


 public static AppletType register () {

 applet_type.id = typeof (MenuApplet);
 return applet_type;
 }

 :)


___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] ftp library with vala

2012-08-13 Thread PCMan
Hello,
To the best of my knowledge, libcurl is the most comprehensive and reliable one.
I'd suggest using it. Since its APIs are very simple, it won't be too
hard to fix the binding.
The most parts of libcurl are controlled by flags defined with
#defines and enum values.
The real API functions are few.
You need to encapsulate the flags/option values, though.
Even doing it manually shouldn't be too difficult.
My vote is for libcurl and fortunately, it's well-documented.

Good luck!

On Mon, Aug 13, 2012 at 2:57 PM, tomw t...@ubilix.com wrote:
 Hi folks,

 what library would you recommend to be used with vala for providing ftp
 and ftp/TLS connectivity? Libcurl [1, 2] could be a candidate but is
 seems that the bindings are not up to date. Any suggestions?

 Thanks,

 [1] https://github.com/giuliopaci/ValaBindingsDevelopment/
 [2] http://curl.haxx.se/libcurl/

 --
 tomw t...@ubilix.com

 ___
 vala-list mailing list
 vala-list@gnome.org
 https://mail.gnome.org/mailman/listinfo/vala-list
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Get default terminal emulator?

2012-06-22 Thread PCMan
On Fri, Jun 22, 2012 at 6:46 PM, Thomas Jollans t...@jollybox.de wrote:
 Hi list,

 How do I get the user's default terminal emulator with GLib/GIO? I would
 assume it involves GLib.AppInfo in some way, but it's not as straightforward
 as that since there isn't really a MIME type associated with opening a
 terminal window as far as I know.

 Is there even a freedesktop-standard way of doing this? On GNOME, I imagine
 one could go into the depths of GSettings, but can that work for non Gnome
 users? On Debian/Ubuntu, running x-terminal-emulator will get you the system
 default, but that doesn't exist on other systems and disregards the user's
 preferences.

 Thanks
 Thomas
 ___

Unfortunately, no. They hard-coded a list of well-known terminal
emulators, and try them one by one.
This is what GAppInfo does in glib/gio. The worst thing is, there is
no config option for this.
The config value in gconf/gsettings does not change the behavior of GAppInfo.
The glib/gio devs know this, but they just did not fix it.
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Too many arguments in generated code

2012-04-05 Thread PCMan
On Thu, Apr 5, 2012 at 4:53 PM, tomw t...@ubilix.com wrote:

 Hi,

 I'm about to port the Skeltrack [1] skeleton tracker to Vala. So far
 everything works fine, except getting the actual joints from the joint
 list. The code in C is pretty straight forward:

 head = skeltrack_joint_list_get_joint (list,
   SKELTRACK_JOINT_ID_HEAD);

 which in Vala is:

 var head = JointList.get_joint(list, Skeltrack.JointId.HEAD);

 The generated code from Vala however looks like:

 skeltrack_joint_list_get_joint (list, SKELTRACK_JOINT_ID_HEAD, _tmp2_);
 head = _tmp2_;

 which makes the compiler complain that there are too many arguments.

 The respective part in the vapi looks like:

 [CCode (cheader_filename = skeltrack.h)]
[SimpleType]
public class JointList {
public static void free (Skeltrack.JointList list);
public static Skeltrack.Joint get_joint
 (Skeltrack.JointList list, Skeltrack.JointId id);
}


 Any clue why that happens?


Why not do it like this?

[CCode (cheader_filename = skeltrack.h,free_functionjoint_list_free)]
[SimpleType]
public class JointList {
public Skeltrack.Joint get_joint(Skeltrack.JointId id);
}

I think this is the proper way to do it.



 thanks,

 --tomw

 [1]  https://github.com/joaquimrocha/Skeltrack.git

 ___
 vala-list mailing list
 vala-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/vala-list

___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] How to use [ModuleInit] and GTypeModule?

2012-02-16 Thread PCMan
The sample here did not mention GTypeModule and did not contain
[ModuleInit], either.
https://live.gnome.org/Vala/TypeModules
Though its title is TypeModules, it did not show how to use GTypeModule.
I tried to google for some exmples and found that three is an undocumented
attribute [ModuleInit].
http://swik.net/GNOME/Planet+GNOME/Abderrahim+Kitouni:+Writing+Anjuta+plugins+in+Vala
How to use this correctly? Or should it be used?
Please help. Thank you all!
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Safe call operator

2012-02-01 Thread PCMan
This can induce hard to debug errors.
For example, something should raise an error or an execption now may return
0 only.
This return value might accidentally be used by other parts of the program.
When the project become larger, it's hard to trace this bug.

On Tue, Jan 31, 2012 at 11:27 PM, Artem Tarasov
lomerei...@googlemail.comwrote:

  As a starter, Java rejected that syntax.

 Yeah, but in Java at least a NullPointerException is thrown when null
 dereferencing occurs. In Vala the only option to provide null-safety
 is explicit checking for null after each method call in a chain.
 ___
 vala-list mailing list
 vala-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/vala-list

___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] How to define a const string array in Vala?

2011-12-21 Thread PCMan
I C language, I can do this:
const char* strs[] = {
  string1,
  string2,
  string3,
  NULL
};

In Vala, I cannot find a way to do the same.
Defining a string[] will cause copy of every constant string.
If I use unowned, like this:

unowned string strs[] = {
  ...
};

This did not generate the same result.
Every element of the string array gets copied.

So, If I need an array containing constant unowned strings, how to define
it in Vala?
Besides, in C language, we can write const char* const *.
In Vala, I cannot find equivalent stuff.
Help is needed.

Thanks a lot!
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Debugging

2011-12-16 Thread PCMan
I believe that he is talking about reading generated C code during
debugging.
When there is a crash, gdb listed generated C code rather than vala source.
As everyone knows, the C code generated by vala is not quite readable and
contains quite a lot of temporary variables, which makes debugging annoying
sometimes.
On Thu, Dec 15, 2011 at 6:16 PM, Levi Bard 
taktaktaktaktaktaktaktaktak...@gmail.com wrote:

  Is anyone working on improving the debugging experience with vala?

 In what respect? MonoDevelop's gdb addin (and I guess, by extension,
 many/most gdb frontends) Just Works for debugging Vala projects.
 ___
 vala-list mailing list
 vala-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/vala-list

___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Can adding new virtual method break ABI?

2011-12-16 Thread PCMan
If you need to do these things manually, then what's the point in using
vala? It's the job of compilers.
People who like to do the job of compilers manually should use GObject/C
instead.
Manually filling a virtual function table and calculate offset of
pointers are really of fun. lol
Creating some empty functions for padding is even easier and more readable
IMO.

On Wed, Dec 14, 2011 at 6:15 PM, Mikkel Kamstrup Erlandsen 
mikkel.kamst...@gmail.com wrote:

 On 12 December 2011 12:15, Jürg Billeter j...@bitron.ch wrote:
  On Mon, 2011-12-12 at 12:12 +0100, Luca Bruno wrote:
 
  On Mon, Dec 12, 2011 at 12:01 PM, Jürg Billeter j...@bitron.ch wrote:
  On Sun, 2011-12-11 at 11:34 +0100, Luca Bruno wrote:
   2011/12/11 Tal Hadad tal...@hotmail.com
  
This idea is based on the assumption that the size of
  XClass struct
doesn't matter and can be changed(Am I right?).
Also, how does the virtual method order is currently done
  by Vala? Is it
alphabetic or by the order of the decelerations?
   
  
   The ordering does not matter, the padding does.
 
  Ordering matters as well. Vala uses declaration order.
 
  We're talking about virtual methods, aren't we? There's no ABI break
  if the order of N pointers is exchanged.
 
  When a subclass overrides a virtual method, the class_init function uses
  the offset of the virtual function pointer. If that offset changes, the
  subclass will need to be recompiled to work again.

 Indeed.

 Would it make sense to a [CCode (vfunc_padding = 8)] to class
 declarations? This could then be decremented when new virtual
 functions are added (to the end of the class!).

 Cheers,
 Mikkel
 ___
 vala-list mailing list
 vala-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/vala-list

___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Queue failed to free elements during destruction

2011-11-16 Thread PCMan
Hi list,
Is it by design or it's a bug?
I noticed that data elements of Queue are not freed during destruction of
the queue.
For example:

[Compact]
class Data {
  public string data1;
  public string data2;
}

class Test {
  Test() {
  }

  private QueueData? queue;
}

The generated C code did not free Data in the queue in destructor of Test
class.
With ListData, all data are correctly freed.
I'm currently using vala 0.1.4.
Can anyone confirm this or tell me the correct way of using class/struct
with Queue?

Thanks
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Returning StringBuilder.str in functions causes unnecessary strdup().

2011-11-06 Thread PCMan
Hello,
I examined the code generated by vala and found a problem.
Vala does an unnecessary g_strdup() call if I return StringBuilder.str as
return value.
For example:

function string get_str() {
  var str = new StringBuilder();
  str.append(some stuff);
  return str.str
}

Ideally this should generate
return g_string_free(str, FALSE);

but currently vala returns something like
result = g_strdup(str.str);
g_string_free(str, TRUE);
return result;

Apparently, this causes a unnecessary strdup() call.
Is it possible to return g_string_free(str, FALSE) instead?
Maybe I missed some ownership transfer thing?

Thanks
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] How to get a const substring without copying?

2011-11-06 Thread PCMan
Hello,
It's me again.
In C language, sometimes we do this:
char* uri = ftp://140.112.172.1;;
char* ip = str + 6;  // get the IP part of the string without copying.

With vala, either string.substring() or string[start:end] needs copying.
Is it possible to do the above in vala? In trivial cases this causes no
difference.
However, for more performance critical code, this can reduce many
unnecessary malloc/free.
Is this possible in Vala anyways?
I cannot find any clues in the tutorials and the docs.

Thanks
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] How to generate inline C functions?

2011-11-05 Thread PCMan
Hi list,
Is there any CCode attribute to make the generated C function inline?
Or, is it possible to generate C macros instead of functions with vala?

For example:
class Test {
  inline public void func1() {
  }

  [Macro]
  public void func2() {
  }
}

The generated result:

inline void test_func1(Test* test) {
}

#define test_func2(test) { \
}

Another question is, is it possible to use bit-field in vala classes?
Like this:
class Test {
  private bool b1 : 1;
  private bool b2 : 1;
  private bool b3 : 1;
  private uint i1 : 4;
}

These questions are mostly for performance reason.
Otherwise I'm satisfied with vala.
These features are what I frequently used in C/C++ and I hope that I can
have them in Vala.

Thanks
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] How to ignore exceptions?

2011-10-30 Thread PCMan
Hi all,
I started using Vala recently and I'm confused by exception handling in
Vala.
I'm quite used to write C/GObject code and handles GError.
However, with exceptions, flow-control becomes quite different.
For example, I'm reading values from a KeyFile.
With C/glib, I can pass NULL GError* pointer to g_key_file_get_string() to
ignore any errors.
If the errors are not critical for my program, it's safe to ignore them all
like this.

str1 = g_key_file_get_string(kf, group, key, NULL);
str2 = g_key_file_get_string(kf, group, key, NULL);
str3 = g_key_file_get_string(kf, group, key, NULL);
if( !str1  !str2  !str3)
return FALSE;

With Vala, I cannot do this. If I use try/catch, things are totally
different.

try {
str1 = kf.get_string(group, key);
str2 = kf.get_string(group, key);
str3 = kf.get_string(group, key);
}
catch(KeyFile.Error error) {
// If anyone of the preceding calls fails, we get here.
// then I cannot continue getting the remaining strings from key file.
}
If get str1 fails, the excution jumps to catch() block, and I cannot
continue reading str2 and str3.

Of course I can do this:
try {
str1 = kf.get_string(group, key);
}
catch(KeyFile.Error error) {
}
try {
str2 = kf.get_string(group, key);
}
catch(KeyFile.Error error) {
}
try {
str3 = kf.get_string(group, key);
}
catch(KeyFile.Error error) {
}

Apparently, this looks even worse then its C/glib counterpart.
So, how to ignore the GErrors/vala excaptions anyways?

Thank you all.
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] How to ignore exceptions?

2011-10-30 Thread PCMan
Is it possible to suppress these compiler warnings and not turn off all of
the warnings at the same time?

On Sun, Oct 30, 2011 at 9:04 PM, JM interfl...@gmx.net wrote:

 just don't use the try-catch block:

  str1 = kf.get_string(group, key);
  str2 = kf.get_string(group, key);
  str3 = kf.get_string(group, key);

 This will give you a warning during compile but should be the thing you
 are looking for.

 jm.


 Am Sonntag, den 30.10.2011, 19:04 +0800 schrieb PCMan:
  Hi all,
  I started using Vala recently and I'm confused by exception handling in
  Vala.
  I'm quite used to write C/GObject code and handles GError.
  However, with exceptions, flow-control becomes quite different.
  For example, I'm reading values from a KeyFile.
  With C/glib, I can pass NULL GError* pointer to g_key_file_get_string()
 to
  ignore any errors.
  If the errors are not critical for my program, it's safe to ignore them
 all
  like this.
 
  str1 = g_key_file_get_string(kf, group, key, NULL);
  str2 = g_key_file_get_string(kf, group, key, NULL);
  str3 = g_key_file_get_string(kf, group, key, NULL);
  if( !str1  !str2  !str3)
  return FALSE;
 
  With Vala, I cannot do this. If I use try/catch, things are totally
  different.
 
  try {
  str1 = kf.get_string(group, key);
  str2 = kf.get_string(group, key);
  str3 = kf.get_string(group, key);
  }
  catch(KeyFile.Error error) {
  // If anyone of the preceding calls fails, we get here.
  // then I cannot continue getting the remaining strings from key
 file.
  }
  If get str1 fails, the excution jumps to catch() block, and I cannot
  continue reading str2 and str3.
 
  Of course I can do this:
  try {
  str1 = kf.get_string(group, key);
  }
  catch(KeyFile.Error error) {
  }
  try {
  str2 = kf.get_string(group, key);
  }
  catch(KeyFile.Error error) {
  }
  try {
  str3 = kf.get_string(group, key);
  }
  catch(KeyFile.Error error) {
  }
 
  Apparently, this looks even worse then its C/glib counterpart.
  So, how to ignore the GErrors/vala excaptions anyways?
 
  Thank you all.
  ___
  vala-list mailing list
  vala-list@gnome.org
  http://mail.gnome.org/mailman/listinfo/vala-list


 ___
 vala-list mailing list
 vala-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/vala-list

___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] How to mix vala code and C code in one automake-based project correctly?

2011-10-27 Thread PCMan
If I did not get it wrong, it seems to generate a single header file g
mpc-extras.h.
For what I want, I prefer generating file_a.[ch] for file_a.vala,
file_b.[ch] for file_b.vala, and file_c.[ch] for file_c.vala. Each vala file
can has its own generated *.c and *.h files.
Is this possible with autotools?

On Thu, Oct 27, 2011 at 3:25 PM, Qball Cow qb...@aggervaccae.nl wrote:

 Gmpc does what you want in it build system. So you might want to look at
 it. Http://git.musicpd.org it mixes vala,c and gob. Vala is handled by
 automake (used to do it with custom rules) only issue atm is parallel build.
 Basically:
 1. Write a binding file for your C code.
 2. Make vala generate and use one header file for your vala files. This can
 be done by the vala_args makefile argument (see gmpc src/makefile).

 Good luck, feel free to mail if you need help.

 R,

 Q
 On Oct 27, 2011 6:54 AM, PCMan pcman...@gmail.com wrote:

 Hello,
 I'm the developer of LXDE project and I started using Vala last night.
 Most parts of our existing code are written in pure C with or without
 GObject.
 Now I want to do further development in vala.
 To mix vala code with existing C code, I cannot find any good guide on the
 internet.
 Some existing guides are for writing vapi files to call C code in vala.
 Others telling you how to compile vala code with automake or valac.

 However, none of them solve my problems.
 I want to have a project developed with vala and C.
 I need to call the functions and GObjects in C files from vala.
 Also, I need to call vala generated objects and functions from my C code
 as
 well.
 I cannot use the valac -C --header .h trick as valac is called by
 automake.
 In addition, if I write something like this in Makefile.am, it does not
 work.

 bin_PROGRAMS=myprog
 myprog_SOURCES= \
  file1.c \
  file2.c \
  file3.vala \
  file4.vala \
  file5.c

 In this way, C code will be treated as vala, or vala code will be treated
 as
 C.
 Autotools do not seem to handle this well. What's the correct way to do
 it?

 For calling vala code from C code, a generated *.h file is needed.
 I tried adding --header xxx.h to VALA_FLAGS and it seemed to work.
 However, it generated a huge single header file for all *.vala files
 compiled rather than file1.h for file1.vala, file2.h for file2.vala, etc.
 How to generate separate *.h files for every single vala file with
 autotools?
 Or, if this is not supported by autotools, can CMake do this?

 I hope these problems can be solved easily so I can do future development
 in
 Vala rather than having to keep C/GObject.

 Thank you all

 ___
 vala-list mailing list
 vala-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/vala-list


___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] How to mix vala code and C code in one automake-based project correctly?

2011-10-27 Thread PCMan


 For C from Vala calls, feel free to borrow ideas from Spek:
 https://github.com/alexkay/spek

 Also check out Sampala: https://github.com/tadeboro/Sampala


and how about the opposite, calling vala from C?
Adding --header or -H to vala flags will only generate a single large header
file for all *.vala files being compiled.
Can I generate one *.h per *.vala file with automake?
I could not find a good and clean way to do it.
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Fail to generate C code for following vala code, is this a bug?

2010-03-27 Thread PCMan
Thanks you guys for the help.
I use my own modified version of gio.vapi and remove the *_finish
functions from those interfaces. Then, it works.
Although I don't know why it works. Thank you again.

On Sat, Mar 27, 2010 at 5:56 AM, Jan Hudec b...@ucw.cz wrote:
 On Sat, Mar 27, 2010 at 03:57:26 +0800, PCMan wrote:
  So, the problem is that the function return values are falsely
  marked as unowned in the VAPI. I reported a bug for it at
  https://bugzilla.gnome.org/show_bug.cgi?id=614044
 
  However, with Vala, how can I make vala methods return a newly
  allocated GList with all objects in it having increased ref_count?
  Automatic ref couting management in Vala is handy if you only use it
  in Vala but I find it difficult to make things right when interfacing
  with C code. I need to check the generated C code to see if it does
  what I really want. Any better guide for this? Already read Vala
  tutorial, but I still haven't get it.
  Just don't mark the list as unowned.

 But in the glib2 vapi, prototype of that API has 'unowned', but in C,
 the returned list should be freed by the caller. So how can I override
 this method in correct way?

 The bug in the vapi has to be fixed.

 --
                                                 Jan 'Bulb' Hudec b...@ucw.cz

___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] PolicyKit vapi for Vala?

2010-03-27 Thread PCMan
Hi all,
Another question, does anyone have a vapi file for Policykit?
I tried to generate one with vala-gen-introspect according to vala
tutorial but failed.
Running vala-gen-introspect results in error messages + crashes.
Have anyone tried this?
As policykit is used more and more in conjunction with dbus, this is a
must-have for vala.
Vala has perfect dbus support. So if vala has vapi for policykit, this
can greatly facilitate the utilization of dbus and policykit.
___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Fail to generate C code for following vala code, is this a bug?

2010-03-26 Thread PCMan
Hi list,
I tried to use Vala for the first time and the following code failed
to generate correct C code.
Is this a bug of vala or what's wrong with my code? (code is attached
to the end of this mail)

In addition, if I want to override a virtual function in a parent
class with the prototype like this:
public virtual unowned GLib.List get_volumes ();

How can I return an unowned GLib.List in my override function? I tried
and tried but nothing works.
This doesn't seem to be in Vala tutorial and I couldn't find
information on google.
The section in the tutorial related to weak ref and unowned didn't
talk about using this with GLib.List.
The tutorial for GLib.List doesn't mention this, either.
I have used gtk+/glib with C language for years and now I really want
to try Vala. Please help me.
Thank you very much!

--

using GLib;

namespace UDisks
{

public class Volume : GLib.Object, GLib.Volume
{
public Volume() {
}

public bool can_eject () {
return true;
}

public bool can_mount () {
return true;
}

public async bool eject (GLib.MountUnmountFlags flags,
GLib.Cancellable? cancellable) throws GLib.Error {
return true;
}

public bool eject_finish (GLib.AsyncResult _result) throws GLib.Error {
return true;
}

public async bool eject_with_operation (GLib.MountUnmountFlags
flags, GLib.MountOperation? mount_operation, GLib.Cancellable?
cancellable) throws GLib.Error {
return true;
}

public bool eject_with_operation_finish (GLib.AsyncResult _result)
throws GLib.Error {
return true;
}

public unowned string enumerate_identifiers () {
return ;
}

public unowned GLib.File get_activation_root (){
return null;
}

public unowned GLib.Drive get_drive () {
return null;
}

public unowned GLib.Icon get_icon () {
return null;
}

public unowned string get_identifier (string kind)
{
return ;
}

public unowned GLib.Mount get_mount () {
return null;
}

public unowned string get_name () {
return ;
}

public unowned string get_uuid () {
return ;
}

public bool mount_finish (GLib.AsyncResult _result) throws GLib.Error {
return true;
}

public void mount_fn (GLib.MountMountFlags flags,
GLib.MountOperation? mount_operation, GLib.Cancellable? cancellable,
GLib.AsyncReadyCallback callback) {

}

public bool should_automount () {
return false;
}
}

}
___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Fail to generate C code for following vala code, is this a bug?

2010-03-26 Thread PCMan
On Sat, Mar 27, 2010 at 3:06 AM, Julian Andres Klode j...@jak-linux.org wrote:
 On Sat, Mar 27, 2010 at 02:37:37AM +0800, PCMan wrote:
 On Sat, Mar 27, 2010 at 12:17 AM, Julian Andres Klode j...@jak-linux.org 
 wrote:
  Well, than f_finish() should probably not be there in the Volume
  interface; so I think that's a bug.
 So how can I fix this? Ship with a custom glib vapi file and remove
 *_finish from GVolume? Will this work? Or, can you make automatic
 generation of *_finish optional in Vala, or make the automatically
 generated *_finish override the abstract method in parent interface if
 its found?
 It's a bug: https://bugzilla.gnome.org/show_bug.cgi?id=614045


  For the second question, if I want to return a unowned GList, it has
  to be owned by the class and cannot be a local variable, right? Would
  you please add this to vala tutorial? I found it not documented and
  this behavior is not easy to figure out. In addition, this is not
  consistent with GObject with C. In C we can create a new GList and
  return it without the need to make it owned by anyone. The callee of
  the function is responsible to free the list.
 
  Because the list is unowned in can not be local, as it would go
  away once the function returns. If you want to return a locally
  created object, the return value can only be owned.
 This is quite different from C and C++ and is hard to understand for a
 C programmer I think.
 No, it's not. The difference is just that instead of manually freeing
 the returned pointer, the return values are marked as unowned/owned,
 and Vala then adds code to free owned values automatically.

 In short, if you have to free a return value in C, it is owned; if
 you don't have to free it, it is unowned.


 However, I don't get it. Let take GVolumeMonitor::get_volumes as  example.
 It returns unowned GLib.List. So if I want to implement that, I should
 create a list and make it owned by the object instance and then return
 it unowned. However this is slightly different from the behavior of
 glib in C. In C GVolumeMonitor::get_volumes returns a
 newly-allocated GList containing a list of GObjects. The caller is
 responsible to g_list_foreach(list, g_object_unref, NULL); and then
 g_list_free(list);
 So, the problem is that the function return values are falsely
 marked as unowned in the VAPI. I reported a bug for it at
 https://bugzilla.gnome.org/show_bug.cgi?id=614044

 However, with Vala, how can I make vala methods return a newly
 allocated GList with all objects in it having increased ref_count?
 Automatic ref couting management in Vala is handy if you only use it
 in Vala but I find it difficult to make things right when interfacing
 with C code. I need to check the generated C code to see if it does
 what I really want. Any better guide for this? Already read Vala
 tutorial, but I still haven't get it.
 Just don't mark the list as unowned.

But in the glib2 vapi, prototype of that API has 'unowned', but in C,
the returned list should be freed by the caller. So how can I override
this method in correct way?

 --
 Julian Andres Klode  - Debian Developer, Ubuntu Member

 See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/.

___
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list