-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
…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
9632b20
to
32baa89
Compare
do you mean this would be an API break for third party drivers?
I can't think of a better one. |
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ```
32baa89
to
a010318
Compare
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
I'm not totally sure this a good idea/approach