diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2017-11-28 10:23:08 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2017-11-28 10:23:08 +0100 |
| commit | b693f2cf7cc745d77242b6132eeb35ea8fd6a843 (patch) | |
| tree | c12745c563fcc4da45348b42c99cc67b4101a593 /src | |
| parent | 3ca8752d7226b441df5c98a2e489f913a01b6273 (diff) | |
| parent | 3175dce5fcec54fef6299cc8b595d84db5b29cf4 (diff) | |
| download | PROJ-b693f2cf7cc745d77242b6132eeb35ea8fd6a843.tar.gz PROJ-b693f2cf7cc745d77242b6132eeb35ea8fd6a843.zip | |
Merge remote-tracking branch 'aaronpuchert/static-assert'
Diffstat (limited to 'src')
| -rw-r--r-- | src/PJ_cart.c | 1 | ||||
| -rw-r--r-- | src/PJ_helmert.c | 1 | ||||
| -rw-r--r-- | src/PJ_horner.c | 1 | ||||
| -rw-r--r-- | src/PJ_pipeline.c | 1 | ||||
| -rw-r--r-- | src/nad2bin.c | 12 | ||||
| -rw-r--r-- | src/nad_init.c | 10 | ||||
| -rw-r--r-- | src/pj_gridinfo.c | 78 | ||||
| -rw-r--r-- | src/pj_gridlist.c | 10 | ||||
| -rw-r--r-- | src/proj_api.h | 2 | ||||
| -rw-r--r-- | src/proj_internal.h | 2 | ||||
| -rw-r--r-- | src/projects.h | 11 |
11 files changed, 30 insertions, 99 deletions
diff --git a/src/PJ_cart.c b/src/PJ_cart.c index cd1995c1..12b5876a 100644 --- a/src/PJ_cart.c +++ b/src/PJ_cart.c @@ -43,7 +43,6 @@ #define PJ_LIB__ #include "proj_internal.h" #include "projects.h" -#include <assert.h> #include <stddef.h> #include <math.h> #include <errno.h> diff --git a/src/PJ_helmert.c b/src/PJ_helmert.c index 79c7ad53..34bb7a68 100644 --- a/src/PJ_helmert.c +++ b/src/PJ_helmert.c @@ -43,7 +43,6 @@ Last update: 2017-05-15 ***********************************************************************/ #define PJ_LIB__ -#include <assert.h> #include <stddef.h> #include <errno.h> #include "proj_internal.h" diff --git a/src/PJ_horner.c b/src/PJ_horner.c index 6f1450cd..fe0452d6 100644 --- a/src/PJ_horner.c +++ b/src/PJ_horner.c @@ -78,7 +78,6 @@ #define PJ_LIB__ #include "proj_internal.h" #include "projects.h" -#include <assert.h> #include <stddef.h> #include <math.h> #include <errno.h> diff --git a/src/PJ_pipeline.c b/src/PJ_pipeline.c index 35f79213..c8ce8582 100644 --- a/src/PJ_pipeline.c +++ b/src/PJ_pipeline.c @@ -102,7 +102,6 @@ Thomas Knudsen, thokn@sdfe.dk, 2016-05-20 #include "proj_internal.h" #include "projects.h" -#include <assert.h> #include <stddef.h> #include <errno.h> PROJ_HEAD(pipeline, "Transformation pipeline manager"); diff --git a/src/nad2bin.c b/src/nad2bin.c index 0001189c..8401df79 100644 --- a/src/nad2bin.c +++ b/src/nad2bin.c @@ -1,10 +1,10 @@ /* Convert bivariate ASCII NAD27 to NAD83 tables to NTv2 binary structure */ #include <stdio.h> #include <stdlib.h> -#include <assert.h> #define PJ_LIB__ -#include <projects.h> +#include "proj_internal.h" +#include "projects.h" #define U_SEC_TO_RAD 4.848136811095359935899141023e-12 /************************************************************************/ @@ -177,8 +177,8 @@ int main(int argc, char **argv) { exit(2); } - assert( MAX_TAB_ID == 80 ); - assert( sizeof(int) == 4 ); /* for ct.lim.lam/phi */ + STATIC_ASSERT( MAX_TAB_ID == 80 ); + STATIC_ASSERT( sizeof(pj_int32) == 4 ); /* for ct.lim.lam/phi */ memset( header, 0, sizeof(header) ); @@ -267,13 +267,13 @@ int main(int argc, char **argv) { { unsigned char achHeader[11*16]; double dfValue; - int nGSCount = ct.lim.lam * ct.lim.phi; + pj_int32 nGSCount = ct.lim.lam * ct.lim.phi; LP ur; ur.lam = ct.ll.lam + (ct.lim.lam-1) * ct.del.lam; ur.phi = ct.ll.phi + (ct.lim.phi-1) * ct.del.phi; - assert( sizeof(nGSCount) == 4 ); + STATIC_ASSERT( sizeof(nGSCount) == 4 ); memset( achHeader, 0, sizeof(achHeader) ); diff --git a/src/nad_init.c b/src/nad_init.c index a9082f8f..99342aa5 100644 --- a/src/nad_init.c +++ b/src/nad_init.c @@ -32,16 +32,6 @@ #include <errno.h> #include <string.h> -#ifdef _WIN32_WCE -/* assert.h includes all Windows API headers and causes 'LP' name clash. - * Here assert we disable assert() for Windows CE. - * TODO - mloskot: re-implement porting friendly assert - */ -# define assert(exp) ((void)0) -#else -# include <assert.h> -#endif /* _WIN32_WCE */ - /************************************************************************/ /* swap_words() */ /* */ diff --git a/src/pj_gridinfo.c b/src/pj_gridinfo.c index ad4695ca..9b9a8d82 100644 --- a/src/pj_gridinfo.c +++ b/src/pj_gridinfo.c @@ -28,21 +28,12 @@ #define PJ_LIB__ -#include <projects.h> +#include "proj_internal.h" +#include "projects.h" #include <string.h> #include <math.h> #include <errno.h> -#ifdef _WIN32_WCE -/* assert.h includes all Windows API headers and causes 'LP' name clash. - * Here assert we disable assert() for Windows CE. - * TODO - mloskot: re-implement porting friendly assert - */ -# define assert(exp) ((void)0) -#else -# include <assert.h> -#endif /* _WIN32_WCE */ - /************************************************************************/ /* swap_words() */ /* */ @@ -431,23 +422,8 @@ static int pj_gridinfo_init_ntv2( projCtx ctx, PAFile fid, PJ_GRIDINFO *gilist ) int num_subfiles, subfile; int must_swap; - assert( sizeof(int) == 4 ); - assert( sizeof(double) == 8 ); -#ifdef _MSC_VER -#pragma warning( push ) -/* disable conditional expression is constant */ -#pragma warning( disable : 4127 ) -#endif - if( sizeof(int) != 4 || sizeof(double) != 8 ) -#ifdef _MSC_VER -#pragma warning( pop ) -#endif - { - pj_log( ctx, PJ_LOG_ERROR, - "basic types of inappropraiate size in pj_gridinfo_init_ntv2()" ); - pj_ctx_set_errno( ctx, -38 ); - return 0; - } + STATIC_ASSERT( sizeof(pj_int32) == 4 ); + STATIC_ASSERT( sizeof(double) == 8 ); /* -------------------------------------------------------------------- */ /* Read the overview header. */ @@ -541,8 +517,8 @@ static int pj_gridinfo_init_ntv2( projCtx ctx, PAFile fid, PJ_GRIDINFO *gilist ) ct->del.lam = *((double *) (header+9*16+8)); ct->del.phi = *((double *) (header+8*16+8)); - ct->lim.lam = (int) (fabs(ur.lam-ct->ll.lam)/ct->del.lam + 0.5) + 1; - ct->lim.phi = (int) (fabs(ur.phi-ct->ll.phi)/ct->del.phi + 0.5) + 1; + ct->lim.lam = (pj_int32) (fabs(ur.lam-ct->ll.lam)/ct->del.lam + 0.5) + 1; + ct->lim.phi = (pj_int32) (fabs(ur.phi-ct->ll.phi)/ct->del.phi + 0.5) + 1; pj_log( ctx, PJ_LOG_DEBUG_MINOR, "NTv2 %s %dx%d: LL=(%.9g,%.9g) UR=(%.9g,%.9g)\n", @@ -669,23 +645,8 @@ static int pj_gridinfo_init_ntv1( projCtx ctx, PAFile fid, PJ_GRIDINFO *gi ) struct CTABLE *ct; LP ur; - assert( sizeof(int) == 4 ); - assert( sizeof(double) == 8 ); -#ifdef _MSC_VER -#pragma warning( push ) -/* disable conditional expression is constant */ -#pragma warning( disable : 4127 ) -#endif - if( sizeof(int) != 4 || sizeof(double) != 8 ) -#ifdef _MSC_VER -#pragma warning( pop ) -#endif - { - pj_log( ctx, PJ_LOG_ERROR, - "basic types of inappropraiate size in nad_load_ntv1()" ); - pj_ctx_set_errno( ctx, -38 ); - return 0; - } + STATIC_ASSERT( sizeof(pj_int32) == 4 ); + STATIC_ASSERT( sizeof(double) == 8 ); /* -------------------------------------------------------------------- */ /* Read the header. */ @@ -734,8 +695,8 @@ static int pj_gridinfo_init_ntv1( projCtx ctx, PAFile fid, PJ_GRIDINFO *gi ) ur.phi = *((double *) (header+40)); ct->del.lam = *((double *) (header+104)); ct->del.phi = *((double *) (header+88)); - ct->lim.lam = (int) (fabs(ur.lam-ct->ll.lam)/ct->del.lam + 0.5) + 1; - ct->lim.phi = (int) (fabs(ur.phi-ct->ll.phi)/ct->del.phi + 0.5) + 1; + ct->lim.lam = (pj_int32) (fabs(ur.lam-ct->ll.lam)/ct->del.lam + 0.5) + 1; + ct->lim.phi = (pj_int32) (fabs(ur.phi-ct->ll.phi)/ct->del.phi + 0.5) + 1; pj_log( ctx, PJ_LOG_DEBUG_MINOR, "NTv1 %dx%d: LL=(%.9g,%.9g) UR=(%.9g,%.9g)", @@ -769,23 +730,8 @@ static int pj_gridinfo_init_gtx( projCtx ctx, PAFile fid, PJ_GRIDINFO *gi ) double xorigin,yorigin,xstep,ystep; int rows, columns; - assert( sizeof(int) == 4 ); - assert( sizeof(double) == 8 ); -#ifdef _MSC_VER -#pragma warning( push ) -/* disable conditional expression is constant */ -#pragma warning( disable : 4127 ) -#endif - if( sizeof(int) != 4 || sizeof(double) != 8 ) -#ifdef _MSC_VER -#pragma warning( pop ) -#endif - { - pj_log( ctx, PJ_LOG_ERROR, - "basic types of inappropraiate size in nad_load_gtx()" ); - pj_ctx_set_errno( ctx, -38 ); - return 0; - } + STATIC_ASSERT( sizeof(pj_int32) == 4 ); + STATIC_ASSERT( sizeof(double) == 8 ); /* -------------------------------------------------------------------- */ /* Read the header. */ diff --git a/src/pj_gridlist.c b/src/pj_gridlist.c index 4617591c..fbefdcea 100644 --- a/src/pj_gridlist.c +++ b/src/pj_gridlist.c @@ -33,16 +33,6 @@ #include <string.h> #include <math.h> -#ifdef _WIN32_WCE -/* assert.h includes all Windows API headers and causes 'LP' name clash. - * Here assert we disable assert() for Windows CE. - * TODO - mloskot: re-implement porting friendly assert - */ -# define assert(exp) ((void)0) -#else -# include <assert.h> -#endif /* _WIN32_WCE */ - static PJ_GRIDINFO *grid_list = NULL; #define PJ_MAX_PATH_LENGTH 1024 diff --git a/src/proj_api.h b/src/proj_api.h index 50999b71..f5ced282 100644 --- a/src/proj_api.h +++ b/src/proj_api.h @@ -69,10 +69,8 @@ extern "C" { -#ifndef PROJ_H extern char const pj_release[]; /* global release id string */ extern int pj_errno; /* global error return code */ -#endif #ifndef PROJ_INTERNAL_H /* replaced by enum proj_log_level in proj_internal.h */ diff --git a/src/proj_internal.h b/src/proj_internal.h index fd6dc75d..4e70e690 100644 --- a/src/proj_internal.h +++ b/src/proj_internal.h @@ -48,6 +48,8 @@ extern "C" { #endif +#define STATIC_ASSERT(COND) ((void)sizeof(char[(COND) ? 1 : -1])) + #ifndef PJ_TODEG #define PJ_TODEG(rad) ((rad)*180.0/M_PI) #endif diff --git a/src/projects.h b/src/projects.h index 99df0e3e..8c0f81fa 100644 --- a/src/projects.h +++ b/src/projects.h @@ -43,6 +43,7 @@ #endif /* standard inclusions */ +#include <limits.h> #include <math.h> #include <stdio.h> #include <stdlib.h> @@ -78,6 +79,14 @@ extern "C" { # define ABS(x) ((x<0) ? (-1*(x)) : x) #endif +#if INT_MAX == 2147483647 +typedef int pj_int32; +#elif LONG_MAX == 2147483647 +typedef long pj_int32; +#else +#warning It seems no 32-bit integer type is available +#endif + /* maximum path/filename */ #ifndef MAX_PATH_FILENAME #define MAX_PATH_FILENAME 1024 @@ -618,7 +627,7 @@ PJ *pj_projection_specific_setup_##name (PJ *P) #define MAX_TAB_ID 80 typedef struct { float lam, phi; } FLP; -typedef struct { int lam, phi; } ILP; +typedef struct { pj_int32 lam, phi; } ILP; struct CTABLE { char id[MAX_TAB_ID]; /* ascii info */ |
