[Vala] valac-0.12 incorrectly (?) copies array element before passing it to struct function

2011-07-16 Thread Alexander Kurtz
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

2011-07-16 Thread Alexander Kurtz
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


[Vala] Segfault when using a signal which takes a delegate as parameter: Known issue?

2011-04-17 Thread Alexander Kurtz
Hi,

I'm pretty sure this is a bug:

$ cat Test.vala 
class Test : Object {
delegate void MyDelegate();
signal void my_signal(MyDelegate d);
static void main(){
}
}
$ valac-0.12 Test.vala 
Segmentation fault
$ 

My questions are:
 1. Can you reproduce this behavior?
 2. Is this a known issue or shall I file a new bug?

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


[Vala] How can I download the Vala sources securely?

2011-04-13 Thread Alexander Kurtz
Hi,

how can I download the latest Vala sources securely? Neither the
FTP-Server[1] nor the GIT-Server[2] support HTTPS and download.gnome.org
presents some strange login screen[3] when queried via HTTPS.

There are some checksums available[4], but I couldn't find any
GPG-signed files. Or is there some way to directly authenticate the code
in git?

Best regards

Alexander Kurtz

[1] https://ftp.gnome.org/pub/gnome/sources/vala
[2] https://git.gnome.org/browse/vala/
[3] https://download.gnome.org/sources/vala/0.12/
[4] http://ftp.gnome.org/pub/GNOME/sources/vala/0.12/vala-0.12.0.sha256sum


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


[Vala] [PATCH] x11: Add XTest bindings

2011-04-11 Thread Alexander Kurtz
Hi everybody,

I've attached bindings for the XTest extension (aka libxtst) and a small
demonstration program which will start/pause your music player.

This is how it should work:

$ valac --pkg=x11 --pkg=xtst --vapidir=. Test.vala  ./Test 
sizeof(char) = 1, sizeof(int) = 4, sizeof(long) = 4
sizeof(X.KeyCode) = 1, sizeof(X.KeySym) = 4, sizeof(X.ID) = 4
Display :0.0 opened
String XF86AudioPlay has keysym 0x1008FF14
Keysym 0x1008FF14 has keycode 172
Keycode 172 pressed
Keycode 172 released
Display :0.0 flushed
$

Please note that this patch needs the patch I submitted earlier[1].

I'm looking forward to any comments/criticism/whatever! If everything is
ok, I would be happy if you could merge this into master.

Best regards

Alexander Kurtz

[1] http://mail.gnome.org/archives/vala-list/2011-April/msg00036.html
/* xtst.vapi
 *
 * Copyright (C) 2011  Alexander Kurtz
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Alexander Kurtz kurtz.a...@googlemail.com
 */


[CCode (cprefix = , lower_case_cprefix = , cheader_filename = X11/extensions/XTest.h)]
namespace X {
	class Test {
		[CCode (cname = XTestQueryExtension)]
		public static bool query_extension(Display display, out int event_base_return, out int error_base_return, out int major_version_return, out int minor_version_return);

		[CCode (cname = XTestCompareCursorWithWindow)]
		public static bool compare_cursor_with_window(Display display, Window window, Cursor cursor);

		[CCode (cname = XTestCompareCurrentCursorWithWindow)]
		public static bool compare_current_cursor_with_window(Display display, Window window);

		[CCode (cname = XTestFakeKeyEvent)]
		public static int fake_key_event(Display display, uint keycode, bool is_press, ulong delay);

		[CCode (cname = XTestFakeButtonEvent)]
		public static int fake_button_event(Display display, uint button, bool is_press, ulong delay);

		[CCode (cname = XTestFakeMotionEvent)]
		public static int fake_motion_event(Display display, int screen_number, int x, int y, ulong delay);
	
		[CCode (cname = XTestFakeRelativeMotionEvent)]
		public static int fake_relative_motion_event(Display display, int screen_number, int x, int y, ulong delay);

