Re: [Vala] Name clashes in generated C code

2010-12-29 Thread Jan Hudec
On Tue, Dec 28, 2010 at 15:32:07 -0800, Anatol Pomozov wrote:
 I am sure using [CCode] is ok for libraries as well if cprefix value
 does not change very often.

The reason to try to avoid [CCode] for libraries is that users of the library
will expect the code to follow some naming convention, which vala does by
default. When you resolve a name conflict with [CCode], you make it harder
for user to remember which of the objects the original name belongs to and
what is the name of that symbol for the other object, thus making it slightly
less user friendly. There will be no techincal problems.

Of course, changing the attribute will probably break API or ABI
compatibility. But there are many changes that will and you need to be
careful about all of them when maintaining library.

-- 
 Jan 'Bulb' Hudec b...@ucw.cz
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


[Vala] Potential memory leak?

2010-12-29 Thread Alexander Krivács Schrøder
Hi. I have a question.

If you look at the documentation for the
gtk_source_completion_proposal_get_text () C function:
http://library.gnome.org/devel/gtksourceview/2.9/GtkSourceCompletionProposal.html#gtk-source-completion-proposal-get-text

It says The returned string must be freed with g_free(). However,
this Vala code:

=
string procedure = proposal.get_text();
=

generates this C code:

=
char* procedure;
[...]
procedure = g_strdup (gtk_source_completion_proposal_get_text (proposal));
[...]
_g_free0 (procedure);
=

Isn't this a memory leak? The original string returned from the
gtk_source_completion_proposal_get_text, which the documentation says
to free, is never freed.
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Potential memory leak?

2010-12-29 Thread Jürg Billeter
On Wed, 2010-12-29 at 20:45 +0100, Abderrahim Kitouni wrote:
 Hello,
   في ر، 29-12-2010 عند 18:34 +0100 ، كتب Alexander Krivács Schrøder:
  Hi. I have a question.
  
  If you look at the documentation for the
  gtk_source_completion_proposal_get_text () C function:
  http://library.gnome.org/devel/gtksourceview/2.9/GtkSourceCompletionProposal.html#gtk-source-completion-proposal-get-text
  
  It says The returned string must be freed with g_free(). 
 [...]
  Isn't this a memory leak?
 It is. But this is not intentional : the bindings are auto generated and
 often return values are marked as unowned while they should be freed.
 
 Feel free to file a bug.

This is now fixed in master.

Jürg

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


Re: [Vala] string - bytes conversion in Vala

2010-12-29 Thread Anatol Pomozov
Hi

On Thu, Dec 23, 2010 at 12:37 AM, Anatol Pomozov
anatol.pomo...@gmail.com wrote:
 Hi,

 I manipulate with strings in my application such as storing/reading
 to/from binary files. And I need to convert a string to/from array of
 bytes. What is the best way of doing it in Vala?

 Looking into string class http://valadoc.org/glib-2.0/string.html I
 see a method called string#to_utf8() that converts string to array of
 chars. But I cannot find any other methods.

 So I have 2 questions:
  - How to convert a string to array of chars in encoding different
 from UTF8. Something like this one
 http://download.oracle.com/javase/6/docs/api/java/lang/String.html#getBytes(java.nio.charset.Charset)
  - How to convert array of chars/uint8 back to string? Like this one
 http://download.oracle.com/javase/6/docs/api/java/lang/String.html#String(byte[],
 java.nio.charset.Charset)

I think I found a way to convert string to bytes in Vala. Actually it
is as simple as casting string to char* and back. Under the hood
strings in vala is just a pointer to char.

Here is an example that shows it:

  string hello = abcd;
  char* ch = (char*) hello;
  stdout.printf(%c\n, ch[1]); // Second char, that is 'b'

  char[] bytes = new char[4]; // 3 symbols and null-terminator
  bytes[0] = '1';
  bytes[1] = '2';
  bytes[2] = '3';
  bytes[3] = 0;
  string str = (string)bytes;
  stdout.printf(@$str\n);
  stdout.printf(%d\n, (int)str.length); // Prints '3'

WRT question 'how to convert strings to different encodings' I think
this should help
http://library.gnome.org/devel/glib/unstable/glib-Character-Set-Conversion.html
I haven't it used though.
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] string - bytes conversion in Vala

2010-12-29 Thread Anatol Pomozov
On Wed, Dec 29, 2010 at 3:51 PM, Anatol Pomozov
anatol.pomo...@gmail.com wrote:
 Hi

 On Thu, Dec 23, 2010 at 12:37 AM, Anatol Pomozov
 anatol.pomo...@gmail.com wrote:
 Hi,

 I manipulate with strings in my application such as storing/reading
 to/from binary files. And I need to convert a string to/from array of
 bytes. What is the best way of doing it in Vala?

 Looking into string class http://valadoc.org/glib-2.0/string.html I
 see a method called string#to_utf8() that converts string to array of
 chars. But I cannot find any other methods.

 So I have 2 questions:
  - How to convert a string to array of chars in encoding different
 from UTF8. Something like this one
 http://download.oracle.com/javase/6/docs/api/java/lang/String.html#getBytes(java.nio.charset.Charset)
  - How to convert array of chars/uint8 back to string? Like this one
 http://download.oracle.com/javase/6/docs/api/java/lang/String.html#String(byte[],
 java.nio.charset.Charset)

 I think I found a way to convert string to bytes in Vala. Actually it
 is as simple as casting string to char* and back. Under the hood
 strings in vala is just a pointer to char.

 Here is an example that shows it:

  string hello = abcd;
  char* ch = (char*) hello;
  stdout.printf(%c\n, ch[1]); // Second char, that is 'b'

It actually produces an interesting effect. You *can* change content
of a string (that are claimed as immutable)

  string hello = abcd;
  char* ch = (char*) hello;
  ch[0] = 'z';
  stdout.printf(hello); // Prints 'zbcd'

PS Casting string to/from char* is an interesting technique and worth
mention about it in the tutorial.
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list