From fbf96e7a81be6dd88708912977e8f9960df050df Mon Sep 17 00:00:00 2001 From: vincentvaroquauxads <77161488+vincentvaroquauxads@users.noreply.github.com> Date: Thu, 12 Sep 2024 17:38:40 +0200 Subject: [PATCH] HasVSIHandler also tests externally registered handlers (fix ubuntu 20.04) (#135) --- godal.cpp | 12 ++++++------ godal.go | 4 ++-- godal.h | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/godal.cpp b/godal.cpp index 025137a..4720055 100644 --- a/godal.cpp +++ b/godal.cpp @@ -1770,20 +1770,20 @@ namespace cpl } // namespace cpl -bool VSIHasGoHandler(const char *pszPrefix) +int godalVSIHasGoHandler(const char *pszPrefix) { CSLConstList papszPrefix = VSIFileManager::GetPrefixes(); for( size_t i = 0; papszPrefix && papszPrefix[i]; ++i ) { if(strcmp(papszPrefix[i],pszPrefix)==0) { - return true; + return TRUE; } } - return false; + return FALSE; } -void VSIInstallGoHandler(cctx *ctx, const char *pszPrefix, size_t bufferSize, size_t cacheSize) +void godalVSIInstallGoHandler(cctx *ctx, const char *pszPrefix, size_t bufferSize, size_t cacheSize) { - bool alreadyExists = VSIHasGoHandler(pszPrefix); + bool alreadyExists = godalVSIHasGoHandler(pszPrefix) != 0; godalWrap(ctx); if (alreadyExists) { CPLError(CE_Failure, CPLE_AppDefined, "handler already registered on prefix"); @@ -1986,4 +1986,4 @@ void godalGCPListToGeoTransform(cctx *ctx, goGCPList GCPList, int numGCPs, doubl CPLFree(GDALGCPList); godalUnwrap(); -} \ No newline at end of file +} diff --git a/godal.go b/godal.go index 902c715..599dda1 100644 --- a/godal.go +++ b/godal.go @@ -3886,7 +3886,7 @@ func RegisterVSIHandler(prefix string, handler KeySizerReaderAt, opts ...VSIHand return fmt.Errorf("handler already registered on prefix") } cgc := createCGOContext(nil, opt.errorHandler) - C.VSIInstallGoHandler(cgc.cPointer(), C.CString(prefix), C.size_t(opt.bufferSize), C.size_t(opt.cacheSize)) + C.godalVSIInstallGoHandler(cgc.cPointer(), C.CString(prefix), C.size_t(opt.bufferSize), C.size_t(opt.cacheSize)) if err := cgc.close(); err != nil { return err } @@ -3900,7 +3900,7 @@ func RegisterVSIHandler(prefix string, handler KeySizerReaderAt, opts ...VSIHand // HasVSIHandler returns true if a VSIHandler is registered for this prefix func HasVSIHandler(prefix string) bool { - return bool(C.VSIHasGoHandler(C.CString(prefix))) + return C.godalVSIHasGoHandler(C.CString(prefix)) != 0 } // BuildVRT runs the GDALBuildVRT function and creates a VRT dataset from a list of datasets diff --git a/godal.h b/godal.h index c834a8e..fd9dfed 100644 --- a/godal.h +++ b/godal.h @@ -130,8 +130,8 @@ extern "C" { void godalStartTransaction(cctx *ctx, GDALDatasetH ds, int bForce); void godalDatasetRollbackTransaction(cctx *ctx, GDALDatasetH ds); void godalCommitTransaction(cctx *ctx, GDALDatasetH ds); - bool VSIHasGoHandler(const char *pszPrefix); - void VSIInstallGoHandler(cctx *ctx, const char *pszPrefix, size_t bufferSize, size_t cacheSize); + int godalVSIHasGoHandler(const char *pszPrefix); + void godalVSIInstallGoHandler(cctx *ctx, const char *pszPrefix, size_t bufferSize, size_t cacheSize); void godalGetColorTable(GDALRasterBandH bnd, GDALPaletteInterp *interp, int *nEntries, short **entries); void godalSetColorTable(cctx *ctx, GDALRasterBandH bnd, GDALPaletteInterp interp, int nEntries, short *entries);