		[CCode (cname = XTestGrabControl)]
		public static int grab_control(Display display, bool impervious);

		[CCode (cname = XTestSetGContextOfGC)]
		public static void set_g_context_of_gc(GC gc, GContext gid);

		[CCode (cname = XTestSetVisualIDOfVisual)]
		public static void set_visual_id_of_visual(Visual visual, VisualID visualid);

		[CCode (cname = XTestDiscard)]
		public static Status discard(Display display);
	}
}
x11
class Test : Object {
	public static void main(){
		string keystr = XF86AudioPlay;

		stdout.printf(sizeof(char) = %lu, sizeof(int) = %lu, sizeof(long) = %lu\n,
			sizeof(char), sizeof(int), sizeof(long));

		stdout.printf(sizeof(X.KeyCode) = %lu, sizeof(X.KeySym) = %lu, sizeof(X.ID) = %lu\n,
			sizeof(X.KeyCode), sizeof(X.KeySym), sizeof(X.ID));

		X.Display display = new X.Display();
		stdout.printf(Display %s opened\n, display.display_string());

		X.KeySym keysym  = X.string_to_keysym(keystr);
		stdout.printf(String %s has keysym 0x%lX\n, keystr, keysym);

		X.KeyCode keycode = display.keysym_to_keycode(keysym);
		stdout.printf(Keysym 0x%lX has keycode %lu\n, keysym, keycode);

		X.Test.fake_key_event(display, (int) keycode, true, 0);
		stdout.printf(Keycode %lu pressed\n, keycode);
	
		X.Test.fake_key_event(display, (int) keycode, false, 0);
		stdout.printf(Keycode %lu released\n, keycode);

		display.flush();
		stdout.printf(Display %s flushed\n, display.display_string());
	}
}


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] [PATCH] x11: Add XTest bindings

2011-04-11 Thread Alexander Kurtz
Am Montag, den 11.04.2011, 15:19 +0200 schrieb Luca Bruno:
 Thanks for your contribution. I'd suggest you to report bugs into bugzilla
 so that patches don't get forgotten.

https://bugzilla.gnome.org/show_bug.cgi?id=647465

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] [PATCH] x11: add several type definitions from X.h

2011-04-11 Thread Alexander Kurtz
Am Donnerstag, den 07.04.2011, 12:51 +0200 schrieb Alexander Kurtz:
 I'm currently working on writing Vala bindings for the XTest extension.
 For that to work I need several simple type definitions
 from /usr/include/X11/X.h which aren't yet defined in x11.vapi.
 
 The attached patch adds these type definitions. Please include it in
 master if there are no objections.

https://bugzilla.gnome.org/show_bug.cgi?id=647464


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


[Vala] [PATCH] x11: add several type definitions from X.h

2011-04-07 Thread Alexander Kurtz
Hi,

I'm currently working on writing Vala bindings for the XTest extension.
For that to work I need several simple type definitions
from /usr/include/X11/X.h which aren't yet defined in x11.vapi.

The attached patch adds these type definitions. Please include it in
master if there are no objections.

Best regards

Alexander Kurtz
diff -Naur a/x11.vapi b/x11.vapi
--- a/x11.vapi	2011-04-06 09:02:54.0 +0200
+++ b/x11.vapi	2011-04-07 12:36:42.403108945 +0200
@@ -1,6 +1,7 @@
 /* x11.vapi
  *
  * Copyright (C) 2009  Jürg Billeter
+ * Copyright (C) 2011  Alexander Kurtz
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -16,8 +17,9 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
  *
- * Author:
+ * Authors:
  * 	Jürg Billeter j...@bitron.ch
+ * 	Alexander Kurtz kurtz.a...@googlemail.com
  */
 
 [CCode (cprefix = , lower_case_cprefix = , cheader_filename = X11/Xlib.h,X11/Xatom.h,X11/Xutil.h,X11/Xregion.h)]
@@ -327,6 +329,48 @@
 	public struct Pixmap : Drawable	{
 	}
 
