From: Steven H. <snh...@gm...> - 2007-06-04 23:20:20
|
On Mon, 4 Jun 2007, Gordan Bobic wrote: > Steven Hirsch wrote: > >> You will have more success using the approach I suggested. If all you >> want is to get back a wrapped pointer, just declare something like: >> >> float *FloatCreate( float *Array ) { >> return Array; >> } > > That is exactly what I tried first. But when I try: > $DataV = MyCLib::FloatCreate(\@Data); > > I similarly get: > TypeError in method 'FloatCreate', argument 1 of type 'float *' I think you can apply a typemap to one specific function. Also, I believe you must define the typemap before anything that expects to use it. > Here's the whole of the code I'm using: > %inline > %{ > float *FloatCreate (float *Array) > { > return Array; > } > %} > > %typemap(in) float * > { > AV *tempav; > I32 len; > int i; > SV **tv; > if (!SvROK($input)) > croak("Argument $argnum is not a reference."); > if (SvTYPE(SvRV($input)) != SVt_PVAV) > croak("Argument $argnum is not an array."); > tempav = (AV*)SvRV($input); > len = av_len(tempav); > $1 = (float *) malloc(len * sizeof(float)); > for (i = 0; i < len; i++) > { > tv = av_fetch(tempav, i, 0); > $1[i] = (float) SvNV(*tv); > } > }; > > On a separate note, won't this kill pointer passing in any other context > (i.e. non arrays)? Can a typemap be identified on a pair of values, > somehow, so that it only triggers if I pass (int, float*)? Typemaps can (probably) do what you need, but I end up pulling my hair out of my head every time I have to code one. Perhaps you can typedef float* to something with a unique name and typemap that? Something like: %inline %{ typedef float* float_ptr_t; %} Then do your typemap thusly: %typemap(in) float_ptr_t { ... }; Finally: void your_routine ( float_ptr_t arg ) { Might work. Can anyone else on the list help? Steve -- |