Hi. I was playing around with Vala and Genie and I noticed that in the
case of Genie, the compiler adds an extra '\ n' sequence at the end of
some strings. Is that supposed to be?


Test program in Genie

// hello.gs
init
       var caption = "Hello World!\n"
       var hello = new HelloWorld ()
       var message = hello.say (caption)
       print ("Message: %s\n", message)

class HelloWorld : Object

       def say (greeting : string) : string

               print (greeting)
               return "OK"


Some fragments of a program in C

// hello.c

...

void _vala_main (gchar** args, int args_length1) {
       gchar* _tmp0_;
       gchar* caption;
       HelloWorld* _tmp1_;
       HelloWorld* hello;
       gchar* _tmp2_ = NULL;
       gchar* message;
       _tmp0_ = g_strdup ("Hello World!\n");
       caption = _tmp0_;
       _tmp1_ = hello_world_new ();
       hello = _tmp1_;
       _tmp2_ = hello_world_say (hello, caption);
       message = _tmp2_;
       g_print ("Message: %s\n\n", message); // <-- an extra '\n' here
       _g_free0 (message);
       _g_object_unref0 (hello);
       _g_free0 (caption);
}

...

gchar* hello_world_say (HelloWorld* self, const gchar* greeting) {
       gchar* result = NULL;
       const gchar* _tmp0_;
       gchar* _tmp1_;
       gchar* _tmp2_;
       gchar* _tmp3_;
       g_return_val_if_fail (self != NULL, NULL);
       g_return_val_if_fail (greeting != NULL, NULL);
       _tmp0_ = greeting;
       _tmp1_ = g_strconcat (_tmp0_, "\n", NULL); // <-- an extra '\n' here
       _tmp2_ = _tmp1_;
       g_print ("%s", _tmp2_);
       _g_free0 (_tmp2_);
       _tmp3_ = g_strdup ("OK");
       result = _tmp3_;
       return result;
}

...
/* hello.c generated by valac 0.14.0, the Vala compiler
 * generated from hello.gs, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>


#define TYPE_HELLO_WORLD (hello_world_get_type ())
#define HELLO_WORLD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_HELLO_WORLD, HelloWorld))
#define HELLO_WORLD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_HELLO_WORLD, HelloWorldClass))
#define IS_HELLO_WORLD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_HELLO_WORLD))
#define IS_HELLO_WORLD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_HELLO_WORLD))
#define HELLO_WORLD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_HELLO_WORLD, HelloWorldClass))

typedef struct _HelloWorld HelloWorld;
typedef struct _HelloWorldClass HelloWorldClass;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _HelloWorldPrivate HelloWorldPrivate;

struct _HelloWorld {
	GObject parent_instance;
	HelloWorldPrivate * priv;
};

struct _HelloWorldClass {
	GObjectClass parent_class;
};


static gpointer hello_world_parent_class = NULL;

void _vala_main (gchar** args, int args_length1);
HelloWorld* hello_world_new (void);
HelloWorld* hello_world_construct (GType object_type);
GType hello_world_get_type (void) G_GNUC_CONST;
gchar* hello_world_say (HelloWorld* self, const gchar* greeting);
enum  {
	HELLO_WORLD_DUMMY_PROPERTY
};


void _vala_main (gchar** args, int args_length1) {
	gchar* _tmp0_;
	gchar* caption;
	HelloWorld* _tmp1_;
	HelloWorld* hello;
	gchar* _tmp2_ = NULL;
	gchar* message;
	_tmp0_ = g_strdup ("Hello World!\n");
	caption = _tmp0_;
	_tmp1_ = hello_world_new ();
	hello = _tmp1_;
	_tmp2_ = hello_world_say (hello, caption);
	message = _tmp2_;
	g_print ("Message: %s\n\n", message);
	_g_free0 (message);
	_g_object_unref0 (hello);
	_g_free0 (caption);
}


int main (int argc, char ** argv) {
	g_type_init ();
	_vala_main (argv, argc);
	return 0;
}


gchar* hello_world_say (HelloWorld* self, const gchar* greeting) {
	gchar* result = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (greeting != NULL, NULL);
	_tmp0_ = greeting;
	_tmp1_ = g_strconcat (_tmp0_, "\n", NULL);
	_tmp2_ = _tmp1_;
	g_print ("%s", _tmp2_);
	_g_free0 (_tmp2_);
	_tmp3_ = g_strdup ("OK");
	result = _tmp3_;
	return result;
}


HelloWorld* hello_world_construct (GType object_type) {
	HelloWorld * self = NULL;
	self = (HelloWorld*) g_object_new (object_type, NULL);
	return self;
}


HelloWorld* hello_world_new (void) {
	return hello_world_construct (TYPE_HELLO_WORLD);
}


static void hello_world_class_init (HelloWorldClass * klass) {
	hello_world_parent_class = g_type_class_peek_parent (klass);
}


static void hello_world_instance_init (HelloWorld * self) {
}


GType hello_world_get_type (void) {
	static volatile gsize hello_world_type_id__volatile = 0;
	if (g_once_init_enter (&hello_world_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (HelloWorldClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) hello_world_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (HelloWorld), 0, (GInstanceInitFunc) hello_world_instance_init, NULL };
		GType hello_world_type_id;
		hello_world_type_id = g_type_register_static (G_TYPE_OBJECT, "HelloWorld", &g_define_type_info, 0);
		g_once_init_leave (&hello_world_type_id__volatile, hello_world_type_id);
	}
	return hello_world_type_id__volatile;
}



_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to