Re: [Vala] Problem while creating a vapi file for a typedef'd pointer.



On Fri, Feb 12, 2010 at 17:40:16 +0100, Abderrahim Kitouni wrote:
Hi,

Geoffrey Blackman wrote:
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;
I don't know if this is bindable in vala (i.e. you may need to use
typedef struct __vpiHandle *vpiHandle;
but this should be something like
[Compact]
[CCode (cname="struct __vpiHandle"]
public class Handle {...}

I therefor need to define a type in my vapi file which will map to vpiHandle
and behave like a pointer.

I'd like to explain some things here.
   [SimpleType]
SimpleType means it should be passed by value, it definietly won't
behave like a pointer.

Well, it will be a pointer, if you bind a pointer as a simple type. With the
one exception -- vala won't want to compare it with null. You could' however,
do something like
    [SimpleType]
    [CCode (cname="vpiHandle")]
    public struct Handle {
        [CCode (cname="NULL")]
        public static Handle none;
        ...
    }
Than you still can't compare with null, but can compare with Handle.none with
the same effect.

[...]
Note that the '?' indicating that the iterate method can return null has
caused argv to have type 'vpiHandle*' rather than the vpiHandle returned by
for a struct, '?' means it's boxed (that's the only way for it to be null).
vpi_iterate.
If I remove the nullable marker I would get the correct type for argv,
however I cannot now test it for null.
because a struct won't behave like a pointer.

Your best bet is a compact class, but this won't work in the void* case.

It will. Vala shouldn't have problem binding void as class...
[Compact]
[CCode (cname="void")]
public class Handle {...}

Since C will implicitly cast between void* and anything*, I actually think
binding void would be a better solution than binding "struct __vpiHandle".
You'll need to set the ref/unref resp. copy/free functions, but you need to
do that anyway.

-- 
                                                 Jan 'Bulb' Hudec <bulb ucw cz>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]