Skip to content
Permalink
Browse files
Use thread safe proj API in all other code paths
  • Loading branch information
nyalldawson committed May 16, 2017
1 parent 4396e53 commit e51737e6e47e8dade4bae19be623702b1c8fcaac
Showing with 16 additions and 7 deletions.
  1. +7 −3 src/app/qgscustomprojectiondialog.cpp
  2. +9 −4 src/core/qgscoordinatereferencesystem.cpp
@@ -453,8 +453,8 @@ void QgsCustomProjectionDialog::on_pbnCalculate_clicked()
//
// We must check the prj def is valid!
//

projPJ myProj = pj_init_plus( teParameters->toPlainText().toLocal8Bit().data() );
projCtx pContext = pj_ctx_alloc();
projPJ myProj = pj_init_plus_ctx( pContext, teParameters->toPlainText().toLocal8Bit().data() );

QgsDebugMsg( QString( "My proj: %1" ).arg( teParameters->toPlainText() ) );

@@ -465,6 +465,7 @@ void QgsCustomProjectionDialog::on_pbnCalculate_clicked()
projectedX->setText( QLatin1String( "" ) );
projectedY->setText( QLatin1String( "" ) );
pj_free( myProj );
pj_ctx_free( pContext );
return;

}
@@ -480,10 +481,11 @@ void QgsCustomProjectionDialog::on_pbnCalculate_clicked()
projectedX->setText( QLatin1String( "" ) );
projectedY->setText( QLatin1String( "" ) );
pj_free( myProj );
pj_ctx_free( pContext );
return;
}

projPJ wgs84Proj = pj_init_plus( GEOPROJ4.toLocal8Bit().data() ); //defined in qgis.h
projPJ wgs84Proj = pj_init_plus_ctx( pContext, GEOPROJ4.toLocal8Bit().data() ); //defined in qgis.h

if ( !wgs84Proj )
{
@@ -492,6 +494,7 @@ void QgsCustomProjectionDialog::on_pbnCalculate_clicked()
projectedX->setText( QLatin1String( "" ) );
projectedY->setText( QLatin1String( "" ) );
pj_free( wgs84Proj );
pj_ctx_free( pContext );
return;
}

@@ -517,6 +520,7 @@ void QgsCustomProjectionDialog::on_pbnCalculate_clicked()
//
pj_free( myProj );
pj_free( wgs84Proj );
pj_ctx_free( pContext );

}

@@ -1099,16 +1099,18 @@ void QgsCoordinateReferenceSystem::setProj4String( const QString &proj4String )
// e.g if they lack a +ellps parameter, it will automatically add +ellps=WGS84, but as
// we use the original mProj4 with QgsCoordinateTransform, it will fail to initialize
// so better detect it now.
projPJ proj = pj_init_plus( proj4String.trimmed().toLatin1().constData() );
projCtx pContext = pj_ctx_alloc();
projPJ proj = pj_init_plus_ctx( pContext, proj4String.trimmed().toLatin1().constData() );
if ( !proj )
{
QgsDebugMsgLevel( "proj.4 string rejected by pj_init_plus()", 4 );
QgsDebugMsgLevel( "proj.4 string rejected by pj_init_plus_ctx()", 4 );
d->mIsValid = false;
}
else
{
pj_free( proj );
}
pj_ctx_free( pContext );
d->mWkt.clear();
setMapUnits();
}
@@ -2020,6 +2022,8 @@ int QgsCoordinateReferenceSystem::syncDatabase()
sqlite3_errmsg( database ) );
}

projCtx pContext = pj_ctx_alloc();

#if !defined(PJ_VERSION) || PJ_VERSION!=470
sql = QStringLiteral( "select auth_name,auth_id,parameters from tbl_srs WHERE auth_name<>'EPSG' AND NOT deprecated AND NOT noupdate" );
if ( sqlite3_prepare( database, sql.toLatin1(), sql.size(), &select, &tail ) == SQLITE_OK )
@@ -2031,11 +2035,11 @@ int QgsCoordinateReferenceSystem::syncDatabase()
const char *params = reinterpret_cast< const char * >( sqlite3_column_text( select, 2 ) );

QString input = QStringLiteral( "+init=%1:%2" ).arg( QString( auth_name ).toLower(), auth_id );
projPJ pj = pj_init_plus( input.toLatin1() );
projPJ pj = pj_init_plus_ctx( pContext, input.toLatin1() );
if ( !pj )
{
input = QStringLiteral( "+init=%1:%2" ).arg( QString( auth_name ).toUpper(), auth_id );
pj = pj_init_plus( input.toLatin1() );
pj = pj_init_plus_ctx( pContext, input.toLatin1() );
}

if ( pj )
@@ -2099,6 +2103,7 @@ int QgsCoordinateReferenceSystem::syncDatabase()
sqlite3_finalize( select );
#endif

pj_ctx_free( pContext );

if ( sqlite3_exec( database, "COMMIT", nullptr, nullptr, nullptr ) != SQLITE_OK )
{

0 comments on commit e51737e

Please sign in to comment.