From: William S F. <ws...@fu...> - 2010-04-13 19:10:41
|
Tyler Sample wrote: > It's funny how quickly I was able to get templates and arrays working, but > this has me stumped: > > I've got code in a header (that is set in stone..can't modify) that looks > like this: > typedef void * MyHandleType; > > Currently, this gets converted to a SWIGTYPE_p_void for all the functions > that use it (hundreds). What I would like to do is 1) have SWIG not treat > this object as a pointer, and 2) instruct SWIG in a language-agnostic > fashion to generate a similar typedef for the target language and use it. SWIG is already doing this - it is treating it as a specific type - SWIGTYPE_p_void. If you are lumped with wrapping void * all over the place, you are going to have to come up with some customisations and ideas on how to improve this from the target language. How do you want it to work for your chosen target languages. > I > don't know if this is actually possible as general purpose code since I'm > not aware of the capabilities of most scripting languages. If casting the > void * to an integer would help, I'm willing to do that, as long as I can do > that once in the interface file, rather than for each function it's used in. > > Alternately, if this just can't be done, my target language for now is C#. > So if I do have to write a language-specific typemap, I guess I'd like it to > generate code like so: > typedef IntPtr MyHandleType; > alternately, > typedef Object MyHandleType; > might be acceptable if it keeps SWIG from worrying about what is being > pointed to. (IIRC, it is not actually used as a pointer in many cases.) > > I have read the documentation on typemaps here: > http://www.swig.org/Doc1.3/Typemaps.html > Unfortunately, despite a careful reading and looking at several examples, I > don't feel like I have a good understanding of how to use this obviously > very powerful feature. > > There are functions that pass back an array of handles: "MyHandleType > *handleArray", and I feel like I've got a good grip on how to handle that as > long as SWIG isn't trying to treat MyHandleType as anything other than a > value. > > Hope that all makes sense! If I can clarify my problem in any way, please > let me know! There are c# typemap examples in CSharp.html documentation. For void *, you could copy or %apply the void *VOID_INT_PTR typemaps in csharp.swg. They marshal void * as IntPtr. Typemaps are language specific. William |