The Vala Tutorial says:

  Defining new Type from other

  Defining a new type is a matter of derive it from the one you need.
  Here are some examples:

  /* defining an alias for a basic type (equivalent to typedef int Integer in 
C)*/
  [SimpleType]
  public struct Integer : uint {
  }

but when I try this, I get code that references undefined integer_dup()
and integer_free() operations.

Is this a bug in the valac code generation, or in the tutorial?

Attached is the vala source and generated C code for a test case.
It's also a bit worrisome that the C output uses both 'int32_t' and
'gint32' for the Integer type, depending on how it's used.

-m
/* defining an alias for a basic type (equivalent to typedef int Integer in C)*/
[SimpleType]
public struct Foo : int32 {}

void bar(Foo x) {
  int32 y = x + 3;
}


/* typedefish.c generated by valac 0.15.0, the Vala compiler
 * generated from typedefish.vala, do not modify */

/* defining an alias for a basic type (equivalent to typedef int Integer in C)*/

#include <glib.h>
#include <glib-object.h>
#include <stdint.h>




void bar (int32_t x);


GType foo_get_type (void) {
	static volatile gsize foo_type_id__volatile = 0;
	if (g_once_init_enter (&foo_type_id__volatile)) {
		GType foo_type_id;
		foo_type_id = g_boxed_type_register_static ("int32_t", (GBoxedCopyFunc) foo_dup, (GBoxedFreeFunc) foo_free);
		g_once_init_leave (&foo_type_id__volatile, foo_type_id);
	}
	return foo_type_id__volatile;
}


void bar (int32_t x) {
	int32_t _tmp0_;
	gint32 y;
	_tmp0_ = x;
	y = (gint32) (_tmp0_ + 3);
}



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

Reply via email to