+	[SimpleType]
+	[IntegerType (rank = 9)]
+	[CCode (cname = Mask)]
+	public struct Mask {
+	}
+
+	[SimpleType]
+	[IntegerType (rank = 9)]
+	[CCode (cname = VisualID)]
+	public struct VisualID {
+	}
+
+	[SimpleType]
+	[IntegerType (rank = 9)]
+	[CCode (cname = Time)]
+	public struct Time {
+	}
+
+	[SimpleType]
+	[IntegerType (rank = 9)]
+	[CCode (cname = Cursor)]
+	public struct Cursor {
+	}
+
+	[SimpleType]
+	[IntegerType (rank = 9)]
+	[CCode (cname = GContext)]
+	public struct GContext {
+	}
+
+	[SimpleType]
+	[IntegerType (rank = 9)]
+	[CCode (cname = KeySym)]
+	public struct KeySym {
+	}
+
+	[SimpleType]
+	[IntegerType (rank = 9)]
+	[CCode (cname = KeyCode)]	
+	public struct KeyCode {
+	}
+
 	public struct Visual {
 	}
 


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] [PATCH] add missing XStringToKeysym() function to x11.vapi

2011-04-04 Thread Alexander Kurtz
Am Montag, den 04.04.2011, 15:41 +0200 schrieb Luca Bruno:
 What about [CCode (array_length = false)] ulong[] ?

Damn, I really should learn how to read!

XGetKeyboardMapping()'s manpage says:

The X server arbitrarily chooses the keysyms_per_key‐
code_return value to be large enough to report all requested
symbols.  A special KeySym value of NoSymbol is used to fill
in unused elements for individual KeyCodes.  To free the stor‐
age returned by XGetKeyboardMapping, use XFree.

So the unowned keyword is actually the wrong part. Remove that ...

-   public unowned uint[] get_keyboard_mapping (uint first_keycode, 
int keycode_count, ref int keysyms_per_keycode_return);
+   public ulong[] get_keyboard_mapping (uchar first_keycode, int 
keycode_count, ref int keysyms_per_keycode_return);

... et voilà, no more segfaults when using an array:

$ valac --vapidir=b --pkg=x11 Test.vala  ./Test 
On this system sizeof(char) is 1 bytes, sizeof(int) is 4 bytes and 
sizeof(long) is 8 bytes.
The minimal keycode is 8, the maximal keycode is 255 which makes a 
total of 248 keycodes.
With this keyboard mapping there are 7 keysyms per keycode, detailed 
mapping follows:
   KeyCode   0 has KeySyms:0h0h0h0h 
   0h0h0h 
[...]
   KeyCode 247 has KeySyms:0h0h0h0h 
   0h0h0h


I've attached updated versions of the patch and the test program.

Best regards

Alexander Kurtz
diff -Naur a/x11.vapi b/x11.vapi
--- a/x11.vapi	2011-03-31 01:57:13.395022312 +0200
+++ b/x11.vapi	2011-04-04 18:01:03.456464821 +0200
@@ -88,7 +88,7 @@
 		public void force_screensaver (int mode);
 
 		[CCode (cname = XGetKeyboardMapping, array_length = false)]
-		public unowned uint[] get_keyboard_mapping (uint first_keycode, int keycode_count, ref int keysyms_per_keycode_return);
+		public ulong[] get_keyboard_mapping (uchar first_keycode, int keycode_count, ref int keysyms_per_keycode_return);
 
 		[CCode (cname = XGetModifierMapping)]
 		public ModifierKeymap get_modifier_mapping ();
@@ -133,7 +133,7 @@
 		public int keycodes (ref int min_keycodes_return, ref int max_keycodes_return);
 
 		[CCode (cname = XKeysymToKeycode)]
-		public int keysym_to_keycode (uint keysym);
+		public uchar keysym_to_keycode (ulong keysym);
 
 		[CCode (cname = XLastKnownRequestProcessed)]
 		public ulong last_known_request_processed ();
