Skip to content

Commit d896c01

Browse files
committed
[GRASS] prepared off_t fix on windows
1 parent c418526 commit d896c01

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/providers/grass/qgsgrassprovider.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,30 @@ extern "C"
7171
#undef __STDC__
7272
#endif
7373

74+
// Vect_rewrite_line and Vect_delete_line use int in GRASS 6 and off_t in GRASS 7 for line id argument.
75+
// off_t size is not specified by C, POSIX specifies it as signed integer and its size depends on compiler.
76+
// 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.
77+
// 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.
78+
// See: https://lists.osgeo.org/pipermail/grass-dev/2015-June/075539.html
79+
// https://lists.osgeo.org/pipermail/grass-dev/2015-September/076338.html
80+
// TODO: get real off_t size from GRASS, probably contribute a patch which will save 'g.version -g' to a header file during compilation
81+
#if GRASS_VERSION_MAJOR < 7
82+
typedef int Vect_rewrite_line_function_type( struct Map_info *, int, int, struct line_pnts *, struct line_cats * );
83+
typedef int Vect_delete_line_function_type( struct Map_info *, int );
84+
#else
85+
#ifdef Q_OS_WIN
86+
// TODO: switch to qint64 and compile with msvc (expected comilation error or warning)
87+
typedef off_t grass_off_t;
88+
//typedef qint64 grass_off_t;
89+
#else
90+
typedef off_t grass_off_t;
91+
#endif
92+
typedef off_t Vect_rewrite_line_function_type( struct Map_info *, grass_off_t, int, const struct line_pnts *, const struct line_cats * );
93+
typedef int Vect_delete_line_function_type( struct Map_info *, grass_off_t );
94+
#endif
95+
Vect_rewrite_line_function_type *Vect_rewrite_line_function_pointer = Vect_rewrite_line;
96+
Vect_delete_line_function_type *Vect_delete_line_function_pointer = Vect_delete_line;
97+
7498
static QString GRASS_KEY = "grass";
7599

76100
QgsGrassProvider::QgsGrassProvider( QString uri )
@@ -748,7 +772,7 @@ int QgsGrassProvider::rewriteLine( int oldLid, int type, struct line_pnts *Point
748772
int newLid = -1;
749773
G_TRY
750774
{
751-
newLid = Vect_rewrite_line( map(), oldLid, type, Points, Cats );
775+
newLid = Vect_rewrite_line_function_pointer( map(), oldLid, type, Points, Cats );
752776

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

781-
return ( Vect_delete_line( map(), line ) );
805+
return ( Vect_delete_line_function_pointer( map(), line ) );
782806
}
783807

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

0 commit comments

Comments
 (0)