[Qgis-developer] Crash in thread on FILE opened by a lib compiled by MinGW

Even Rouault even.rouault at spatialys.com
Fri Jun 19 02:32:00 PDT 2015


Le vendredi 19 juin 2015 11:04:39, Radim Blazek a écrit :
> Hi,
> 
> I am trying to fix QGIS (compiled by MSVC) crashes with GRASS 7
> (compiled by MinGW) on Windows. I have traced down that it crashes
> when functions are called on a FILE structure which was created by a
> library (libgrass_gis.7.0.0.dll in this case) compiled by MinGW in a
> thread in an application compiled by MSVC. It crashes in Microsoft
> _lock_file(FILE *pf) where pf is casted to _FILEX:
> 
>     EnterCriticalSection( &(((_FILEX *)pf)->lock) );
> 
> where _FILEX is defined as
> 
>     typedef struct {
>         FILE f;
>         CRITICAL_SECTION lock;
>     }   _FILEX;
> 
> Most probably, when the file is opened in a library compiled by MinGW,
> it is not allocated as _FILEX but as FILE and accessing the lock is
> causing the crash. Does anybody have deeper insight into the problem
> and how to solve it?
> 
> It does not happen with GRASS 6 compiled with MinGW. Are you aware of
> any difference between GRASS 6 and 7 build in OSGeo4W? E.g. different
> GCC version or compilation options?

I cannot comment on this particular case, but in the Windows world, I believe 
the internal layout of FILE structure is specific to the C runtime used, so you 
cannot exchange them between different compilers. If you want to mix them, the 
library must return an opaque pointer to the using code and provide all needed 
functions to manipulate and free it.

/* Opaque type */
typedef struct mySuperFile mySuperFile;

mySuperFile* MyLibReturnFile(...);
int MyLibReadFile(mySuperFile*, ...); /* use same protype as fread() */
void MyLibCloseFile(mySuperFile*);


> 
> It works if the library is compiled by MSVC.
> 
> Radim
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the Qgis-developer mailing list