class Test : Object {
	public static void main(){
		int min_keycodes_return = 0;
		int max_keycodes_return = 0;
		int keysyms_per_keycode_return = 0;
		X.Display display = new X.Display();

		stdout.printf(On this system sizeof(char) is %lu bytes, sizeof(int) is %lu bytes and sizeof(long) is %lu bytes.\n, sizeof(char), sizeof(int), sizeof(long));

		display.keycodes(ref min_keycodes_return, ref max_keycodes_return);
		int keycode_count = max_keycodes_return - min_keycodes_return + 1;

		stdout.printf(The minimal keycode is %d, the maximal keycode is %d which makes a total of %d keycodes.\n, min_keycodes_return, max_keycodes_return, keycode_count);

		ulong[] mapping = display.get_keyboard_mapping((uchar) min_keycodes_return, keycode_count, ref keysyms_per_keycode_return);
		
		stdout.printf(With this keyboard mapping there are %d keysyms per keycode, detailed mapping follows:\n, keysyms_per_keycode_return);

		for(int i = 0; i  keycode_count; i++){
			stdout.printf(   KeyCode %3d has KeySyms: , i);
			for(int j = 0; j  keysyms_per_keycode_return; j++){
stdout.printf(%8lXh , mapping[i * keysyms_per_keycode_return + j]);
			}
			stdout.printf(\n);
		}
	}
}


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] [PATCH] add missing XStringToKeysym() function to x11.vapi

2011-04-04 Thread Alexander Kurtz
Am Montag, den 04.04.2011, 20:24 +0200 schrieb Luca Bruno:
 Pushed thanks.

Great, thank you!

Now on to the main task: The attached patch adds the XKeycodeToKeysym(),
XStringToKeysym(), XKeysymToString and XConvertCase() functions. I've
also written and attached a small test program. What do you think?

Best regards

Alexander Kurtz
diff -Naur a/x11.vapi b/x11.vapi
--- a/x11.vapi	2011-04-04 18:01:03.456464821 +0200
+++ b/x11.vapi	2011-04-04 20:10:21.002671803 +0200
@@ -135,6 +135,9 @@
 		[CCode (cname = XKeysymToKeycode)]
 		public uchar keysym_to_keycode (ulong keysym);
 
+		[CCode (cname = XKeycodeToKeysym)]
+		public ulong keycode_to_keysym (uchar keycode, int index);
+
 		[CCode (cname = XLastKnownRequestProcessed)]
 		public ulong last_known_request_processed ();
 
@@ -948,5 +951,14 @@
 	public const uint XK_Scroll_Lock;
 	public const uint XK_Super_L;
 	public const uint XK_Super_R;
+
+	[CCode (cname = XStringToKeysym)]
+	public ulong string_to_keysym (string key);
+
+	[CCode (cname = XKeysymToString)]
+	public unowned string keysym_to_string (ulong keysym);
+
+	[CCode (cname = XConvertCase)]
+	public void convert_case (ulong keysym, out ulong lower_return, out ulong upper_return);
 }
 
class XFooToBarTest : Object {
	public static void main(){
		string keystr =a;
		ulong keysym = 0x0061;
		uchar keycode = 0x0026;
		ulong lower;
		ulong upper;

		X.Display display = new X.Display();

		X.convert_case(keysym, out lower, out upper);

		stdout.printf(string %s has keysym %lu\n,
			keystr, X.string_to_keysym(keystr));

		stdout.printf(keysym %lu has string %s\n,
			keysym, X.keysym_to_string(keysym));

		stdout.printf(keysym %lu has keycode %d\n,
			keysym, display.keysym_to_keycode(keysym));

		stdout.printf(keycode %d has keysym %lu\n,
			keycode, display.keycode_to_keysym(keycode, 0));

		stdout.printf(keysym %lu (%s) has lower case keysm %lu (%s)\n,
			keysym, X.keysym_to_string(keysym),
			lower, X.keysym_to_string(lower));

		stdout.printf(keysym %lu (%s) has upper case keysm %lu (%s)\n,
			keysym, X.keysym_to_string(keysym),
			upper, X.keysym_to_string(upper));
	}
}


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] [PATCH] add missing XStringToKeysym() function to x11.vapi

