From: William S F. <ws...@fu...> - 2013-08-08 18:10:34
|
There is no magic, this is a multi-argument typemap. Just search the typemap library for LENGTH to find them and read about multi-argument typemaps - http://www.swig.org/Doc2.0/Typemaps.html#Typemaps_multi_argument_typemaps_patterns William On 17/07/13 03:16, Alexander Solovets wrote: > Thanks Bob! I did not think about adding typemap separately for the > second argument. Anyway I am still interested in understanding how > exactly that 'const char *STRING, size_t LENGTH' works. > > > On Wed, Jul 17, 2013 at 12:35 PM, Bob Hood <bh...@co... > <mailto:bh...@co...>> wrote: > > On 7/16/2013 6:19 PM, Alexander Solovets wrote: > > Greetings all! > > > > I am trying to wrap > > > > foo(const int *data, size_t len) > > > > in Python interface. I discovered that the following typemap can > be used > > > > %typemap(in) (const void *data, size_t len) = (const char > *STRING, size_t > > LENGTH) > > > > This works fine, but I want to impose additional check that "len" is > > divisible by sizeof(int). In order to do that I tried to find > definition of > > (const char *STRING, size_t LENGTH), but failed to do that. Is > this "magic" > > typemapping done internally in swig? I'm just trying to > understand how can I > > combine several parameters in one. > > I may be using this incorrectly, but might a typecheck address this > for you? > Something like: > > %typemap(check) size_t len { > if (($1 % sizeof(int)) != 0) { > SWIG_exception(SWIG_ValueError,"Expected value not > divisible by > sizeof(int)."); > } > } > > probably with some casting, since "size_t" and "int" may not be the same > sizes, depending upon how you are building. > > You might also want to give the variable a name something more > unique than > "len" just to make sure the typecheck doesn't apply to all "size_t len" > patterns, just those where you want to validate the division. > > ------------------------------------------------------------------------------ > See everything from the browser to the database with AppDynamics > Get end-to-end visibility with application monitoring from AppDynamics > Isolate bottlenecks and diagnose root cause in seconds. > Start your free trial of AppDynamics Pro today! > http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk > _______________________________________________ > Swig-user mailing list > Swi...@li... <mailto:Swi...@li...> > https://lists.sourceforge.net/lists/listinfo/swig-user > > > > > -- > С уважением, Александр > > > ------------------------------------------------------------------------------ > See everything from the browser to the database with AppDynamics > Get end-to-end visibility with application monitoring from AppDynamics > Isolate bottlenecks and diagnose root cause in seconds. > Start your free trial of AppDynamics Pro today! > http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk > > > > _______________________________________________ > Swig-user mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-user > |