Skip to content

Commit

Permalink
Merge pull request #1179 from alanstewart-terragotech/macos-fix-compile
Browse files Browse the repository at this point in the history
OSX: fix build failures due to json-c
  • Loading branch information
rouault authored Jan 8, 2019
2 parents ee9dc4f + c3b17f3 commit dfe030c
Show file tree
Hide file tree
Showing 29 changed files with 210 additions and 186 deletions.
9 changes: 8 additions & 1 deletion gdal/ci/travis/osx/before_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
set -e

brew update
brew uninstall postgis gdal
if brew ls --versions postgis >/dev/null
then
brew uninstall postgis
fi
if brew ls --versions gdal >/dev/null
then
brew uninstall gdal
fi
brew install sqlite3 ccache
3 changes: 2 additions & 1 deletion gdal/ci/travis/osx/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ make install
export PATH=$HOME/install-gdal/bin:$PWD/apps/.libs:$PATH
export DYLD_LIBRARY_PATH=$HOME/install-gdal/lib
export GDAL_DATA=$HOME/install-gdal/share/gdal
export PYTHONPATH=$PWD/swig/python/build/lib.macosx-10.12-intel-2.7:$PWD/swig/python/build/lib.macosx-10.11-x86_64-2.7
export PYTHONPATH=$PWD/swig/python/build/lib.macosx-10.12-intel-2.7:$PWD/swig/python/build/lib.macosx-10.11-x86_64-2.7:$PWD/swig/python/build/lib.macosx-10.12-x86_64-2.7

cd ../autotest/cpp
echo $PATH
#sudo rm -rf /usr/local/Cellar/gdal/1.10.1_1/*
Expand Down
2 changes: 1 addition & 1 deletion gdal/ci/travis/osx/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

export PYTHONPATH=$PWD/gdal/swig/python/build/lib.macosx-10.12-intel-2.7:$PWD/gdal/swig/python/build/lib.macosx-10.11-x86_64-2.7
export PYTHONPATH=$PWD/gdal/swig/python/build/lib.macosx-10.12-intel-2.7:$PWD/gdal/swig/python/build/lib.macosx-10.11-x86_64-2.7:$PWD/gdal/swig/python/build/lib.macosx-10.12-x86_64-2.7
export PYTEST="pytest -vv -p no:sugar --color=no"

