Changes between Version 1 and Version 2 of Ticket #6602


Ignore:
Timestamp:
Jul 21, 2016, 9:40:43 AM (8 years ago)
Author:
Kurt Schwehr
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #6602

    • Property Status newassigned
  • Ticket #6602 – Description

    v1 v2  
    2020- Revert and give up in despair
    2121- Can we cast in the C code?
     22- Convert C code to C++ (doesn't help mapserver, which is C)
    2223- Or?
    2324
    24 Reported by EvenR.  Need an example failure.
     25Reported by EvenR.
     26
     27Example code that is failing (from Ubuntu 14.04 @ r34748):
     28
     29{{{#!c
     30/* avc_e00read.c */
     31static int _AVCE00ReadBuildSqueleton(AVCE00ReadPtr psInfo,
     32                                     char **papszCoverDir)
     33{
     34
     35/* ... */
     36
     37    szFname = (psInfo->eCoverType==AVCCoverV7 ||
     38               psInfo->eCoverType==AVCCoverPC2 ) ? "arc.adf": "arc";
     39    if ( (iFile=CSLFindString(papszCoverDir, szFname)) != -1 &&
     40         (psFile = AVCBinReadOpen(psInfo->pszCoverPath, szFname,
     41                                  psInfo->eCoverType, AVCFileARC,
     42                                  psInfo->psDBCSInfo)) != NULL)
     43    {
     44}}}
     45
     46Fails like:
     47
     48{{{
     49avc_e00read.c: In function '_AVCE00ReadBuildSqueleton':
     50avc_e00read.c:1040:5: warning: passing argument 1 of 'CSLFindString' from incompatible pointer type [enabled by default]
     51     if ( (iFile=CSLFindString(papszCoverDir, szFname)) != -1 &&
     52     ^
     53In file included from avc.h:119:0,
     54                 from avc_e00read.c:129:
     55/home/schwehr/src/gdal/gdal/port/cpl_string.h:106:13: note: expected 'const char * const*' but argument is of type 'char **'
     56 int CPL_DLL CSLFindString( const char * const *, const char * );
     57}}}
     58
     59Could cast in C:
     60{{{#!c
     61    szFname = (psInfo->eCoverType==AVCCoverV7 ||
     62               psInfo->eCoverType==AVCCoverPC2 ) ? "arc.adf": "arc";
     63    if ( (iFile=CSLFindString((const char * const *)papszCoverDir, szFname)) != -1 &&
     64         (psFile = AVCBinReadOpen(psInfo->pszCoverPath, szFname,
     65                                  psInfo->eCoverType, AVCFileARC,
     66                                  psInfo->psDBCSInfo)) != NULL)
     67    {
     68
     69}}}
     70
     71Or modify cpl_string.h to present non-const to C. (least bad so far)
     72{{{#!c++
     73#ifdef __cplusplus
     74int CPL_DLL CSLFindString( const char * const *, const char * );
     75int CPL_DLL CSLFindStringCaseSensitive( const char * const *, const char * );
     76int CPL_DLL CSLPartialFindString( const char * const *papszHaystack,
     77                                  const char * pszNeedle );
     78#else
     79// Present non-const to C code that does not like passing non-const to const.
     80int CPL_DLL CSLFindString( char **, const char * );
     81int CPL_DLL CSLFindStringCaseSensitive( char **, const char * );
     82int CPL_DLL CSLPartialFindString( char **papszHaystack,
     83                                  const char * pszNeedle );
     84#endif
     85}}}