Skip to content

[Feat] Remove checks for GDAL v1 and v2 #2645

@wenzeslaus

Description

@wenzeslaus

Is your feature request related to a problem? Please describe.

We have 76 occurrences of GDAL_VERSION_NUM check for C preprocessor if statements spread over 21 files. Most of these check are for v1 and v2 of GDAL. The code would be simpler without them.

Describe the solution you'd like

Remove all checks for v1 and v2. Leave only code for new versions for cases where there is code for old and new version. That is, assume most recent GDAL v2.

Use GDAL_COMPUTE_VERSION for v3 checks (4 places) instead of the computed number. GDAL_COMPUTE_VERSION is defined at the same place in GDAL as GDAL_VERSION_NUM (gdal_version.h) and it is used in the Vector API tutorial.

Describe alternatives you've considered

Remove checks for v3 too (all are 3.0.0), require v3 as minimum. Perhaps too big a jump. There is enough v2 checks to be removed to make a difference while keeping the compatibility high.

Removing only the v1 checks and leaving the v2 checks there: GRASS GIS would still compile with some undefined version of v1, but would assume the features are there. I think there is no need to support GDAL 1 in GRASS GIS 8.3, so I would just assume in the code it's some latest release from the v2 series.

Don't remove any of the checks, but just use GDAL_COMPUTE_VERSION for clarity. This adds readability, but does not simplify the overall code structure.

Additional context

Resulting simplified code may resolve a GNU indent issue ./vector/v.in.ogr/main.c:1457: Error:Stmt nesting error reported in #1630.

In CI we are mostly using Ubuntu 20.04 which has GDAL 3.0.4.

The search (related to the numbers above) can be done with:

grep --color=auto --exclude-dir={.git,OBJ.*,locale,dist.*,bin.*} -IrnE GDAL_VERSION_NUM | grep "GDAL_VERSION_NUM [<=>]" | grep "\#if" | wc -l
grep --color=auto --exclude-dir={.git,OBJ.*,locale,dist.*,bin.*} -IrnE GDAL_VERSION_NUM | grep "GDAL_VERSION_NUM [<=>]" | grep "\#if" | sed 's+:.*++g' | sort | uniq | wc -l
grep --color=auto --exclude-dir={.git,OBJ.*,locale,dist.*,bin.*} -IrnE GDAL_VERSION_NUM | grep "GDAL_VERSION_NUM [<=>]" | grep "\#if" | grep " 3" | wc -l

Metadata

Metadata

Assignees

No one assigned

    Labels

    CRelated code is in CenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions