Skip to content

Commit

Permalink
[GRASS] prepared off_t fix on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Oct 14, 2015
1 parent c418526 commit d896c01
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/providers/grass/qgsgrassprovider.cpp
Expand Up @@ -71,6 +71,30 @@ extern "C"
#undef __STDC__
#endif

// Vect_rewrite_line and Vect_delete_line use int in GRASS 6 and off_t in GRASS 7 for line id argument.
// off_t size is not specified by C, POSIX specifies it as signed integer and its size depends on compiler.
// In OSGeo4W 32bit the off_t size is 8 bytes in GRASS (compiled with MinGW), and 4 bytes QGIS (compiled with MSVC), which is causing crashes.
// The problem with off_t size was also reported for custom build of QGIS on Xubuntu 14.04 LTS using GRASS 7.0.1-2~ubuntu14.04.1.
// See: https://lists.osgeo.org/pipermail/grass-dev/2015-June/075539.html
// https://lists.osgeo.org/pipermail/grass-dev/2015-September/076338.html
// TODO: get real off_t size from GRASS, probably contribute a patch which will save 'g.version -g' to a header file during compilation
#if GRASS_VERSION_MAJOR < 7
typedef int Vect_rewrite_line_function_type( struct Map_info *, int, int, struct line_pnts *, struct line_cats * );
typedef int Vect_delete_line_function_type( struct Map_info *, int );
#else
#ifdef Q_OS_WIN
// TODO: switch to qint64 and compile with msvc (expected comilation error or warning)
typedef off_t grass_off_t;
//typedef qint64 grass_off_t;
#else
typedef off_t grass_off_t;
#endif
typedef off_t Vect_rewrite_line_function_type( struct Map_info *, grass_off_t, int, const struct line_pnts *, const struct line_cats * );
typedef int Vect_delete_line_function_type( struct Map_info *, grass_off_t );
#endif
Vect_rewrite_line_function_type *Vect_rewrite_line_function_pointer = Vect_rewrite_line;
Vect_delete_line_function_type *Vect_delete_line_function_pointer = Vect_delete_line;

static QString GRASS_KEY = "grass";

QgsGrassProvider::QgsGrassProvider( QString uri )
Expand Down Expand Up @@ -748,7 +772,7 @@ int QgsGrassProvider::rewriteLine( int oldLid, int type, struct line_pnts *Point
int newLid = -1;
G_TRY
{
newLid = Vect_rewrite_line( map(), oldLid, type, Points, Cats );
newLid = Vect_rewrite_line_function_pointer( map(), oldLid, type, Points, Cats );

// oldLids are maping to the very first, original version (used by undo)
int oldestLid = oldLid;
Expand Down Expand Up @@ -778,7 +802,7 @@ int QgsGrassProvider::deleteLine( int line )
if ( !isEdited() )
return -1;

return ( Vect_delete_line( map(), line ) );
return ( Vect_delete_line_function_pointer( map(), line ) );
}

int QgsGrassProvider::findLine( double x, double y, int type, double threshold )
Expand Down

0 comments on commit d896c01

Please sign in to comment.