[gdal-dev] Breaking API Change
Andrew Bell
andrew.bell.ia at gmail.com
Sat Jan 31 14:32:42 PST 2026
On Fri, Jan 30, 2026 at 6:44 PM Even Rouault <even.rouault at spatialys.com>
wrote:
> Andrew,
>
> we regularly do slightly forward incompatible changes in the C++ API, and
> they are documented in
> https://gdal.org/en/latest/user/migration_guide.html .
>
> That change has the advantage of avoiding potential usage errors, in
> particular erroneous use of CSLDestroy() on the return value, which was
> possible when we returned "char **". That way, you can distinguish that
> GetMetadata() return doesn't need to be freed, whereas methods such as
> GDALDataset::GetMetadataDomainList() or GetFileList() that return a
> "char**" do need to have their return value CSLDestroy()'ed after use
>
I guess my feeling is that if the interface has been good enough for 30
years than it doesn't really need to be changed. Programmers need to take
responsibility to use a library properly.
You could leave the current interface in place and add functions to provide
better safety and an interface more expected by C++ programmers. For
example:
std::vector<std::string> Metadata(const std::string& domain = "")
{
std::vector<std::string> v;
char **p = GetMetadata(domain.c_str());
while (p)
v.emplace_back(*p++);
return v;
}
std::vector<std::string_view> MetadataView(const std::string& domain =
"")
{
std::vector<std::string_view> v;
char **p = GetMetadata(domain.c_str());
while (p)
v.emplace_back(*p++);
return v;
}
These functions can be made const without too much trouble as well.
--
Andrew Bell
andrew.bell.ia at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20260131/0b95f6eb/attachment-0001.htm>
More information about the gdal-dev
mailing list