Re: [Vala] Documenting 'async' / WAS: Further speculations on couroutines, generators and threads : Emulating Go's goroutines and channels in Vala
On Fri, Jul 15, 2011 at 04:43:20PM -0500, Jim Peters wrote: Thanks. I've created a new page on the wiki trying to make the 'async' stuff easier to understand: http://live.gnome.org/Vala/AsyncMethods I've added the old GIO example (updated to shutdown nicely), a Generator example, and an example that starts a background thread. I'm not sure what the procedure is for documentation, or who owns what. This page could be merged with the Tutorial if someone thinks that is a good idea. If there is anything incorrect, I'm happy to fix it -- Thanks for the help. Anyway, it's better to either add that to the tutorial, or if it's a detailed/reference doc add it to the manual. Creating new pages will make the documentation more sparse. -- http://www.debian.org - The Universal Operating System ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] Documenting 'async' / WAS: Further speculations on couroutines, generators and threads : Emulating Go's goroutines and channels in Vala
On Fri, Jul 15, 2011 at 04:43:20PM -0500, Jim Peters wrote: Thanks. I've created a new page on the wiki trying to make the 'async' stuff easier to understand: http://live.gnome.org/Vala/AsyncMethods I've added the old GIO example (updated to shutdown nicely), a Generator example, and an example that starts a background thread. Forgot to say that those long examples should go in different pages and referenced under the examples. -- http://www.debian.org - The Universal Operating System ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] Documenting 'async' / WAS: Further speculations on couroutines, generators and threads : Emulating Go's goroutines and channels in Vala
Just a small suggestion for the async examples. It would be worth while for absolute beginners to add a line on how to compile the examples (with the --pkg gio-2.0 --pkg threads options etc,,, ) so that the examples can be compiled right away. Serge. On Sat, Jul 16, 2011 at 8:28 AM, Luca Bruno lethalma...@gmail.com wrote: On Fri, Jul 15, 2011 at 04:43:20PM -0500, Jim Peters wrote: Thanks. I've created a new page on the wiki trying to make the 'async' stuff easier to understand: http://live.gnome.org/Vala/AsyncMethods I've added the old GIO example (updated to shutdown nicely), a Generator example, and an example that starts a background thread. Forgot to say that those long examples should go in different pages and referenced under the examples. -- http://www.debian.org - The Universal Operating System ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
[Vala] support for elif
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi all: Have you considered to support elif in Vala as syntax sugar for else if ..., like in python? Thanks. - -- Nos leemos RASTER(Linux user #228804) ras...@rastersoft.com http://www.rastersoft.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk4haQQACgkQXEZvyfy1ha9f/wCfbk+TZPEHSjTNe8Aw3ul0ZmTC h3EAniHu6sxWCcDd8ufygV4jVVscBkza =+uoR -END PGP SIGNATURE- ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] support for elif
On Sat, Jul 16, 2011 at 12:33:40PM +0200, rastersoft wrote: Hi all: Have you considered to support elif in Vala as syntax sugar for else if ..., like in python? In python else if is syntax error. There's no gain in using elif. -- http://www.debian.org - The Universal Operating System ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] Documenting 'async' / WAS: Further speculations on couroutines, generators and threads : Emulating Go's goroutines and channels in Vala
Serge Hulne wrote: 2. Async methods have virtually no use outside the scope of event-driven GTK+ applications (except perhaps as a way to implement additional Vala features like Luca Bruno's generator, but at the cost of runtime-performance). I think people will find uses for async methods if they understand how they work. Certainly when I was working coding GUI applications in Java, there were many times I could have used this kind of method (e.g. doing a long sequence of database queries and then presenting the results on the GUI). Instead I had to code up long chains of ugly callbacks, or improvise other non-intuitive solutions. 3. There is always a way to write an equivalent program without async methods (with just ordinary function calls), except for applications with a graphical interface (GTK+ applications). 4. That a program avoiding async methods will always : - be more readable (simpler). - perform faster. Not true. It might be a lot more ugly without async depending on what is being coded. The speed cost of async is relative, i.e. if there is a lot more processing or waiting happening than callbacks then the callback cost won't be significant. In your word-parsing example, though, the callback cost is significant. Also, I think that local temporary variables probably can't be optimised away by the C compiler in async methods, because they are stored in a structure. So there may be a performance hit because of that. 5. That async methods are not about runtime performance, but exclusively about: - callbacks for graphical interfaces. - convenience (as an alternative to an ordinary function call, when it seems convenient to do so). 6. That async methods are not at all meant to provide a way to run ancillary tasks in the background, in order to gain runtime performance. You can implement an async method which creates a background thread and yields until the thread completes. Question about combining async and threads in the generator example: - Would it be possible to combine the last two examples for the following purpose: - Would it not be possible alternatively, for the generator, to call (slightly more indirectly) the feed() function in an independent thread, accumulate the last N results in a queue (N being a parameter to pass to the generator), so that the generator would still appear to return one result at time, in order, but in fact they would be pulled from the queue, while the feed function keeps running in the background feeding the queue (the queue would act as a buffer, storing the last N results of the feed() method). This doesn't need async methods at all. You could write a normal iterator which starts a thread and sets up an async queue and waits on one end whilst the thread fills it on the other end. You pay for thread startup time, plus any locking/synchronization overhead. You gain because of the buffering in the queue, plus the ability to spread the load over different cores. It is a trade-off which could go either way according to the specific case. If you want to spend all day optimising the Generator, you could also try implementing 'fast iterators' like in Apple Objective-C, where the generator code fills a buffer with N items, and then iterator runs through emptying it, and then they switch again. Jim -- Jim Peters (_)/=\~/_(_) j...@uazu.net (_) /=\ ~/_ (_) Uazú (_)/=\~/_(_)http:// in Peru(_) /=\ ~/_ (_)uazu.net ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] opengl and gtk+-3.0
Am Freitag, den 24.06.2011, 19:57 +0200 schrieb august: Is there any way right now to open a GL context up inside of a GTK+3 window using vala? Yes there is, but it's not as straightforward since nobody ported gtkglext yet. You should be able to create the context yourself using glx (not sure about systems without xorg though). I haven't done this myself yet so I'm afraid I cannot help you directly but you can take a look at the glchess source in the gnome-games repository http://git.gnome.org/browse/gnome-games/ to see an example (chess-view-3d.vala). Hope that helps. Thanks for the link. I finally got a chance to look at it. But, afaict, the glchess source you mention uses GTK+2's Drawable class and glXSwapBuffers to do some indirect drawing in GL. What I am after is a straight forward GL context that can easily be used in GTK+3. Is there no such thing (using vala or c)? thanks -august. ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
[Vala] valac-0.12 incorrectly (?) copies array element before passing it to struct function
Hi, if you compile and run the attached trivial test program, this will be the output: $ ./test element.data = 42, array[23].data = 0 $ If you look at the intermediate C-code, it's clear what happens: 70 foo_bar (element); 71 _tmp2_ = array[23]; 72 foo_bar (_tmp2_); 73 fprintf (stdout, element.data = %d, array[23].data = %d\n, element.data, array[23].data); So while a single variable will be directly passed (by reference) to the modifying function, an element of an array will first be copied to a temporary variable and a reference to that temporary variable will be passed along. Since only the temporary variable will be modified this won't have any affect on the array. Unless this is the intended behavior, I think vala shouldn't copy structs before passing them to some function when they are elements of an array. At the very least, the behavior should be consistent regardless whether it's an array of structs or a single struct. If this is already fixed or if I'm just too stupid to write correct code, just tell me so! Best regards Alexander Kurtz struct Foo { int data; public void bar(){ data = 42; } } void main(){ Foo element = { 0 }; Foo[] array = new Foo[100]; element.bar(); array[23].bar(); stdout.printf(element.data = %d, array[23].data = %d\n, element.data, array[23].data); } /* test.c generated by valac 0.12.1, the Vala compiler * generated from test.vala, do not modify */ #include glib.h #include glib-object.h #include string.h #include stdio.h #define TYPE_FOO (foo_get_type ()) typedef struct _Foo Foo; struct _Foo { gint data; }; GType foo_get_type (void) G_GNUC_CONST; Foo* foo_dup (const Foo* self); void foo_free (Foo* self); void foo_bar (Foo *self); void _vala_main (void); void foo_bar (Foo *self) { (*self).data = 42; } Foo* foo_dup (const Foo* self) { Foo* dup; dup = g_new0 (Foo, 1); memcpy (dup, self, sizeof (Foo)); return dup; } void foo_free (Foo* self) { g_free (self); } GType foo_get_type (void) { static volatile gsize foo_type_id__volatile = 0; if (g_once_init_enter (foo_type_id__volatile)) { GType foo_type_id; foo_type_id = g_boxed_type_register_static (Foo, (GBoxedCopyFunc) foo_dup, (GBoxedFreeFunc) foo_free); g_once_init_leave (foo_type_id__volatile, foo_type_id); } return foo_type_id__volatile; } void _vala_main (void) { Foo _tmp0_ = {0}; Foo element; Foo* _tmp1_ = NULL; Foo* array; gint array_length1; gint _array_size_; Foo _tmp2_; _tmp0_.data = 0; element = _tmp0_; _tmp1_ = g_new0 (Foo, 100); array = _tmp1_; array_length1 = 100; _array_size_ = 100; foo_bar (element); _tmp2_ = array[23]; foo_bar (_tmp2_); fprintf (stdout, element.data = %d, array[23].data = %d\n, element.data, array[23].data); array = (g_free (array), NULL); } int main (int argc, char ** argv) { g_type_init (); _vala_main (); return 0; } signature.asc Description: This is a digitally signed message part ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] valac-0.12 incorrectly (?) copies array element before passing it to struct function
On Sat, Jul 16, 2011 at 08:51:28PM +0200, Alexander Kurtz wrote: Hi, if you compile and run the attached trivial test program, this will be the output: $ ./test element.data = 42, array[23].data = 0 $ If you look at the intermediate C-code, it's clear what happens: 70foo_bar (element); 71_tmp2_ = array[23]; 72foo_bar (_tmp2_); 73fprintf (stdout, element.data = %d, array[23].data = %d\n, element.data, array[23].data); So while a single variable will be directly passed (by reference) to the modifying function, an element of an array will first be copied to a temporary variable and a reference to that temporary variable will be passed along. Since only the temporary variable will be modified this won't have any affect on the array. Unless this is the intended behavior, I think vala shouldn't copy structs before passing them to some function when they are elements of an array. At the very least, the behavior should be consistent regardless whether it's an array of structs or a single struct. If this is already fixed or if I'm just too stupid to write correct code, just tell me so! Please report a bug. -- http://www.debian.org - The Universal Operating System ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] valac-0.12 incorrectly (?) copies array element before passing it to struct function
On Sat, 2011-07-16 at 21:22 +0200, Luca Bruno wrote: Please report a bug. Done, thanks! https://bugzilla.gnome.org/show_bug.cgi?id=654753 Best regards Alexander Kurtz signature.asc Description: This is a digitally signed message part ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] [Bug] valac doesn't add #include gio/gio.h when the file doesn't include main
On Sat, Jul 16, 2011 at 10:21:01PM +0300, Tal Hadad wrote: Continue from my last mail about my tries for writing DBus client(for MPRIS 2), I've got a new problem, which I fixed easily. I have a main.vala, which contain the main function, and other file named PlayersList.vala . The PlayersList.vala contain a class, named PlayersList, which one of its field is a Vala interface(client) which defines a DBus proxy. I've added --pkg gio-2.0 to compile script, but still it doesn't add #include gio/gio.h to PlayersList.c, only for main.c! In result, when I put the PlayersList class in PlayersList.vala, it gives me this error: PlayersList.vala.c:57:51: error: unknown type name ‘GDBusConnection’ And when I put this class in main.vala instead, it compiles fine, for the reason I mentioned above ^^ My valac version 0.12.1, in debian testing(16/7/11) Please report a bug to bugzilla.gnome.org . -- http://www.debian.org - The Universal Operating System ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] Documenting 'async' / WAS: Further speculations on couroutines, generators and threads : Emulating Go's goroutines and channels in Vala
Luca Bruno wrote: I've created a new page on the wiki trying to make the 'async' stuff easier to understand: http://live.gnome.org/Vala/AsyncMethods Thanks for the help. Anyway, it's better to either add that to the tutorial, or if it's a detailed/reference doc add it to the manual. Creating new pages will make the documentation more sparse. I've moved the contents of Vala/AsyncMethods to Vala/Tutorial and Vala/AsyncSamples and deleted that page. AsyncSamples is now linked from the documentation page. I replaced the old Asynchronous Methods section in the tutorial after checking that everything it said was covered in the new text. The original GIO example has gone into the AsyncSamples page. The busy wait example seemed more confusing than helpful as the busy wait itself made no difference to the result. I hope this all looks okay -- Jim -- Jim Peters (_)/=\~/_(_) j...@uazu.net (_) /=\ ~/_ (_) Uazú (_)/=\~/_(_)http:// in Peru(_) /=\ ~/_ (_)uazu.net ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
[Vala] sqlite blob to GTK image
Hello, I'm not very experienced with Vala or GTK and I was trying to display a jpg picture from a sqlite db... thanks the the Internet I was able to find some code from different sources to get it to work: unowned uint8[] data = (uint8[]) stmt.column_blob(9); data.length = stmt.column_bytes(9); var data2 = data; FileUtils.set_data(temp.jpg, data2); Pixbuf pixbuf = new Pixbuf.from_file_at_scale(temp.jpg,320,240,true); var image1 = builder.get_object (image1) as Gtk.Image; image1.set_from_pixbuf(pixbuf); However I'm not happy to have to save the data to a file... to load it again to display it. (I consier this a workaround) I'm sure there is a more elegant way doing this, could someone please give me a hint or point me in the right direction on how to do that. Thanks, Markus PS: this is for a ham radio exam study program: https://github.com/alpharesearch/HEH2011 that is still very alpha ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] sqlite blob to GTK image
On Sat, 2011-07-16 at 21:11 -0400, Markus Schulz wrote: Hello, I'm not very experienced with Vala or GTK and I was trying to display a jpg picture from a sqlite db... thanks the the Internet I was able to find some code from different sources to get it to work: unowned uint8[] data = (uint8[]) stmt.column_blob(9); data.length = stmt.column_bytes(9); var data2 = data; FileUtils.set_data(temp.jpg, data2); Pixbuf pixbuf = new Pixbuf.from_file_at_scale(temp.jpg,320,240,true); var image1 = builder.get_object (image1) as Gtk.Image; image1.set_from_pixbuf(pixbuf); However I'm not happy to have to save the data to a file... to load it again to display it. (I consier this a workaround) I'm sure there is a more elegant way doing this, could someone please give me a hint or point me in the right direction on how to do that. You could use GLib.MemoryInputStream.from_data (it's in GIO) to load your data into a GLib.InputStream, then use Gdk.Pixbuf.from_stream to get your pixbuf. If performance is critical (and you're willing/able to write some bindings) it should be possible to wrap the sqlite3_blob struct in a GInputStream subclass. Actually, I think I'll look into doing that for SQLHeavy--thanks for the idea ;) -Evan ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
[Vala] Pango bindings - generated code contains errors?
Hello, Using something like Pango.Language.from_string(xx).get_sample_string(); results in undefined reference to `pango_language_free' I looked, sure enough that function doesn't exist, unless it is a recent addition. The docs on my system say it should not be freed. I got around it by doing Language * lang = Language.from_string(xx); return lang-get_sample_string(); Being a total newbie I'm not sure if I'm just doing something silly here or if this is a bug so I figured I'd ask here before filing. :-) If it is a bug, maybe it's related to commit 5d6c21cebd3c5a4fdbf50cfa780729ba863c2909 ? ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list