]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Use pg_malloc_object() and pg_alloc_array() variants in frontend code
authorMichael Paquier <michael@paquier.xyz>
Fri, 27 Feb 2026 09:59:41 +0000 (18:59 +0900)
committerMichael Paquier <michael@paquier.xyz>
Fri, 27 Feb 2026 09:59:41 +0000 (18:59 +0900)
This commit updates the frontend tools (src/bin/, contrib/ and
src/test/) to use the memory allocation variants based on
pg_malloc_object() and pg_malloc_array() in various code paths.  This
does not cover all the allocations, but a good chunk of them.

Like all the changes of this kind (31d3847a37be, etc.), this should
encourage any future code to use this new style.

Author: Andreas Karlsson <andreas@proxel.se>
Discussion: https://postgr.es/m/cfb645da-6b3a-4f22-9bcc-5bc46b0e9c61@proxel.se

39 files changed:
contrib/oid2name/oid2name.c
src/bin/initdb/initdb.c
src/bin/pg_amcheck/pg_amcheck.c
src/bin/pg_basebackup/pg_basebackup.c
src/bin/pg_basebackup/pg_recvlogical.c
src/bin/pg_basebackup/streamutil.c
src/bin/pg_basebackup/walmethods.c
src/bin/pg_combinebackup/load_manifest.c
src/bin/pg_combinebackup/pg_combinebackup.c
src/bin/pg_combinebackup/reconstruct.c
src/bin/pg_combinebackup/write_manifest.c
src/bin/pg_ctl/pg_ctl.c
src/bin/pg_rewind/datapagemap.c
src/bin/pg_rewind/libpq_source.c
src/bin/pg_rewind/local_source.c
src/bin/pg_rewind/pg_rewind.c
src/bin/pg_rewind/timeline.c
src/bin/pg_upgrade/check.c
src/bin/pg_upgrade/function.c
src/bin/pg_upgrade/info.c
src/bin/pg_upgrade/parallel.c
src/bin/pg_upgrade/slru_io.c
src/bin/pg_upgrade/tablespace.c
src/bin/pg_upgrade/task.c
src/bin/pg_verifybackup/astreamer_verify.c
src/bin/pg_verifybackup/pg_verifybackup.c
src/bin/pgbench/exprparse.y
src/bin/pgbench/pgbench.c
src/bin/psql/command.c
src/bin/psql/copy.c
src/bin/psql/crosstabview.c
src/bin/psql/describe.c
src/bin/psql/tab-complete.in.c
src/bin/psql/variables.c
src/bin/scripts/reindexdb.c
src/test/isolation/isolationtester.c
src/test/isolation/specparse.y
src/test/modules/libpq_pipeline/libpq_pipeline.c
src/test/regress/pg_regress.c

index 63e6ce2dae82c6f5cd880cb9c5214332e2fc5a09..1e9efcd395326844d50a8c4deb5cb2c95971618c 100644 (file)
@@ -237,13 +237,13 @@ add_one_elt(char *eltname, eary *eary)
        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);
@@ -400,7 +400,7 @@ sql_exec(PGconn *conn, const char *todo, bool quiet)
        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));
 
@@ -585,11 +585,11 @@ main(int argc, char **argv)
        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;
index 7c49dd433a70c73ec002ebf1fa003e68ce38e2d7..53ec1544ff3675b337ad14b0f96591582a83fdc6 100644 (file)
@@ -444,7 +444,7 @@ escape_quotes_bki(const char *src)
 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);
@@ -687,7 +687,7 @@ readfile(const char *path)
        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))
@@ -696,7 +696,7 @@ readfile(const char *path)
                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);
index 03e24a2577ca3ade11d71114d76b84215244ba0c..09ba0596400b50b2db5bba2884302380d7ab7df9 100644 (file)
@@ -1338,7 +1338,7 @@ extend_pattern_info_array(PatternInfoArray *pia)
        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));
 
@@ -1593,7 +1593,7 @@ compile_database_list(PGconn *conn, SimplePtrList *databases,
 
        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)
@@ -1738,7 +1738,7 @@ compile_database_list(PGconn *conn, SimplePtrList *databases,
                        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);
                }
