Skip to content

Commit 6accda4

Browse files
author
pcav
committed
Revert patch uncorrectly applied
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11434 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent f05e245 commit 6accda4

File tree

7 files changed

+163
-141
lines changed

7 files changed

+163
-141
lines changed

src/plugins/grass/qgsgrassmodel.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class QgsGrassModelItem
3737
{
3838
public:
3939
QgsGrassModelItem( QgsGrassModelItem *parent, int row, QString name,
40-
QString path, int type );
40+
QString path, int type );
4141
QgsGrassModelItem();
4242
~QgsGrassModelItem();
4343

@@ -81,7 +81,7 @@ QgsGrassModelItem::QgsGrassModelItem()
8181

8282
QgsGrassModelItem::~QgsGrassModelItem()
8383
{
84-
for ( int i = 0; i < mChildren.size(); i++ )
84+
for ( int i = 0; i < mChildren.size();i++ )
8585
{
8686
delete mChildren[i];
8787
}
@@ -606,13 +606,13 @@ void QgsGrassModel::addItems( QgsGrassModelItem *item, QStringList list, int typ
606606

607607
// Add new items
608608

609-
for ( int i = 0; i < list.size(); i++ )
609+
for ( int i = 0; i < list.size();i++ )
610610
{
611611
QString name = list.at( i );
612612
// QgsDebugMsg(QString("? add %1").arg(name));
613613

614614
int insertAt = item->mChildren.size();
615-
for ( int i = 0; i < item->mChildren.size(); i++ )
615+
for ( int i = 0; i < item->mChildren.size();i++ )
616616
{
617617
if ( item->mChildren[i]->name() == name )
618618
{
@@ -897,6 +897,7 @@ QVariant QgsGrassModel::data( const QModelIndex &index, int role ) const
897897
default:
898898
return mIconDirectory;
899899
}
900+
return mIconDirectory;
900901
}
901902
return item->data( role );
902903
}

src/plugins/grass/qgsgrassnewmapset.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -1268,20 +1268,17 @@ void QgsGrassNewMapset::createMapset()
12681268

12691269
int ret = 0;
12701270

1271-
try
1271+
QgsGrass::resetError();
1272+
if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
12721273
{
12731274
ret = G_make_location( location.toAscii().data(), &mCellHead, mProjInfo, mProjUnits, stdout );
12741275
}
1275-
catch ( QgsGrass::Exception &e )
1276-
{
1277-
ret = -1;
1278-
Q_UNUSED( e );
1279-
}
1276+
QgsGrass::clearErrorEnv();
12801277

1281-
if ( ret != 0 )
1278+
if ( QgsGrass::getError() == QgsGrass::FATAL || ret != 0 )
12821279
{
12831280
QMessageBox::warning( this, tr( "Create location" ),
1284-
tr( "Cannot create new location: %1" ).arg( QgsGrass::errorMessage() ) );
1281+
tr( "Cannot create new location: %1" ).arg( QgsGrass::getErrorMessage() ) );
12851282
return;
12861283
}
12871284

src/plugins/grass/qgsgrassplugin.cpp

+22-24
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,14 @@ void QgsGrassPlugin::addVector()
301301
QgsGrass::setLocation( sel->gisdbase, sel->location );
302302

303303
/* Open vector */
304-
try
305-
{
306-
Vect_set_open_level( 2 );
307-
struct Map_info map;
308-
int level = Vect_open_old_head( &map, sel->map.toAscii().data(),
309-
sel->mapset.toAscii().data() );
304+
QgsGrass::resetError();
305+
Vect_set_open_level( 2 );
306+
struct Map_info map;
307+
int level = Vect_open_old_head( &map, sel->map.toAscii().data(),
308+
sel->mapset.toAscii().data() );
310309

310+
if ( QgsGrass::getError() != QgsGrass::FATAL )
311+
{
311312
if ( level >= 2 )
312313
{
313314
// Count layers
@@ -335,9 +336,9 @@ void QgsGrassPlugin::addVector()
335336

336337
Vect_close( &map );
337338
}
338-
catch ( QgsGrass::Exception &e )
339+
else
339340
{
340-
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS vector:\n %1" ).arg( e.what() ) );
341+
QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS vector:\n %1" ).arg( QgsGrass::getErrorMessage() ) );
341342
}
342343

343344
qGisInterface->addVectorLayer( uri, name, "grass" );
@@ -485,28 +486,25 @@ void QgsGrassPlugin::newVector()
485486
QgsGrass::getDefaultLocation(),
486487
QgsGrass::getDefaultMapset() );
487488

488-
try
489-
{
490-
struct Map_info Map;
491-
Vect_open_new( &Map, name.toAscii().data(), 0 );
489+
QgsGrass::resetError();
490+
struct Map_info Map;
491+
Vect_open_new( &Map, name.toAscii().data(), 0 );
492492

493-
#if defined(GRASS_VERSION_MAJOR) && defined(GRASS_VERSION_MINOR) && \
494-
( ( GRASS_VERSION_MAJOR == 6 && GRASS_VERSION_MINOR >= 4 ) || GRASS_VERSION_MAJOR > 6 )
495-
Vect_build( &Map );
496-
#else
497-
Vect_build( &Map, stderr );
498-
#endif
499-
Vect_set_release_support( &Map );
500-
Vect_close( &Map );
501-
}
502-
catch ( QgsGrass::Exception &e )
493+
if ( QgsGrass::getError() == QgsGrass::FATAL )
503494
{
504495
QMessageBox::warning( 0, tr( "Warning" ),
505-
tr( "Cannot create new vector: %1" ).arg( e.what() ) );
496+
tr( "Cannot create new vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
506497
return;
507498
}
508499

509-
500+
#if defined(GRASS_VERSION_MAJOR) && defined(GRASS_VERSION_MINOR) && \
501+
( ( GRASS_VERSION_MAJOR == 6 && GRASS_VERSION_MINOR >= 4 ) || GRASS_VERSION_MAJOR > 6 )
502+
Vect_build( &Map );
503+
#else
504+
Vect_build( &Map, stderr );
505+
#endif
506+
Vect_set_release_support( &Map );
507+
Vect_close( &Map );
510508

511509
// Open in GRASS vector provider
512510

src/plugins/grass/qgsgrassselect.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,15 @@ QStringList QgsGrassSelect::vectorLayers( QString gisdbase,
410410
// Call to setjmp() returns 0 first time. In case of fatal error,
411411
// our error routine uses longjmp() to come back to this context,
412412
// this time setjmp() will return non-zero value and we can continue...
413-
414-
try
413+
if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
415414
{
416415
level = Vect_open_old_head( &map, ( char * ) mapName.toAscii().data(), ( char * ) mapset.toAscii().data() );
417416
}
418-
catch ( QgsGrass::Exception &e )
417+
QgsGrass::clearErrorEnv();
418+
419+
if ( QgsGrass::getError() == QgsGrass::FATAL )
419420
{
420-
QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( e.what() ) );
421+
QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
421422
return list;
422423
}
423424

src/providers/grass/qgsgrass.cpp

+33-9
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ void GRASS_EXPORT QgsGrass::init( void )
5454
// Set error function
5555
G_set_error_routine( &error_routine );
5656

57-
if ( initialized )
58-
return;
57+
if ( initialized ) return;
5958

6059
QSettings settings;
6160

@@ -356,7 +355,7 @@ int QgsGrass::initialized = 0;
356355

357356
bool QgsGrass::active = 0;
358357

359-
QgsGrass::GERROR QgsGrass::lastError = QgsGrass::OK;
358+
QgsGrass::GERROR QgsGrass::error = QgsGrass::OK;
360359

361360
QString QgsGrass::error_message;
362361

@@ -368,6 +367,9 @@ QString QgsGrass::mMapsetLock;
368367
QString QgsGrass::mGisrc;
369368
QString QgsGrass::mTmp;
370369

370+
jmp_buf QgsGrass::mFatalErrorEnv;
371+
bool QgsGrass::mFatalErrorEnvActive = false;
372+
371373
int QgsGrass::error_routine( char *msg, int fatal )
372374
{
373375
return error_routine(( const char* ) msg, fatal );
@@ -381,30 +383,52 @@ int QgsGrass::error_routine( const char *msg, int fatal )
381383

382384
if ( fatal )
383385
{
386+
error = FATAL;
384387
// we have to do a long jump here, otherwise GRASS >= 6.3 will kill our process
385-
throw QgsGrass::Exception( msg );
388+
if ( mFatalErrorEnvActive )
389+
longjmp( mFatalErrorEnv, 1 );
390+
else
391+
{
392+
QMessageBox::warning( 0, QObject::tr( "Uncatched fatal GRASS error" ), msg );
393+
abort();
394+
}
386395
}
387396
else
388-
lastError = WARNING;
397+
error = WARNING;
389398

390399
return 1;
391400
}
392401

393402
void GRASS_EXPORT QgsGrass::resetError( void )
394403
{
395-
lastError = OK;
404+
error = OK;
396405
}
397406

398-
int GRASS_EXPORT QgsGrass::error( void )
407+
int GRASS_EXPORT QgsGrass::getError( void )
399408
{
400-
return lastError;
409+
return error;
401410
}
402411

403-
QString GRASS_EXPORT QgsGrass::errorMessage( void )
412+
QString GRASS_EXPORT QgsGrass::getErrorMessage( void )
404413
{
405414
return error_message;
406415
}
407416

417+
jmp_buf GRASS_EXPORT &QgsGrass::fatalErrorEnv()
418+
{
419+
if ( mFatalErrorEnvActive )
420+
QgsDebugMsg( "fatal error environment already active." );
421+
mFatalErrorEnvActive = true;
422+
return mFatalErrorEnv;
423+
}
424+
425+
void GRASS_EXPORT QgsGrass::clearErrorEnv()
426+
{
427+
if ( !mFatalErrorEnvActive )
428+
QgsDebugMsg( "fatal error environment already deactive." );
429+
mFatalErrorEnvActive = false;
430+
}
431+
408432
QString GRASS_EXPORT QgsGrass::openMapset( QString gisdbase, QString location, QString mapset )
409433
{
410434
QgsDebugMsg( QString( "gisdbase = %1" ).arg( gisdbase.toLocal8Bit().constData() ) );

src/providers/grass/qgsgrass.h

+16-13
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,15 @@ extern "C"
2424
}
2525

2626
#include <QString>
27+
#include <setjmp.h>
2728

2829
/*!
2930
Methods for C library initialization and error handling.
3031
*/
3132
class QgsGrass
3233
{
33-
public:
34-
class Exception
35-
{
36-
QString mMsg;
37-
public:
38-
Exception( const char *msg ) : mMsg( msg ) {}
39-
QString what() const { return mMsg; }
40-
};
4134

35+
public:
4236
//! Get info about the mode
4337
/*! QgsGrass may be running in active or passive mode.
4438
* Active mode means that GISRC is set up and GISRC file is available,
@@ -70,9 +64,10 @@ class QgsGrass
7064
*/
7165
static GRASS_EXPORT void setMapset( QString gisdbase, QString location, QString mapset );
7266

73-
//! Error codes returned by error()
67+
//! Error codes returned by GetError()
7468
enum GERROR { OK, /*!< OK. No error. */
75-
WARNING /*!< Warning, non fatal error. Should be printed by application. */
69+
WARNING, /*!< Warning, non fatal error. Should be printed by application. */
70+
FATAL /*!< Fatal error. Function faild. */
7671
};
7772

7873
//! Map type
@@ -82,10 +77,10 @@ class QgsGrass
8277
static GRASS_EXPORT void resetError( void ); // reset error status
8378

8479
//! Check if any error occured in lately called functions. Returns value from ERROR.
85-
static GRASS_EXPORT int error( void );
80+
static GRASS_EXPORT int getError( void );
8681

8782
//! Get last error message
88-
static GRASS_EXPORT QString errorMessage( void );
83+
static GRASS_EXPORT QString getErrorMessage( void );
8984

9085
/** \brief Open existing GRASS mapset
9186
* \return NULL string or error message
@@ -165,6 +160,10 @@ class QgsGrass
165160
static GRASS_EXPORT int versionRelease();
166161
static GRASS_EXPORT QString versionString();
167162

163+
static GRASS_EXPORT jmp_buf& fatalErrorEnv();
164+
static GRASS_EXPORT void clearErrorEnv();
165+
166+
168167
private:
169168
static int initialized; // Set to 1 after initialization
170169
static bool active; // is active mode
@@ -173,7 +172,7 @@ class QgsGrass
173172
static QString defaultMapset;
174173

175174
/* last error in GRASS libraries */
176-
static GERROR lastError; // static, because used in constructor
175+
static GERROR error; // static, because used in constructor
177176
static QString error_message;
178177

179178
// G_set_error_routine has two versions of the function's first argument it expects:
@@ -189,6 +188,10 @@ class QgsGrass
189188
static QString mGisrc;
190189
// Temporary directory where GISRC and sockets are stored
191190
static QString mTmp;
191+
192+
// Context saved before a call to routine that can produce a fatal error
193+
static jmp_buf mFatalErrorEnv;
194+
static bool mFatalErrorEnvActive;
192195
};
193196

194197
#endif // QGSGRASS_H

0 commit comments

Comments
 (0)