[Vala] Problem while creating a vapi file for a typedef'd pointer.
- From: Geoffrey Blackman <geoff gblackman co uk>
- To: vala-list gnome org
- Subject: [Vala] Problem while creating a vapi file for a typedef'd pointer.
- Date: Fri, 12 Feb 2010 15:11:37 +0000
Hi,
I'm attempting to create a vapi file for Verilog VPI and have run into a
problem with a opaque pointer type.
Different implementations of VPI define the type vpiHandle differently. Two
examples are
typedef void *vpiHandle;
typedef struct __vpiHandle *vpiHandle;
I therefor need to define a type in my vapi file which will map to vpiHandle
and behave like a pointer.
My initial atempts look something like the following.
namespace Vpi {
[CCode (cname="PLI_INT32", cprefix="vpi")]
public enum Type {
SysTfCall,
Argument
}
[SimpleType]
[CCode (cname = "vpiHandle", free_function="vpi_free_object")]
public struct Handle {
[CCode (cname="vpi_iterate", instance_pos=2 )]
public Handle? iterate(Type type);
}
[CCode (cname="vpi_handle")]
public static Handle GetHandle(Type type, Handle? r);
}
using Vpi;
public class Test {
public static int calltf(string? user_data) {
Handle p = GetHandle(Vpi.Type.SysTfCall, null);
Handle? argv = p.iterate(Vpi.Type.Argument);
if (argv != null) {
// do something...
}
return 0;
}
}
Which generates the following code
gint test_calltf (const char* user_data) {
vpiHandle p;
vpiHandle* argv;
gint _tmp0;
p = vpi_handle (vpiSysTfCall, NULL);
argv = vpi_iterate (vpiArgument, p);
if (&argv != NULL) {
}
/* do something...*/
return (_tmp0 = 0, (argv == NULL ? NULL : (argv = (g_free (argv),
NULL))), _tmp0);
}
Note that the '?' indicating that the iterate method can return null has
caused argv to have type 'vpiHandle*' rather than the vpiHandle returned by
vpi_iterate.
If I remove the nullable marker I would get the correct type for argv,
however I cannot now test it for null.
Equality operation: `null' and `Vpi.Handle' are incompatible
For reference, the code I am trying to have generated would look something
like
vpiHandle p;
vpiHandle argv;
p = vpi_handle (vpiSysTfCall, NULL);
argv = vpi_iterate (vpiArgument, p);
if (argv != NULL) {
// do something...
}
Any help in correctly defining vpiHandle would be apreciated.
Thanks
--
Geoff Blackman
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]