Menu

#878 no warning for multiple %module statements

None
closed-wont-fix
nobody
parsing (146)
3
2025-06-09
2007-12-06
No

if you have a .i file
%module module1
%module module2

SWIG just accepts it without comment. It should generate a warning on this matter.
Note: I think one of the test-suite actually has this code, so generating an error is not desirable result.

Discussion

  • Olly Betts

    Olly Betts - 2012-05-12
    • labels: --> parsing
     
  • Olly Betts

    Olly Betts - 2022-01-25

    This is still the case. The second %module isn't ignored entirely it seems - it looks like any parameters will be handled as if they were all present in a single %module but the name is ignored. That doesn't really seem an intentional or very useful feature though.

    We can't just warn if the name is already set though as that's how the documented -module overriding %module is implemented.

     
  • Olly Betts

    Olly Betts - 2022-02-15

    Examples/test-suite/extend_template.i has:

    %module extend_template
    %module xxx // should be ignored
    

    The extra module statement uselessly shows as added by:

    commit 12a43edc2df8853e8e0315f742e57be88f0c4269
    Author: Dave Beazley <dave-swig@dabeaz.com>
    Date:   Sat Nov 30 22:01:28 2002 +0000
    
        The great merge
    
    
        git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    

    But the comment was added by:

    commit faf8fee8772c8d26ce184854aede993edc728676
    Author: William S Fulton <wsf@fultondesigns.co.uk>
    Date:   Thu Mar 4 18:27:23 2010 +0000
    
        minor comment added
    
        git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11894 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    
    diff --git a/Examples/test-suite/extend_template.i b/Examples/test-suite/extend_template.i
    index a39ac546..265c8767 100644
    --- a/Examples/test-suite/extend_template.i
    +++ b/Examples/test-suite/extend_template.i
    @@ -1,5 +1,5 @@
     %module extend_template
    -%module xxx
    +%module xxx // should be ignored
     namespace oss { // this doesn't 
      %extend Foo<0> { 
         int test1(int x) { return x; }
    

    So it seems at least back then this was expected to be ignored.

    There is however a documented warning:

    316. Repeated %module directive.
    

    However nothing currently seems to actually emit warning 316 or WARN_PARSE_MODULE_REPEAT. I also don't see anything in git history which does, but it's hard to check history for 316 as it's very noisy even as a word.

     
  • Olly Betts

    Olly Betts - 2025-06-09
    • status: open --> closed-wont-fix
    • Group: -->
     
  • Olly Betts

    Olly Betts - 2025-06-09

    We also rely on this being accepted in some testcases - e.g. preproc_constants_c.i contains %include "preproc_constants.i" but both contain %module directives.

    I can see an argument for warning about this, but %module is both conventionally and most naturally put at the very top of the file, so in practice I don't think this situation is going to occur in a way which causes confusion in real world use.

    Fixing would seem to require adding a warning and adjusting all the uses in the testsuite to either suppress that warning, or reworking so cases like the above have a stub for both C and C++ variants which both %include a third interface file without %module. That seems more effort than justified by the marginal benefit.

    Given we've had this open since 2007 and nobody's cared enough to come up with a patch in all that time I'm going to close as "won't fix".

     

Log in to post a comment.

MongoDB Logo MongoDB