2011-04-04 Thread Alexander Kurtz
Am Montag, den 04.04.2011, 22:37 +0200 schrieb Luca Bruno:
 Pushed thanks.

It's just great how easy  quick problems can be fixed in cooperation
with an active upstream! Expect further patches soon...

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


[Vala] [PATCH] fix double free in x11.vapi

2011-04-04 Thread Alexander Kurtz
Hi,

This works with Vala 0.10.4:

$ cat test.vala 
void main(){
X.Display disp = new X.Display();
stdout.printf(%s\n, disp.display_string());
}
$ valac --pkg=x11 test.vala  ./test 
:0.0 
$

This doesn't work with Vala 0.10.4:

$ cat test.vala 
void main(){
X.Display disp = new X.Display();
stdout.printf(%s\n, disp.display_string());
stdout.printf(%s\n, disp.display_string());
}
$ valac --pkg=x11 test.vala  ./test 
:0.0

*** glibc detected *** ./test: double free or corruption (fasttop): 
0x08509958 ***
[...]

The attached patch fixes the issue for me. Please include it in master
if you have no objections.

Best regards

Alexander Kurtz
diff -Naur a/x11.vapi b/x11.vapi
--- a/x11.vapi	2011-04-04 22:49:53.0 +0200
+++ b/x11.vapi	2011-04-04 20:13:27.0 +0200
@@ -76,7 +76,7 @@
 		public unowned Screen screen_by_id (int screen_number);
 
 		[CCode (cname = DisplayString)]
-		public string display_string ();
+		public unowned string display_string ();
 
 		[CCode (cname = XQLength)]
 		public int event_queue_length ();


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] [PATCH] add missing XStringToKeysym() function to x11.vapi

2011-04-01 Thread Alexander Kurtz
Am Donnerstag, den 31.03.2011, 08:10 +0200 schrieb Luca Bruno: 
 Looks ok to me as far as you tested those changes.

Ok, here we go:

Looking at the header for the X11 protocol[1] reveals two things which
are important for Vala's X11 bindings:

 a) Since x11.vapi is a client library it must not define _XSERVER64
(lines 59-61). As a consquence, XID is defined to be an unsigned 
long (line 66). Therefore KeySym is also defined to be an unsigned 
long (line 106).

 b) KeyCode is defined to be an unsigned char (line 108).

This can easily be verified by a simple test program (source attached): 

$ uname -m; gcc -lX11 print_sizes.c -o print_sizes; ./print_sizes
x86_64
sizeof(XID)=8, sizeof(KeySym)=8, sizeof(KeyCode)=1
$ 

The attached patch fixes x11.vapi which wrongly uses uint for KeySym and
int for KeyCode. There aren't many changes since most functions specify
the types of their parameters directly instead of using the aliases.

The patch also fixes another bug: XGetKeyboardMapping() returns a
pointer to an array whose size is determined by the parameters
keycode_count and the (output parameter) keysyms_per_keycode_return. It
doesn't return a valid Vala array. Trying to assign it's return value to
such an array will result in a segfault.

The attached test program will demonstrate that everything works
correctly now. If you don't have any objections, please merge the patch
into master. After that I will submit another patch adding all
XFooToBar() functions.

Best regards

Alexander Kurtz

[1] http://cgit.freedesktop.org/xorg/proto/xproto/tree/X.h
[2] http://cgit.freedesktop.org/xorg/lib/libX11/tree/include/X11/Xlib.h 
diff -Naur a/x11.vapi b/x11.vapi
--- a/x11.vapi	2011-03-31 01:57:13.395022312 +0200
+++ b/x11.vapi	2011-04-01 16:46:51.723714836 +0200
@@ -88,7 +88,7 @@
 		public void force_screensaver (int mode);
 
 		[CCode (cname = XGetKeyboardMapping, array_length = false)]
