From 244a24104ded3a4573aeffa32160af21f76cbce6 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 15 Dec 2020 00:51:46 +0100 Subject: Revise error codes to have a reduced set exposed in the public API. Fixes #2482 And also add proj_context_errno_string() Revise gie 'expect failure errno XXXX' strings --- src/transformations/horner.cpp | 50 +++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 13 deletions(-) (limited to 'src/transformations/horner.cpp') diff --git a/src/transformations/horner.cpp b/src/transformations/horner.cpp index 2c049186..d88ea152 100644 --- a/src/transformations/horner.cpp +++ b/src/transformations/horner.cpp @@ -460,12 +460,12 @@ PJ *PROJECTION(horner) { degree = pj_param(P->ctx, P->params, "ideg").i; if (degree < 0 || degree > 10000) { /* What are reasonable minimum and maximums for degree? */ - proj_log_debug (P, "Horner: Degree is unreasonable: %d", degree); - return horner_freeup (P, PJD_ERR_INVALID_ARG); + proj_log_error (P, _("Horner: Degree is unreasonable: %d"), degree); + return horner_freeup (P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } } else { - proj_log_debug (P, "Horner: Must specify polynomial degree, (+deg=n)"); - return horner_freeup (P, PJD_ERR_MISSING_ARGS); + proj_log_error (P, _("Horner: Must specify polynomial degree, (+deg=n)")); + return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); } if (pj_param (P->ctx, P->params, "tfwd_c").i || pj_param (P->ctx, P->params, "tinv_c").i) /* complex polynomium? */ @@ -473,7 +473,7 @@ PJ *PROJECTION(horner) { Q = horner_alloc (degree, complex_polynomia); if (Q == nullptr) - return horner_freeup (P, ENOMEM); + return horner_freeup (P, PROJ_ERR_INVALID_OP /*ENOMEM*/); P->opaque = Q; if (complex_polynomia) { @@ -483,9 +483,15 @@ PJ *PROJECTION(horner) { n = 2*degree + 2; if (0==parse_coefs (P, Q->fwd_c, "fwd_c", n)) - return horner_freeup (P, PJD_ERR_MISSING_ARGS); + { + proj_log_error (P, _("Horner: missing fwd_c")); + return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); + } if (0==parse_coefs (P, Q->inv_c, "inv_c", n)) - return horner_freeup (P, PJD_ERR_MISSING_ARGS); + { + proj_log_error (P, _("Horner: missing inv_c")); + return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); + } P->fwd4d = complex_horner_forward_4d; P->inv4d = complex_horner_reverse_4d; } @@ -493,19 +499,37 @@ PJ *PROJECTION(horner) { else { n = horner_number_of_coefficients (degree); if (0==parse_coefs (P, Q->fwd_u, "fwd_u", n)) - return horner_freeup (P, PJD_ERR_MISSING_ARGS); + { + proj_log_error (P, _("Horner: missing fwd_u")); + return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); + } if (0==parse_coefs (P, Q->fwd_v, "fwd_v", n)) - return horner_freeup (P, PJD_ERR_MISSING_ARGS); + { + proj_log_error (P, _("Horner: missing fwd_v")); + return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); + } if (0==parse_coefs (P, Q->inv_u, "inv_u", n)) - return horner_freeup (P, PJD_ERR_MISSING_ARGS); + { + proj_log_error (P, _("Horner: missing inv_u")); + return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); + } if (0==parse_coefs (P, Q->inv_v, "inv_v", n)) - return horner_freeup (P, PJD_ERR_MISSING_ARGS); + { + proj_log_error (P, _("Horner: missing inv_v")); + return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); + } } if (0==parse_coefs (P, (double *)(Q->fwd_origin), "fwd_origin", 2)) - return horner_freeup (P, PJD_ERR_MISSING_ARGS); + { + proj_log_error (P, _("Horner: missing fwd_origin")); + return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); + } if (0==parse_coefs (P, (double *)(Q->inv_origin), "inv_origin", 2)) - return horner_freeup (P, PJD_ERR_MISSING_ARGS); + { + proj_log_error (P, _("Horner: missing inv_origin")); + return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); + } if (0==parse_coefs (P, &Q->range, "range", 1)) Q->range = 500000; -- cgit v1.2.3 From df96a13d2c9b70bc18cec1b08eea5b2b068127d7 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 15 Dec 2020 15:32:40 +0100 Subject: Various operations: remove explicit short name prefixing in log messages now that it is automatically added --- src/transformations/horner.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/transformations/horner.cpp') diff --git a/src/transformations/horner.cpp b/src/transformations/horner.cpp index d88ea152..e32a6b99 100644 --- a/src/transformations/horner.cpp +++ b/src/transformations/horner.cpp @@ -414,7 +414,7 @@ static int parse_coefs (PJ *P, double *coefs, const char *param, int ncoefs) { buf = static_cast(calloc (strlen (param) + 2, sizeof(char))); if (nullptr==buf) { - proj_log_error (P, "Horner: No memory left"); + proj_log_error (P, "No memory left"); return 0; } @@ -430,7 +430,7 @@ static int parse_coefs (PJ *P, double *coefs, const char *param, int ncoefs) { for (i = 0; i < ncoefs; i++) { if (i > 0) { if ( next == nullptr || ','!=*next) { - proj_log_error (P, "Horner: Malformed polynomium set %s. need %d coefs", param, ncoefs); + proj_log_error (P, "Malformed polynomium set %s. need %d coefs", param, ncoefs); return 0; } init = ++next; @@ -460,11 +460,11 @@ PJ *PROJECTION(horner) { degree = pj_param(P->ctx, P->params, "ideg").i; if (degree < 0 || degree > 10000) { /* What are reasonable minimum and maximums for degree? */ - proj_log_error (P, _("Horner: Degree is unreasonable: %d"), degree); + proj_log_error (P, _("Degree is unreasonable: %d"), degree); return horner_freeup (P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); } } else { - proj_log_error (P, _("Horner: Must specify polynomial degree, (+deg=n)")); + proj_log_error (P, _("Must specify polynomial degree, (+deg=n)")); return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); } @@ -484,12 +484,12 @@ PJ *PROJECTION(horner) { n = 2*degree + 2; if (0==parse_coefs (P, Q->fwd_c, "fwd_c", n)) { - proj_log_error (P, _("Horner: missing fwd_c")); + proj_log_error (P, _("missing fwd_c")); return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); } if (0==parse_coefs (P, Q->inv_c, "inv_c", n)) { - proj_log_error (P, _("Horner: missing inv_c")); + proj_log_error (P, _("missing inv_c")); return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); } P->fwd4d = complex_horner_forward_4d; @@ -500,34 +500,34 @@ PJ *PROJECTION(horner) { n = horner_number_of_coefficients (degree); if (0==parse_coefs (P, Q->fwd_u, "fwd_u", n)) { - proj_log_error (P, _("Horner: missing fwd_u")); + proj_log_error (P, _("missing fwd_u")); return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); } if (0==parse_coefs (P, Q->fwd_v, "fwd_v", n)) { - proj_log_error (P, _("Horner: missing fwd_v")); + proj_log_error (P, _("missing fwd_v")); return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); } if (0==parse_coefs (P, Q->inv_u, "inv_u", n)) { - proj_log_error (P, _("Horner: missing inv_u")); + proj_log_error (P, _("missing inv_u")); return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); } if (0==parse_coefs (P, Q->inv_v, "inv_v", n)) { - proj_log_error (P, _("Horner: missing inv_v")); + proj_log_error (P, _("missing inv_v")); return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); } } if (0==parse_coefs (P, (double *)(Q->fwd_origin), "fwd_origin", 2)) { - proj_log_error (P, _("Horner: missing fwd_origin")); + proj_log_error (P, _("missing fwd_origin")); return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); } if (0==parse_coefs (P, (double *)(Q->inv_origin), "inv_origin", 2)) { - proj_log_error (P, _("Horner: missing inv_origin")); + proj_log_error (P, _("missing inv_origin")); return horner_freeup (P, PROJ_ERR_INVALID_OP_MISSING_ARG); } if (0==parse_coefs (P, &Q->range, "range", 1)) -- cgit v1.2.3 From b020666081223adb8a623e6b3ad2c6a3b2ce077a Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 15 Dec 2020 17:48:24 +0100 Subject: horner.cpp: remove uses of EINVAL and EDOM errno --- src/transformations/horner.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/transformations/horner.cpp') diff --git a/src/transformations/horner.cpp b/src/transformations/horner.cpp index e32a6b99..f9403d2b 100644 --- a/src/transformations/horner.cpp +++ b/src/transformations/horner.cpp @@ -115,7 +115,7 @@ struct horner { } // anonymous namespace typedef struct horner HORNER; -static PJ_UV horner_func (const HORNER *transformation, PJ_DIRECTION direction, PJ_UV position); +static PJ_UV horner_func (PJ* P, const HORNER *transformation, PJ_DIRECTION direction, PJ_UV position); static HORNER *horner_alloc (size_t order, int complex_polynomia); static void horner_free (HORNER *h); @@ -181,7 +181,7 @@ static HORNER *horner_alloc (size_t order, int complex_polynomia) { /**********************************************************************/ -static PJ_UV horner_func (const HORNER *transformation, PJ_DIRECTION direction, PJ_UV position) { +static PJ_UV horner_func (PJ* P, const HORNER *transformation, PJ_DIRECTION direction, PJ_UV position) { /*********************************************************************** A reimplementation of the classic Engsager/Poder 2D Horner polynomial @@ -237,7 +237,6 @@ summing the tiny high order elements first. case PJ_INV: /* inverse */ break; default: /* invalid */ - errno = EINVAL; return uv_error; } @@ -259,7 +258,7 @@ summing the tiny high order elements first. } if ((fabs(n) > range) || (fabs(e) > range)) { - errno = EDOM; + proj_errno_set(P, PROJ_ERR_COORD_TRANSFM_OUTSIDE_PROJECTION_DOMAIN); return uv_error; } @@ -297,12 +296,12 @@ summing the tiny high order elements first. static PJ_COORD horner_forward_4d (PJ_COORD point, PJ *P) { - point.uv = horner_func ((HORNER *) P->opaque, PJ_FWD, point.uv); + point.uv = horner_func (P, (HORNER *) P->opaque, PJ_FWD, point.uv); return point; } static PJ_COORD horner_reverse_4d (PJ_COORD point, PJ *P) { - point.uv = horner_func ((HORNER *) P->opaque, PJ_INV, point.uv); + point.uv = horner_func (P, (HORNER *) P->opaque, PJ_INV, point.uv); return point; } @@ -310,7 +309,7 @@ static PJ_COORD horner_reverse_4d (PJ_COORD point, PJ *P) { /**********************************************************************/ -static PJ_UV complex_horner (const HORNER *transformation, PJ_DIRECTION direction, PJ_UV position) { +static PJ_UV complex_horner (PJ *P, const HORNER *transformation, PJ_DIRECTION direction, PJ_UV position) { /*********************************************************************** A reimplementation of a classic Engsager/Poder Horner complex @@ -337,7 +336,6 @@ polynomial evaluation engine. case PJ_INV: /* inverse */ break; default: /* invalid */ - errno = EINVAL; return uv_error; } @@ -366,7 +364,7 @@ polynomial evaluation engine. } if ((fabs(n) > range) || (fabs(e) > range)) { - errno = EDOM; + proj_errno_set(P, PROJ_ERR_COORD_TRANSFM_OUTSIDE_PROJECTION_DOMAIN); return uv_error; } @@ -387,12 +385,12 @@ polynomial evaluation engine. static PJ_COORD complex_horner_forward_4d (PJ_COORD point, PJ *P) { - point.uv = complex_horner ((HORNER *) P->opaque, PJ_FWD, point.uv); + point.uv = complex_horner (P, (HORNER *) P->opaque, PJ_FWD, point.uv); return point; } static PJ_COORD complex_horner_reverse_4d (PJ_COORD point, PJ *P) { - point.uv = complex_horner ((HORNER *) P->opaque, PJ_INV, point.uv); + point.uv = complex_horner (P, (HORNER *) P->opaque, PJ_INV, point.uv); return point; } -- cgit v1.2.3 From a27c0255e7b8e6aab1b91e49fd7870d1ee4e1a80 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 15 Dec 2020 17:53:29 +0100 Subject: Remap ENOMEM from PROJ_ERR_INVALID_OP to PROJ_ERR_OTHER --- src/transformations/horner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/transformations/horner.cpp') diff --git a/src/transformations/horner.cpp b/src/transformations/horner.cpp index f9403d2b..7c8ad192 100644 --- a/src/transformations/horner.cpp +++ b/src/transformations/horner.cpp @@ -471,7 +471,7 @@ PJ *PROJECTION(horner) { Q = horner_alloc (degree, complex_polynomia); if (Q == nullptr) - return horner_freeup (P, PROJ_ERR_INVALID_OP /*ENOMEM*/); + return horner_freeup (P, PROJ_ERR_OTHER /*ENOMEM*/); P->opaque = Q; if (complex_polynomia) { -- cgit v1.2.3