Skip to content

Commit

Permalink
OGR CT: no longer enforce C locale if running against latest proj tha…
Browse files Browse the repository at this point in the history
…t is locale safe (i.e. with fix for OSGeo/PROJ#226)

git-svn-id: https://svn.osgeo.org/gdal/trunk/gdal@29493 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information
rouault committed Jul 7, 2015
1 parent 1f615cf commit a747997
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions ogr/ogrct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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 )
Expand All @@ -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() */
/************************************************************************/
Expand Down Expand Up @@ -552,6 +574,11 @@ int OGRProj4CT::Initialize( OGRSpatialReference * poSourceIn,
OGRSpatialReference * poTargetIn )

{
if( bProjLocaleSafe )
{
return InitializeNoLock(poSourceIn, poTargetIn);
}

CPLLocaleC oLocaleEnforcer;
if (pjctx != NULL)
{
Expand Down

0 comments on commit a747997

Please sign in to comment.