[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[Vala] Various tests with the new contract support, but also with non-GLib.Object classes
- From: Philip Van Hoof <spam pvanhoof be>
- To: vala-list gnome org
- Subject: [Vala] Various tests with the new contract support, but also with non-GLib.Object classes
- Date: Thu, 24 Apr 2008 01:22:38 +0200
I was just testing various things in vala, and noticed this:
pvanhoof schtrumpf:~$ ./test
** Message: test.vala:31: 100
** Message: test.vala:21: 99
pvanhoof schtrumpf:~$
I attached the test.vala file, since in class Test x will be initialized
to 100, and foo returns bar + x, those values are not right afaik.
ps. I peeked at the .c file, and self->x is never set to 100.
Also note that the ensures is never checked in the generated .c file
[esc]:/x =
"E486: Pattern not found: x ="
--
Philip Van Hoof, freelance software developer
home: me at pvanhoof dot be
gnome: pvanhoof at gnome dot org
http://pvanhoof.be/blog
http://codeminded.be
using GLib;
public class Test
{
int x = 100;
public int foo (int bar) requires (bar > 0) ensures (result > 0)
{
return bar + x;
}
}
public class App {
static Test y;
public static void* thread_func () {
int t;
t = y.foo (99);
message ("%d", t);
return null;
}
static weak Thread u;
static void test () {
Test t = new Test ();
int j;
j = t.foo(100);
message ("%d", j);
y = #t;
u = Thread.create(thread_func, true);
}
static int main (string[] args) {
test ();
u.join ();
return 1;
}
}
#include "test.h"
#include <stdlib.h>
#include <string.h>
static Test* app_y;
static GThread* app_u;
static void* _app_thread_func_gthread_func (gpointer self);
static void app_test (void);
static gint app_main (char** args, int args_length1);
gint test_foo (Test* self, gint bar) {
g_return_val_if_fail (self != NULL, 0);
g_return_val_if_fail (bar > 0, 0);
return bar + self->x;
}
Test* test_new (void) {
Test* self;
self = g_slice_new0 (Test);
return self;
}
void test_free (Test* self) {
g_slice_free (Test, self);
}
void* app_thread_func (void) {
gint t;
t = 0;
t = test_foo (app_y, 99);
g_message ("test.vala:21: %d", t);
return NULL;
}
static void* _app_thread_func_gthread_func (gpointer self) {
return app_thread_func ();
}
static void app_test (void) {
GError * inner_error;
Test* t;
gint j;
Test* _tmp1;
Test* _tmp0;
inner_error = NULL;
t = test_new ();
j = 0;
j = test_foo (t, 100);
g_message ("test.vala:31: %d", j);
_tmp1 = NULL;
_tmp0 = NULL;
app_y = (_tmp1 = (_tmp0 = t, t = NULL, _tmp0), (app_y == NULL ? NULL : (app_y = (test_free (app_y), NULL))), _tmp1);
app_u = g_thread_create (_app_thread_func_gthread_func, NULL, TRUE, &inner_error);
(t == NULL ? NULL : (t = (test_free (t), NULL)));
}
static gint app_main (char** args, int args_length1) {
app_test ();
g_thread_join (app_u);
return 1;
}
int main (int argc, char ** argv) {
g_thread_init (NULL);
g_type_init ();
return app_main (argv, argc);
}
App* app_new (void) {
App* self;
self = g_slice_new0 (App);
return self;
}
void app_free (App* self) {
g_slice_free (App, self);
}
#ifndef __TEST_H__
#define __TEST_H__
#include <glib.h>
#include <glib-object.h>
G_BEGIN_DECLS
typedef struct _Test Test;
typedef struct _App App;
struct _Test {
gint x;
};
struct _App {
};
gint test_foo (Test* self, gint bar);
Test* test_new (void);
void test_free (Test* self);
void* app_thread_func (void);
App* app_new (void);
void app_free (App* self);
G_END_DECLS
#endif
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]