Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#5795 closed defect (fixed)

SWIG 3.0.3 complains about “Unknown SWIG preprocessor directive” in ogr_python.i

Reported by: gagern Owned by: hobu
Priority: normal Milestone: 1.11.2
Component: SWIG (all bindings) Version: 1.11.1
Severity: normal Keywords:
Cc:

Description

ogr_python.i contains Python comments, i.e. lines starting with a sequence of spaces followed by #. SWIG interprets lines of this form as preprocessor directives, according to its manual. Until recently, unknown preprocessor directives were ignored, but since SWIG ticket 217 got addressed for SWIG 3.0.3, these lines will now cause error messages. This was observed in Gentoo bug 534168.

It would be nice if GDAL could work with recent versions of SWIG, e.g. by removing these comments, reformatting them in some way that doesn't interfere with the preprocessor (C-style comments might work) or perhaps enclosing everything in a %{…%} block so that the preprocessor will ignore such things. Of the suggested approaches, I've only tried removing the comments, which obviously works but might make maintaining the code a bit harder.

Attachments (1)

gdal5795a.patch (5.6 KB ) - added by gagern 9 years ago.
Patch: turn # into

Download all attachments as: .zip

Change History (5)

comment:1 by Even Rouault, 9 years ago

Patch welcome, and possibly compatible with SWIG 2.X. Removing comments is clearly not an option.

by gagern, 9 years ago

Attachment: gdal5795a.patch added

Patch: turn # into

comment:2 by gagern, 9 years ago

Experiments indicate that // has the same effect that # had so far (i.e. the line gets dropped). Tested on SWIG 2.0.12, 3.0.2 and 3.0.3, but only looking at the sources generated by SWIG, not actually building and testing the whole GDAL library. This patch is the result of a search and replace, and turned ## into //#. If you dislike that, feel free to change things to ////, /// or whatever you prefer.

comment:3 by Even Rouault, 9 years ago

Milestone: 1.11.2
Resolution: fixed
Status: newclosed

Using wasn't an option either as this makes invalid Python code. The solution is to use %{ %} instead of just { }. And this is compatible with all SWIG versions.

trunk r28295 "Python bindings: fix processing error of ogr_python.i with SWIG 3 (#5795)"

trunk r28296 "Python bindings: preventive fix similar as ogr_python.i to avoid potential compat problems with SWIG 3 (#5795)"

trunk r28297 "Complementary fix for ogr_python.i (#5795)"

branches/1.11 r28298 "Python bindings: fix processing error of ogr_python.i with SWIG 3 (#5795)"

comment:4 by gagern, 9 years ago

Thanks for the quick fix! I thought I had inspected the generated ogr.py file and found that the // comments were not included in that, but I might have missed something. In any case, using # inside python code is more natural, so this solution looks clearly superior. I forwarded r28298 to the Gentoo bug report.

Note: See TracTickets for help on using tickets.