-		public unowned uint[] get_keyboard_mapping (uint first_keycode, int keycode_count, ref int keysyms_per_keycode_return);
+		public unowned ulong* get_keyboard_mapping (uchar first_keycode, int keycode_count, ref int keysyms_per_keycode_return);
 
 		[CCode (cname = XGetModifierMapping)]
 		public ModifierKeymap get_modifier_mapping ();
@@ -133,7 +133,7 @@
 		public int keycodes (ref int min_keycodes_return, ref int max_keycodes_return);
 
 		[CCode (cname = XKeysymToKeycode)]
-		public int keysym_to_keycode (uint keysym);
+		public uchar keysym_to_keycode (ulong keysym);
 
 		[CCode (cname = XLastKnownRequestProcessed)]
 		public ulong last_known_request_processed ();
#include stdio.h
#include X11/X.h

int main(int argc, char **argv){
	printf(sizeof(XID)=%d, sizeof(KeySym)=%d, sizeof(KeyCode)=%d\n, sizeof(XID), sizeof(KeySym), sizeof(KeyCode));
}
class Test : Object {
	public static void main(){
		int min_keycodes_return = 0;
		int max_keycodes_return = 0;
		int keysyms_per_keycode_return = 0;
		X.Display display = new X.Display();

		stdout.printf(On this system sizeof(char) is %lu bytes, sizeof(int) is %lu bytes and sizeof(long) is %lu bytes.\n, sizeof(char), sizeof(int), sizeof(long));

		display.keycodes(ref min_keycodes_return, ref max_keycodes_return);
		int keycode_count = max_keycodes_return - min_keycodes_return + 1;

		stdout.printf(The minimal keycode is %d, the maximal keycode is %d which makes a total of %d keycodes.\n, min_keycodes_return, max_keycodes_return, keycode_count);

		ulong* mapping = display.get_keyboard_mapping((uchar) min_keycodes_return, keycode_count, ref keysyms_per_keycode_return);

		stdout.printf(With this keyboard mapping there are %d keysyms per keycode, detailed mapping follows:\n, keysyms_per_keycode_return);

		for(int i = 0; i  keycode_count; i++){
			stdout.printf(   KeyCode %3d has KeySyms: , i);
			for(int j = 0; j  keysyms_per_keycode_return; j++){
stdout.printf(%8lXh , mapping[i * keysyms_per_keycode_return + j]);
			}
			stdout.printf(\n);
		}
	}
}


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


[Vala] [PATCH] fix typo in x11.vapi

2011-03-30 Thread Alexander Kurtz
Hi,

This patch fixes a small typo in the X11 bindings of Vala 0.10.4:

--- x11.vapi.orig   2011-03-14 13:56:11.087734497 +0100
+++ x11.vapi2011-03-14 13:57:16.400729669 +0100
@@ -202,7 +202,7 @@
public int select_input (Window w, long event_mask);
 
[CCode (cname = XSendEvent)]
-   public void send_event (Window w, bool prpagate, long 
event_mask, ref Event event_send);
+   public void send_event (Window w, bool propagate, long 
event_mask, ref Event event_send);
 
[CCode (cname = XSetCloseDownMode)]
public void set_close_down_mode (int close_mode);

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] [PATCH] add missing XStringToKeysym() function to x11.vapi

2011-03-30 Thread Alexander Kurtz
Am Mittwoch, den 30.03.2011, 21:43 +0200 schrieb Luca Bruno:
 I'd rather put that static function outside Display, what do you think?

IMHO XStringToKeysym() is somewhat similar to XKeysymToKeycode() which
(of course) is inside Display. Consider this example code:

Display display = new X.Display();
int keysym = display.string_to_keysym(keystr);
int keycode = display.keysym_to_keycode(keysym);

