After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 548897 - Wrapping c code segment (snippet) around cfunc in .vapi files
Wrapping c code segment (snippet) around cfunc in .vapi files
Status: RESOLVED WONTFIX
Product: vala
Classification: Core
Component: general
0.3.x
Other All
: Normal enhancement
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2008-08-21 18:19 UTC by rainwoodman
Modified: 2008-08-23 06:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
To enable this feature. quite primitive. (4.74 KB, patch)
2008-08-21 18:24 UTC, rainwoodman
none Details | Review
updated patch, translating parameter names and 'this', also improved formatting. (6.42 KB, patch)
2008-08-22 02:40 UTC, rainwoodman
none Details | Review
Better coding style, both in vala and the generated code. (8.50 KB, patch)
2008-08-22 04:26 UTC, rainwoodman
none Details | Review
[CCode snippet ] in .vapi files (11.18 KB, patch)
2008-08-22 06:38 UTC, rainwoodman
none Details | Review
Removed duplicated function declarations. (13.08 KB, patch)
2008-08-22 08:15 UTC, rainwoodman
none Details | Review
array length (13.60 KB, patch)
2008-08-22 08:58 UTC, rainwoodman
none Details | Review

Description rainwoodman 2008-08-21 18:19:55 UTC
Patch follows.

To compiler the following program.

using GLib;
class ClassA: Object {
	[CCode (snippet="return g_strdup(b);")]
	public string method(string b);
	public static void main(string [] args) {
		ClassA obj = new ClassA();
		string test = "hello world";
		string b = obj.method(test);
		message("%s = %s", test, b);
	}
}
Comment 1 rainwoodman 2008-08-21 18:24:32 UTC
Created attachment 117152 [details] [review]
To enable this feature. quite primitive.

Added a new CCodeNode type CCodeSnippet; 
Added a new CCode hint snippet;
Added a constructor in Scanner to scan a string.
SourceFile to accept a null file name ( for the snippet)

This is a proof-idea patch,

Vala.Scanner is reused to scan the snippet code but nothing is done after the scanning. The variables in the snippet should be translated from vala name to cname after scanning.
Comment 2 rainwoodman 2008-08-22 02:40:41 UTC
Created attachment 117167 [details] [review]
updated patch, translating parameter names and 'this', also improved formatting.

Still in progress.
Comment 3 rainwoodman 2008-08-22 04:26:00 UTC
Created attachment 117174 [details] [review]
Better coding style, both in vala and the generated code. 

[CCode (snippet="....")] is working now. Please test.
Comment 4 rainwoodman 2008-08-22 06:36:41 UTC
I changed the name of the bug to reflect the change of focus. Now it is fully possible to solve Bug 547236.


This is an example line of modified glib-2.0.vapi with this new feature:

public class string {
    [CCode (cname = "strstr")]
    public weak string? str (string needle);
    [CCode (cname = "g_str_has_prefix")]
    public bool has_prefix (string prefix);
    [CCode (cname = "g_str_has_suffix")]
    public bool has_suffix (string suffix);
    [CCode (cname = "g_strdup_printf"), PrintfFormat]
    public string printf (...);
    [CCode (cname = "sscanf", cheader_filename = "stdio.h")]
    public int scanf (...);
    [CCode (cname = "g_strconcat")]
    public string concat (string string2, ...);
    [CCode (cname = "g_strndup")]
    public string ndup (ulong n); /* FIXME: only UTF-8 */
    [CCode (cname = "g_strescape")]
    public string escape (string exceptions);
    [CCode (cname = "g_strcompress")]
    public string compress ();

/***********************/
    [CCode (cname = "g_strmysplit", snippet = "gchar ** rt = g_strsplit(this, delimiter, max_tokens); *result_length1 = rt?g_strv_length(rt):0; return rt;")]
    public string[] mysplit (string delimiter, int max_tokens = 0);
/**>>>>>>>>>>>>>>>>>>>*/
    [CCode (cname = "g_strsplit")]
    [NoArrayLength]
    public string[] split (string delimiter, int max_tokens = 0);
/**<<<<<<<<<<<<<<<<<<<<*/

...
...

Comment 5 rainwoodman 2008-08-22 06:38:39 UTC
Created attachment 117182 [details] [review]
[CCode snippet ] in .vapi files
Comment 6 rainwoodman 2008-08-22 08:15:41 UTC
Created attachment 117189 [details] [review]
Removed duplicated function declarations. 

1. Because Vala.CCodeNode now supports a equal method,
Vala.CCodeFragment is modified to disalow adding two idential CCodeNodes.

Further work against Vala.DynamicMethod can kill the vast number of static wrappers for dynamic methods. (was one function for each)

2. It solves the duplicated wrappers problem
3. now we always use a prefixed name for the wrapper.
Comment 7 rainwoodman 2008-08-22 08:58:59 UTC
Created attachment 117192 [details] [review]
array length

Array.length is parsed.
Comment 8 Alexey Lubimov 2008-08-22 22:59:59 UTC
last patch (http://bugzilla.gnome.org/attachment.cgi?id=117192&action=view) failed to compile 


vala/valascanner.vala:56.3-56.16: error: class creation methods only allow property assignment statements
	_buffer = str;
		^^^^^^^^^^^^^^

        
        char* current ;
        char* end ;
...
        string _buffer;
....

        public Scanner.string (string str) {
                _buffer = str;
                current = _buffer;
                end = current + _buffer.size();
        }


As You can see, property's current, end and _buffer set in constructor but not marked as public XXX {get;construct;} 

Comment 9 rainwoodman 2008-08-23 00:14:25 UTC
it compiles with Vala 0.3.5.
Comment 10 Alexey Lubimov 2008-08-23 05:35:03 UTC
vala/valascanner.vala:56.3-56.16: error: class creation methods only allow property assignment statements
		_buffer = str;
		^^^^^^^^^^^^^^

[avl@localhost SPECS]$ valac --version
Vala 0.3.5

maybe, it compiles with vala from svn trunk?
Comment 11 rainwoodman 2008-08-23 05:48:15 UTC
No. It compiles with 

The patch is against vala trunk.
and the patched vala is compilable with vala 0.3.5.


Comment 12 Alexey Lubimov 2008-08-23 06:42:23 UTC
No, it compiles only by valac from trunk.

e.g. 2 stages

1) build and install vala & vala-devel from trunk

2) apply patch, build and install patched vala 

Released version 0.3.5 from tarball not suitable for build patched version.
 
Comment 13 Alexey Lubimov 2008-08-23 06:47:12 UTC
another regress

with enabled build option --enable-gen-project:


make[2]: Entering directory `/home/avl/RPM/BUILD/vala-0.3.5/gen-project'
../compiler/valac -C --vapidir ./../vapi --pkg config --pkg gtk+-2.0 --basedir .. valaprojectgenerator.vala
make[2]: *** [vala-gen-project.vala.stamp] Segmentation fault


without patch, build sucessfully

with patch, but without --enable-gen-project build sucessfully too