Menu

#333 [PATCH] Parse defines inside enums

None
closed
None
5
2022-11-02
2012-12-31
No

This allows the main libbfd header to be parsed. Patch is against 2.0.9.

1 Attachments

Discussion

  • Olly Betts

    Olly Betts - 2013-01-08

    Do you have an isolated test case for the problem this is trying to solve?

    We really want to have test coverage for something like this to make sure we don't break it with changes in the future.

    (I've checked the current testsuite with the patch and it doesn't seem to break anything).

     
  • Younes Manton

    Younes Manton - 2013-01-08

    Here's a minimal example that shows the problem:

    test.h

    enum foo
    {
    alpha=0,
    #define bar -1
    beta=1
    };
    

    test.i

    %module test
    %{
    #include "test.h"
    %}
    
    %include "test.h"
    

    Without patch:

    $ swig -python test.i
    test.h:4: Error: Syntax error in input(1).

    With patch:

    $ swig -python test.i

     
  • Olly Betts

    Olly Betts - 2013-01-08

    Oh, this rings a bell now - it was reported here:

    https://sourceforge.net/p/swig/bugs/428/

    The testcase there was pretty similar:

    typedef enum {
    eZero = 0

    define ONE 1

    } EFoo;

    Thanks very much for your testcase. I'll slot it into the testsuite and commit this soon.

     
  • William Fulton

    William Fulton - 2013-04-18
    • status: open --> closed
    • assigned_to: William Fulton
    • Group: -->
     
  • William Fulton

    William Fulton - 2013-04-18

    The patch was unsuitable as it started skipping some enums values and didn't allow macros to be defined everywhere in the enum list. I've fixed this up though and committed for swig-2.0.10. Thanks for the start though.

    BTW, why are macros defined in enums like this? I can't see the point.

     
  • Younes Manton

    Younes Manton - 2013-04-22

    Locality of reference I suppose. I didn't write the header I needed parsed but for some enums it had related macros defined right below.

    Thanks for fixing it.

     
  • Thomas Brain

    Thomas Brain - 2019-01-15

    This is still broken when two #defines are declared back-to-back in the header. i.e.

    enum FooEnum {
      ENUM1 = 0,
      ENUM2 = 1,
    
    #define MACRO_DEF1 "Hello"
    #define MACRO_DEF2 "World!"
    
      ENUM3 = 2,
      ENUM4 = 3,
    };
    

    The second #define fails

     
  • Olly Betts

    Olly Betts - 2022-11-02

    The two #define case was fixed in SWIG 4.0.0 (thanks to your report).

     

Log in to post a comment.