Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WLYmD-0001HN-Hq for pgsql-odbc@arkaria.postgresql.org; Thu, 06 Mar 2014 13:55:57 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WLYmC-00050d-T4 for pgsql-odbc@arkaria.postgresql.org; Thu, 06 Mar 2014 13:55:56 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WLYmA-00050U-Q3 for pgsql-odbc@postgresql.org; Thu, 06 Mar 2014 13:55:54 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WLYm5-0001Oa-R8 for pgsql-odbc@postgresql.org; Thu, 06 Mar 2014 13:55:52 +0000 Received: from sc9-mailhost1.vmware.com (sc9-mailhost1.vmware.com [10.113.161.71]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id B86BB28441; Thu, 6 Mar 2014 05:55:48 -0800 (PST) Received: from zcs-prod-ext-mta-1.vmware.com (zcs-prod-ext-mta-1.vmware.com [10.113.62.223]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id B6386183AC; Thu, 6 Mar 2014 05:55:48 -0800 (PST) Received: from zcs-prod-ext-mta-1.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTP id 3934E12002F; Thu, 6 Mar 2014 05:55:46 -0800 (PST) Received: from [192.168.1.90] (zimbra-prod-ext-proxy-vip.vmware.com [10.113.63.87]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTPSA; Thu, 6 Mar 2014 05:55:45 -0800 (PST) Message-ID: <53187E62.4080907@vmware.com> Date: Thu, 06 Mar 2014 15:55:46 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10 MIME-Version: 1.0 To: Michael Paquier CC: PostgreSQL mailing lists Subject: Re: Elimination of (more or less) all compilation warnings on OSX References: In-Reply-To: Content-Type: multipart/mixed; boundary="------------070804030700010004080008" X-Pg-Spam-Score: -6.9 (------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org This is a multi-part message in MIME format. --------------070804030700010004080008 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 03/06/2014 03:10 PM, Michael Paquier wrote: > Hi all, > > Before beginning my real quest for odbc, please find attached a patch > that cleans up 99% of the code warnings I saw on OSX (and actually > some of them on Windows). All those warnings are caused by incorrect > casts, so fixing them is trivial... But there were quite a lot of > them, I think I fixed 100~200 of them... Those warnings are the reason I added -Wno-pointer-sign to the compiler options. Looks like your compiler on OS X doesn't recognize that. In addition to being ugly, suppressing the warnings with casts can make you miss genuine bugs if you change the type of a variable. For example, if you have something like this: char *foo; unsigned char *bar; ... foo = bar; And you the definition of 'bar' to: struct mystruct *bar; With -Wno-pointer-sign, the compiler will still warn you about that. But if you had suppressed that by: foo = (char *) bar; you will not get a warning. So I'm generally not in favor of just sprinkling new casts to suppress these warnings. In some cases a cast is the best solution, for sure, but in general we should rather be consistent with the pointer types we use. For example, attached is a patch that fixes up convert.c. It actually *removes* one such cast, which is no longer necessary. That's more work than just adding casts, but that's what we should do, if anything. We're bound to need some casts, because the ODBC API tends to use unsigned char pointers while all the libc string functions use signed. But that should be limited to the interface stuff. For example, SQLExecDirect has to use an unsigned "SQLCHAR *" in the function signature, and PGAPI_ExecDirect is the implementation of that, but in PGAPI_ExecDirect, after we convert the SQLCHAR * and length to a string, we can deal with it as a signed pointer. Actually, just changing the signature of make_string slashes the number of warnings significantly: -char *make_string(const char *s, ssize_t len, char *buf, size_t bufsize); +char *make_string(const SQLCHAR *s, SQLINTEGER len, char *buf, size_t bufsize); - Heikki --------------070804030700010004080008 Content-Type: text/x-diff; name="fix-convert-dot-c-casts.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix-convert-dot-c-casts.patch" diff --git a/convert.c b/convert.c index d8b0304..354b298 100644 --- a/convert.c +++ b/convert.c @@ -142,10 +142,10 @@ char *mapFuncs[][2] = { }; static const char *mapFunction(const char *func, int param_count); -static int conv_from_octal(const UCHAR *s); -static SQLLEN pg_bin2hex(const UCHAR *src, UCHAR *dst, SQLLEN length); +static int conv_from_octal(const char *s); +static SQLLEN pg_bin2hex(const char *src, char *dst, SQLLEN length); #ifdef UNICODE_SUPPORT -static SQLLEN pg_bin2whex(const UCHAR *src, SQLWCHAR *dst, SQLLEN length); +static SQLLEN pg_bin2whex(const char *src, SQLWCHAR *dst, SQLLEN length); #endif /* UNICODE_SUPPORT */ /*--------- @@ -1600,7 +1600,7 @@ inolog("2stime fr=%d\n", std_time.fr); SQL_NUMERIC_STRUCT *ns; int i, nlen, bit, hval, tv, dig, sta, olen; char calv[SQL_MAX_NUMERIC_LEN * 3]; - const UCHAR *wv; + const char *wv; BOOL dot_exist; len = sizeof(SQL_NUMERIC_STRUCT); @@ -1931,7 +1931,7 @@ inolog("SQL_C_VARBOOKMARK value=%d\n", ival); #define FLGP_MULTIPLE_STATEMENT (1L << 5) #define FLGP_SELECT_FOR_READONLY (1L << 6) typedef struct _QueryParse { - const UCHAR *statement; + const char *statement; int statement_type; size_t opos; Int4 from_pos; /* PG comm length restriction */ @@ -1984,7 +1984,7 @@ QP_initialize(QueryParse *q, const StatementClass *stmt) #define FLGB_LITERAL_EXTENSION (1L << 10) #define FLGB_HEX_BIN_FORMAT (1L << 11) typedef struct _QueryBuild { - UCHAR *query_statement; + char *query_statement; size_t str_size_limit; size_t str_alsize; size_t npos; @@ -2197,7 +2197,7 @@ static int processParameters(QueryParse *qp, QueryBuild *qb, size_t *output_count, SQLLEN param_pos[][2]); static size_t -convert_to_pgbinary(const UCHAR *in, char *out, size_t len, QueryBuild *qb); +convert_to_pgbinary(const char *in, char *out, size_t len, QueryBuild *qb); static ssize_t enlarge_query_statement(QueryBuild *qb, size_t newsize) @@ -2881,7 +2881,7 @@ copy_statement_with_parameters(StatementClass *stmt, BOOL buildPrepareStatement) QueryParse query_org, *qp; QueryBuild query_crt, *qb; - UCHAR *new_statement; + char *new_statement; BOOL begin_first = FALSE, prepare_dummy_cursor = FALSE, bPrepConv; ConnectionClass *conn = SC_get_conn(stmt); @@ -3195,12 +3195,12 @@ Int4 findTag(const char *tag, char dollar_quote, int ccsc) } static -Int4 findIdentifier(const UCHAR *str, int ccsc, const UCHAR **nextdel) +Int4 findIdentifier(const char *str, int ccsc, const char **nextdel) { Int4 strlen = 0; encoded_str encstr; unsigned char tchar; - const UCHAR *sptr; + const char *sptr; BOOL dquote = FALSE; *nextdel = NULL; @@ -3543,7 +3543,7 @@ inner_process_tokens(QueryParse *qp, QueryBuild *qb) qb->dollar_number = 0; if (0 != (qp->flags & FLGP_USING_CURSOR)) { - const UCHAR *vp = &(qp->statement[qp->opos + 1]); + const char *vp = &(qp->statement[qp->opos + 1]); while (*vp && isspace(*vp)) vp++; @@ -5047,7 +5047,7 @@ convert_escape(QueryParse *qp, QueryBuild *qb) if (stricmp(key, "call") == 0) { Int4 funclen; - const UCHAR *nextdel; + const char *nextdel; if (SQL_ERROR == QB_start_brace(qb)) { @@ -5193,7 +5193,7 @@ convert_escape(QueryParse *qp, QueryBuild *qb) if (2 == param_count) { BOOL add_cast = FALSE, add_quote = FALSE; - const UCHAR *pptr; + const char *pptr; from = param_pos[0][0]; to = param_pos[0][1]; @@ -5258,7 +5258,7 @@ mylog("%d-%d num=%s SQL_BIT=%d\n", to, from, num, SQL_BIT); } else { - const UCHAR *mapptr; + const char *mapptr; SQLLEN paramlen; int pidx; @@ -5619,7 +5619,7 @@ convert_pgbinary_to_char(const char *value, char *rgbValue, ssize_t cbValueMax) static int -conv_from_octal(const UCHAR *s) +conv_from_octal(const char *s) { ssize_t i; int y = 0; @@ -5633,7 +5633,7 @@ conv_from_octal(const UCHAR *s) /* convert octal escapes to bytes */ size_t -convert_from_pgbinary(const UCHAR *value, UCHAR *rgbValue, SQLLEN cbValueMax) +convert_from_pgbinary(const char *value, char *rgbValue, SQLLEN cbValueMax) { size_t i, ilen = strlen(value); @@ -5731,7 +5731,7 @@ conv_to_octal2(UCHAR val, char *octal) /* convert non-ascii bytes to octal escape sequences */ static size_t -convert_to_pgbinary(const UCHAR *in, char *out, size_t len, QueryBuild *qb) +convert_to_pgbinary(const char *in, char *out, size_t len, QueryBuild *qb) { CSTR func = "convert_to_pgbinary"; UCHAR inc; @@ -5746,7 +5746,7 @@ convert_to_pgbinary(const UCHAR *in, char *out, size_t len, QueryBuild *qb) out[o++] = escape_in_literal; out[o++] = '\\'; out[o++] = 'x'; - o += pg_bin2hex(in, (UCHAR *) out + o, len); + o += pg_bin2hex(in, out + o, len); return o; } for (i = 0; i < len; i++) @@ -5778,21 +5778,21 @@ convert_to_pgbinary(const UCHAR *in, char *out, size_t len, QueryBuild *qb) static const char *hextbl = "0123456789ABCDEF"; #define def_bin2hex(type) \ - (const UCHAR *src, type *dst, SQLLEN length) \ + (const char *src, type *dst, SQLLEN length) \ { \ - const UCHAR *src_wk; \ + const char *src_wk; \ UCHAR chr; \ type *dst_wk; \ BOOL backwards; \ int i; \ \ backwards = FALSE; \ - if ((UCHAR *)dst < src) \ + if ((char *) dst < src) \ { \ - if ((UCHAR *) (dst + 2 * (length - 1)) > src + length - 1) \ + if ((char *) (dst + 2 * (length - 1)) > src + length - 1) \ return -1; \ } \ - else if ((UCHAR *) dst < src + length) \ + else if ((char *) dst < src + length) \ backwards = TRUE; \ if (backwards) \ { \ @@ -5821,14 +5821,14 @@ pg_bin2whex def_bin2hex(SQLWCHAR) #endif /* UNICODE_SUPPORT */ static SQLLEN -pg_bin2hex def_bin2hex(UCHAR) +pg_bin2hex def_bin2hex(char) SQLLEN -pg_hex2bin(const UCHAR *src, UCHAR *dst, SQLLEN length) +pg_hex2bin(const char *src, char *dst, SQLLEN length) { UCHAR chr; - const UCHAR *src_wk; - UCHAR *dst_wk; + const char *src_wk; + char *dst_wk; SQLLEN i; int val; BOOL HByte = TRUE; diff --git a/convert.h b/convert.h index 818b881..984eff5 100644 --- a/convert.h +++ b/convert.h @@ -52,8 +52,8 @@ size_t convert_linefeeds(const char *s, char *dst, size_t max, BOOL convlf, BOO size_t convert_special_chars(const char *si, char *dst, SQLLEN used, UInt4 flags,int ccsc, int escape_ch); int convert_pgbinary_to_char(const char *value, char *rgbValue, ssize_t cbValueMax); -size_t convert_from_pgbinary(const UCHAR *value, UCHAR *rgbValue, SQLLEN cbValueMax); -SQLLEN pg_hex2bin(const UCHAR *in, UCHAR *out, SQLLEN len); +size_t convert_from_pgbinary(const char *value, char *rgbValue, SQLLEN cbValueMax); +SQLLEN pg_hex2bin(const char *in, char *out, SQLLEN len); int convert_lo(StatementClass *stmt, const void *value, SQLSMALLINT fCType, PTR rgbValue, SQLLEN cbValueMax, SQLLEN *pcbValue); Int4 findTag(const char *str, char dollar_quote, int ccsc); --------------070804030700010004080008 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc --------------070804030700010004080008--