Skip to content

Commit e76c489

Browse files
committed
Apply special processings of PROJ_LIB to PROJ_DATA as well
PROJ 9.1 recognizes the PROJ_DATA environment variable, as a replacement for PROJ_LIB (both are still recognized by PROJ >= 9.1. PROJ_LIB will be retired in PROJ 10, whose release is unplanned for now) Cf OSGeo/PROJ#3253
1 parent 60ae46a commit e76c489

7 files changed

Lines changed: 56 additions & 53 deletions

File tree

map2img.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ int main(int argc, char *argv[])
139139
if(msGetGlobalDebugLevel() >= MS_DEBUGLEVEL_TUNING)
140140
msGettimeofday(&requeststarttime, NULL);
141141

142-
/* Use PROJ_LIB env vars if set */
143-
msProjLibInitFromEnv();
142+
/* Use PROJ_DATA/PROJ_LIB env vars if set */
143+
msProjDataInitFromEnv();
144144

145145
/* Use MS_ERRORFILE and MS_DEBUGLEVEL env vars if set */
146146
if ( msDebugInitFromEnv() != MS_SUCCESS ) {

mapobject.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ int msSetConfigOption( mapObj *map, const char *key, const char *value)
166166
{
167167
/* We have special "early" handling of this so that it will be */
168168
/* in effect when the projection blocks are parsed and pj_init is called. */
169-
if( strcasecmp(key,"PROJ_LIB") == 0 ) {
169+
if( strcasecmp(key,"PROJ_DATA") == 0 || strcasecmp(key,"PROJ_LIB") == 0 ) {
170170
/* value may be relative to map path */
171-
msSetPROJ_LIB( value, map->mappath );
171+
msSetPROJ_DATA( value, map->mappath );
172172
}
173173

174174
/* Same for MS_ERRORFILE, we want it to kick in as early as possible
@@ -220,8 +220,9 @@ void msApplyMapConfigOptions( mapObj *map )
220220
key != NULL;
221221
key = msNextKeyFromHashTable( &(map->configoptions), key ) ) {
222222
const char *value = msLookupHashTable( &(map->configoptions), key );
223-
if( strcasecmp(key,"PROJ_LIB") == 0 ) {
224-
msSetPROJ_LIB( value, map->mappath );
223+
if( strcasecmp(key,"PROJ_DATA") == 0 ||
224+
strcasecmp(key,"PROJ_LIB") == 0 ) {
225+
msSetPROJ_DATA( value, map->mappath );
225226
} else if( strcasecmp(key,"MS_ERRORFILE") == 0 ) {
226227
msSetErrorFile( value, map->mappath );
227228
} else {

mapproject.c

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
#include "cpl_conv.h"
4040
#include "ogr_srs_api.h"
4141

42-
static char *ms_proj_lib = NULL;
42+
static char *ms_proj_data = NULL;
4343
#if PROJ_VERSION_MAJOR >= 6
44-
static unsigned ms_proj_lib_change_counter = 0;
44+
static unsigned ms_proj_data_change_counter = 0;
4545
#endif
4646

4747
typedef struct LinkedListOfProjContext LinkedListOfProjContext;
@@ -79,7 +79,7 @@ typedef struct
7979
struct projectionContext
8080
{
8181
PJ_CONTEXT* proj_ctx;
82-
unsigned ms_proj_lib_change_counter;
82+
unsigned ms_proj_data_change_counter;
8383
int ref_count;
8484
pjCacheEntry pj_cache[PJ_CACHE_ENTRY_SIZE];
8585
int pj_cache_size;
@@ -865,13 +865,13 @@ int msProcessProjection(projectionObj *p)
865865
return -1;
866866
}
867867
}
868-
if( p->proj_ctx->ms_proj_lib_change_counter != ms_proj_lib_change_counter )
868+
if( p->proj_ctx->ms_proj_data_change_counter != ms_proj_data_change_counter )
869869
{
870870
msAcquireLock( TLOCK_PROJ );
871-
p->proj_ctx->ms_proj_lib_change_counter = ms_proj_lib_change_counter;
871+
p->proj_ctx->ms_proj_data_change_counter = ms_proj_data_change_counter;
872872
{
873-
const char* const paths[1] = { ms_proj_lib };
874-
proj_context_set_search_paths(p->proj_ctx->proj_ctx, 1, ms_proj_lib ? paths : NULL);
873+
const char* const paths[1] = { ms_proj_data };
874+
proj_context_set_search_paths(p->proj_ctx->proj_ctx, 1, ms_proj_data ? paths : NULL);
875875
}
876876
msReleaseLock( TLOCK_PROJ );
877877
}
@@ -2501,103 +2501,104 @@ static const char *msProjFinder( const char *filename)
25012501
if( filename == NULL )
25022502
return NULL;
25032503

2504-
if( ms_proj_lib == NULL )
2504+
if( ms_proj_data == NULL )
25052505
return filename;
25062506

2507-
last_filename = (char *) malloc(strlen(filename)+strlen(ms_proj_lib)+2);
2508-
sprintf( last_filename, "%s/%s", ms_proj_lib, filename );
2507+
last_filename = (char *) malloc(strlen(filename)+strlen(ms_proj_data)+2);
2508+
sprintf( last_filename, "%s/%s", ms_proj_data, filename );
25092509

25102510
return last_filename;
25112511
}
25122512
#endif
25132513

25142514
/************************************************************************/
2515-
/* msProjLibInitFromEnv() */
2515+
/* msProjDataInitFromEnv() */
25162516
/************************************************************************/
2517-
void msProjLibInitFromEnv()
2517+
void msProjDataInitFromEnv()
25182518
{
25192519
const char *val;
25202520

2521-
if( (val=CPLGetConfigOption( "PROJ_LIB", NULL )) != NULL ) {
2522-
msSetPROJ_LIB(val, NULL);
2521+
if( (val=CPLGetConfigOption( "PROJ_DATA", NULL )) != NULL ||
2522+
(val=CPLGetConfigOption( "PROJ_LIB", NULL )) != NULL ) {
2523+
msSetPROJ_DATA(val, NULL);
25232524
}
25242525
}
25252526

25262527
/************************************************************************/
2527-
/* msSetPROJ_LIB() */
2528+
/* msSetPROJ_DATA() */
25282529
/************************************************************************/
2529-
void msSetPROJ_LIB( const char *proj_lib, const char *pszRelToPath )
2530+
void msSetPROJ_DATA( const char *proj_data, const char *pszRelToPath )
25302531

25312532
{
25322533
char *extended_path = NULL;
25332534

25342535
/* Handle relative path if applicable */
2535-
if( proj_lib && pszRelToPath
2536-
&& proj_lib[0] != '/'
2537-
&& proj_lib[0] != '\\'
2538-
&& !(proj_lib[0] != '\0' && proj_lib[1] == ':') ) {
2536+
if( proj_data && pszRelToPath
2537+
&& proj_data[0] != '/'
2538+
&& proj_data[0] != '\\'
2539+
&& !(proj_data[0] != '\0' && proj_data[1] == ':') ) {
25392540
struct stat stat_buf;
25402541
extended_path = (char*) msSmallMalloc(strlen(pszRelToPath)
2541-
+ strlen(proj_lib) + 10);
2542-
sprintf( extended_path, "%s/%s", pszRelToPath, proj_lib );
2542+
+ strlen(proj_data) + 10);
2543+
sprintf( extended_path, "%s/%s", pszRelToPath, proj_data );
25432544

25442545
#ifndef S_ISDIR
25452546
# define S_ISDIR(x) ((x) & S_IFDIR)
25462547
#endif
25472548

25482549
if( stat( extended_path, &stat_buf ) == 0
25492550
&& S_ISDIR(stat_buf.st_mode) )
2550-
proj_lib = extended_path;
2551+
proj_data = extended_path;
25512552
}
25522553

25532554

25542555
msAcquireLock( TLOCK_PROJ );
25552556
#if PROJ_VERSION_MAJOR >= 6
2556-
if( proj_lib == NULL && ms_proj_lib == NULL )
2557+
if( proj_data == NULL && ms_proj_data == NULL )
25572558
{
25582559
/* do nothing */
25592560
}
2560-
else if( proj_lib != NULL && ms_proj_lib != NULL &&
2561-
strcmp(proj_lib, ms_proj_lib) == 0 )
2561+
else if( proj_data != NULL && ms_proj_data != NULL &&
2562+
strcmp(proj_data, ms_proj_data) == 0 )
25622563
{
25632564
/* do nothing */
25642565
}
25652566
else
25662567
{
2567-
ms_proj_lib_change_counter++;
2568-
free( ms_proj_lib );
2569-
ms_proj_lib = proj_lib ? msStrdup(proj_lib) : NULL;
2568+
ms_proj_data_change_counter++;
2569+
free( ms_proj_data );
2570+
ms_proj_data = proj_data ? msStrdup(proj_data) : NULL;
25702571
}
25712572
#else
25722573
{
25732574
static int finder_installed = 0;
2574-
if( finder_installed == 0 && proj_lib != NULL) {
2575+
if( finder_installed == 0 && proj_data != NULL) {
25752576
finder_installed = 1;
25762577
pj_set_finder( msProjFinder );
25772578
}
25782579
}
25792580

2580-
if (proj_lib == NULL) pj_set_finder(NULL);
2581+
if (proj_data == NULL) pj_set_finder(NULL);
25812582

2582-
if( ms_proj_lib != NULL ) {
2583-
free( ms_proj_lib );
2584-
ms_proj_lib = NULL;
2583+
if( ms_proj_data != NULL ) {
2584+
free( ms_proj_data );
2585+
ms_proj_data = NULL;
25852586
}
25862587

25872588
if( last_filename != NULL ) {
25882589
free( last_filename );
25892590
last_filename = NULL;
25902591
}
25912592

2592-
if( proj_lib != NULL )
2593-
ms_proj_lib = msStrdup( proj_lib );
2593+
if( proj_data != NULL )
2594+
ms_proj_data = msStrdup( proj_data );
25942595
#endif
25952596
msReleaseLock( TLOCK_PROJ );
25962597

25972598
#if GDAL_VERSION_MAJOR >= 3
2598-
if( ms_proj_lib != NULL )
2599+
if( ms_proj_data != NULL )
25992600
{
2600-
const char* const apszPaths[] = { ms_proj_lib, NULL };
2601+
const char* const apszPaths[] = { ms_proj_data, NULL };
26012602
OSRSetPROJSearchPaths(apszPaths);
26022603
}
26032604
#endif

mapproject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ but are not directly exposed by the mapscript module
156156
MS_DLL_EXPORT void msAxisDenormalizePoints( projectionObj *proj, int count,
157157
double *x, double *y );
158158

159-
MS_DLL_EXPORT void msSetPROJ_LIB( const char *, const char * );
160-
MS_DLL_EXPORT void msProjLibInitFromEnv();
159+
MS_DLL_EXPORT void msSetPROJ_DATA( const char *, const char * );
160+
MS_DLL_EXPORT void msProjDataInitFromEnv();
161161

162162
int msProjIsGeographicCRS(projectionObj* proj);
163163
#if PROJ_VERSION_MAJOR >= 6

mapserv-config.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ static int loadConfig(configObj *config)
108108
static void msConfigSetConfigOption(const char* key, const char* value)
109109
{
110110
CPLSetConfigOption(key, value);
111-
if( strcasecmp(key,"PROJ_LIB") == 0 ) {
112-
msSetPROJ_LIB( value, nullptr );
111+
if( strcasecmp(key,"PROJ_DATA") == 0 ||
112+
strcasecmp(key,"PROJ_LIB") == 0 ) {
113+
msSetPROJ_DATA( value, nullptr );
113114
}
114115
}
115116

mapservutil.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,8 +2010,8 @@ int msCGIHandler(const char *query_string, void **out_buffer, size_t *buffer_len
20102010

20112011
msIO_installStdoutToBuffer();
20122012

2013-
/* Use PROJ_LIB env vars if set */
2014-
msProjLibInitFromEnv();
2013+
/* Use PROJ_DATA/PROJ_LIB env vars if set */
2014+
msProjDataInitFromEnv();
20152015

20162016
/* Use MS_ERRORFILE and MS_DEBUGLEVEL env vars if set */
20172017
if( msDebugInitFromEnv() != MS_SUCCESS ) {

maputil.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,8 +2008,8 @@ int msSetup()
20082008
msThreadInit();
20092009
#endif
20102010

2011-
/* Use PROJ_LIB env vars if set */
2012-
msProjLibInitFromEnv();
2011+
/* Use PROJ_DATA/PROJ_LIB env vars if set */
2012+
msProjDataInitFromEnv();
20132013

20142014
/* Use MS_ERRORFILE and MS_DEBUGLEVEL env vars if set */
20152015
if (msDebugInitFromEnv() != MS_SUCCESS)
@@ -2069,7 +2069,7 @@ void msCleanup()
20692069
# endif
20702070
pj_deallocate_grids();
20712071
#endif
2072-
msSetPROJ_LIB( NULL, NULL );
2072+
msSetPROJ_DATA( NULL, NULL );
20732073
msProjectionContextPoolCleanup();
20742074

20752075
#if defined(USE_CURL)

0 commit comments

Comments
 (0)