[Vala] Problems with virtual extern methods.

2009-05-31 Thread Yu Feng
Dear List,

I don't think virtual extern method is precisely defined in vala; the
code produced by 0.7.2 is kinda of weird with an undefined static _real
function.

I propose for virtual extern method we do the follows:
 
(1) assume both the accessor function and the _real function as extern
symbols in the produced ccode; 
(2) the vtable is initialized in the same way as non-extern methods; the
external _real cfunction is used to fill in the table;
(3) the accessor function is declared in the public header by valac, as
done for non-virtual members.

I made a patch for this proposal under

http://bugzilla.gnome.org/show_bug.cgi?id=584400

I am wondering if anyone wants to review it.

Regards,

Yu

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


Re: [Vala] Ownership and strings

2009-05-31 Thread Yu Feng
On Mon, 2009-06-01 at 04:04 +0200, Jiří Zárevúcky wrote:
> Dne 1. červen 2009 0:51 Yu Feng  napsal(a):
> > What aspects about string handling do you want to know though?
> >
> > For the memory management maybe you want to search for the keyword
> > `Compact' in the tutorial about the references and ownership aspect of
> > string and other compact types in vala.
> >
> > http://live.gnome.org/Vala/Tutorial
> >
> 
> Oh... for some reason I forgot to read that tutorial :-/ Final exams
> are obviously frying my brain...
> 
> > I wrote that paragraph and would like to learn some feedback from you if
> > it is clear or ambiguous.
> >
> 
> Quite clear, I understand the concept now. Thanks. :)

Thanks too!
> 
> Although there is a case I'm not really sure about...
> 
> class StringTest
> {
>   public string some_string
>   {
>   get {
>   var s = "fdfdf";
You can't create a initially unowned memory object. 
 
The string constants, like "fdfdf" are statically owned. In other words,
the owner is the program's global heap. As long as the program is in the
memory, they are not destroyed. The semantic analyzer deducts that `var
s' should be a strong reference. Now because string is a compact class,
"fdfdf" is copied with g_strcpy(as specified in glib-2.0.vapi:803) to
associate `var s' with a new object.

You are right member properties, aka member fields with getter and
setters are special. Although they are not declared as weak/unowned, the
reference you get by the implicit invocation of the getter is always
unowned. The reason for this default behavior is to be consistent with
older version and GTK conventions. This(important fact) is not mentioned
anywhere other than the mail-list or the bugzilla, as far as I know.

Now you want to return this strong reference within a method that
returns a weak reference. Because after the function has returned, the
local variable `var s' is out of scope, and the object `var s' pointing
to is destroyed. However the returned weak reference of this destroyed
object is passed out. The innocent caller of this method now receives an
invalid weak reference pointing to an ruined memory area. This is an
undefined behavior; vala compiler avoids this wrong thing at the
compilation stage.

For your example, these three alternatives should work:
class StringTest
{
public string some_string
{
get {
   /* A weak reference to a statically owned string */
return "fdfdf";
}
}
}

or 

class StringTest 
{
private string _some_string;
public string some_string
{
get {
/* plenty of them in vala*/
if(_some_string == null) {
_some_string = "dfdfd";
}
return _some_string;
}
}
}

or, a worst one:

class StringTest 
{
public string # some_string
{
get {
/* Declare the method as returning an owned(strong) reference to a string */
var s = "fdfdf";
return s
}
}
}

I hope this explanation clarifies it all.

- Yu
>   return s;
>   }
>   }
> }
> 
> 
> Now when I try to compile it, it gives me an error.
> "Local variable with strong reference used as return value and method
> return type has not been declared to transfer ownership".
> 
> Now it's fairly obvious this is some special property behavior (normal
> method works fine), but I don't really understand why does it differ.
> 
> On the other hand, it works when I change the variable to "unowned
> string". Then it compiles, but the string isn't owned by anything. Is
> it even allocated? If so, I guess the ownership is transferred to the
> first strong variable it is assigned to, right? Then, what happens
> when the variable goes out of scope without any strong assignment?
> 
> I would really appreciate a paragraph about how initially unowned
> non-reference-counted objects are handled. :) Thanks in advance.

BTW: there is no such initially unowned object in native VALA, no matter
it is compact or reference counted. I bet you heard about the name from
GObject/GTK. Refer to gobject-2.0.vapi:222. If an GLib object is an
instance of InitiallyUnowned, vala will sink it for you, then pass the
ownership to the first reference variable.



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


Re: [Vala] [PATCH] Tiny patch regarding gdk-x11 vapi.

