1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-25 12:03:53 +03:00

More unconstify use

Replace casts whose only purpose is to cast away const with the
unconstify() macro.

Discussion: https://www.postgresql.org/message-id/flat/53a28052-f9f3-1808-fed9-460fd43035ab%402ndquadrant.com
This commit is contained in:
Peter Eisentraut
2019-01-29 01:16:24 +01:00
parent cf40dc65b6
commit 37d9916020
25 changed files with 57 additions and 55 deletions

View File

@@ -464,7 +464,7 @@ pg_convert(PG_FUNCTION_ARGS)
pg_verify_mbstr_len(src_encoding, src_str, len, false);
/* perform conversion */
dest_str = (char *) pg_do_encoding_conversion((unsigned char *) src_str,
dest_str = (char *) pg_do_encoding_conversion((unsigned char *) unconstify(char *, src_str),
len,
src_encoding,
dest_encoding);
@@ -561,7 +561,7 @@ char *
pg_any_to_server(const char *s, int len, int encoding)
{
if (len <= 0)
return (char *) s; /* empty string is always valid */
return unconstify(char *, s); /* empty string is always valid */
if (encoding == DatabaseEncoding->encoding ||
encoding == PG_SQL_ASCII)
@@ -570,7 +570,7 @@ pg_any_to_server(const char *s, int len, int encoding)
* No conversion is needed, but we must still validate the data.
*/
(void) pg_verify_mbstr(DatabaseEncoding->encoding, s, len, false);
return (char *) s;
return unconstify(char *, s);
}
if (DatabaseEncoding->encoding == PG_SQL_ASCII)
@@ -600,7 +600,7 @@ pg_any_to_server(const char *s, int len, int encoding)
(unsigned char) s[i])));
}
}
return (char *) s;
return unconstify(char *, s);
}
/* Fast path if we can use cached conversion function */
@@ -608,7 +608,7 @@ pg_any_to_server(const char *s, int len, int encoding)
return perform_default_encoding_conversion(s, len, true);
/* General case ... will not work outside transactions */
return (char *) pg_do_encoding_conversion((unsigned char *) s,
return (char *) pg_do_encoding_conversion((unsigned char *) unconstify(char *, s),
len,
encoding,
DatabaseEncoding->encoding);
@@ -634,17 +634,17 @@ char *
pg_server_to_any(const char *s, int len, int encoding)
{
if (len <= 0)
return (char *) s; /* empty string is always valid */
return unconstify(char *, s); /* empty string is always valid */
if (encoding == DatabaseEncoding->encoding ||
encoding == PG_SQL_ASCII)
return (char *) s; /* assume data is valid */
return unconstify(char *, s); /* assume data is valid */
if (DatabaseEncoding->encoding == PG_SQL_ASCII)
{
/* No conversion is possible, but we must validate the result */
(void) pg_verify_mbstr(encoding, s, len, false);
return (char *) s;
return unconstify(char *, s);
}
/* Fast path if we can use cached conversion function */
@@ -652,7 +652,7 @@ pg_server_to_any(const char *s, int len, int encoding)
return perform_default_encoding_conversion(s, len, false);
/* General case ... will not work outside transactions */
return (char *) pg_do_encoding_conversion((unsigned char *) s,
return (char *) pg_do_encoding_conversion((unsigned char *) unconstify(char *, s),
len,
DatabaseEncoding->encoding,
encoding);
@@ -687,7 +687,7 @@ perform_default_encoding_conversion(const char *src, int len,
}
if (flinfo == NULL)
return (char *) src;
return unconstify(char *, src);
/*
* Allocate space for conversion result, being wary of integer overflow