From: Michael Meskes Date: Thu, 17 Sep 2015 13:41:04 +0000 (+0200) Subject: Let compiler handle size calculation of bool types. X-Git-Tag: REL9_0_23~30 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=44297a058ea05cd78b33612ce303f3caec11e3ab;p=postgresql Let compiler handle size calculation of bool types. Back in the day this did not work, but modern compilers should handle it themselves. --- diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c index 2f4231db15..059e3f8906 100644 --- a/src/interfaces/ecpg/ecpglib/data.c +++ b/src/interfaces/ecpg/ecpglib/data.c @@ -422,27 +422,13 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno, case ECPGt_bool: if (pval[0] == 'f' && pval[1] == '\0') { - if (offset == sizeof(char)) - *((char *) (var + offset * act_tuple)) = false; - else if (offset == sizeof(int)) - *((int *) (var + offset * act_tuple)) = false; - else - ecpg_raise(lineno, ECPG_CONVERT_BOOL, - ECPG_SQLSTATE_DATATYPE_MISMATCH, - NULL); + *((bool *) (var + offset * act_tuple)) = false; pval++; break; } else if (pval[0] == 't' && pval[1] == '\0') { - if (offset == sizeof(char)) - *((char *) (var + offset * act_tuple)) = true; - else if (offset == sizeof(int)) - *((int *) (var + offset * act_tuple)) = true; - else - ecpg_raise(lineno, ECPG_CONVERT_BOOL, - ECPG_SQLSTATE_DATATYPE_MISMATCH, - NULL); + *((bool *) (var + offset * act_tuple)) = true; pval++; break; } diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c index 4a32ddf158..43e3dd8427 100644 --- a/src/interfaces/ecpg/ecpglib/execute.c +++ b/src/interfaces/ecpg/ecpglib/execute.c @@ -756,18 +756,9 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari { strcpy(mallocedval, "{"); - if (var->offset == sizeof(char)) - for (element = 0; element < asize; element++) - sprintf(mallocedval + strlen(mallocedval), "%c,", (((char *) var->value)[element]) ? 't' : 'f'); + for (element = 0; element < asize; element++) + sprintf(mallocedval + strlen(mallocedval), "%c,", (((bool *) var->value)[element]) ? 't' : 'f'); - /* - * this is necessary since sizeof(C++'s bool)==sizeof(int) - */ - else if (var->offset == sizeof(int)) - for (element = 0; element < asize; element++) - sprintf(mallocedval + strlen(mallocedval), "%c,", (((int *) var->value)[element]) ? 't' : 'f'); - else - ecpg_raise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL); strcpy(mallocedval + strlen(mallocedval) - 1, "}"); }