Skip to content

Commit

Permalink
Merge pull request #9436 from rouault/shapelib_cpp_compiles_fixes
Browse files Browse the repository at this point in the history
Shapelib: compile it as C++
  • Loading branch information
rouault authored Mar 9, 2024
2 parents 9ce0731 + 9a4a7b1 commit 4f1938c
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ogr/ogrsf_frmts/shape/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ target_include_directories(ogr_Shape PRIVATE $<TARGET_PROPERTY:ogrsf_generic,SOU
# shapelib
if (GDAL_USE_SHAPELIB_INTERNAL)
# ogrshape.h shapefil.h dbfopen.c sbnsearch.c shpopen.c shptree.c
add_library(shapelib OBJECT sbnsearch_wrapper.c shpopen_wrapper.c shptree_wrapper.c dbfopen_wrapper.c)
add_library(shapelib OBJECT sbnsearch_wrapper.cpp shpopen_wrapper.cpp shptree_wrapper.cpp dbfopen_wrapper.cpp)
gdal_standard_includes(shapelib)
target_compile_definitions(shapelib PUBLIC -DSAOffset=vsi_l_offset)
target_compile_options(shapelib PRIVATE ${GDAL_C_WARNING_FLAGS})
target_compile_options(shapelib PRIVATE ${GDAL_CXX_WARNING_FLAGS} ${WFLAG_OLD_STYLE_CAST} ${WFLAG_EFFCXX})
if (RENAME_INTERNAL_SHAPELIB_SYMBOLS)
target_compile_definitions(shapelib PUBLIC -DRENAME_INTERNAL_SHAPELIB_SYMBOLS -DSHPAPI_CALL=)
endif ()
Expand Down
13 changes: 7 additions & 6 deletions ogr/ogrsf_frmts/shape/dbfopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,8 @@ const char SHPAPI_CALL1(*)
SHPDate SHPAPI_CALL DBFReadDateAttribute(DBFHandle psDBF, int iRecord,
int iField)
{
const char *pdateValue = DBFReadStringAttribute(psDBF, iRecord, iField);
const char *pdateValue = STATIC_CAST(
const char *, DBFReadAttribute(psDBF, iRecord, iField, 'D'));

SHPDate date;

Expand Down Expand Up @@ -1435,17 +1436,17 @@ int SHPAPI_CALL DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity,
/* Assign all the record fields. */
/* -------------------------------------------------------------------- */
int j;
if (STATIC_CAST(int, strlen(STATIC_CAST(char *, pValue))) >
if (STATIC_CAST(int, strlen(STATIC_CAST(const char *, pValue))) >
psDBF->panFieldSize[iField])
j = psDBF->panFieldSize[iField];
else
{
memset(pabyRec + psDBF->panFieldOffset[iField], ' ',
psDBF->panFieldSize[iField]);
j = STATIC_CAST(int, strlen(STATIC_CAST(char *, pValue)));
j = STATIC_CAST(int, strlen(STATIC_CAST(const char *, pValue)));
}

strncpy(
memcpy(
REINTERPRET_CAST(char *, pabyRec + psDBF->panFieldOffset[iField]),
STATIC_CAST(const char *, pValue), j);
}
Expand Down Expand Up @@ -1532,7 +1533,7 @@ int SHPAPI_CALL DBFWriteLogicalAttribute(DBFHandle psDBF, int iRecord,
int SHPAPI_CALL DBFWriteDateAttribute(DBFHandle psDBF, int iRecord, int iField,
const SHPDate *lValue)
{
if (NULL == lValue)
if (SHPLIB_NULLPTR == lValue)
return false;
/* check for supported digit range, but do not check for valid date */
if (lValue->year < 0 || lValue->year > 9999)
Expand All @@ -1544,7 +1545,7 @@ int SHPAPI_CALL DBFWriteDateAttribute(DBFHandle psDBF, int iRecord, int iField,
char dateValue[9]; /* "yyyyMMdd\0" */
snprintf(dateValue, sizeof(dateValue), "%04d%02d%02d", lValue->year,
lValue->month, lValue->day);
return (DBFWriteStringAttribute(psDBF, iRecord, iField, dateValue));
return (DBFWriteAttributeDirectly(psDBF, iRecord, iField, dateValue));
}

/************************************************************************/
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions ogr/ogrsf_frmts/shape/shapefil_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@

/* in-place uint32_t* swap */
#define SHP_SWAP32(p) \
*STATIC_CAST(uint32_t *, p) = _SHP_SWAP32(*STATIC_CAST(uint32_t *, p))
*REINTERPRET_CAST(uint32_t *, p) = \
_SHP_SWAP32(*REINTERPRET_CAST(uint32_t *, p))
/* in-place uint64_t* swap */
#define SHP_SWAP64(p) \
*STATIC_CAST(uint64_t *, p) = _SHP_SWAP64(*STATIC_CAST(uint64_t *, p))
*REINTERPRET_CAST(uint64_t *, p) = \
_SHP_SWAP64(*REINTERPRET_CAST(uint64_t *, p))
/* in-place double* swap */
#define SHP_SWAPDOUBLE(x) \
do \
Expand Down
8 changes: 4 additions & 4 deletions ogr/ogrsf_frmts/shape/shpopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ SHPHandle SHPAPI_CALL SHPCreateLL(const char *pszLayer, int nShapeType,
psHooks->Error(szErrorMsg);

free(pszFullname);
return NULL;
return SHPLIB_NULLPTR;
}

memcpy(pszFullname + nLenWithoutExtension, ".shx", 5);
Expand All @@ -1002,7 +1002,7 @@ SHPHandle SHPAPI_CALL SHPCreateLL(const char *pszLayer, int nShapeType,

free(pszFullname);
psHooks->FClose(fpSHP);
return NULL;
return SHPLIB_NULLPTR;
}

free(pszFullname);
Expand Down Expand Up @@ -1056,7 +1056,7 @@ SHPHandle SHPAPI_CALL SHPCreateLL(const char *pszLayer, int nShapeType,
free(pszFullname);
psHooks->FClose(fpSHP);
psHooks->FClose(fpSHX);
return NULL;
return SHPLIB_NULLPTR;
}

/* -------------------------------------------------------------------- */
Expand All @@ -1080,7 +1080,7 @@ SHPHandle SHPAPI_CALL SHPCreateLL(const char *pszLayer, int nShapeType,
free(pszFullname);
psHooks->FClose(fpSHP);
psHooks->FClose(fpSHX);
return NULL;
return SHPLIB_NULLPTR;
}

SHPHandle psSHP = STATIC_CAST(SHPHandle, calloc(sizeof(SHPInfo), 1));
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 4f1938c

Please sign in to comment.