@@ -2202,7 +2202,7 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrList *relations,
                {
                        /* 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));
index 1e3a8203f778df47d6b63e10652e139fb73b1748..fa169a8d6423b27e8cfd0f0d4463a8ad93d5889c 100644 (file)
@@ -320,7 +320,7 @@ kill_bgchild_atexit(void)
 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;
@@ -623,7 +623,7 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier,
                                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;
index abc6cd85a6dbf2b3d302e636a9b3255ac526bd65..be71783b370e14e2ef95c924ebf9a7f3dca6663b 100644 (file)
@@ -820,7 +820,7 @@ main(int argc, char **argv)
                                        }
 
                                        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;
index 1d404e778a03a07dabe138f52cb1aa75bd9292bd..76abdfa2ae6ce026bbad77c4cda288048462f0ce 100644 (file)
@@ -94,8 +94,8 @@ GetConnection(void)
                                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
@@ -117,8 +117,8 @@ GetConnection(void)
        }
        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++;
index 17d22c79f68a037b8f5ec4917076a0dadb7585f6..3a6b3b5f45bef8a725f6aca0676c2676d7c47dbd 100644 (file)
@@ -102,7 +102,7 @@ static char *
 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,
@@ -275,7 +275,7 @@ dir_open_for_write(WalWriteMethod *wwmethod, const char *pathname,
                }
        }
 
-       f = pg_malloc0(sizeof(DirectoryMethodFile));
+       f = pg_malloc0_object(DirectoryMethodFile);
 #ifdef HAVE_LIBZ
        if (wwmethod->compression_algorithm == PG_COMPRESSION_GZIP)
                f->gzfp = gzfp;
@@ -643,7 +643,7 @@ CreateWalDirectoryMethod(const char *basedir,
 {
        DirectoryMethodData *wwmethod;
 
-       wwmethod = pg_malloc0(sizeof(DirectoryMethodData));
+       wwmethod = pg_malloc0_object(DirectoryMethodData);
        *((const WalWriteMethodOps **) &wwmethod->base.ops) =
                &WalDirectoryMethodOps;
        wwmethod->base.compression_algorithm = compression_algorithm;
@@ -825,7 +825,7 @@ static char *
 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 : "");
@@ -859,7 +859,7 @@ tar_open_for_write(WalWriteMethod *wwmethod, const char *pathname,
 #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;
@@ -893,7 +893,7 @@ tar_open_for_write(WalWriteMethod *wwmethod, const char *pathname,
                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);
@@ -1360,7 +1360,7 @@ CreateWalTarMethod(const char *tarbase,
        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;
index c363ac6187e45f424b84f3721d818a3cd8291a01..2e50b7af4d217601011af987a0ab667fd9404e59 100644 (file)
@@ -85,7 +85,7 @@ load_backup_manifests(int n_backups, char **backup_directories)
        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]);
 
@@ -139,7 +139,7 @@ load_backup_manifest(char *backup_directory)
        /* 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;
index b9f26ce782e476dadd5d9fc1aeb2f8557f8db47a..ac7eb0940d574d1d445c51b6f01cff23979df6f2 100644 (file)
@@ -455,7 +455,7 @@ main(int argc, char *argv[])
 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;
@@ -1171,7 +1171,7 @@ process_directory_recursively(Oid tsoid,
 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;
@@ -1259,7 +1259,7 @@ scan_for_existing_tablespaces(char *pathname, cb_options *opt)
                }
 
                /* Create a new tablespace object. */
-               ts = pg_malloc0(sizeof(cb_tablespace));
+               ts = pg_malloc0_object(cb_tablespace);
                ts->oid = oid;
 
                /*
index da60f7d0297cd6122f59c2cf6fef6808f90809a6..3349aa2441d29f650cc9832abc953658632519fe 100644 (file)
@@ -120,7 +120,7 @@ reconstruct_from_incremental_file(char *input_filename,
         * 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
@@ -135,8 +135,8 @@ reconstruct_from_incremental_file(char *input_filename,
         * 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
@@ -483,7 +483,7 @@ make_incremental_rfile(char *filename)
        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);
        }
@@ -512,7 +512,7 @@ make_rfile(char *filename, bool missing_ok)
 {
        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)
        {
index 4f3ed2c173ccaa3fa7f98b51067d8fae36385cb4..715286043b5875c748a3053d71e3991f9f972bf4 100644 (file)
@@ -47,7 +47,7 @@ static size_t hex_encode(const uint8 *src, size_t len, char *dst);
 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;
index 122856b599ecfbedd60831862bef8f27a68b54ba..3cc61455dcb08464445e3e74a6e9be13bb86390c 100644 (file)
@@ -346,7 +346,7 @@ readfile(const char *path, int *numlines)
        {
                /* empty file */
                close(fd);
-               result = (char **) pg_malloc(sizeof(char *));
+               result = pg_malloc_object(char *);
                *result = NULL;
                return result;
        }
