Menu

#1007 xml module doesn't respect field declaration order

None
closed-wont-fix
nobody
xml (6)
5
2026-01-22
2009-04-08
No

It seems that the xml module doesn't respect field declaration order of nested structs.
An interface file that reproduces the problem is attached.

Discussion

  • Andrea Fazzi

    Andrea Fazzi - 2009-04-08

    interface file and xml generated wrapper

     
  • William Fulton

    William Fulton - 2009-10-07

    Extra info from Andrea's email about this to swig-user:

    I noticed an unexpected behaviour in the generation of the XML wrapper
    code of nested structs. It seems that the declaration of the nested
    struct comes *after* the declaration of the container struct.

    E.g.

    typedef struct {
    struct {
    char a;
    } nested;
    } my_struct;

    Looking at SWIG documentation I understand that the example below should
    be transformed in something like:

    typedef struct {
    char a;
    } my_struct_nested;

    typedef struct {
    my_struct_nested nested;
    } my_struct;

    But it seems that the generated XML wrapper code doesn't reflect the
    situation above. In fact, the definition of my_struct_nested comes
    *after* the definition of my_struct.

     
  • Olly Betts

    Olly Betts - 2022-03-09

    Still seems to be the case with current git master.

     
  • Olly Betts

    Olly Betts - 2024-10-17

    @wsfulton Did your recent nested class change to -xml address this too?

     
  • Olly Betts

    Olly Betts - 2026-01-22
    • status: open --> closed-wont-fix
    • Group: -->
     
  • Olly Betts

    Olly Betts - 2026-01-22

    It seems not.

    However, we don't really define what the generated XML looks like - AFAICS we just say:

    The XML is a dump of SWIG's internal parse tree and as such it is subject to change at any time as and when SWIG's implementation changes.

    Therefore I'm not sure that the relative order of things in the XML should be expected to reflect declaration order. We're really just dumping SWIG's internal data structure as XML and the data structure in memory isn't ordered in this way.

    I think consumers probably need to read all the data and build up a structure from it, then use that to resolve cases such as this.

    Also pragmatically this was been open for approaching 17 years without anyone caring enough to try to enforce the requested ordering, so realistically it's unlikely that's going to happen. So I'm closing as "wont-fix".

     

Log in to post a comment.

MongoDB Logo MongoDB