So, in total I would consider it more intuitive if all these XFooToBar()
functions would be in the same place (I plan to also submit a patch
which would add the other functions).

However, it's not that important after all, just do what you think is
best!

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] [PATCH] add missing XStringToKeysym() function to x11.vapi

2011-03-30 Thread Alexander Kurtz
Am Mittwoch, den 30.03.2011, 23:01 +0200 schrieb Luca Bruno:
 Let's say Keysym was an enum (it's not the case because there's a really 
 huge number of keysyms starting with XK_).
 In this scenario string_to_keysym should have been an instance method of
 this Keysym enum. Therefore it's a method that _only_ belongs to keysyms and
 has nothing to do with Display, while the keycode is tied to the Display.

I am almost finished with adding all XFooToBar() functions, but I think
I found another bug:

The current x11 bindings say:
KeySym == uint
KeyCode == int

However, the header files say something else:

$ grep -r typedef /usr/include/X11/ | grep 'KeySym;'
/usr/include/X11/X.h:typedef XID KeySym;
$ grep -r typedef /usr/include/X11/ | grep 'XID;'
/usr/include/X11/Xdefs.h:typedef unsigned long XID;
/usr/include/X11/Xdefs.h:typedef CARD32 XID;
/usr/include/X11/X.h:typedef unsigned long XID;
/usr/include/X11/X.h:typedef CARD32 XID;
$ grep -r typedef /usr/include/X11/ | grep 'KeyCode;'
/usr/include/X11/X.h:typedef unsigned char KeyCode;
$ 

According to the header files this would be correct:

KeySym == ulong
KeyCode == uchar

If I use the old definitions, I get segfaults when using XConvertCase().
With the new definitions everything works fine.

Can you confirm that the new definitions are correct before I submit my
final patch?

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


[Vala] x11-improvements 1/4: fix typo in x11.vapi

2011-03-14 Thread Alexander Kurtz
Hi,

This patch fixes a small typo in the X11 bindings of Vala 0.10.4:

--- x11.vapi.orig   2011-03-14 13:56:11.087734497 +0100
+++ x11.vapi2011-03-14 13:57:16.400729669 +0100
@@ -202,7 +202,7 @@
public int select_input (Window w, long event_mask);
 
[CCode (cname = XSendEvent)]
-   public void send_event (Window w, bool prpagate, long 
event_mask, ref Event event_send);
+   public void send_event (Window w, bool propagate, long 
event_mask, ref Event event_send);
 
[CCode (cname = XSetCloseDownMode)]
public void set_close_down_mode (int close_mode);

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


[Vala] x11-improvements 2/4: fix use-after-free in x11.vapi

2011-03-14 Thread Alexander Kurtz
Hi,

This works with Vala 0.10.4:

$ cat test.vala 
void main(){
X.Display disp = new X.Display();
stdout.printf(%s\n, disp.display_string());
}
$ valac --pkg=x11 test.vala  ./test 
:0.0 
$

This doesn't work with Vala 0.10.4:

$ cat test.vala 
void main(){
X.Display disp = new X.Display();
stdout.printf(%s\n, disp.display_string());
stdout.printf(%s\n, disp.display_string());
}
$ valac --pkg=x11 test.vala  ./test 
:0.0

*** glibc detected *** ./test: double free or corruption (fasttop): 0x08509958 
***
[...]

This patch fixes the issues for me:

--- x11.vapi.orig   2011-03-14 14:07:46.731734844 +0100
+++ x11.vapi2011-03-14 14:08:04.103728858 +0100
@@ -76,7 +76,7 @@
public unowned Screen screen_by_id (int screen_number);
 
[CCode (cname = DisplayString)]
-   public string display_string ();
+   public unowned string display_string ();
 
[CCode (cname = XQLength)]
public int event_queue_length ();

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


[Vala] x11-improvements 3/4: add missing function to x11.vapi

2011-03-14 Thread Alexander Kurtz
Hi,