@@ -374,7 +374,7 @@ readfile(const char *path, int *numlines)
        }
 
        /* 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 */
index 94bac43fb924dd44c1397d8e9c5223848d65a039..8e8cdda50050f3ee915d64e7570321ede64a287c 100644 (file)
@@ -76,7 +76,7 @@ datapagemap_iterate(datapagemap_t *map)
 {
        datapagemap_iterator_t *iter;
 
-       iter = pg_malloc(sizeof(datapagemap_iterator_t));
+       iter = pg_malloc0_object(datapagemap_iterator_t);
        iter->map = map;
        iter->nextblkno = 0;
 
index 15a05d9a8d0a0ed3808d579e73d494f2e2842bd7..6955bc575eaa2b8e3597d9aa86cd9ef73e319ee1 100644 (file)
@@ -84,7 +84,7 @@ init_libpq_source(PGconn *conn)
 
        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;
index 97d6f65009be86d21a3a5012f2dbb8d4a82ea1a5..4841cf01fb700ab8abfc6f3cb8a306f60e888ece 100644 (file)
@@ -39,7 +39,7 @@ init_local_source(const char *datadir)
 {
        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;
index d0aafd7e7a6531e4a9bcced38f88e360c201a1e5..9d745d4b25b461f44ad302d6e28ad44f43073be9 100644 (file)
@@ -874,7 +874,7 @@ getTimelineHistory(TimeLineID tli, bool is_source, int *nentries)
         */
        if (tli == 1)
        {
-               history = (TimeLineHistoryEntry *) pg_malloc(sizeof(TimeLineHistoryEntry));
+               history = pg_malloc_object(TimeLineHistoryEntry);
                history->tli = tli;
                history->begin = history->end = InvalidXLogRecPtr;
                *nentries = 1;
index 69f589f67c9a352e27bbb9e03474d29ef1e46d0e..dda06eaa0bc6b5e3b120cba8e04fa4ba1787612b 100644 (file)
@@ -91,7 +91,7 @@ rewind_parseTimeLineHistory(char *buffer, TimeLineID targetTLI, int *nentries)
                lasttli = tli;
 
                nlines++;
-               entries = pg_realloc(entries, nlines * sizeof(TimeLineHistoryEntry));
+               entries = pg_realloc_array(entries, TimeLineHistoryEntry, nlines);
 
                entry = &entries[nlines - 1];
                entry->tli = tli;
@@ -115,9 +115,9 @@ rewind_parseTimeLineHistory(char *buffer, TimeLineID targetTLI, int *nentries)
         */
        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;
index 5afa65db98e33f962ceb90c6d6cddb27b8e3b708..eb35c68d4502c388fa6f8b29fc2ece20af9bd67d 100644 (file)
@@ -482,8 +482,8 @@ check_for_data_types_usage(ClusterInfo *cluster)
        }
 
        /* 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++)
        {
index 850c9238c11ac6bde17d9cb9e3f0a2d80999a158..a3184f95665ccbf2523096e7f2cea4660aeb3de3 100644 (file)
@@ -83,7 +83,7 @@ get_loadable_libraries(void)
        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 "
@@ -105,7 +105,7 @@ get_loadable_libraries(void)
         * 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++)
index ad4b1530e6d1b276a6ddc1e623885e00d88f8ad8..8c5679b80976efe79a55b7dfbe8294fe2630d20f 100644 (file)
@@ -53,8 +53,7 @@ gen_db_file_maps(DbInfo *old_db, DbInfo *new_db,
        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
@@ -364,7 +363,7 @@ get_template0_info(ClusterInfo *cluster)
        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");
@@ -433,7 +432,7 @@ get_db_infos(ClusterInfo *cluster)
        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++)
        {
@@ -579,7 +578,7 @@ static void
 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");
@@ -785,7 +784,7 @@ process_old_cluster_logical_slot_infos(DbInfo *dbinfo, PGresult *res, void *arg)
                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");
index 6945f71fcf12b33d29168c9d2c1199e3db6dd993..f0406de84ee3197fd2d7981fd80c287ebf50145d 100644 (file)
@@ -85,13 +85,13 @@ parallel_exec_prog(const char *log_file, const char *opt_log_file,
                /* 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
@@ -99,7 +99,7 @@ parallel_exec_prog(const char *log_file, const char *opt_log_file,
                         * 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;
@@ -188,13 +188,13 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
                /* 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
@@ -202,7 +202,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
                         * 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;
index ae3e224d7b124ed2175abce7c78c4f575d912160..2188a287850d88d46a3ecc844ae2f95336de4cd5 100644 (file)
@@ -26,7 +26,7 @@ static void SlruFlush(SlruSegState *state);
 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;
index 0ec5644a639d9c9109f342dbd1ee360e99c428f9..95ea7819457bc021db99a09d6a6f6dfa493d7b67 100644 (file)
@@ -69,9 +69,9 @@ get_tablespace_paths(void)
        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
        {
index 3d958527528874ded915d84d82f3d8b45707a535..b6eb29e1f3a635870e5c3abd4077d450be389099 100644 (file)
@@ -116,7 +116,7 @@ typedef struct UpgradeTaskSlot
 UpgradeTask *
 upgrade_task_create(void)
 {
-       UpgradeTask *task = pg_malloc0(sizeof(UpgradeTask));
+       UpgradeTask *task = pg_malloc0_object(UpgradeTask);
 
        task->queries = createPQExpBuffer();
 
@@ -154,8 +154,8 @@ upgrade_task_add_step(UpgradeTask *task, const char *query,
 {
        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;
@@ -421,7 +421,7 @@ void
 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;
index 0edc8123b43fb36623d4863c9073e57517afce3a..26c98186530c3e373e113dc658d79bafc066586b 100644 (file)
@@ -79,7 +79,7 @@ astreamer_verify_content_new(astreamer *next, verifier_context *context,
        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;
 }
index f9f2d457f2fb6212313517cb1cc6af1afc6481de..cbc9447384fa556596d0047515b18dc10a36d793 100644 (file)
@@ -418,7 +418,7 @@ parse_manifest_file(char *manifest_path)
        /* 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;
@@ -970,7 +970,7 @@ precheck_tar_backup_file(verifier_context *context, char *relpath,
         * 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;
@@ -1065,7 +1065,7 @@ verify_backup_checksums(verifier_context *context)
 
        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)
index 8dd6c8811f28819c22d09631dae5c0bd1b867b3e..6dd809950fda08968cf2937692ff451249200ee1 100644 (file)
@@ -167,7 +167,7 @@ function: FUNCTION                  { $$ = find_func(yyscanner, $1); pg_free($1); }
 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;
@@ -178,7 +178,7 @@ make_null_constant(void)
 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;
@@ -189,7 +189,7 @@ make_integer_constant(int64 ival)
 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;
@@ -200,7 +200,7 @@ make_double_constant(double dval)
 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;
@@ -211,7 +211,7 @@ make_boolean_constant(bool bval)
 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;
@@ -415,12 +415,12 @@ make_elist(PgBenchExpr *expr, PgBenchExprList *list)
 
        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;
 
@@ -453,7 +453,7 @@ make_func(yyscan_t yyscanner, int fnumber, PgBenchExprList *args)
 {
        int                     len = elist_length(args);
 
-       PgBenchExpr *expr = pg_malloc(sizeof(PgBenchExpr));
+       PgBenchExpr *expr = pg_malloc_object(PgBenchExpr);
 
        Assert(fnumber >= 0);
 
index cb4e986092e2a8e035e76fa4d25d730a9f0371b4..1dae918cc09d2d14fd05dc78567fdf9605344801 100644 (file)
@@ -1774,7 +1774,7 @@ enlargeVariables(Variables *variables, int needed)
        {
                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);
        }
 }
 
@@ -3067,7 +3067,7 @@ allocCStatePrepared(CState *st)
 {
        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];
@@ -3075,7 +3075,7 @@ allocCStatePrepared(CState *st)
 
                for (numcmds = 0; script->commands[numcmds] != NULL; numcmds++)
                        ;
-               st->prepared[i] = pg_malloc0(sizeof(bool) * numcmds);
+               st->prepared[i] = pg_malloc0_array(bool, numcmds);
        }
 }
 
@@ -5659,7 +5659,7 @@ create_sql_command(PQExpBuffer buf)
                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 */
@@ -5755,7 +5755,7 @@ process_backslash_command(PsqlScanState sstate, const char *source,
        }
 
        /* 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);
@@ -6011,7 +6011,7 @@ ParseScript(const char *script, const char *desc, int weight)
        /* 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 */
@@ -6114,7 +6114,7 @@ ParseScript(const char *script, const char *desc, int weight)
                {
                        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 */
@@ -6844,7 +6844,7 @@ main(int argc, char **argv)
                }
        }
 
-       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")))
@@ -7298,7 +7298,7 @@ main(int argc, char **argv)
 
        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 */
@@ -7412,7 +7412,7 @@ main(int argc, char **argv)
        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++)