2009-05-31 Thread Jürg Billeter
On Sat, 2009-05-30 at 18:30 -0300, Alexandre Moreira wrote:
> I am dealing with the new x11 binding and a few things (trying to port
> a System Tray manager to Vala) and I found that there is (what I
> believe to be) a tiny mistake in gdk-x11 vapi files.
> 
> Gdk.x11_screen_get_xscreen is returning a Gdk.Screen, where it should
> return a X.Screen, so I'm sending you the simplest patch possible:
> changing Gdk to X

Thanks for the patch. gdk-x11-2.0.vapi is - like most .vapi files -
generated from files in vapi/packages/ as indicated on the first line of
the .vapi file. This means that we should update the input files and
regenerate the .vapi, instead of directly modifying the .vapi file.

I've pushed updated bindings to git master, let me know if there are
more issues.

Jürg

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


Re: [Vala] [PATCH] Enhance X11 bindings and fix some cnames

2009-05-31 Thread Jürg Billeter
On Sun, 2009-05-31 at 14:48 -0400, Michael B. Trausch wrote:
> (Resending a modified patch, per juergbi.)
> 
> This patch fixes cnames for the X11 bindings and provides bindings for
> new methods which came from my original bindings that I wrote for
> AllTray earlier this year.

Thanks, pushed.

Jürg

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


[Vala] [PATCH] Enhance X11 bindings and fix some cnames

2009-05-31 Thread Michael B. Trausch

(Resending a modified patch, per juergbi.)

This patch fixes cnames for the X11 bindings and provides bindings for
new methods which came from my original bindings that I wrote for
AllTray earlier this year.

Signed-off-by: Michael B. Trausch 
---
 vapi/x11.vapi |  236
- 1 files
changed, 233 insertions(+), 3 deletions(-)

--- Mike

-- 
Fix the cause, not the symptom.
--- Steve Maguire
From 422f788fa199e8b86dd437a016381a7d3aa2b2b9 Mon Sep 17 00:00:00 2001
From: Michael B. Trausch 
Date: Sun, 31 May 2009 14:38:50 -0400
Subject: [PATCH] Enhance X11 bindings and fix some cnames

This patch fixes cnames for the X11 bindings and provides bindings for
new methods which came from my original bindings that I wrote for
AllTray earlier this year.

Signed-off-by: Michael B. Trausch 
---
 vapi/x11.vapi |  236 -
 1 files changed, 233 insertions(+), 3 deletions(-)

