if (eary->alloc == 0)
{
eary ->alloc = 8;
- eary ->array = (char **) pg_malloc(8 * sizeof(char *));
+ eary ->array = pg_malloc_array(char *, 8);
}
else if (eary->num >= eary->alloc)
{
eary ->alloc *= 2;
- eary ->array = (char **) pg_realloc(eary->array,
- eary->alloc * sizeof(char *));
+ eary ->array = pg_realloc_array(eary->array, char *,
+ eary->alloc);
}
eary ->array[eary->num] = pg_strdup(eltname);
nfields = PQnfields(res);
/* for each field, get the needed width */
- length = (int *) pg_malloc(sizeof(int) * nfields);
+ length = pg_malloc_array(int, nfields);
for (j = 0; j < nfields; j++)
length[j] = strlen(PQfname(res, j));
struct options *my_opts;
PGconn *pgconn;
- my_opts = (struct options *) pg_malloc(sizeof(struct options));
+ my_opts = pg_malloc_object(struct options);
- my_opts->oids = (eary *) pg_malloc(sizeof(eary));
- my_opts->tables = (eary *) pg_malloc(sizeof(eary));
- my_opts->filenumbers = (eary *) pg_malloc(sizeof(eary));
+ my_opts->oids = pg_malloc_object(eary);
+ my_opts->tables = pg_malloc_object(eary);
+ my_opts->filenumbers = pg_malloc_object(eary);
my_opts->oids->num = my_opts->oids->alloc = 0;
my_opts->tables->num = my_opts->tables->alloc = 0;
static void
add_stringlist_item(_stringlist **listhead, const char *str)
{
- _stringlist *newentry = pg_malloc(sizeof(_stringlist));
+ _stringlist *newentry = pg_malloc_object(_stringlist);
_stringlist *oldentry;
newentry->str = pg_strdup(str);
initStringInfo(&line);
maxlines = 1024;
- result = (char **) pg_malloc(maxlines * sizeof(char *));
+ result = pg_malloc_array(char *, maxlines);
n = 0;
while (pg_get_line_buf(infile, &line))
if (n >= maxlines - 1)
{
maxlines *= 2;
- result = (char **) pg_realloc(result, maxlines * sizeof(char *));
+ result = pg_realloc_array(result, char *, maxlines);
}
result[n++] = pg_strdup(line.data);
PatternInfo *result;
pia->len++;
- pia->data = (PatternInfo *) pg_realloc(pia->data, pia->len * sizeof(PatternInfo));
+ pia->data = pg_realloc_array(pia->data, PatternInfo, pia->len);
result = &pia->data[pia->len - 1];
memset(result, 0, sizeof(*result));
if (initial_dbname)
{
- DatabaseInfo *dat = (DatabaseInfo *) pg_malloc0(sizeof(DatabaseInfo));
+ DatabaseInfo *dat = pg_malloc0_object(DatabaseInfo);
/* This database is included. Add to list */
if (opts.verbose)
if (opts.verbose)
pg_log_info("including database \"%s\"", datname);
- dat = (DatabaseInfo *) pg_malloc0(sizeof(DatabaseInfo));
+ dat = pg_malloc0_object(DatabaseInfo);
dat->datname = pstrdup(datname);
simple_ptr_list_append(databases, dat);
}
{
/* Current record pertains to a relation */
- RelationInfo *rel = (RelationInfo *) pg_malloc0(sizeof(RelationInfo));
+ RelationInfo *rel = pg_malloc0_object(RelationInfo);
Assert(OidIsValid(oid));
Assert((is_heap && !is_btree) || (is_btree && !is_heap));
static void
tablespace_list_append(const char *arg)
{
- TablespaceListCell *cell = (TablespaceListCell *) pg_malloc0(sizeof(TablespaceListCell));
+ TablespaceListCell *cell = pg_malloc0_object(TablespaceListCell);
char *dst;
char *dst_ptr;
const char *arg_ptr;
lo;
char statusdir[MAXPGPATH];
- param = pg_malloc0(sizeof(logstreamer_param));
+ param = pg_malloc0_object(logstreamer_param);
param->timeline = timeline;
param->sysidentifier = sysidentifier;
param->wal_compress_algorithm = wal_compress_algorithm;
}
noptions += 1;
- options = pg_realloc(options, sizeof(char *) * noptions * 2);
+ options = pg_realloc_array(options, char *, noptions * 2);
options[(noptions - 1) * 2] = data;
options[(noptions - 1) * 2 + 1] = val;
argcount++;
}
- keywords = pg_malloc0((argcount + 1) * sizeof(*keywords));
- values = pg_malloc0((argcount + 1) * sizeof(*values));
+ keywords = pg_malloc0_array(const char *, argcount + 1);
+ values = pg_malloc0_array(const char *, argcount + 1);
/*
* Set dbname here already, so it can be overridden by a dbname in the
}
else
{
- keywords = pg_malloc0((argcount + 1) * sizeof(*keywords));
- values = pg_malloc0((argcount + 1) * sizeof(*values));
+ keywords = pg_malloc0_array(const char *, argcount + 1);
+ values = pg_malloc0_array(const char *, argcount + 1);
keywords[i] = "dbname";
values[i] = (dbname == NULL) ? "replication" : dbname;
i++;
dir_get_file_name(WalWriteMethod *wwmethod,
const char *pathname, const char *temp_suffix)
{
- char *filename = pg_malloc0(MAXPGPATH * sizeof(char));
+ char *filename = pg_malloc0_array(char, MAXPGPATH);
snprintf(filename, MAXPGPATH, "%s%s%s",
pathname,
}
}
- f = pg_malloc0(sizeof(DirectoryMethodFile));
+ f = pg_malloc0_object(DirectoryMethodFile);
#ifdef HAVE_LIBZ
if (wwmethod->compression_algorithm == PG_COMPRESSION_GZIP)
f->gzfp = gzfp;
{
DirectoryMethodData *wwmethod;
- wwmethod = pg_malloc0(sizeof(DirectoryMethodData));
+ wwmethod = pg_malloc0_object(DirectoryMethodData);
*((const WalWriteMethodOps **) &wwmethod->base.ops) =
&WalDirectoryMethodOps;
wwmethod->base.compression_algorithm = compression_algorithm;
tar_get_file_name(WalWriteMethod *wwmethod, const char *pathname,
const char *temp_suffix)
{
- char *filename = pg_malloc0(MAXPGPATH * sizeof(char));
+ char *filename = pg_malloc0_array(char, MAXPGPATH);
snprintf(filename, MAXPGPATH, "%s%s",
pathname, temp_suffix ? temp_suffix : "");
#ifdef HAVE_LIBZ
if (wwmethod->compression_algorithm == PG_COMPRESSION_GZIP)
{
- tar_data->zp = (z_streamp) pg_malloc(sizeof(z_stream));
+ tar_data->zp = pg_malloc_object(z_stream);
tar_data->zp->zalloc = Z_NULL;
tar_data->zp->zfree = Z_NULL;
tar_data->zp->opaque = Z_NULL;
return NULL;
}
- tar_data->currentfile = pg_malloc0(sizeof(TarMethodFile));
+ tar_data->currentfile = pg_malloc0_object(TarMethodFile);
tar_data->currentfile->base.wwmethod = wwmethod;
tmppath = tar_get_file_name(wwmethod, pathname, temp_suffix);
const char *suffix = (compression_algorithm == PG_COMPRESSION_GZIP) ?
".tar.gz" : ".tar";
- wwmethod = pg_malloc0(sizeof(TarMethodData));
+ wwmethod = pg_malloc0_object(TarMethodData);
*((const WalWriteMethodOps **) &wwmethod->base.ops) =
&WalTarMethodOps;
wwmethod->base.compression_algorithm = compression_algorithm;
manifest_data **result;
int i;
- result = pg_malloc(sizeof(manifest_data *) * n_backups);
+ result = pg_malloc_array(manifest_data *, n_backups);
for (i = 0; i < n_backups; ++i)
result[i] = load_backup_manifest(backup_directories[i]);
/* Create the hash table. */
ht = manifest_files_create(initial_size, NULL);
- result = pg_malloc0(sizeof(manifest_data));
+ result = pg_malloc0_object(manifest_data);
result->files = ht;
context.private_data = result;
context.version_cb = combinebackup_version_cb;
static void
add_tablespace_mapping(cb_options *opt, char *arg)
{
- cb_tablespace_mapping *tsmap = pg_malloc0(sizeof(cb_tablespace_mapping));
+ cb_tablespace_mapping *tsmap = pg_malloc0_object(cb_tablespace_mapping);
char *dst;
char *dst_ptr;
char *arg_ptr;
static void
remember_to_cleanup_directory(char *target_path, bool rmtopdir)
{
- cb_cleanup_dir *dir = pg_malloc(sizeof(cb_cleanup_dir));
+ cb_cleanup_dir *dir = pg_malloc_object(cb_cleanup_dir);
dir->target_path = target_path;
dir->rmtopdir = rmtopdir;
}
/* Create a new tablespace object. */
- ts = pg_malloc0(sizeof(cb_tablespace));
+ ts = pg_malloc0_object(cb_tablespace);
ts->oid = oid;
/*
* Every block must come either from the latest version of the file or
* from one of the prior backups.
*/
- source = pg_malloc0(sizeof(rfile *) * (1 + n_prior_backups));
+ source = pg_malloc0_array(rfile *, 1 + n_prior_backups);
/*
* Use the information from the latest incremental file to figure out how
* need to obtain it and at what offset in that file it's stored.
* sourcemap gives us the first of these things, and offsetmap the latter.
*/
- sourcemap = pg_malloc0(sizeof(rfile *) * block_length);
- offsetmap = pg_malloc0(sizeof(off_t) * block_length);
+ sourcemap = pg_malloc0_array(rfile *, block_length);
+ offsetmap = pg_malloc0_array(off_t, block_length);
/*
* Every block that is present in the newest incremental file should be
if (rf->num_blocks > 0)
{
rf->relative_block_numbers =
- pg_malloc0(sizeof(BlockNumber) * rf->num_blocks);
+ pg_malloc0_array(BlockNumber, rf->num_blocks);
read_bytes(rf, rf->relative_block_numbers,
sizeof(BlockNumber) * rf->num_blocks);
}
{
rfile *rf;
- rf = pg_malloc0(sizeof(rfile));
+ rf = pg_malloc0_object(rfile);
rf->filename = pstrdup(filename);
if ((rf->fd = open(filename, O_RDONLY | PG_BINARY, 0)) < 0)
{
manifest_writer *
create_manifest_writer(char *directory, uint64 system_identifier)
{
- manifest_writer *mwriter = pg_malloc(sizeof(manifest_writer));
+ manifest_writer *mwriter = pg_malloc_object(manifest_writer);
snprintf(mwriter->pathname, MAXPGPATH, "%s/backup_manifest", directory);
mwriter->fd = -1;
{
/* empty file */
close(fd);
- result = (char **) pg_malloc(sizeof(char *));
+ result = pg_malloc_object(char *);
*result = NULL;
return result;
}
}
/* set up the result buffer */
- result = (char **) pg_malloc((nlines + 1) * sizeof(char *));
+ result = pg_malloc_array(char *, nlines + 1);
*numlines = nlines;
/* now split the buffer into lines */
{
datapagemap_iterator_t *iter;
- iter = pg_malloc(sizeof(datapagemap_iterator_t));
+ iter = pg_malloc0_object(datapagemap_iterator_t);
iter->map = map;
iter->nextblkno = 0;
init_libpq_conn(conn);
- src = pg_malloc0(sizeof(libpq_source));
+ src = pg_malloc0_object(libpq_source);
src->common.traverse_files = libpq_traverse_files;
src->common.fetch_file = libpq_fetch_file;
{
local_source *src;
- src = pg_malloc0(sizeof(local_source));
+ src = pg_malloc0_object(local_source);
src->common.traverse_files = local_traverse_files;
src->common.fetch_file = local_fetch_file;
*/
if (tli == 1)
{
- history = (TimeLineHistoryEntry *) pg_malloc(sizeof(TimeLineHistoryEntry));
+ history = pg_malloc_object(TimeLineHistoryEntry);
history->tli = tli;
history->begin = history->end = InvalidXLogRecPtr;
*nentries = 1;
lasttli = tli;
nlines++;
- entries = pg_realloc(entries, nlines * sizeof(TimeLineHistoryEntry));
+ entries = pg_realloc_array(entries, TimeLineHistoryEntry, nlines);
entry = &entries[nlines - 1];
entry->tli = tli;
*/
nlines++;
if (entries)
- entries = pg_realloc(entries, nlines * sizeof(TimeLineHistoryEntry));
+ entries = pg_realloc_array(entries, TimeLineHistoryEntry, nlines);
else
- entries = pg_malloc(1 * sizeof(TimeLineHistoryEntry));
+ entries = pg_malloc_array(TimeLineHistoryEntry, 1);
entry = &entries[nlines - 1];
entry->tli = targetTLI;
}
/* Allocate memory for queries and for task states */
- queries = pg_malloc0(sizeof(char *) * n_data_types_usage_checks);
- states = pg_malloc0(sizeof(struct data_type_check_state) * n_data_types_usage_checks);
+ queries = pg_malloc0_array(char *, n_data_types_usage_checks);
+ states = pg_malloc0_array(struct data_type_check_state, n_data_types_usage_checks);
for (int i = 0; i < n_data_types_usage_checks; i++)
{
struct loadable_libraries_state state;
char *query;
- state.ress = (PGresult **) pg_malloc(old_cluster.dbarr.ndbs * sizeof(PGresult *));
+ state.ress = pg_malloc_array(PGresult *, old_cluster.dbarr.ndbs);
state.totaltups = 0;
query = psprintf("SELECT DISTINCT probin "
* plugins.
*/
n_libinfos = state.totaltups + count_old_cluster_logical_slots();
- os_info.libraries = (LibraryInfo *) pg_malloc(sizeof(LibraryInfo) * n_libinfos);
+ os_info.libraries = pg_malloc_array(LibraryInfo, n_libinfos);
totaltups = 0;
for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
bool all_matched = true;
/* There will certainly not be more mappings than there are old rels */
- maps = (FileNameMap *) pg_malloc(sizeof(FileNameMap) *
- old_db->rel_arr.nrels);
+ maps = pg_malloc_array(FileNameMap, old_db->rel_arr.nrels);
/*
* Each of the RelInfo arrays should be sorted by OID. Scan through them
if (PQntuples(dbres) != 1)
pg_fatal("template0 not found");
- locale = pg_malloc(sizeof(DbLocaleInfo));
+ locale = pg_malloc_object(DbLocaleInfo);
i_datencoding = PQfnumber(dbres, "encoding");
i_datlocprovider = PQfnumber(dbres, "datlocprovider");
i_spclocation = PQfnumber(res, "spclocation");
ntups = PQntuples(res);
- dbinfos = (DbInfo *) pg_malloc0(sizeof(DbInfo) * ntups);
+ dbinfos = pg_malloc0_array(DbInfo, ntups);
for (tupnum = 0; tupnum < ntups; tupnum++)
{
process_rel_infos(DbInfo *dbinfo, PGresult *res, void *arg)
{
int ntups = PQntuples(res);
- RelInfo *relinfos = (RelInfo *) pg_malloc(sizeof(RelInfo) * ntups);
+ RelInfo *relinfos = pg_malloc_array(RelInfo, ntups);
int i_reloid = PQfnumber(res, "reloid");
int i_indtable = PQfnumber(res, "indtable");
int i_toastheap = PQfnumber(res, "toastheap");
int i_caught_up;
int i_invalid;
- slotinfos = (LogicalSlotInfo *) pg_malloc(sizeof(LogicalSlotInfo) * num_slots);
+ slotinfos = pg_malloc_array(LogicalSlotInfo, num_slots);
i_slotname = PQfnumber(res, "slot_name");
i_plugin = PQfnumber(res, "plugin");
/* parallel */
#ifdef WIN32
if (thread_handles == NULL)
- thread_handles = pg_malloc(user_opts.jobs * sizeof(HANDLE));
+ thread_handles = pg_malloc_array(HANDLE, user_opts.jobs);
if (exec_thread_args == NULL)
{
int i;
- exec_thread_args = pg_malloc(user_opts.jobs * sizeof(exec_thread_arg *));
+ exec_thread_args = pg_malloc_array(exec_thread_arg *, user_opts.jobs);
/*
* For safety and performance, we keep the args allocated during
* thread different from the one that allocated it.
*/
for (i = 0; i < user_opts.jobs; i++)
- exec_thread_args[i] = pg_malloc0(sizeof(exec_thread_arg));
+ exec_thread_args[i] = pg_malloc0_object(exec_thread_arg);
}
cur_thread_args = (void **) exec_thread_args;
/* parallel */
#ifdef WIN32
if (thread_handles == NULL)
- thread_handles = pg_malloc(user_opts.jobs * sizeof(HANDLE));
+ thread_handles = pg_malloc_array(HANDLE, user_opts.jobs);
if (transfer_thread_args == NULL)
{
int i;
- transfer_thread_args = pg_malloc(user_opts.jobs * sizeof(transfer_thread_arg *));
+ transfer_thread_args = pg_malloc_array(transfer_thread_arg *, user_opts.jobs);
/*
* For safety and performance, we keep the args allocated during
* thread different from the one that allocated it.
*/
for (i = 0; i < user_opts.jobs; i++)
- transfer_thread_args[i] = pg_malloc0(sizeof(transfer_thread_arg));
+ transfer_thread_args[i] = pg_malloc0_object(transfer_thread_arg);
}
cur_thread_args = (void **) transfer_thread_args;
static SlruSegState *
AllocSlruSegState(const char *dir)
{
- SlruSegState *state = pg_malloc(sizeof(*state));
+ SlruSegState *state = pg_malloc_object(SlruSegState);
state->dir = pstrdup(dir);
state->fn = NULL;
if (PQntuples(res) != 0)
{
old_cluster.tablespaces =
- (char **) pg_malloc(old_cluster.num_tablespaces * sizeof(char *));
+ pg_malloc_array(char *, old_cluster.num_tablespaces);
new_cluster.tablespaces =
- (char **) pg_malloc(new_cluster.num_tablespaces * sizeof(char *));
+ pg_malloc_array(char *, new_cluster.num_tablespaces);
}
else
{
UpgradeTask *
upgrade_task_create(void)
{
- UpgradeTask *task = pg_malloc0(sizeof(UpgradeTask));
+ UpgradeTask *task = pg_malloc0_object(UpgradeTask);
task->queries = createPQExpBuffer();
{
UpgradeTaskStep *new_step;
- task->steps = pg_realloc(task->steps,
- ++task->num_steps * sizeof(UpgradeTaskStep));
+ task->steps = pg_realloc_array(task->steps, UpgradeTaskStep,
+ ++task->num_steps);
new_step = &task->steps[task->num_steps - 1];
new_step->process_cb = process_cb;
upgrade_task_run(const UpgradeTask *task, const ClusterInfo *cluster)
{
int jobs = Max(1, user_opts.jobs);
- UpgradeTaskSlot *slots = pg_malloc0(sizeof(UpgradeTaskSlot) * jobs);
+ UpgradeTaskSlot *slots = pg_malloc0_array(UpgradeTaskSlot, jobs);
dbs_complete = 0;
dbs_processing = 0;
streamer->tblspc_oid = tblspc_oid;
if (!context->skip_checksums)
- streamer->checksum_ctx = pg_malloc(sizeof(pg_checksum_context));
+ streamer->checksum_ctx = pg_malloc_object(pg_checksum_context);
return &streamer->base;
}
/* Create the hash table. */
ht = manifest_files_create(initial_size, NULL);
- result = pg_malloc0(sizeof(manifest_data));
+ result = pg_malloc0_object(manifest_data);
result->files = ht;
context.private_data = result;
context.version_cb = verifybackup_version_cb;
* Append the information to the list for complete verification at a later
* stage.
*/
- tar = pg_malloc(sizeof(tar_file));
+ tar = pg_malloc_object(tar_file);
tar->relpath = pstrdup(relpath);
tar->tblspc_oid = tblspc_oid;
tar->compress_algorithm = compress_algorithm;
progress_report(false);
- buffer = pg_malloc(READ_CHUNK_SIZE * sizeof(uint8));
+ buffer = pg_malloc_array(uint8, READ_CHUNK_SIZE);
manifest_files_start_iterate(manifest->files, &it);
while ((m = manifest_files_iterate(manifest->files, &it)) != NULL)
static PgBenchExpr *
make_null_constant(void)
{
- PgBenchExpr *expr = pg_malloc(sizeof(PgBenchExpr));
+ PgBenchExpr *expr = pg_malloc_object(PgBenchExpr);
expr->etype = ENODE_CONSTANT;
expr->u.constant.type = PGBT_NULL;
static PgBenchExpr *
make_integer_constant(int64 ival)
{
- PgBenchExpr *expr = pg_malloc(sizeof(PgBenchExpr));
+ PgBenchExpr *expr = pg_malloc_object(PgBenchExpr);
expr->etype = ENODE_CONSTANT;
expr->u.constant.type = PGBT_INT;
static PgBenchExpr *
make_double_constant(double dval)
{
- PgBenchExpr *expr = pg_malloc(sizeof(PgBenchExpr));
+ PgBenchExpr *expr = pg_malloc_object(PgBenchExpr);
expr->etype = ENODE_CONSTANT;
expr->u.constant.type = PGBT_DOUBLE;
static PgBenchExpr *
make_boolean_constant(bool bval)
{
- PgBenchExpr *expr = pg_malloc(sizeof(PgBenchExpr));
+ PgBenchExpr *expr = pg_malloc_object(PgBenchExpr);
expr->etype = ENODE_CONSTANT;
expr->u.constant.type = PGBT_BOOLEAN;
static PgBenchExpr *
make_variable(char *varname)
{
- PgBenchExpr *expr = pg_malloc(sizeof(PgBenchExpr));
+ PgBenchExpr *expr = pg_malloc_object(PgBenchExpr);
expr->etype = ENODE_VARIABLE;
expr->u.variable.varname = varname;
if (list == NULL)
{
- list = pg_malloc(sizeof(PgBenchExprList));
+ list = pg_malloc_object(PgBenchExprList);
list->head = NULL;
list->tail = NULL;
}
- cons = pg_malloc(sizeof(PgBenchExprLink));
+ cons = pg_malloc_object(PgBenchExprLink);
cons->expr = expr;
cons->next = NULL;
{
int len = elist_length(args);
- PgBenchExpr *expr = pg_malloc(sizeof(PgBenchExpr));
+ PgBenchExpr *expr = pg_malloc_object(PgBenchExpr);
Assert(fnumber >= 0);
{
variables->max_vars = needed + VARIABLES_ALLOC_MARGIN;
variables->vars = (Variable *)
- pg_realloc(variables->vars, variables->max_vars * sizeof(Variable));
+ pg_realloc_array(variables->vars, Variable, variables->max_vars);
}
}
{
Assert(st->prepared == NULL);
- st->prepared = pg_malloc(sizeof(bool *) * num_scripts);
+ st->prepared = pg_malloc_array(bool *, num_scripts);
for (int i = 0; i < num_scripts; i++)
{
ParsedScript *script = &sql_script[i];
for (numcmds = 0; script->commands[numcmds] != NULL; numcmds++)
;
- st->prepared[i] = pg_malloc0(sizeof(bool) * numcmds);
+ st->prepared[i] = pg_malloc0_array(bool, numcmds);
}
}
return NULL;
/* Allocate and initialize Command structure */
- my_command = (Command *) pg_malloc(sizeof(Command));
+ my_command = pg_malloc0_object(Command);
initPQExpBuffer(&my_command->lines);
appendPQExpBufferStr(&my_command->lines, p);
my_command->first_line = NULL; /* this is set later */
}
/* Allocate and initialize Command structure */
- my_command = (Command *) pg_malloc0(sizeof(Command));
+ my_command = pg_malloc0_object(Command);
my_command->type = META_COMMAND;
my_command->argc = 0;
initSimpleStats(&my_command->stats);
/* Initialize all fields of ps */
ps.desc = desc;
ps.weight = weight;
- ps.commands = (Command **) pg_malloc(sizeof(Command *) * alloc_num);
+ ps.commands = pg_malloc_array(Command *, alloc_num);
initStats(&ps.stats, 0);
/* Prepare to parse script */
{
alloc_num += COMMANDS_ALLOC_NUM;
ps.commands = (Command **)
- pg_realloc(ps.commands, sizeof(Command *) * alloc_num);
+ pg_realloc_array(ps.commands, Command *, alloc_num);
}
/* Done if we reached EOF */
}
}
- state = (CState *) pg_malloc0(sizeof(CState));
+ state = pg_malloc0_object(CState);
/* set random seed early, because it may be used while parsing scripts. */
if (!set_random_seed(getenv("PGBENCH_RANDOM_SEED")))
if (nclients > 1)
{
- state = (CState *) pg_realloc(state, sizeof(CState) * nclients);
+ state = pg_realloc_array(state, CState, nclients);
memset(state + 1, 0, sizeof(CState) * (nclients - 1));
/* copy any -D switch values to all clients */
PQfinish(con);
/* set up thread data structures */
- threads = (TState *) pg_malloc(sizeof(TState) * nthreads);
+ threads = pg_malloc_array(TState, nthreads);
nclients_dealt = 0;
for (i = 0; i < nthreads; i++)
static socket_set *
alloc_socket_set(int count)
{
- return (socket_set *) pg_malloc0(sizeof(socket_set));
+ return pg_malloc0_object(socket_set);
}
static void
/* Loop till we have a connection or fail, which we might've already */
while (success)
{
- const char **keywords = pg_malloc((nconnopts + 1) * sizeof(*keywords));
- const char **values = pg_malloc((nconnopts + 1) * sizeof(*values));
+ const char **keywords = pg_malloc_array(const char *, nconnopts + 1);
+ const char **values = pg_malloc_array(const char *, nconnopts + 1);
int paramnum = 0;
PQconninfoOption *ci;
{
printQueryOpt *save;
- save = (printQueryOpt *) pg_malloc(sizeof(printQueryOpt));
+ save = pg_malloc_object(printQueryOpt);
/* Flat-copy all the scalar fields, then duplicate sub-structures. */
memcpy(save, popt, sizeof(printQueryOpt));
return NULL;
}
- result = pg_malloc0(sizeof(struct copy_options));
+ result = pg_malloc0_object(struct copy_options);
result->before_tofrom = pg_strdup(""); /* initialize for appending */
num_columns = piv_columns.count;
num_rows = piv_rows.count;
- array_columns = (pivot_field *)
- pg_malloc(sizeof(pivot_field) * num_columns);
+ array_columns = pg_malloc_array(pivot_field, num_columns);
- array_rows = (pivot_field *)
- pg_malloc(sizeof(pivot_field) * num_rows);
+ array_rows = pg_malloc_array(pivot_field, num_rows);
avlCollectFields(&piv_columns, piv_columns.root, array_columns, 0);
avlCollectFields(&piv_rows, piv_rows.root, array_rows, 0);
* map associating each piv_columns[].rank to its index in piv_columns.
* This avoids an O(N^2) loop later.
*/
- horiz_map = (int *) pg_malloc(sizeof(int) * num_columns);
+ horiz_map = pg_malloc_array(int, num_columns);
for (i = 0; i < num_columns; i++)
horiz_map[piv_columns[i].rank] = i;
static void
avlInit(avl_tree *tree)
{
- tree->end = (avl_node *) pg_malloc0(sizeof(avl_node));
+ tree->end = pg_malloc0_object(avl_node);
tree->end->children[0] = tree->end->children[1] = tree->end;
tree->count = 0;
tree->root = tree->end;
if (current == tree->end)
{
- avl_node *new_node = (avl_node *)
- pg_malloc(sizeof(avl_node));
+ avl_node *new_node = pg_malloc_object(avl_node);
new_node->height = 1;
new_node->field = field;
* every header entry] */
int i;
- hmap = (int *) pg_malloc(sizeof(int) * num_columns * 2);
+ hmap = pg_malloc_array(int, num_columns * 2);
for (i = 0; i < num_columns; i++)
{
char *val = piv_columns[i].sort_value;
return false;
nrows = PQntuples(res);
- attr = pg_malloc0((nrows + 1) * sizeof(*attr));
+ attr = pg_malloc0_array(char *, nrows + 1);
printTableInit(&cont, &myopt, _("List of roles"), ncols, nrows);
* storing "Publications:" string) + publication schema mapping
* count + 1 (for storing NULL).
*/
- footers = (char **) pg_malloc((1 + pub_schema_tuples + 1) * sizeof(char *));
+ footers = pg_malloc_array(char *, 1 + pub_schema_tuples + 1);
footers[0] = pg_strdup(_("Publications:"));
/* Might be an empty set - that's ok */
if (*nvars >= *maxvars)
{
*maxvars *= 2;
- *varnames = (char **) pg_realloc(*varnames,
- ((*maxvars) + 1) * sizeof(char *));
+ *varnames = pg_realloc_array(*varnames, char *, (*maxvars) + 1);
}
(*varnames)[(*nvars)++] = psprintf("%s%s%s", prefix, varname, suffix);
int i;
struct _variable *ptr;
- varnames = (char **) pg_malloc((maxvars + 1) * sizeof(char *));
+ varnames = pg_malloc_array(char *, maxvars + 1);
for (ptr = pset.vars->next; ptr; ptr = ptr->next)
{
* This is usually much more space than we need, but it's cheaper than
* doing a separate malloc() for each word.
*/
- previous_words = (char **) pg_malloc(point * sizeof(char *));
+ previous_words = pg_malloc_array(char *, point);
*buffer = outptr = (char *) pg_malloc(point * 2);
/*
{
struct _variable *ptr;
- ptr = pg_malloc(sizeof *ptr);
+ ptr = pg_malloc_object(struct _variable);
ptr->name = NULL;
ptr->value = NULL;
ptr->substitute_hook = NULL;
/* not present, make new entry ... unless we were asked to delete */
if (value)
{
- current = pg_malloc(sizeof *current);
+ current = pg_malloc_object(struct _variable);
current->name = pg_strdup(name);
current->value = pg_strdup(value);
current->substitute_hook = NULL;
}
/* not present, make new entry */
- current = pg_malloc(sizeof *current);
+ current = pg_malloc_object(struct _variable);
current->name = pg_strdup(name);
current->value = NULL;
current->substitute_hook = shook;
* database itself, so build a list with a single entry.
*/
Assert(user_list == NULL);
- process_list = pg_malloc0(sizeof(SimpleStringList));
+ process_list = pg_malloc0_object(SimpleStringList);
simple_string_list_append(process_list, PQdb(conn));
break;
return NULL;
}
- tables = pg_malloc0(sizeof(SimpleStringList));
+ tables = pg_malloc0_object(SimpleStringList);
/* Build qualified identifiers for each table */
for (int i = 0; i < ntups; i++)
return;
}
- *table_list = pg_malloc0(sizeof(SimpleOidList));
+ *table_list = pg_malloc0_object(SimpleOidList);
/*
* Build two lists, one with table OIDs and the other with fully-qualified
* extra for lock wait detection and global work.
*/
nconns = 1 + testspec->nsessions;
- conns = (IsoConnInfo *) pg_malloc0(nconns * sizeof(IsoConnInfo));
+ conns = pg_malloc0_array(IsoConnInfo, nconns);
atexit(disconnect_atexit);
for (i = 0; i < nconns; i++)
for (i = 0; i < testspec->nsessions; i++)
nallsteps += testspec->sessions[i]->nsteps;
- allsteps = pg_malloc(nallsteps * sizeof(Step *));
+ allsteps = pg_malloc_array(Step *, nallsteps);
k = 0;
for (i = 0; i < testspec->nsessions; i++)
nsteps += testspec->sessions[i]->nsteps;
/* Create PermutationStep workspace array */
- steps = (PermutationStep *) pg_malloc0(sizeof(PermutationStep) * nsteps);
- stepptrs = (PermutationStep **) pg_malloc(sizeof(PermutationStep *) * nsteps);
+ steps = pg_malloc0_array(PermutationStep, nsteps);
+ stepptrs = pg_malloc_array(PermutationStep *, nsteps);
for (i = 0; i < nsteps; i++)
stepptrs[i] = steps + i;
* A pile is actually just an integer which tells how many steps we've
* already picked from this pile.
*/
- piles = pg_malloc(sizeof(int) * testspec->nsessions);
+ piles = pg_malloc_array(int, testspec->nsessions);
for (i = 0; i < testspec->nsessions; i++)
piles[i] = 0;
int nwaiting = 0;
PermutationStep **waiting;
- waiting = pg_malloc(sizeof(PermutationStep *) * testspec->nsessions);
+ waiting = pg_malloc_array(PermutationStep *, testspec->nsessions);
printf("\nstarting permutation:");
for (i = 0; i < nsteps; i++)
}
| setup_list setup
{
- $$.elements = pg_realloc($1.elements,
- ($1.nelements + 1) * sizeof(void *));
+ $$.elements = pg_realloc_array($1.elements, void *,
+ $1.nelements + 1);
$$.elements[$1.nelements] = $2;
$$.nelements = $1.nelements + 1;
}
session_list:
session_list session
{
- $$.elements = pg_realloc($1.elements,
- ($1.nelements + 1) * sizeof(void *));
+ $$.elements = pg_realloc_array($1.elements, void *,
+ $1.nelements + 1);
$$.elements[$1.nelements] = $2;
$$.nelements = $1.nelements + 1;
}
| session
{
$$.nelements = 1;
- $$.elements = pg_malloc(sizeof(void *));
+ $$.elements = pg_malloc_object(void *);
$$.elements[0] = $1;
}
;
session:
SESSION identifier opt_setup step_list opt_teardown
{
- $$ = pg_malloc(sizeof(Session));
+ $$ = pg_malloc_object(Session);
$$->name = $2;
$$->setupsql = $3;
$$->steps = (Step **) $4.elements;
step_list:
step_list step
{
- $$.elements = pg_realloc($1.elements,
- ($1.nelements + 1) * sizeof(void *));
+ $$.elements = pg_realloc_array($1.elements, void *,
+ $1.nelements + 1);
$$.elements[$1.nelements] = $2;
$$.nelements = $1.nelements + 1;
}
| step
{
$$.nelements = 1;
- $$.elements = pg_malloc(sizeof(void *));
+ $$.elements = pg_malloc_object(void *);
$$.elements[0] = $1;
}
;
step:
STEP identifier sqlblock
{
- $$ = pg_malloc(sizeof(Step));
+ $$ = pg_malloc_object(Step);
$$->name = $2;
$$->sql = $3;
$$->session = -1; /* until filled */
permutation_list:
permutation_list permutation
{
- $$.elements = pg_realloc($1.elements,
- ($1.nelements + 1) * sizeof(void *));
+ $$.elements = pg_realloc_array($1.elements, void *,
+ $1.nelements + 1);
$$.elements[$1.nelements] = $2;
$$.nelements = $1.nelements + 1;
}
| permutation
{
$$.nelements = 1;
- $$.elements = pg_malloc(sizeof(void *));
+ $$.elements = pg_malloc_object(void *);
$$.elements[0] = $1;
}
;
permutation:
PERMUTATION permutation_step_list
{
- $$ = pg_malloc(sizeof(Permutation));
+ $$ = pg_malloc_object(Permutation);
$$->nsteps = $2.nelements;
$$->steps = (PermutationStep **) $2.elements;
}
permutation_step_list:
permutation_step_list permutation_step
{
- $$.elements = pg_realloc($1.elements,
- ($1.nelements + 1) * sizeof(void *));
+ $$.elements = pg_realloc_array($1.elements, void *,
+ $1.nelements + 1);
$$.elements[$1.nelements] = $2;
$$.nelements = $1.nelements + 1;
}
| permutation_step
{
$$.nelements = 1;
- $$.elements = pg_malloc(sizeof(void *));
+ $$.elements = pg_malloc_object(void *);
$$.elements[0] = $1;
}
;
permutation_step:
identifier
{
- $$ = pg_malloc(sizeof(PermutationStep));
+ $$ = pg_malloc_object(PermutationStep);
$$->name = $1;
$$->blockers = NULL;
$$->nblockers = 0;
}
| identifier '(' blocker_list ')'
{
- $$ = pg_malloc(sizeof(PermutationStep));
+ $$ = pg_malloc_object(PermutationStep);
$$->name = $1;
$$->blockers = (PermutationStepBlocker **) $3.elements;
$$->nblockers = $3.nelements;
blocker_list:
blocker_list ',' blocker
{
- $$.elements = pg_realloc($1.elements,
- ($1.nelements + 1) * sizeof(void *));
+ $$.elements = pg_realloc_array($1.elements, void *,
+ $1.nelements + 1);
$$.elements[$1.nelements] = $3;
$$.nelements = $1.nelements + 1;
}
| blocker
{
$$.nelements = 1;
- $$.elements = pg_malloc(sizeof(void *));
+ $$.elements = pg_malloc_object(void *);
$$.elements[0] = $1;
}
;
blocker:
identifier
{
- $$ = pg_malloc(sizeof(PermutationStepBlocker));
+ $$ = pg_malloc_object(PermutationStepBlocker);
$$->stepname = $1;
$$->blocktype = PSB_OTHER_STEP;
$$->num_notices = -1;
}
| identifier NOTICES INTEGER
{
- $$ = pg_malloc(sizeof(PermutationStepBlocker));
+ $$ = pg_malloc_object(PermutationStepBlocker);
$$->stepname = $1;
$$->blocktype = PSB_NUM_NOTICES;
$$->num_notices = $3;
}
| '*'
{
- $$ = pg_malloc(sizeof(PermutationStepBlocker));
+ $$ = pg_malloc_object(PermutationStepBlocker);
$$->stepname = NULL;
$$->blocktype = PSB_ONCE;
$$->num_notices = -1;
nopts++;
nopts++; /* for the NULL terminator */
- keywords = pg_malloc(sizeof(char *) * nopts);
- vals = pg_malloc(sizeof(char *) * nopts);
+ keywords = pg_malloc_array(const char *, nopts);
+ vals = pg_malloc_array(const char *, nopts);
i = 0;
for (PQconninfoOption *opt = opts; opt->keyword != NULL; ++opt)
nopts++;
nopts++; /* NULL terminator */
- keywords = pg_malloc0(sizeof(char *) * nopts);
- vals = pg_malloc0(sizeof(char *) * nopts);
+ keywords = pg_malloc0_array(const char *, nopts);
+ vals = pg_malloc0_array(const char *, nopts);
i = 0;
for (PQconninfoOption *opt = opts; opt->keyword != NULL; ++opt)
void
add_stringlist_item(_stringlist **listhead, const char *str)
{
- _stringlist *newentry = pg_malloc(sizeof(_stringlist));
+ _stringlist *newentry = pg_malloc_object(_stringlist);
_stringlist *oldentry;
newentry->str = pg_strdup(str);
*/
if (string_matches_pattern(host_platform, platform))
{
- _resultmap *entry = pg_malloc(sizeof(_resultmap));
+ _resultmap *entry = pg_malloc_object(_resultmap);
entry->test = pg_strdup(buf);
entry->type = pg_strdup(file_type);
int i;
#ifdef WIN32
- PID_TYPE *active_pids = pg_malloc(num_tests * sizeof(PID_TYPE));
+ PID_TYPE *active_pids = pg_malloc_array(PID_TYPE, num_tests);
memcpy(active_pids, pids, num_tests * sizeof(PID_TYPE));
#endif