1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-25 13:17:41 +03:00

Standardize naming of malloc/realloc/strdup wrapper functions.

We had a number of variants on the theme of "malloc or die", with the
majority named like "pg_malloc", but by no means all.  Standardize on the
names pg_malloc, pg_malloc0, pg_realloc, pg_strdup.  Get rid of pg_calloc
entirely in favor of using pg_malloc0.

This is an essentially cosmetic change, so no back-patch.  (I did find
a couple of places where psql and pg_dump were using plain malloc or
strdup instead of the pg_ versions, but they don't look significant
enough to bother back-patching.)
This commit is contained in:
Tom Lane
2012-10-02 15:35:10 -04:00
parent 779f80b75d
commit a563d94180
28 changed files with 223 additions and 256 deletions

View File

@@ -109,14 +109,8 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
do
{
#define PARAMS_ARRAY_SIZE 7
const char **keywords = malloc(PARAMS_ARRAY_SIZE * sizeof(*keywords));
const char **values = malloc(PARAMS_ARRAY_SIZE * sizeof(*values));
if (!keywords || !values)
{
fprintf(stderr, _("%s: out of memory\n"), progname);
exit(1);
}
const char **keywords = pg_malloc(PARAMS_ARRAY_SIZE * sizeof(*keywords));
const char **values = pg_malloc(PARAMS_ARRAY_SIZE * sizeof(*values));
keywords[0] = "host";
values[0] = pghost;
@@ -305,6 +299,30 @@ pg_strdup(const char *string)
return tmp;
}
void *
pg_malloc(size_t size)
{
void *tmp;
tmp = malloc(size);
if (!tmp)
{
fprintf(stderr, _("out of memory\n"));
exit(EXIT_FAILURE);
}
return tmp;
}
void *
pg_malloc0(size_t size)
{
void *tmp;
tmp = pg_malloc(size);
MemSet(tmp, 0, size);
return tmp;
}
/*
* Check yes/no answer in a localized way. 1=yes, 0=no, -1=neither.
*/

View File

@@ -51,5 +51,7 @@ extern bool yesno_prompt(const char *question);
extern void setup_cancel_handler(void);
extern char *pg_strdup(const char *string);
extern void *pg_malloc(size_t size);
extern void *pg_malloc0(size_t size);
#endif /* COMMON_H */