echo 'Running CPP unit tests'
Expand Down
4 changes: 2 additions & 2 deletions gdal/frmts/eeda/eedacommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
std::vector<EEDAIBandDesc> BuildBandDescArray(json_object* poBands,
std::map<CPLString, CPLString>& oMapCodeToWKT)
{
const int nBandCount = json_object_array_length( poBands );
const auto nBandCount = json_object_array_length( poBands );
std::vector<EEDAIBandDesc> aoBandDesc;

for(int i = 0; i < nBandCount; i++)
for(auto i = decltype(nBandCount){0}; i < nBandCount; i++)
{
json_object* poBand = json_object_array_get_idx(poBands, i);
if( poBand == nullptr || json_object_get_type(poBand) != json_type_object )
Expand Down
6 changes: 3 additions & 3 deletions gdal/frmts/eeda/eedadataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ GDALEEDALayer::GDALEEDALayer(GDALEEDADataset* poDS,
return;
}

const int nFields = json_object_array_length(poFields);
for( int i=0; i<nFields; i++ )
const auto nFields = json_object_array_length(poFields);
for( auto i=decltype(nFields){0}; i<nFields; i++ )
{
json_object* poField = json_object_array_get_idx(poFields, i);
if( poField && json_object_get_type(poField) == json_type_object )
Expand Down Expand Up @@ -381,7 +381,7 @@ OGRFeature* GDALEEDALayer::GetNextRawFeature()
{
CPLString osNextPageToken;
if( m_poCurPageAssets != nullptr &&
m_nIndexInPage >= json_object_array_length(m_poCurPageAssets) )
m_nIndexInPage >= static_cast<int>(json_object_array_length(m_poCurPageAssets)) )
{
json_object* poToken =
CPL_json_object_object_get(m_poCurPageObj, "nextPageToken");
Expand Down
2 changes: 1 addition & 1 deletion gdal/frmts/hdf5/bagdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ constexpr float fDEFAULT_NODATA = 1000000.0f;
/************************************************************************/

#ifdef DEBUG
static int h5check(int ret, const char* filename, int line)
template<class T> static T h5check(T ret, const char* filename, int line)
{
if( ret < 0 )
{
Expand Down
3 changes: 1 addition & 2 deletions gdal/frmts/mbtiles/mbtilesdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,11 @@ char* MBTilesDataset::FindKey(int iPixel, int iLine)
}
if (poGrid != nullptr && json_object_is_type(poGrid, json_type_array))
{
int nLines;
int nFactor;
json_object* poRow;
char* pszRow = nullptr;

nLines = json_object_array_length(poGrid);
const auto nLines = json_object_array_length(poGrid);
if (nLines == 0)
goto end;

Expand Down
7 changes: 4 additions & 3 deletions gdal/frmts/plmosaic/plmosaicdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,8 +1108,8 @@ std::vector<CPLString> PLMosaicDataset::ListSubdatasets()
return aosNameList;
}

const int nMosaics = json_object_array_length(poMosaics);
for(int i=0;i< nMosaics;i++)
const auto nMosaics = json_object_array_length(poMosaics);
for(auto i=decltype(nMosaics){0};i< nMosaics;i++)
{
const char* pszName = nullptr;
const char* pszCoordinateSystem = nullptr;
Expand Down Expand Up @@ -1416,7 +1416,8 @@ const char* PLMosaicDataset::GetLocationInfo(int nPixel, int nLine)
{
CPLXMLNode* psScenes =
CPLCreateXMLNode(psRoot, CXT_Element, "Scenes");
for(int i = 0; i < json_object_array_length(poItems); i++ )
const auto nItemsLength = json_object_array_length(poItems);
for(auto i = decltype(nItemsLength){0}; i < nItemsLength; i++ )
{
json_object* poObj = json_object_array_get_idx(poItems, i);
if ( poObj && json_object_get_type(poObj) == json_type_object )
Expand Down
4 changes: 2 additions & 2 deletions gdal/frmts/rda/rdadataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,8 @@ bool GDALRDADataset::ParseConnectionString( GDALOpenInfo* poOpenInfo )

if(poParams != nullptr &&
json_object_get_type(poParams) == json_type_array ) {
const int nSize = json_object_array_length(poParams);
for (int i = 0; i < nSize; ++i) {
const auto nSize = json_object_array_length(poParams);
for (auto i = decltype(nSize){0}; i < nSize; ++i) {
json_object *ds = json_object_array_get_idx(poParams, i);
if (ds != nullptr) {
json_object_iter it;
Expand Down
18 changes: 9 additions & 9 deletions gdal/ogr/ogrfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3941,39 +3941,39 @@ void OGRFeature::SetField( int iField, const char * pszValue )
if( pszValue[0] == '[' && pszValue[strlen(pszValue)-1] == ']' &&
OGRJSonParse(pszValue, &poJSonObj, false) )
{
const int nLength = json_object_array_length(poJSonObj);
const auto nLength = json_object_array_length(poJSonObj);
if( eType == OFTIntegerList && nLength > 0 )
{
std::vector<int> anValues;
for( int i = 0; i < nLength; i++ )
for( auto i = decltype(nLength){0}; i < nLength; i++ )
{
json_object* poItem =
json_object_array_get_idx(poJSonObj, i);
anValues.push_back( json_object_get_int( poItem ) );
}
SetField( iField, nLength, &(anValues[0]) );
SetField( iField, static_cast<int>(nLength), &(anValues[0]) );
}
else if( eType == OFTInteger64List && nLength > 0 )
{
std::vector<GIntBig> anValues;
for( int i = 0; i < nLength; i++ )
for( auto i = decltype(nLength){0}; i < nLength; i++ )
{
json_object* poItem =
json_object_array_get_idx(poJSonObj, i);
anValues.push_back( json_object_get_int64( poItem ) );
}
SetField( iField, nLength, &(anValues[0]) );
SetField( iField, static_cast<int>(nLength), &(anValues[0]) );
}
else if( eType == OFTRealList && nLength > 0 )
{
std::vector<double> adfValues;
for( int i = 0; i < nLength; i++ )
for( auto i = decltype(nLength){0}; i < nLength; i++ )
{
json_object* poItem =
json_object_array_get_idx(poJSonObj, i);
adfValues.push_back( json_object_get_double( poItem ) );
}
SetField( iField, nLength, &(adfValues[0]) );
SetField( iField, static_cast<int>(nLength), &(adfValues[0]) );
}

json_object_put(poJSonObj);
Expand Down Expand Up @@ -4078,8 +4078,8 @@ void OGRFeature::SetField( int iField, const char * pszValue )
OGRJSonParse(pszValue, &poJSonObj, false) )
{
CPLStringList aoList;
const int nLength = json_object_array_length(poJSonObj);
for( int i = 0; i < nLength; i++ )
const auto nLength = json_object_array_length(poJSonObj);
for( auto i = decltype(nLength){0}; i < nLength; i++ )
{
json_object* poItem =
json_object_array_get_idx(poJSonObj, i);
Expand Down
4 changes: 2 additions & 2 deletions gdal/ogr/ogrsf_frmts/amigocloud/ogramigoclouddatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ bool OGRAmigoCloudDataSource::ListDatasets()
CPLprintf("List of available datasets for project id: %s\n", GetProjectId());
CPLprintf("| id \t | name\n");
CPLprintf("|--------|-------------------\n");
const int nSize = json_object_array_length(poResults);
for(int i = 0; i < nSize; ++i) {
const auto nSize = json_object_array_length(poResults);
for(auto i = decltype(nSize){0}; i < nSize; ++i) {
json_object *ds = json_object_array_get_idx(poResults, i);
if(ds!=nullptr) {
const char *name = nullptr;
Expand Down
6 changes: 3 additions & 3 deletions gdal/ogr/ogrsf_frmts/amigocloud/ogramigocloudlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ OGRFeature *OGRAmigoCloudLayer::GetNextRawFeature()
json_object_put(poCachedObj);
poCachedObj = poObj;

nFetchedObjects = json_object_array_length(poRows);
nFetchedObjects = static_cast<decltype(nFetchedObjects)>(json_object_array_length(poRows));
iNextInFetchedObjects = 0;
}

Expand Down Expand Up @@ -334,9 +334,9 @@ void OGRAmigoCloudLayer::EstablishLayerDefn(const char* pszLayerName,
return;
}

int size = json_object_array_length(poFields);
auto size = json_object_array_length(poFields);

for(int i=0; i< size; i++)
for(auto i=decltype(size){0}; i< size; i++)
{
json_object *obj = json_object_array_get_idx(poFields, i);

Expand Down
4 changes: 2 additions & 2 deletions gdal/ogr/ogrsf_frmts/amigocloud/ogramigocloudtablelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ OGRFeatureDefn * OGRAmigoCloudTableLayer::GetLayerDefnInternal(CPL_UNUSED json_o
if(poRows!=nullptr && json_object_get_type(poRows) == json_type_array)
{
mFIDs.clear();
auto nLength = json_object_array_length(poRows);
for(decltype(nLength) i = 0; i < nLength; i++)
const auto nLength = json_object_array_length(poRows);
for(auto i = decltype(nLength){0}; i < nLength; i++)
{
json_object *obj = json_object_array_get_idx(poRows, i);

Expand Down
2 changes: 1 addition & 1 deletion gdal/ogr/ogrsf_frmts/carto/ogrcartolayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ OGRFeature *OGRCARTOLayer::GetNextRawFeature()
json_object_put(poCachedObj);
poCachedObj = poObj;

nFetchedObjects = json_object_array_length(poRows);
nFetchedObjects = static_cast<decltype(nFetchedObjects)>(json_object_array_length(poRows));
iNextInFetchedObjects = 0;
}

Expand Down
4 changes: 2 additions & 2 deletions gdal/ogr/ogrsf_frmts/cloudant/ogrcloudantdatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ int OGRCloudantDataSource::Open( const char * pszFilename, int bUpdateIn)
}
}

int nTables = json_object_array_length(poAnswerObj);
auto nTables = json_object_array_length(poAnswerObj);

for(int i=0;i<nTables;i++)
for(auto i=decltype(nTables){0};i<nTables;i++)
{
json_object* poAnswerObjDBName = json_object_array_get_idx(poAnswerObj, i);
if ( json_object_is_type(poAnswerObjDBName, json_type_string) )
Expand Down
8 changes: 4 additions & 4 deletions gdal/ogr/ogrsf_frmts/cloudant/ogrcloudanttablelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ bool OGRCloudantTableLayer::RunSpatialFilterQueryIfNecessary()
return false;
}

int nRows = json_object_array_length(poRows);
for(int i=0;i<nRows;i++)
auto nRows = json_object_array_length(poRows);
for(auto i=decltype(nRows){0};i<nRows;i++)
{
json_object* poRow = json_object_array_get_idx(poRows, i);
if ( poRow == nullptr ||
Expand Down Expand Up @@ -495,8 +495,8 @@ void OGRCloudantTableLayer::LoadMetadata()
OGRFieldDefn oFieldRev("_rev", OFTString);
poFeatureDefn->AddFieldDefn(&oFieldRev);

int nFields = json_object_array_length(poFields);
for(int i=0;i<nFields;i++)
auto nFields = json_object_array_length(poFields);
for(auto i=decltype(nFields){0};i<nFields;i++)
{
json_object* poField = json_object_array_get_idx(poFields, i);
if (poField && json_object_is_type(poField, json_type_object))
Expand Down
6 changes: 3 additions & 3 deletions gdal/ogr/ogrsf_frmts/couchdb/ogrcouchdbdatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ int OGRCouchDBDataSource::Open( const char * pszFilename, int bUpdateIn)
}
}

int nTables = json_object_array_length(poAnswerObj);
for(int i=0;i<nTables;i++)
const auto nTables = json_object_array_length(poAnswerObj);
for(auto i=decltype(nTables){0};i<nTables;i++)
{
json_object* poAnswerObjDBName = json_object_array_get_idx(poAnswerObj, i);
if ( json_object_is_type(poAnswerObjDBName, json_type_string) )
Expand Down Expand Up @@ -893,7 +893,7 @@ OGRLayer * OGRCouchDBDataSource::ExecuteSQLStats( const char *pszSQLCommand )
return nullptr;
}

int nLength = json_object_array_length(poRows);
const auto nLength = json_object_array_length(poRows);
if (nLength != 1)
{
json_object_put(poAnswerObj);
Expand Down
26 changes: 13 additions & 13 deletions gdal/ogr/ogrsf_frmts/couchdb/ogrcouchdblayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,42 +285,42 @@ void OGRCouchDBLayer::ParseFieldValue(OGRFeature* poFeature,
{
if ( json_object_get_type(poValue) == json_type_array )
{
int nLength = json_object_array_length(poValue);
const auto nLength = json_object_array_length(poValue);
int* panVal = static_cast<int *>(
CPLMalloc(sizeof(int) * nLength));
for( int i = 0; i < nLength; i++ )
for( auto i = decltype(nLength){0}; i < nLength; i++ )
{
json_object* poRow = json_object_array_get_idx(poValue, i);
panVal[i] = json_object_get_int(poRow);
}
poFeature->SetField( nField, nLength, panVal );
poFeature->SetField( nField, static_cast<int>(nLength), panVal );
CPLFree(panVal);
}
}
else if( OFTRealList == eType )
{
if ( json_object_get_type(poValue) == json_type_array )
{
const int nLength = json_object_array_length(poValue);
const auto nLength = json_object_array_length(poValue);
double* padfVal = static_cast<double *>(
CPLMalloc(sizeof(double) * nLength));
for( int i = 0; i < nLength; i++ )
for( auto i = decltype(nLength){0}; i < nLength; i++ )
{
json_object* poRow = json_object_array_get_idx(poValue, i);
padfVal[i] = json_object_get_double(poRow);
}
poFeature->SetField( nField, nLength, padfVal );
poFeature->SetField( nField, static_cast<int>(nLength), padfVal );
CPLFree(padfVal);
}
}
else if( OFTStringList == eType )
{
if ( json_object_get_type(poValue) == json_type_array )
{
int nLength = json_object_array_length(poValue);
const auto nLength = json_object_array_length(poValue);
char** papszVal = static_cast<char **>(
CPLMalloc(sizeof(char*) * (nLength+1)));
int i = 0; // Used after for.
auto i = decltype(nLength){0}; // Used after for.
for( ; i < nLength; i++ )
{
json_object* poRow = json_object_array_get_idx(poValue, i);
Expand Down Expand Up @@ -421,10 +421,10 @@ bool OGRCouchDBLayer::BuildFeatureDefnFromRows( json_object* poAnswerObj )
return false;
}

int nRows = json_object_array_length(poRows);
const auto nRows = json_object_array_length(poRows);

json_object* poRow = nullptr;
for(int i=0;i<nRows;i++)
for(auto i=decltype(nRows){0};i<nRows;i++)
{
json_object* poTmpRow = json_object_array_get_idx(poRows, i);
if (poTmpRow != nullptr &&
Expand Down Expand Up @@ -494,8 +494,8 @@ bool OGRCouchDBLayer::FetchNextRowsAnalyseDocs( json_object* poAnswerObj )
return false;
}

int nRows = json_object_array_length(poRows);
for(int i=0;i<nRows;i++)
const auto nRows = json_object_array_length(poRows);
for(auto i=decltype(nRows){0};i<nRows;i++)
{
json_object* poRow = json_object_array_get_idx(poRows, i);
if ( poRow == nullptr ||
Expand Down Expand Up @@ -527,7 +527,7 @@ bool OGRCouchDBLayer::FetchNextRowsAnalyseDocs( json_object* poAnswerObj )
}
}

bEOF = nRows < GetFeaturesToFetch();
bEOF = static_cast<int>(nRows) < GetFeaturesToFetch();

poFeatures = poAnswerObj;

Expand Down
Loading

0 comments on commit dfe030c

Please sign in to comment.