@@ -7993,7 +7993,7 @@ socket_has_input(socket_set *sa, int fd, int idx)
 static socket_set *
 alloc_socket_set(int count)
 {
-       return (socket_set *) pg_malloc0(sizeof(socket_set));
+       return pg_malloc0_object(socket_set);
 }
 
 static void
index 213d48500dec5bd8cae35c655c325a17f35d8480..637f2703db217825c1fdeedc3c8e65e2f6cba0a6 100644 (file)
@@ -4168,8 +4168,8 @@ do_connect(enum trivalue reuse_previous_specification,
        /* 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;
 
@@ -5665,7 +5665,7 @@ savePsetInfo(const printQueryOpt *popt)
 {
        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));
index 892c28894edaf0da0693df36fdd21ddf901af68e..6a8a9792e7d6564eb63b51e535d3845d44f501b4 100644 (file)
@@ -99,7 +99,7 @@ parse_slash_copy(const char *args)
                return NULL;
        }
 
-       result = pg_malloc0(sizeof(struct copy_options));
+       result = pg_malloc0_object(struct copy_options);
 
        result->before_tofrom = pg_strdup("");  /* initialize for appending */
 
index 3b268e4164179ba8fec58a997444676058c282e8..111e8823bdbe7917a7eef05fe0002f33c4a4c88f 100644 (file)
@@ -245,11 +245,9 @@ PrintResultInCrosstab(const PGresult *res)
        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);
@@ -312,7 +310,7 @@ printCrosstab(const PGresult *result,
         * 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;
 
@@ -437,7 +435,7 @@ error:
 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;
@@ -532,8 +530,7 @@ avlInsertNode(avl_tree *tree, avl_node **node, pivot_field field)
 
        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;
@@ -591,7 +588,7 @@ rankSort(int num_columns, pivot_field *piv_columns)
                                                                 * 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;
index 571a6a003d5e2b950963af9b21296f87a3452c18..4352991e5414ef11caecc049b607c5667d8706bb 100644 (file)
@@ -3797,7 +3797,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem)
                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);
 
@@ -5306,7 +5306,7 @@ listSchemas(const char *pattern, bool verbose, bool showSystem)
                         * 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 */
index 8b91bc000625a9bb5c6b3338a8d4407ba8086529..b2dba6d10ab94074ea91857331320627af23fa00 100644 (file)
@@ -6324,8 +6324,7 @@ append_variable_names(char ***varnames, int *nvars,
        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);
@@ -6350,7 +6349,7 @@ complete_from_variables(const char *text, const char *prefix, const char *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)
        {
@@ -6928,7 +6927,7 @@ get_previous_words(int point, char **buffer, int *nwords)
         * 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);
 
        /*
index 1cd082db157194f101cfb2f650d2a040189ba0b8..f2a28bc9820a0a8ed2d5db1509b111aaa38c64ad 100644 (file)
@@ -54,7 +54,7 @@ CreateVariableSpace(void)
 {
        struct _variable *ptr;
 
-       ptr = pg_malloc(sizeof *ptr);
+       ptr = pg_malloc_object(struct _variable);
        ptr->name = NULL;
        ptr->value = NULL;
        ptr->substitute_hook = NULL;
@@ -353,7 +353,7 @@ SetVariable(VariableSpace space, const char *name, const char *value)
        /* 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;
@@ -416,7 +416,7 @@ SetVariableHooks(VariableSpace space, const char *name,
        }
 
        /* 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;
index 8bab74b59171bafd6f0322e0d20f2d5ae8af7341..d7fb16d3c85dbb0325660a840de449c7a6e073dd 100644 (file)
@@ -322,7 +322,7 @@ reindex_one_database(ConnParams *cparams, ReindexType type,
                                 * 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;
 
@@ -713,7 +713,7 @@ get_parallel_tables_list(PGconn *conn, ReindexType type,
                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++)
@@ -809,7 +809,7 @@ get_parallel_tabidx_list(PGconn *conn,
                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
index a0aec04d994e45af10a01f3d8f717f0ef8f0f670..440c875b8ac6b74318c82a6f617c23fd13881994 100644 (file)
@@ -147,7 +147,7 @@ main(int argc, char **argv)
         * 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++)
@@ -262,7 +262,7 @@ check_testspec(TestSpec *testspec)
        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++)
@@ -417,8 +417,8 @@ run_all_permutations(TestSpec *testspec)
                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;
 
@@ -431,7 +431,7 @@ run_all_permutations(TestSpec *testspec)
         * 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;
 
@@ -524,7 +524,7 @@ run_permutation(TestSpec *testspec, int nsteps, PermutationStep **steps)
        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++)
index b61d789d8f06ef42c3186013982be073c85bc008..f6b9058e55714c13cab81e388acbabcb7ed33ed8 100644 (file)
@@ -83,8 +83,8 @@ setup_list:
                        }
                        | 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;
                        }
@@ -107,15 +107,15 @@ opt_teardown:
 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;
                        }
                ;
@@ -123,7 +123,7 @@ session_list:
 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;
@@ -135,15 +135,15 @@ session:
 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;
                        }
                ;
@@ -152,7 +152,7 @@ step_list:
 step:
                        STEP identifier sqlblock
                        {
-                               $$ = pg_malloc(sizeof(Step));
+                               $$ = pg_malloc_object(Step);
                                $$->name = $2;
                                $$->sql = $3;
                                $$->session = -1; /* until filled */
@@ -175,15 +175,15 @@ opt_permutation_list:
 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;
                        }
                ;
@@ -192,7 +192,7 @@ permutation_list:
 permutation:
                        PERMUTATION permutation_step_list
                        {
-                               $$ = pg_malloc(sizeof(Permutation));
+                               $$ = pg_malloc_object(Permutation);
                                $$->nsteps = $2.nelements;
                                $$->steps = (PermutationStep **) $2.elements;
                        }
@@ -201,15 +201,15 @@ permutation:
 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;
                        }
                ;
@@ -217,7 +217,7 @@ permutation_step_list:
 permutation_step:
                        identifier
                        {
-                               $$ = pg_malloc(sizeof(PermutationStep));
+                               $$ = pg_malloc_object(PermutationStep);
                                $$->name = $1;
                                $$->blockers = NULL;
                                $$->nblockers = 0;
@@ -225,7 +225,7 @@ permutation_step:
                        }
                        | identifier '(' blocker_list ')'
                        {
-                               $$ = pg_malloc(sizeof(PermutationStep));
+                               $$ = pg_malloc_object(PermutationStep);
                                $$->name = $1;
                                $$->blockers = (PermutationStepBlocker **) $3.elements;
                                $$->nblockers = $3.nelements;
@@ -236,15 +236,15 @@ permutation_step:
 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;
                        }
                ;
@@ -252,7 +252,7 @@ blocker_list:
 blocker:
                        identifier
                        {
-                               $$ = pg_malloc(sizeof(PermutationStepBlocker));
+                               $$ = pg_malloc_object(PermutationStepBlocker);
                                $$->stepname = $1;
                                $$->blocktype = PSB_OTHER_STEP;
                                $$->num_notices = -1;
@@ -261,7 +261,7 @@ blocker:
                        }
                        | identifier NOTICES INTEGER
                        {
-                               $$ = pg_malloc(sizeof(PermutationStepBlocker));
+                               $$ = pg_malloc_object(PermutationStepBlocker);
                                $$->stepname = $1;
                                $$->blocktype = PSB_NUM_NOTICES;
                                $$->num_notices = $3;
@@ -270,7 +270,7 @@ blocker:
                        }
                        | '*'
                        {
-                               $$ = pg_malloc(sizeof(PermutationStepBlocker));
+                               $$ = pg_malloc_object(PermutationStepBlocker);
                                $$->stepname = NULL;
                                $$->blocktype = PSB_ONCE;
                                $$->num_notices = -1;
index 409b3a7fa455dba4f2d6bda7a38dc803e15a6aaf..aa0a6bbe762ff9706e0f8040d9e83a204b545920 100644 (file)
@@ -260,8 +260,8 @@ copy_connection(PGconn *conn)
                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)
@@ -1337,8 +1337,8 @@ test_protocol_version(PGconn *conn)
                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)
index b5c0cb647a8da0fdecbd460f0d29eb77d9659938..b8b6a91198763ad0fa293153754dc03080cf0487 100644 (file)
@@ -196,7 +196,7 @@ unlimit_core_size(void)
 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);
@@ -674,7 +674,7 @@ load_resultmap(void)
                 */
                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);
@@ -1557,7 +1557,7 @@ wait_for_tests(PID_TYPE * pids, int *statuses, instr_time *stoptimes,
        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