Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDALDataset::RasterIO() / GDALDatasetRasterIO[Ex](): accept a const int* panBandList, instead of a int*, and related changes #9961

Merged
merged 4 commits into from
May 22, 2024

Conversation

rouault
Copy link
Member

@rouault rouault commented May 17, 2024

Currently GDALDataset::RasterIO() / GDALDatasetRasterIOEx take a "int* panBandList", whereas its semantics is really "const int*".
To do the changes fully one should also change the virtual method GDALDataset::IRasterIO() in a similar way, but that would affect out-of-tree drivers, so I've used a compromise where I changed in-tree code to use a BANDMAP_TYPE define that evaluates to "int *" for backward compatibility, but with an easy way to check it is const ready, with the below

// This macro can be defined to check that GDALDataset::IRasterIO()
// implementations do not alter the passed panBandList. It is not defined
// by default (and should not!), hence int* is used.
\#if defined(GDAL_BANDMAP_TYPE_CONST_SAFE)
\#define BANDMAP_TYPE const int *
\#else
\#define BANDMAP_TYPE int *
\#endif

I'm not totally sure this a good idea/approach

…nt* panBandList, instead of a int*

But no changes to the IRasterIO() virtual method as the moment, assuming
that all implementations do not alter the passed array
@rouault rouault force-pushed the RasterIO_const_panBandList branch from 9632b20 to 32baa89 Compare May 17, 2024 23:49
@elpaso
Copy link
Collaborator

elpaso commented May 20, 2024

but that would affect out-of-tree drivers

do you mean this would be an API break for third party drivers?

I'm not totally sure this a good idea/approach

I can't think of a better one.

.github/workflows/ubuntu_24.04/build.sh Outdated Show resolved Hide resolved
CPL_IGNORE_RET_VAL(psJob->poMEMDS->RasterIO(
GF_Read, psJob->nXOff, psJob->nYOff, psJob->nXSize, psJob->nYSize,
psJob->pBuffer, psJob->nBufXSize, psJob->nBufYSize, psJob->eDT,
psJob->nBandCount, nullptr, 0, 0, psJob->nBandSpace, &sExtraArg));
psJob->nBandCount, anBands.data(), 0, 0, psJob->nBandSpace,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how it this (and previous) change related to the const correctness?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that this code abuses mutlithreading. It does multithreaded read on the same dataset. Before when passing panBandMap==nullptr a temporary array was allocated by GDALDataset::RasterIO(). I changed the later to rather use a member variable to hold the temporary array. And thus there was suddently a concurrent modification of that temporary array causing chaos.

…const int* panBandList

For now we use a #define
```
// This macro can be defined to check that GDALDataset::IRasterIO()
// implementations do not alter the passed panBandList. It is not defined
// by default (and should not!), hence int* is used.
\#if defined(GDAL_BANDMAP_TYPE_CONST_SAFE)
\#define BANDMAP_TYPE const int *
\#else
\#define BANDMAP_TYPE int *
\#endif
```
@rouault rouault force-pushed the RasterIO_const_panBandList branch from 32baa89 to a010318 Compare May 20, 2024 14:04
@rouault rouault merged commit 698d879 into OSGeo:master May 22, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants