From a7479972291827e8e58dccb92efcde77009c4e7b Mon Sep 17 00:00:00 2001 From: rouault Date: Tue, 7 Jul 2015 19:50:35 +0000 Subject: [PATCH] OGR CT: no longer enforce C locale if running against latest proj that is locale safe (i.e. with fix for https://github.com/OSGeo/proj.4/issues/226) git-svn-id: https://svn.osgeo.org/gdal/trunk/gdal@29493 f0d54148-0727-0410-94bb-9a71ac55c965 --- ogr/ogrct.cpp | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/ogr/ogrct.cpp b/ogr/ogrct.cpp index 924ff85253..281e2743ea 100644 --- a/ogr/ogrct.cpp +++ b/ogr/ogrct.cpp @@ -77,6 +77,13 @@ static int (*pfn_pj_ctx_get_errno)( projCtx ) = NULL; static projCtx (*pfn_pj_ctx_alloc)(void) = NULL; static void (*pfn_pj_ctx_free)( projCtx ) = NULL; +// Locale-safe proj starts with 4.10 +#if defined(PJ_LOCALE_SAFE) +static int bProjLocaleSafe = PJ_LOCALE_SAFE; +#else +static int bProjLocaleSafe = FALSE; +#endif + #if (defined(WIN32) || defined(WIN32CE)) && !defined(__MINGW32__) # define LIBNAME "proj.dll" #elif defined(__MINGW32__) @@ -254,6 +261,8 @@ static int LoadProjLibrary_unlocked() pfn_pj_ctx_get_errno = (int (*)( projCtx )) CPLGetSymbol( pszLibName, "pj_ctx_get_errno" ); + bProjLocaleSafe = CPLGetSymbol(pszLibName, "pj_atof") != NULL; + CPLPopErrorHandler(); CPLErrorReset(); #endif @@ -273,6 +282,9 @@ static int LoadProjLibrary_unlocked() pfn_pj_init_plus_ctx = NULL; pfn_pj_ctx_get_errno = NULL; } + + if( bProjLocaleSafe ) + CPLDebug("OGRCT", "Using locale-safe proj version"); if( pfn_pj_transform == NULL ) { @@ -303,19 +315,11 @@ static int LoadProjLibrary() /* forth as possible. */ /************************************************************************/ -char *OCTProj4Normalize( const char *pszProj4Src ) - +static char *OCTProj4NormalizeInternal( const char *pszProj4Src ) { char *pszNewProj4Def, *pszCopy; projPJ psPJSource = NULL; - CPLMutexHolderD( &hPROJMutex ); - - if( !LoadProjLibrary_unlocked() || pfn_pj_dalloc == NULL || pfn_pj_get_def == NULL ) - return CPLStrdup( pszProj4Src ); - - CPLLocaleC oLocaleEnforcer; - psPJSource = pfn_pj_init_plus( pszProj4Src ); if( psPJSource == NULL ) @@ -334,6 +338,24 @@ char *OCTProj4Normalize( const char *pszProj4Src ) return pszCopy; } +char *OCTProj4Normalize( const char *pszProj4Src ) + +{ + CPLMutexHolderD( &hPROJMutex ); + + if( !LoadProjLibrary_unlocked() || pfn_pj_dalloc == NULL || pfn_pj_get_def == NULL ) + return CPLStrdup( pszProj4Src ); + + if( bProjLocaleSafe ) + return OCTProj4NormalizeInternal(pszProj4Src); + else + { + CPLLocaleC oLocaleEnforcer; + return OCTProj4NormalizeInternal(pszProj4Src); + } + +} + /************************************************************************/ /* OCTDestroyCoordinateTransformation() */ /************************************************************************/ @@ -552,6 +574,11 @@ int OGRProj4CT::Initialize( OGRSpatialReference * poSourceIn, OGRSpatialReference * poTargetIn ) { + if( bProjLocaleSafe ) + { + return InitializeNoLock(poSourceIn, poTargetIn); + } + CPLLocaleC oLocaleEnforcer; if (pjctx != NULL) {