Hello. Delegates in VAPI are, in fact, bindings to function pointer (which delegates translate to). So in order to be able to do that, there have to be those pointers defined in the C header (otherwise it won't compile with GCC).
If they aren't, you can still define them, but have to use a little hack [CCode (cname="gpointer")], as Vala AFAIK doesn't have any other way to deal with that. I've noticed you are using pointers incorrectly. For one, you can't do pointer of delegate. The delegate itself is a pointer, so in C you'd have one asterisk too many. Also notice that malocfp and ralocfp are returning void*, not void. Note the parentheses, one asterisk relates to the return value and the second to the argument name. Another thing is that pointers as arguments usually mean either array or output/reference argument (you have to figure that out from docs). So when you have argument "size_t* sz", you'll translate it to "out size_t sz" or "ref size_t sz" or "size_t[] sz", depending on what the real meaning is. Note that it is not a pointer anymore in Vala API. Hope I was helpful. :) 2009/6/14 Shawn Ferris <[email protected]>: > Ok, I think I found the answer to my own question.. it seems thats what > delegates are for: > > public static delegate void malocfp (void* ctxp, size_t* sz); > public static delegate void ralocfp (void* ctxp, void* memptr, size_t* > newsz); > public static delegate void mfreefp (void* ctxp, void* memptr); > > [CCode (cname = "OCIEnvCreate")] > private int Create ( > out Environment* env, > Mode mode, > void* ctxp, > malocfp* malocfp, > ralocfp* ralocfp, > mfreefp* mfreefp, > size_t xtramemsz, > out void* usrmempp > ); > > Could someone corrent me if I'm wrong? > > Appreciate it! > SMF 8D > > On Sat, 2009-06-13 at 18:36 -0600, Shawn Ferris wrote: >> Hi all -- >> >> I've decided I wanna try writing the Oracle OCI bindings for vala.. It's >> probably way out of my league, but I'm gonna try anyway.. unfortunately, >> I don't know C very well, so right out of the gates I'm stuck.. but I >> think if I can get past this, I'm hoping with what I've already learned >> plus this piece, perhaps I'll be able to do the rest. >> >> What I'm doing is working from a sample oci program, trying to implement >> just enough of the vapi to support the sample program.. then extend the >> vapi further as I need it. >> >> Here's what I'm working from, so far: >> >> OCIEnv* env; >> r=OCIEnvCreate( &env, OCI_DEFAULT, 0, 0, 0, 0, 0, 0); >> >> Here's my vapi: >> >> [CCode (cheader_filename = "oci.h")] >> namespace OCI { >> >> [CCode (cname = "OCIEnv")] >> public struct Environment { } >> [CCode (cname = "OCIEnvCreate")] >> public int Create ( >> void* env, >> Mode mode, >> void* (ctxp), >> void* malocfp, >> void* ralocfp, >> void* mfreefp, >> size_t xtramemsz, >> void** usrmempp >> ); >> >> } >> >> (I've got the Mode enum in place too.. just didn't include it here) >> >> This is a blurb from the oci header: >> >> sword OCIEnvCreate ( OCIEnv **envhpp, >> ub4 mode, >> const void *ctxp, >> const void *(*malocfp) >> (void *ctxp, >> size_t size), >> const void *(*ralocfp) >> (void *ctxp, >> void *memptr, >> size_t newsize), >> const void (*mfreefp) >> ( void *ctxp, >> void *memptr)) >> size_t xtramemsz, >> void **usrmempp ); >> >> >> And here's my vala test: >> >> OCI.Environment* env; >> var rt = OCI.Create(&env,Mode.DEFAULT, 0, 0, 0, 0, 0, 0); >> >> env, mode and xtramemsz seem to be working fine how they're defined in >> the vapi.. it's the other 5 that I can't figure out. I believe malocfp, >> ralocfp and mfreefp are callback functions, but with my lack of c >> knowledge, I don't see how it should be ok to pass an int in the case of >> the example. (0) If I redefine the inputs as int, everything compiles >> fine but I'm guessing thats not correct and if I really did have a >> callback function implemented, it would die a horrible death.. so I'd >> like to get it right before continuing. >> >> The error I'm getting is: 'Cannot convert from `int' to `void*'' and I >> understand the error.. just don't know enough about it to avoid it.. no >> pun intended.. >> >> SOO.. if someone would kindly give me a clue, I think armed with that >> knowledge, I may actualy figure this out before too long. >> >> Appreciate the help! >> >> SMF >> > > _______________________________________________ > Vala-list mailing list > [email protected] > http://mail.gnome.org/mailman/listinfo/vala-list > _______________________________________________ Vala-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/vala-list
