Class definition missing from generated C when targetting libc only
Used valac --profile posix libc_class_has_no_body.vala
to compile the following:
void main () {
new Test ();
}
[Compact]
class Test {}
The C compiler stops with error: unknown type name ‘Test’
.
The C generated is:
#include <stddef.h>
#define _test_free0(var) ((var == NULL) ? NULL : (var = (test_free (var), NULL)))
void _vala_main (void);
Test* test_new (void);
void
_vala_main (void)
{
Test* _tmp0_;
Test* _tmp1_;
_tmp0_ = test_new ();
_tmp1_ = _tmp0_;
_test_free0 (_tmp1_);
}
int
main (int argc,
char ** argv)
{
_vala_main ();
return 0;
}
When allowing GLib/GObject code the C is:
#include <glib.h>
typedef struct _Test Test;
#define _test_free0(var) ((var == NULL) ? NULL : (var = (test_free (var), NULL)))
struct _Test {
int dummy;
};
void _vala_main (void);
Test* test_new (void);
void test_free (Test * self);
static void test_instance_init (Test * self,
gpointer klass);
void
_vala_main (void)
{
Test* _tmp0_;
Test* _tmp1_;
_tmp0_ = test_new ();
_tmp1_ = _tmp0_;
_test_free0 (_tmp1_);
}
int
main (int argc,
char ** argv)
{
_vala_main ();
return 0;
}
Test*
test_new (void)
{
Test* self;
self = g_slice_new0 (Test);
test_instance_init (self, NULL);
return self;
}
static void
test_instance_init (Test * self,
gpointer klass)
{
}
void
test_free (Test * self)
{
g_slice_free (Test, self);
}
So even with [Compact]
Vala is currently using GLib for memory management and the gpointer
type.
I'm not sure how the libc target should handle code without [Compact]
, e.g.:
void main () {
new Test ();
}
class Test {}
This currently generates C, but has the addition of Test* test_construct (GType object_type);
and uses _test_unref0
instead of _test_free0
.