From: Sri <w2...@ya...> - 2010-01-20 17:25:09
|
Hi Dave: Thx for the comments. If I understand correctly, I maybe hitting a swig limitation. bummer.. The output from 'swig -E' for the array declaration line is at the bottom of my original mail. Comparing the two examples, why is it that, written one way, the same code works fine with swig (but not the otherway). Are there any swig directives or other tricks to get the preprocessor outout to be influenced? Is there an alternate to -includeall or something? -Sri --- On Wed, 1/20/10, David Beazley <da...@da...> wrote: > From: David Beazley <da...@da...> > Subject: Re: [Swig-user] Error with array size specified via macro - Error: Syntax error in input(3) > To: "Sri" <w2...@ya...> > Cc: "David Beazley" <da...@da...>, swi...@li... > Date: Wednesday, January 20, 2010, 5:10 AM > Try running 'swig -E' and looking at > the output to see what's wrong. I suspect the > problem is that Swig can not evaluate the array dimension > properly--it might not even support arithmetic expressions > for dimensions (I can't remember if that works or not). > > -Dave > > On Jan 20, 2010, at 5:36 AM, Sri wrote: > > > Hi, > > > > I am using SWIG to generate perl wrappers for a fairly > large, existing C API used at work. In the swig > interface file I just include a "master" headerfile that > includes all the other required files. However, I'm > getting "Syntax error in input(3)" error and cant figure out > what I'm doing wrong. The original code compiles fine > with many C compilers. > > > > The problem seems to be due to declaring an arrays' > size via a macro #defined earlier (int nVals[NUM_VALS]; line > in my example below) > > > > I've been able to reproduce the problem with a fairly > simple example. I hope someone knows what I'm doing > wrong or how to workaround this. > > > > Example demonstrating the problem uses : test.i, a.h, > b.h. > > command : swig -includeall -perl5 test.i > > Result: b.h:13: Error: Syntax error in input(3). > > > > Same functionality, rewritten as test2.i doesnot cause > error > > command: swig -perl5 test2.i > > > > Using swig 1.3.40. > > > > ---test.i ---- > > (this is essentially, how my real .i file looks..just > a "master" .h) > > > > %module myTest > > > > %{ > > #include "a.h" > > %} > > > > %include "a.h" > > > > ----a.h---- > > #include "b.h" > > > > ----b.h---- > > > > enum > > { > > FIRST_VAL, > > SECONDVAL, > > MAX_VAL > > }; > > > > #define NUM_VALS ((MAX_VAL/2) + ((MAX_VAL % 2) ? 1: > 0)) > > > > typedef struct > > { > > int aVal; > > int nVals[NUM_VALS]; > > } tMyStruct; > > > > void MyFunc (tMyStruct avar); > > > > > > --- test2.i --- > > > > %module myTest > > > > %{ > > enum > > { > > FIRST_VAL, > > SECONDVAL, > > MAX_VAL > > }; > > > > #define NUM_VALS ((MAX_VAL/2) + ((MAX_VAL % 2) ? 1: > 0)) > > > > typedef struct > > { > > int aVal; > > int nVals[NUM_VALS]; > > } tMyStruct; > > > > %} > > > > void MyFunc (tMyStruct avar); > > > > --- swig preprocessor (-E) output --- > > > > error case, the array declaration expands to this > output: > > > > int nVals[((MAX_VAL/2) + ((MAX_VAL % 2) ? > 1: 0))]; > > > > In working case, the array declaration is unchanged in > the output. > > > > int nVals[NUM_VALS]; > > > > > > > > > > > > > > > ------------------------------------------------------------------------------ > > Throughout its 18-year history, RSA Conference > consistently attracts the > > world's best and brightest in the field, creating > opportunities for Conference > > attendees to learn about information security's most > important issues through > > interactions with peers, luminaries and emerging and > established companies. > > http://p.sf.net/sfu/rsaconf-dev2dev > > _______________________________________________ > > Swig-user mailing list > > Swi...@li... > > https://lists.sourceforge.net/lists/listinfo/swig-user > > |