diff --git a/vapi/x11.vapi b/vapi/x11.vapi
index b7944f3..7f73d9c 100644
--- a/vapi/x11.vapi
+++ b/vapi/x11.vapi
@@ -22,87 +22,202 @@
 
 [CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "X11/Xlib.h,X11/Xatom.h,X11/Xutil.h")]
 namespace X {
+	// Note: must be called before opening a display or calling any other Xlib function,
+	// see http://tronche.com/gui/x/xlib/display/XInitThreads.html
+	[CCode (cname = "XInitThreads")]
+	public Status init_threads ();
+
 	[Compact]
 	[CCode (cname = "Display", ref_function = "", unref_function = "")]
 	public class Display {
+		[CCode (cname = "XOpenDisplay")]
+		public Display (string? name = null);
+
+		[CCode (cname = "XAllPlanes")]
+		public static ulong get_all_planes ();
+
 		[CCode (cname = "XAddToSaveSet")]
 		public int add_to_save_set (Window w);
+
 		[CCode (cname = "XAllowEvents")]
 		public int allow_events (int event_mode, int time);
+
+		[CCode (cname = "XBitmapBitOrder")]
+		public int bitmap_bit_order ();
+
+		[CCode (cname = "XBitmapUnit")]
+		public int bitmap_scanline_unit ();
+
+		[CCode (cname = "XBitmapPad")]
+		public int bitmap_scanline_padding ();
+
 		[CCode (cname = "XChangeProperty")]
 		public int change_property (Window w, Atom property, Atom type, int format, int mode, [CCode (array_length = false)] uchar[] data, int nelements);
+
 		[CCode (cname = "XChangeWindowAttributes")]
 		public int change_window_attributes (Window w, ulong valuemask, SetWindowAttributes attributes);
+
 		[CCode (cname = "XConfigureWindow")]
 		public int configure_window (Window w, uint value_mask, WindowChanges values);
+
 		[CCode (cname = "ConnectionNumber")]
 		public int connection_number ();
+
 		[CCode (cname = "DefaultRootWindow")]
 		public Window default_root_window ();
+
+		[CCode (cname = "XDefaultScreenOfDisplay")]
+		public unowned Screen default_screen ();
+
+		[CCode (cname = "XScreenOfDisplay")]
+		public unowned Screen screen_by_id (int screen_number);
+
 		[CCode (cname = "DisplayString")]
 		public string display_string ();
+
+		[CCode (cname = "XQLength")]
+		public int event_queue_length ();
+
 		[CCode (cname = "XFlush")]
 		public int flush ();
+
 		[CCode (cname = "XGetKeyboardMapping", array_length = false)]
 		public weak uint[] get_keyboard_mapping (uint first_keycode, int keycode_count, ref int keysyms_per_keycode_return);
+
 		[CCode (cname = "XGetModifierMapping")]
 		public ModifierKeymap get_modifier_mapping ();
+
 		[CCode (cname = "XGetSelectionOwner")]
 		public Window get_selection_owner (Atom selection);
+
 		[CCode (cname = "XGetWindowAttributes")]
 		public void get_window_attributes (Window w, out WindowAttributes window_attributes_return);
+
 		[CCode (cname = "XGetWindowProperty")]
 		public int get_window_property (Window w, Atom property, long long_offset, long long_length, bool delete, Atom req_type, out Atom actual_type_return, out int actual_format_return, out ulong nitems_return, out ulong bytes_after_return, out void* prop_return);
+
 		[CCode (cname = "XGrabButton")]
 		public int grab_button (uint button, uint modifiers, Window grab_window, bool owner_events, uint event_mask, int pointer_mode, int keyboard_mode, Window confine_to, uint cursor);
+
 		[CCode (cname = "XGrabPointer")]
 		public int grab_pointer (Window grab_window, bool owner_events, uint event_mask, int pointer_mode, int keyboard_mode, Window confine_to, uint cursor, int time);
+
 		[CCode (cname = "XGrabServer")]
 		public int grab_server ();
+
+		[CCode (cname = "XImageByteOrder")]
+		public int image_byte_order ();
+
 		[CCode (cname = "XInternAtom")]
 		public Atom intern_atom (string atom_name, bool only_if_exists);
+
 		[CCode (cname = "XInternAtoms")]
 		public void intern_atoms (string[] names, bool only_if_exists, [CCode (array_length = false)] Atom[] atoms_return);
+
+		[CCode (cname = "XInternalConnectionNumbers")]
+		public Status internal_connection_numbers (ref int[] fd_return);
+
 		[CCode (cname = "XDisplayKeycodes")]
 		

Re: [Vala] Writing to existing file

2009-05-31 Thread Joss 4

Jürg Billeter wrote:

On Sun, 2009-05-31 at 11:36 +0200, Joss 4 wrote:
  
What I want is to change this line 
var file_stream = file.create (FileCreateFlags.NONE, null); to
something like 

var file_stream = file.open (); 
var data_stream = new DataOutputStream (file_stream);


How can I accomplish this ?



Take a look at GLib.File.append_to[1][2].

Jürg

[1] http://valadoc.org/?pkg=gio-2.0&element=GLib.File.append_to
[2] http://library.gnome.org/devel/gio/stable/GFile.html#g-file-append-to 

Thank you Jurg,
I gave a little look at the links you post me, but I don't want only 
append data but update ; I mean seek , read data record and write.  
It's  up to me if set current file pointer to current or end.

Could I do this ? and how ?


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


Re: [Vala] Writing to existing file

2009-05-31 Thread Jürg Billeter
On Sun, 2009-05-31 at 11:36 +0200, Joss 4 wrote:
> What I want is to change this line 
> var file_stream = file.create (FileCreateFlags.NONE, null); to
> something like 
> 
> var file_stream = file.open (); 
> var data_stream = new DataOutputStream (file_stream);
> 
> How can I accomplish this ?

Take a look at GLib.File.append_to[1][2].

Jürg

[1] http://valadoc.org/?pkg=gio-2.0&element=GLib.File.append_to
[2] http://library.gnome.org/devel/gio/stable/GFile.html#g-file-append-to

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


[Vala] Writing to existing file

2009-05-31 Thread Joss 4

Hi , Guys

I am trying to write to an existing file but I found only a write to a 
new file in http://code.valaide.org


code like this :
var file = File.new_for_path ("samplefile.txt");
   {
   var file_stream = file.create (FileCreateFlags.NONE, null);

   if (file.query_exists (null)) {
   stdout.printf ("File successfully created.\n");
   }

   var data_stream = new DataOutputStream (file_stream);
   data_stream.put_string ("Hello, world", null);
   }
What I want is to change this line
var file_stream = file.create (FileCreateFlags.NONE, null); to something 
like


var file_stream = file.open ();
var data_stream = new DataOutputStream (file_stream);

How can I accomplish this ?


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