Uploaded image for project: 'Data Management'
  1. Data Management
  2. DM-2346

SWIG code enclosed in %python %{ should be outdented to the left margin

    XMLWordPrintable

    Details

    • Team:
      SQuaRE

      Description

      In swig .i files code contained in %pythoncode %

      {...%}

      blocks must be outdented to the left margin for the code to be reliably correctly indented in the interface file and and for comments that start with # to be reliably handled as comments.

      Comments may have leading characters deleted (including the #) which can lead to part of the comment being treated as code. Another failure mode is that the comment has the wrong indentation level. Fortunately these errors usually result a syntax error, or are innocuous.

      Incorrectly indented code can lead to errors that are very hard to detect. One common result is that the added function appears as as a function definition inside another function. Hence the failure produces no python syntax errors, but the added function cannot be called.

      The problem does not always lead to improperly indented code and in some cases I suspect the code is being correctly indented, since I doubt it would work otherwise. Even then it is safest to fix the problem, if only to provide a correct example for others.

        Attachments

          Activity

          Hide
          rhl Robert Lupton added a comment -

          This sounds like a swig bug, can you include the swig bug report in the issue?

          I agree that we probably have to fix it in our files too, but it's a lot of changes in a lot of places.

          Show
          rhl Robert Lupton added a comment - This sounds like a swig bug, can you include the swig bug report in the issue? I agree that we probably have to fix it in our files too, but it's a lot of changes in a lot of places.
          Hide
          rowen Russell Owen added a comment -

          Unfortunately my impression is that the SWIG community doesn't see this as a bug – or at least as something that is safe to tamper with. (I hope I can convince them that the mis-handling of comments is a bug, but I'm doubtful of making it any further than that). I would rather just fix our code. It's a few small changes in a lot of packages. Much of our existing %pythoncode is already outdented to the left margin.

          Show
          rowen Russell Owen added a comment - Unfortunately my impression is that the SWIG community doesn't see this as a bug – or at least as something that is safe to tamper with. (I hope I can convince them that the mis-handling of comments is a bug, but I'm doubtful of making it any further than that). I would rather just fix our code. It's a few small changes in a lot of packages. Much of our existing %pythoncode is already outdented to the left margin.
          Hide
          tjenness Tim Jenness added a comment -

          I've pushed what I believe to be the required change for daf_base. Doesn't make any difference to the generated python file.

          Show
          tjenness Tim Jenness added a comment - I've pushed what I believe to be the required change for daf_base . Doesn't make any difference to the generated python file.
          Hide
          swinbank John Swinbank added a comment -

          Since we no longer use Swig, I think we can close this as "won't fix".

          Show
          swinbank John Swinbank added a comment - Since we no longer use Swig, I think we can close this as "won't fix".

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            rowen Russell Owen
            Watchers:
            Jim Bosch, John Swinbank, Kian-Tat Lim, Paul Price, Robert Lupton, Robyn Allsman [X] (Inactive), Russell Owen, Serge Monkewitz, Simon Krughoff, Tim Jenness
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                CI Builds

                No builds found.