This patch adds a missing function to the X11 bindings of Vala 0.10.4:

--- x11.vapi.orig   2011-03-14 14:09:53.640728903 +0100
+++ x11.vapi2011-03-14 14:14:03.956717821 +0100
@@ -135,6 +135,9 @@
[CCode (cname = XKeysymToKeycode)]
public int keysym_to_keycode (uint keysym);
 
+   [CCode (cname = XStringToKeysym)]
+   public static int string_to_keysym (string key);
+
[CCode (cname = XLastKnownRequestProcessed)]
public ulong last_known_request_processed ();
 
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


[Vala] x11-improvements 4/4: add missing XTest bindings

2011-03-14 Thread Alexander Kurtz
Hi,

Since I didn't find any Vala bindings for the XTest extension, I tried
writing them myself. The results are attached. I have also attached a
small demonstration program which will start/pause your music player.

This is how it should work:

$ valac --vapidir=. --pkg=x11 --pkg=xtst demo.vala  ./demo
Display :0.0 opened
String XF86AudioPlay has keysym 0x1008FF14
Keysym 0x1008FF14 has keycode 172
Keycode 172 pressed
Keycode 172 released
Display :0.0 flushed
$

I'm looking forward to any comments/criticism/whatever!

Best regards

Alexander Kurtz
/* xtst.vapi
 *
 * Copyright (C) 2011  Alexander Kurtz
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Alexander Kurtz kurtz.a...@googlemail.com
 */


[CCode (cprefix = , lower_case_cprefix = , cheader_filename = X11/extensions/XTest.h)]
namespace X {
	public class Test {
		[CCode (cname = XTestQueryExtension)]
		public static bool query_extension(Display display, int event_base_return, int error_base_return, int major_version_return, int minor_version_return);

		//[CCode (cname = XTestCompareCursorWithWindow)]
		//public static bool compare_cursor_with_window(Display display, Window window, Cursor cursor);

		[CCode (cname = XTestCompareCurrentCursorWithWindow)]
		public static bool compare_current_cursor_with_window(Display display, Window window);

		[CCode (cname = XTestFakeKeyEvent)]
		public static int fake_key_event(Display display, uint keycode, bool is_press, ulong delay);

		[CCode (cname = XTestFakeButtonEvent)]
		public static int fake_button_event(Display display, uint button, bool is_press, ulong delay);

		[CCode (cname = XTestFakeMotionEvent)]
		public static int fake_motion_event(Display display, int screen_number, int x, int y, ulong delay);
		
		[CCode (cname = XTestFakeRelativeMotionEvent)]
		public static int fake_relative_motion_event(Display display, int screen_number, int x, int y, ulong delay);

		[CCode (cname = XTestGrabControl)]
		public static int grab_control(Display display, bool impervious);

		//[CCode (cname = XTestSetGContextOfGC)]
		//public static void set_g_context_of_gc(GC gc, GContext gid);

		//[CCode (cname = XTestSetVisualIDOfVisual)]
		//public static void set_visual_id_of_visual(Visual visual, VisualID visualid);

		[CCode (cname = XTestDiscard)]
		public static Status discard(Display display);
	}
}
x11
void main(){
	string keystr = XF86AudioPlay;

	X.Display display = new X.Display();
	stdout.printf(Display %s opened\n, display.display_string());

	int keysym  = display.string_to_keysym(keystr);
	stdout.printf(String %s has keysym 0x%X\n, keystr, keysym);

	int keycode = display.keysym_to_keycode(keysym);
	stdout.printf(Keysym 0x%X has keycode %d\n, keysym, keycode);

	X.Test.fake_key_event(display, keycode, true, 0);
	stdout.printf(Keycode %d pressed\n, keycode);
	
	X.Test.fake_key_event(display, keycode, false, 0);
	stdout.printf(Keycode %d released\n, keycode);

	display.flush();
	stdout.printf(Display %s flushed\n, display.display_string());
}


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