Use more palloc_object() and palloc_array() in contrib/
authorMichael Paquier <michael@paquier.xyz>
Fri, 5 Dec 2025 07:40:26 +0000 (16:40 +0900)
committerMichael Paquier <michael@paquier.xyz>
Fri, 5 Dec 2025 07:40:26 +0000 (16:40 +0900)
The idea is to encourage more the use of these new routines across the
tree, as these offer stronger type safety guarantees than palloc().  In
an ideal world, palloc() would then act as an internal routine of these
flavors, whose footprint in the tree is minimal.

The patch sent by the author is very large, and this chunk of changes
represents something like 10% of the overall patch submitted.

The code compiled is the same before and after this commit, using
objdump to do some validation with a difference taken in-between.  There
are some diffs, which are caused by changes in line numbers because some
of the new allocation formulas are shorter, for the following files:
trgm_regexp.c, xpath.c and pg_walinspect.c.

Author: David Geier <geidav.pg@gmail.com>
Discussion: https://postgr.es/m/ad0748d4-3080-436e-b0bc-ac8f86a3466a@gmail.com

67 files changed:
contrib/amcheck/verify_gin.c
contrib/amcheck/verify_heapam.c
contrib/amcheck/verify_nbtree.c
contrib/basebackup_to_shell/basebackup_to_shell.c
contrib/bloom/blinsert.c
contrib/bloom/blscan.c
contrib/bloom/blutils.c
contrib/bloom/blvacuum.c
contrib/btree_gin/btree_gin.c
contrib/btree_gist/btree_inet.c
contrib/btree_gist/btree_interval.c
contrib/btree_gist/btree_time.c
contrib/btree_gist/btree_ts.c
contrib/btree_gist/btree_utils_num.c
contrib/btree_gist/btree_utils_var.c
contrib/btree_gist/btree_uuid.c
contrib/cube/cube.c
contrib/dict_int/dict_int.c
contrib/dict_xsyn/dict_xsyn.c
contrib/file_fdw/file_fdw.c
contrib/hstore/hstore_gist.c
contrib/hstore/hstore_io.c
contrib/intarray/_int_bool.c
contrib/intarray/_int_gin.c
contrib/intarray/_int_gist.c
contrib/intarray/_intbig_gist.c
contrib/jsonb_plperl/jsonb_plperl.c
contrib/jsonb_plpython/jsonb_plpython.c
contrib/ltree/_ltree_gist.c
contrib/ltree/_ltree_op.c
contrib/ltree/ltree_gist.c
contrib/ltree/ltree_io.c
contrib/ltree/ltree_op.c
contrib/ltree/ltxtquery_io.c
contrib/pageinspect/brinfuncs.c
contrib/pageinspect/btreefuncs.c
contrib/pageinspect/ginfuncs.c
contrib/pageinspect/hashfuncs.c
contrib/pageinspect/heapfuncs.c
contrib/pg_overexplain/pg_overexplain.c
contrib/pg_trgm/trgm_gin.c
contrib/pg_trgm/trgm_gist.c
contrib/pg_trgm/trgm_regexp.c
contrib/pg_visibility/pg_visibility.c
contrib/pg_walinspect/pg_walinspect.c
contrib/pgcrypto/mbuf.c
contrib/pgcrypto/openssl.c
contrib/pgcrypto/pgp-cfb.c
contrib/pgcrypto/pgp-compress.c
contrib/pgcrypto/pgp-decrypt.c
contrib/pgcrypto/pgp-encrypt.c
contrib/pgcrypto/pgp-pgsql.c
contrib/pgcrypto/pgp-pubkey.c
contrib/pgcrypto/px-hmac.c
contrib/pgcrypto/px.c
contrib/seg/seg.c
contrib/sepgsql/label.c
contrib/sepgsql/uavc.c
contrib/spi/refint.c
contrib/sslinfo/sslinfo.c
contrib/tablefunc/tablefunc.c
contrib/test_decoding/test_decoding.c
contrib/tsm_system_rows/tsm_system_rows.c
contrib/tsm_system_time/tsm_system_time.c
contrib/unaccent/unaccent.c
contrib/xml2/xpath.c
contrib/xml2/xslt_proc.c

index efc562275689f52029cc6a1eea30347fedafd8e2..253da4b1f0bdf73ae0e09bf671367c6248c069a0 100644 (file)
@@ -117,7 +117,7 @@ ginReadTupleWithoutState(IndexTuple itup, int *nitems)
    }
    else
    {
-       ipd = (ItemPointer) palloc(sizeof(ItemPointerData) * nipd);
+       ipd = palloc_array(ItemPointerData, nipd);
        memcpy(ipd, ptr, sizeof(ItemPointerData) * nipd);
    }
    *nitems = nipd;
@@ -152,7 +152,7 @@ gin_check_posting_tree_parent_keys_consistency(Relation rel, BlockNumber posting
    leafdepth = -1;
 
    /* Start the scan at the root page */
-   stack = (GinPostingTreeScanItem *) palloc0(sizeof(GinPostingTreeScanItem));
+   stack = palloc0_object(GinPostingTreeScanItem);
    stack->depth = 0;
    ItemPointerSetInvalid(&stack->parentkey);
    stack->parentblk = InvalidBlockNumber;
@@ -354,7 +354,7 @@ gin_check_posting_tree_parent_keys_consistency(Relation rel, BlockNumber posting
                                    stack->blkno, i)));
 
                /* This is an internal page, recurse into the child. */
-               ptr = (GinPostingTreeScanItem *) palloc(sizeof(GinPostingTreeScanItem));
+               ptr = palloc_object(GinPostingTreeScanItem);
                ptr->depth = stack->depth + 1;
 
                /*
@@ -412,7 +412,7 @@ gin_check_parent_keys_consistency(Relation rel,
    leafdepth = -1;
 
    /* Start the scan at the root page */
-   stack = (GinScanItem *) palloc0(sizeof(GinScanItem));
+   stack = palloc0_object(GinScanItem);
    stack->depth = 0;
    stack->parenttup = NULL;
    stack->parentblk = InvalidBlockNumber;
@@ -473,7 +473,7 @@ gin_check_parent_keys_consistency(Relation rel,
 
                elog(DEBUG3, "split detected for blk: %u, parent blk: %u", stack->blkno, stack->parentblk);
 
-               ptr = (GinScanItem *) palloc(sizeof(GinScanItem));
+               ptr = palloc_object(GinScanItem);
                ptr->depth = stack->depth;
                ptr->parenttup = CopyIndexTuple(stack->parenttup);
                ptr->parentblk = stack->parentblk;
@@ -601,7 +601,7 @@ gin_check_parent_keys_consistency(Relation rel,
            {
                GinScanItem *ptr;
 
-               ptr = (GinScanItem *) palloc(sizeof(GinScanItem));
+               ptr = palloc_object(GinScanItem);
                ptr->depth = stack->depth + 1;
                /* last tuple in layer has no high key */
                if (i == maxoff && rightlink == InvalidBlockNumber)
index 4963e9245cb54301a490b761c4890b6433fdd4f8..a090e18c697b2fd7d233f11b07b7e44bedaa8c6a 100644 (file)
@@ -1838,7 +1838,7 @@ check_tuple_attribute(HeapCheckContext *ctx)
    {
        ToastedAttribute *ta;
 
-       ta = (ToastedAttribute *) palloc0(sizeof(ToastedAttribute));
+       ta = palloc0_object(ToastedAttribute);
 
        VARATT_EXTERNAL_GET_POINTER(ta->toast_pointer, attr);
        ta->blkno = ctx->blkno;
index fce8bd9f9f94fbe8c2beb3cc1fad8691a70ce642..f91392a3a4977e75f8c7a81f93038318862ce741 100644 (file)
@@ -399,7 +399,7 @@ bt_check_every_level(Relation rel, Relation heaprel, bool heapkeyspace,
    /*
     * Initialize state for entire verification operation
     */
-   state = palloc0(sizeof(BtreeCheckState));
+   state = palloc0_object(BtreeCheckState);
    state->rel = rel;
    state->heaprel = heaprel;
    state->heapkeyspace = heapkeyspace;
index 8720f5a43727d3a8eb76cbfac4ccaf5e1c339966..345d3ed895d46622252a15f3e112dab24529a6d3 100644 (file)
@@ -136,7 +136,7 @@ shell_get_sink(bbsink *next_sink, void *detail_arg)
     * We remember the current value of basebackup_to_shell.shell_command to
     * be certain that it can't change under us during the backup.
     */
-   sink = palloc0(sizeof(bbsink_shell));
+   sink = palloc0_object(bbsink_shell);
    *((const bbsink_ops **) &sink->base.bbs_ops) = &bbsink_shell_ops;
    sink->base.bbs_next = next_sink;
    sink->target_detail = detail_arg;
index 7866438122f584ff92af4781f81d477f3b71171b..c11e06c34ee5f01f384e881a98b4ec08fdb24f5f 100644 (file)
@@ -151,7 +151,7 @@ blbuild(Relation heap, Relation index, IndexInfo *indexInfo)
 
    MemoryContextDelete(buildstate.tmpCtx);
 
-   result = (IndexBuildResult *) palloc(sizeof(IndexBuildResult));
+   result = palloc_object(IndexBuildResult);
    result->heap_tuples = reltuples;
    result->index_tuples = buildstate.indtuples;
 
index d072f47fe28b5635d4a302b0d34db006285dc18e..0d71edbe91c3672de298fec139647efdf184fc71 100644 (file)
@@ -29,7 +29,7 @@ blbeginscan(Relation r, int nkeys, int norderbys)
 
    scan = RelationGetIndexScan(r, nkeys, norderbys);
 
-   so = (BloomScanOpaque) palloc(sizeof(BloomScanOpaqueData));
+   so = (BloomScanOpaque) palloc_object(BloomScanOpaqueData);
    initBloomState(&so->state, scan->indexRelation);
    so->sign = NULL;
 
@@ -86,7 +86,7 @@ blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
        /* New search: have to calculate search signature */
        ScanKey     skey = scan->keyData;
 
-       so->sign = palloc0(sizeof(BloomSignatureWord) * so->state.opts.bloomLength);
+       so->sign = palloc0_array(BloomSignatureWord, so->state.opts.bloomLength);
 
        for (i = 0; i < scan->numberOfKeys; i++)
        {
index bbeefc3a75b333038ce5771c3572d9770b706f2a..7a468b4a173baad8ce6dcac7f43017c961dd5e8a 100644 (file)
@@ -86,7 +86,7 @@ makeDefaultBloomOptions(void)
    BloomOptions *opts;
    int         i;
 
-   opts = (BloomOptions *) palloc0(sizeof(BloomOptions));
+   opts = palloc0_object(BloomOptions);
    /* Convert DEFAULT_BLOOM_LENGTH from # of bits to # of words */
    opts->bloomLength = (DEFAULT_BLOOM_LENGTH + SIGNWORDBITS - 1) / SIGNWORDBITS;
    for (i = 0; i < INDEX_MAX_KEYS; i++)
index 1485a6a703fd6e68f0f3430e1d4123a7bc00adc8..e68a9008f56c88aaaaf46eae626adc27276e8137 100644 (file)
@@ -42,7 +42,7 @@ blbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
    GenericXLogState *gxlogState;
 
    if (stats == NULL)
-       stats = (IndexBulkDeleteResult *) palloc0(sizeof(IndexBulkDeleteResult));
+       stats = palloc0_object(IndexBulkDeleteResult);
 
    initBloomState(&state, index);
 
@@ -171,7 +171,7 @@ blvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
        return stats;
 
    if (stats == NULL)
-       stats = (IndexBulkDeleteResult *) palloc0(sizeof(IndexBulkDeleteResult));
+       stats = palloc0_object(IndexBulkDeleteResult);
 
    /*
     * Iterate over the pages: insert deleted pages into FSM and collect
index 966b76e591b70b5fae8d1ee69481e08e050e7f4a..afb8b3820af263872effd959453db7d93cea0d03 100644 (file)
@@ -52,7 +52,7 @@ gin_btree_extract_value(FunctionCallInfo fcinfo, bool is_varlena)
 {
    Datum       datum = PG_GETARG_DATUM(0);
    int32      *nentries = (int32 *) PG_GETARG_POINTER(1);
-   Datum      *entries = (Datum *) palloc(sizeof(Datum));
+   Datum      *entries = palloc_object(Datum);
 
    /* Ensure that values stored in the index are not toasted */
    if (is_varlena)
@@ -75,9 +75,9 @@ gin_btree_extract_query(FunctionCallInfo fcinfo,
    StrategyNumber strategy = PG_GETARG_UINT16(2);
    bool      **partialmatch = (bool **) PG_GETARG_POINTER(3);
    Pointer   **extra_data = (Pointer **) PG_GETARG_POINTER(4);
-   Datum      *entries = (Datum *) palloc(sizeof(Datum));
-   QueryInfo  *data = (QueryInfo *) palloc(sizeof(QueryInfo));
-   bool       *ptr_partialmatch = (bool *) palloc(sizeof(bool));
+   Datum      *entries = palloc_object(Datum);
+   QueryInfo  *data = palloc_object(QueryInfo);
+   bool       *ptr_partialmatch = palloc_object(bool);
    int         btree_strat,
                rhs_code;
 
@@ -140,7 +140,7 @@ gin_btree_extract_query(FunctionCallInfo fcinfo,
    data->orig_datum = datum;
    data->entry_datum = entries[0];
    data->typecmp = cmp_fns[rhs_code];
-   *extra_data = (Pointer *) palloc(sizeof(Pointer));
+   *extra_data = palloc_object(Pointer);
    **extra_data = (Pointer) data;
 
    PG_RETURN_POINTER(entries);
@@ -579,7 +579,7 @@ GIN_SUPPORT(time, leftmostvalue_time, time_rhs_is_varlena, NULL, time_cmp_fns)
 static Datum
 leftmostvalue_timetz(void)
 {
-   TimeTzADT  *v = palloc(sizeof(TimeTzADT));
+   TimeTzADT  *v = palloc_object(TimeTzADT);
 
    v->time = 0;
    v->zone = -24 * 3600;       /* XXX is that true? */
@@ -639,7 +639,7 @@ GIN_SUPPORT(date, leftmostvalue_date, date_rhs_is_varlena, date_cvt_fns, date_cm
 static Datum
 leftmostvalue_interval(void)
 {
-   Interval   *v = palloc(sizeof(Interval));
+   Interval   *v = palloc_object(Interval);
 
    INTERVAL_NOBEGIN(v);
 
@@ -657,7 +657,7 @@ GIN_SUPPORT(interval, leftmostvalue_interval, interval_rhs_is_varlena, NULL, int
 static Datum
 leftmostvalue_macaddr(void)
 {
-   macaddr    *v = palloc0(sizeof(macaddr));
+   macaddr    *v = palloc0_object(macaddr);
 
    return MacaddrPGetDatum(v);
 }
@@ -673,7 +673,7 @@ GIN_SUPPORT(macaddr, leftmostvalue_macaddr, macaddr_rhs_is_varlena, NULL, macadd
 static Datum
 leftmostvalue_macaddr8(void)
 {
-   macaddr8   *v = palloc0(sizeof(macaddr8));
+   macaddr8   *v = palloc0_object(macaddr8);
 
    return Macaddr8PGetDatum(v);
 }
@@ -910,7 +910,7 @@ leftmostvalue_uuid(void)
     * palloc0 will create the UUID with all zeroes:
     * "00000000-0000-0000-0000-000000000000"
     */
-   pg_uuid_t  *retval = (pg_uuid_t *) palloc0(sizeof(pg_uuid_t));
+   pg_uuid_t  *retval = palloc0_object(pg_uuid_t);
 
    return UUIDPGetDatum(retval);
 }
index 52bf3e2446e95816d277acf0ab99723f7a56757e..e726375f61d06522b6148dff31c8bb76ed0b328e 100644 (file)
@@ -97,10 +97,10 @@ gbt_inet_compress(PG_FUNCTION_ARGS)
 
    if (entry->leafkey)
    {
-       inetKEY    *r = (inetKEY *) palloc(sizeof(inetKEY));
+       inetKEY    *r = palloc_object(inetKEY);
        bool        failure = false;
 
-       retval = palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        r->lower = convert_network_to_scalar(entry->key, INETOID, &failure);
        Assert(!failure);
        r->upper = r->lower;
index 19eefc60cde3f53a9d0ff0acc4f59b73a60c0017..1fc27f60384ea4a29d8532660153ec301727e7b2 100644 (file)
@@ -150,7 +150,7 @@ gbt_intv_compress(PG_FUNCTION_ARGS)
    {
        char       *r = (char *) palloc(2 * INTERVALSIZE);
 
-       retval = palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
 
        if (entry->leafkey)
        {
@@ -190,10 +190,10 @@ gbt_intv_decompress(PG_FUNCTION_ARGS)
 
    if (INTERVALSIZE != sizeof(Interval))
    {
-       intvKEY    *r = palloc(sizeof(intvKEY));
+       intvKEY    *r = palloc_object(intvKEY);
        char       *key = DatumGetPointer(entry->key);
 
-       retval = palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        memcpy(&r->lower, key, INTERVALSIZE);
        memcpy(&r->upper, key + INTERVALSIZE, INTERVALSIZE);
 
index 9483846c4738bbf92fb9b5b56fef8710ea8ab5a7..e744f1be017fa130a1939a3a4d58b97d0ffcb28c 100644 (file)
@@ -162,11 +162,11 @@ gbt_timetz_compress(PG_FUNCTION_ARGS)
 
    if (entry->leafkey)
    {
-       timeKEY    *r = (timeKEY *) palloc(sizeof(timeKEY));
+       timeKEY    *r = palloc_object(timeKEY);
        TimeTzADT  *tz = DatumGetTimeTzADTP(entry->key);
        TimeADT     tmp;
 
-       retval = palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
 
        /* We are using the time + zone only to compress */
        tmp = tz->time + (tz->zone * INT64CONST(1000000));
index b7bbae2f4d6fb89ebe5a11f3b420c91ed5a4e207..3b163a729cbf4a2501ab72b77c3beebcae3bbd21 100644 (file)
@@ -146,7 +146,7 @@ ts_dist(PG_FUNCTION_ARGS)
 
    if (TIMESTAMP_NOT_FINITE(a) || TIMESTAMP_NOT_FINITE(b))
    {
-       Interval   *p = palloc(sizeof(Interval));
+       Interval   *p = palloc_object(Interval);
 
        p->day = INT_MAX;
        p->month = INT_MAX;
@@ -170,7 +170,7 @@ tstz_dist(PG_FUNCTION_ARGS)
 
    if (TIMESTAMP_NOT_FINITE(a) || TIMESTAMP_NOT_FINITE(b))
    {
-       Interval   *p = palloc(sizeof(Interval));
+       Interval   *p = palloc_object(Interval);
 
        p->day = INT_MAX;
        p->month = INT_MAX;
@@ -212,13 +212,13 @@ gbt_tstz_compress(PG_FUNCTION_ARGS)
 
    if (entry->leafkey)
    {
-       tsKEY      *r = (tsKEY *) palloc(sizeof(tsKEY));
+       tsKEY      *r = palloc_object(tsKEY);
        TimestampTz ts = DatumGetTimestampTz(entry->key);
        Timestamp   gmt;
 
        gmt = tstz_to_ts_gmt(ts);
 
-       retval = palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        r->lower = r->upper = gmt;
        gistentryinit(*retval, PointerGetDatum(r),
                      entry->rel, entry->page,
index 9ba97f96fbfc44fd4a78fd8a343d72c55878320c..51c8836f27a3dc4749a5f2d7196825fee7adf9a8 100644 (file)
@@ -89,7 +89,7 @@ gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
 
        memcpy(&r[0], leaf, tinfo->size);
        memcpy(&r[tinfo->size], leaf, tinfo->size);
-       retval = palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        gistentryinit(*retval, PointerGetDatum(r), entry->rel, entry->page,
                      entry->offset, false);
    }
@@ -156,7 +156,7 @@ gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
            datum = entry->key;
    }
 
-   retval = palloc(sizeof(GISTENTRY));
+   retval = palloc_object(GISTENTRY);
    gistentryinit(*retval, datum, entry->rel, entry->page, entry->offset,
                  false);
    return retval;
index fb466e5aa32ba71c0dd6dbf641d22041ea3b634e..7fbea0cfb7bfd38ddc302728cbcd8bf6f9696c1e 100644 (file)
@@ -40,7 +40,7 @@ gbt_var_decompress(PG_FUNCTION_ARGS)
 
    if (key != (GBT_VARKEY *) DatumGetPointer(entry->key))
    {
-       GISTENTRY  *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+       GISTENTRY  *retval = palloc_object(GISTENTRY);
 
        gistentryinit(*retval, PointerGetDatum(key),
                      entry->rel, entry->page,
@@ -289,7 +289,7 @@ gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
 
        r = gbt_var_key_from_datum(leaf);
 
-       retval = palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        gistentryinit(*retval, PointerGetDatum(r),
                      entry->rel, entry->page,
                      entry->offset, true);
@@ -309,7 +309,7 @@ gbt_var_fetch(PG_FUNCTION_ARGS)
    GBT_VARKEY_R r = gbt_var_key_readable(key);
    GISTENTRY  *retval;
 
-   retval = palloc(sizeof(GISTENTRY));
+   retval = palloc_object(GISTENTRY);
    gistentryinit(*retval, PointerGetDatum(r.lower),
                  entry->rel, entry->page,
                  entry->offset, true);
index 07f304f39f14c21aeb7fbf31610ad855f6ff1129..1091af222d1d1320a682fa2a01185e1a34e358ea 100644 (file)
@@ -108,7 +108,7 @@ gbt_uuid_compress(PG_FUNCTION_ARGS)
        char       *r = (char *) palloc(2 * UUID_LEN);
        pg_uuid_t  *key = DatumGetUUIDP(entry->key);
 
-       retval = palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
 
        memcpy(r, key, UUID_LEN);
        memcpy(r + UUID_LEN, key, UUID_LEN);
index aa47e141f810c2431c42d2b03bc32b18c19d4031..3600457cbc098f181c4fbfcfb088965d9c4f004b 100644 (file)
@@ -471,7 +471,7 @@ g_cube_decompress(PG_FUNCTION_ARGS)
 
    if (key != DatumGetNDBOXP(entry->key))
    {
-       GISTENTRY  *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+       GISTENTRY  *retval = palloc_object(GISTENTRY);
 
        gistentryinit(*retval, PointerGetDatum(key),
                      entry->rel, entry->page,
index bdad52d202897f050e93f6d28a15eec8a6a4277e..5d9523a1a632bf1781c46d11b64a706b68459579 100644 (file)
@@ -38,7 +38,7 @@ dintdict_init(PG_FUNCTION_ARGS)
    DictInt    *d;
    ListCell   *l;
 
-   d = (DictInt *) palloc0(sizeof(DictInt));
+   d = palloc0_object(DictInt);
    d->maxlen = 6;
    d->rejectlong = false;
    d->absval = false;
@@ -83,7 +83,7 @@ dintdict_lexize(PG_FUNCTION_ARGS)
    char       *in = (char *) PG_GETARG_POINTER(1);
    int         len = PG_GETARG_INT32(2);
    char       *txt;
-   TSLexeme   *res = palloc0(sizeof(TSLexeme) * 2);
+   TSLexeme   *res = palloc0_array(TSLexeme, 2);
 
    res[1].lexeme = NULL;
 
index 1ec5285d6d1fc3c5207ad2a025a7b85a4f50f68e..bbb2fd850fd0c4c7035a447ed5935edaf70c45eb 100644 (file)
@@ -109,9 +109,9 @@ read_dictionary(DictSyn *d, const char *filename)
            {
                d->len = (d->len > 0) ? 2 * d->len : 16;
                if (d->syn)
-                   d->syn = (Syn *) repalloc(d->syn, sizeof(Syn) * d->len);
+                   d->syn = repalloc_array(d->syn, Syn, d->len);
                else
-                   d->syn = (Syn *) palloc(sizeof(Syn) * d->len);
+                   d->syn = palloc_array(Syn, d->len);
            }
 
            /* Save first word only if we will match it */
@@ -150,7 +150,7 @@ dxsyn_init(PG_FUNCTION_ARGS)
    ListCell   *l;
    char       *filename = NULL;
 
-   d = (DictSyn *) palloc0(sizeof(DictSyn));
+   d = palloc0_object(DictSyn);
    d->len = 0;
    d->syn = NULL;
    d->matchorig = true;
@@ -235,7 +235,7 @@ dxsyn_lexize(PG_FUNCTION_ARGS)
        char       *end;
        int         nsyns = 0;
 
-       res = palloc(sizeof(TSLexeme));
+       res = palloc_object(TSLexeme);
 
        pos = value;
        while ((syn = find_word(pos, &end)) != NULL)
index 70564a68b137b6aae412bb08ad423d4c5881a4f7..e9cda3c47d15332b18a987e5fd5041b8c8c81158 100644 (file)
@@ -531,7 +531,7 @@ fileGetForeignRelSize(PlannerInfo *root,
     * we might as well get everything and not need to re-fetch it later in
     * planning.
     */
-   fdw_private = (FileFdwPlanState *) palloc(sizeof(FileFdwPlanState));
+   fdw_private = palloc_object(FileFdwPlanState);
    fileGetOptions(foreigntableid,
                   &fdw_private->filename,
                   &fdw_private->is_program,
@@ -712,7 +712,7 @@ fileBeginForeignScan(ForeignScanState *node, int eflags)
     * Save state in node->fdw_state.  We must save enough information to call
     * BeginCopyFrom() again.
     */
-   festate = (FileFdwExecutionState *) palloc(sizeof(FileFdwExecutionState));
+   festate = palloc_object(FileFdwExecutionState);
    festate->filename = filename;
    festate->is_program = is_program;
    festate->options = options;
index 69515dc3d3fbd80f5e558299b6dcb654e729daf7..36825ef867b4288163e0b7c2bf3b9831ef161ec3 100644 (file)
@@ -175,7 +175,7 @@ ghstore_compress(PG_FUNCTION_ARGS)
            }
        }
 
-       retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        gistentryinit(*retval, PointerGetDatum(res),
                      entry->rel, entry->page,
                      entry->offset,
@@ -195,7 +195,7 @@ ghstore_compress(PG_FUNCTION_ARGS)
 
        res = ghstore_alloc(true, siglen, NULL);
 
-       retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        gistentryinit(*retval, PointerGetDatum(res),
                      entry->rel, entry->page,
                      entry->offset,
@@ -429,7 +429,7 @@ ghstore_picksplit(PG_FUNCTION_ARGS)
 
    maxoff = OffsetNumberNext(maxoff);
    /* sort before ... */
-   costvector = (SPLITCOST *) palloc(sizeof(SPLITCOST) * maxoff);
+   costvector = palloc_array(SPLITCOST, maxoff);
    for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
    {
        costvector[j - 1].pos = j;
index 9c53877c4a582882658982297f99c347cfc0a41b..6b01f27c5a4508380322374f701d6de624c1fde2 100644 (file)
@@ -221,7 +221,7 @@ parse_hstore(HSParser *state)
    bool        escaped = false;
 
    state->plen = 16;
-   state->pairs = (Pairs *) palloc(sizeof(Pairs) * state->plen);
+   state->pairs = palloc_array(Pairs, state->plen);
    state->pcur = 0;
    state->ptr = state->begin;
    state->word = NULL;
index 2b2c3f4029ec5cb887bdc6b01439b15271483bbf..f45df86d60c3830a74cb63ff4e122dd1a5a97b6d 100644 (file)
@@ -135,7 +135,7 @@ gettoken(WORKSTATE *state, int32 *val)
 static void
 pushquery(WORKSTATE *state, int32 type, int32 val)
 {
-   NODE       *tmp = (NODE *) palloc(sizeof(NODE));
+   NODE       *tmp = palloc_object(NODE);
 
    tmp->type = type;
    tmp->val = val;
@@ -346,7 +346,7 @@ gin_bool_consistent(QUERYTYPE *query, bool *check)
     * extraction code in ginint4_queryextract.
     */
    gcv.first = items;
-   gcv.mapped_check = (bool *) palloc(sizeof(bool) * query->size);
+   gcv.mapped_check = palloc_array(bool, query->size);
    for (i = 0; i < query->size; i++)
    {
        if (items[i].type == VAL)
@@ -613,7 +613,7 @@ infix(INFIX *in, bool first)
 
        nrm.curpol = in->curpol;
        nrm.buflen = 16;
-       nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
+       nrm.cur = nrm.buf = palloc_array(char, nrm.buflen);
 
        /* get right operand */
        infix(&nrm, false);
@@ -651,7 +651,7 @@ bqarr_out(PG_FUNCTION_ARGS)
 
    nrm.curpol = GETQUERY(query) + query->size - 1;
    nrm.buflen = 32;
-   nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
+   nrm.cur = nrm.buf = palloc_array(char, nrm.buflen);
    *(nrm.cur) = '\0';
    infix(&nrm, true);
 
index b7958d8eca5fb49a3bca477a223e37ead0b9bcfe..c60616c3f772c2787fb5574d013f288ac565425c 100644 (file)
@@ -42,7 +42,7 @@ ginint4_queryextract(PG_FUNCTION_ARGS)
        /*
         * Extract all the VAL items as things we want GIN to check for.
         */
-       res = (Datum *) palloc(sizeof(Datum) * query->size);
+       res = palloc_array(Datum, query->size);
        *nentries = 0;
 
        for (i = 0; i < query->size; i++)
@@ -65,7 +65,7 @@ ginint4_queryextract(PG_FUNCTION_ARGS)
            int32      *arr;
            int32       i;
 
-           res = (Datum *) palloc(sizeof(Datum) * (*nentries));
+           res = palloc_array(Datum, *nentries);
 
            arr = ARRPTR(query);
            for (i = 0; i < *nentries; i++)
index a09b7fa812cb2683b70e6520e83939952248cb45..90cf11c01a50b9e6c3ba7a1fb13e526303295854 100644 (file)
@@ -186,7 +186,7 @@ g_int_compress(PG_FUNCTION_ARGS)
                     errmsg("input array is too big (%d maximum allowed, %d current), use gist__intbig_ops opclass instead",
                            2 * num_ranges - 1, ARRNELEMS(r))));
 
-       retval = palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        gistentryinit(*retval, PointerGetDatum(r),
                      entry->rel, entry->page, entry->offset, false);
 
@@ -276,7 +276,7 @@ g_int_compress(PG_FUNCTION_ARGS)
                     errmsg("data is too sparse, recreate index using gist__intbig_ops opclass instead")));
 
        r = resize_intArrayType(r, len);
-       retval = palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        gistentryinit(*retval, PointerGetDatum(r),
                      entry->rel, entry->page, entry->offset, false);
        PG_RETURN_POINTER(retval);
@@ -306,7 +306,7 @@ g_int_decompress(PG_FUNCTION_ARGS)
    {
        if (in != (ArrayType *) DatumGetPointer(entry->key))
        {
-           retval = palloc(sizeof(GISTENTRY));
+           retval = palloc_object(GISTENTRY);
            gistentryinit(*retval, PointerGetDatum(in),
                          entry->rel, entry->page, entry->offset, false);
            PG_RETURN_POINTER(retval);
@@ -321,7 +321,7 @@ g_int_decompress(PG_FUNCTION_ARGS)
    {                           /* not compressed value */
        if (in != (ArrayType *) DatumGetPointer(entry->key))
        {
-           retval = palloc(sizeof(GISTENTRY));
+           retval = palloc_object(GISTENTRY);
            gistentryinit(*retval, PointerGetDatum(in),
                          entry->rel, entry->page, entry->offset, false);
 
@@ -350,7 +350,7 @@ g_int_decompress(PG_FUNCTION_ARGS)
 
    if (in != (ArrayType *) DatumGetPointer(entry->key))
        pfree(in);
-   retval = palloc(sizeof(GISTENTRY));
+   retval = palloc_object(GISTENTRY);
    gistentryinit(*retval, PointerGetDatum(r),
                  entry->rel, entry->page, entry->offset, false);
 
@@ -535,7 +535,7 @@ g_int_picksplit(PG_FUNCTION_ARGS)
    /*
     * sort entries
     */
-   costvector = (SPLITCOST *) palloc(sizeof(SPLITCOST) * maxoff);
+   costvector = palloc_array(SPLITCOST, maxoff);
    for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
    {
        costvector[i - 1].pos = i;
index 9699fbf3b4fe5479b9d2f65f8bc0a631f2d7067a..0afa8a73b68274812fb4a1d47613ad1f96a0df11 100644 (file)
@@ -174,7 +174,7 @@ g_intbig_compress(PG_FUNCTION_ARGS)
            ptr++;
        }
 
-       retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        gistentryinit(*retval, PointerGetDatum(res),
                      entry->rel, entry->page,
                      entry->offset, false);
@@ -195,7 +195,7 @@ g_intbig_compress(PG_FUNCTION_ARGS)
        }
 
        res = _intbig_alloc(true, siglen, sign);
-       retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        gistentryinit(*retval, PointerGetDatum(res),
                      entry->rel, entry->page,
                      entry->offset, false);
@@ -385,7 +385,7 @@ g_intbig_picksplit(PG_FUNCTION_ARGS)
 
    maxoff = OffsetNumberNext(maxoff);
    /* sort before ... */
-   costvector = (SPLITCOST *) palloc(sizeof(SPLITCOST) * maxoff);
+   costvector = palloc_array(SPLITCOST, maxoff);
    for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
    {
        costvector[j - 1].pos = j;
index c02e2d41af108a899e44fdf4883237254bc21de7..a708d9fd82e00c292dbb82e834b2d704ec4e843a 100644 (file)
@@ -266,7 +266,7 @@ SV_to_JsonbValue(SV *in, JsonbParseState **jsonb_state, bool is_elem)
    /* Push result into 'jsonb_state' unless it is a raw scalar. */
    return *jsonb_state
        ? pushJsonbValue(jsonb_state, is_elem ? WJB_ELEM : WJB_VALUE, &out)
-       : memcpy(palloc(sizeof(JsonbValue)), &out, sizeof(JsonbValue));
+       : memcpy(palloc_object(JsonbValue), &out, sizeof(JsonbValue));
 }
 
 
index 9383615abbfa32ae230bd7da5d3b212bbcff6154..2892e88c58bc61452a4adfde71162e8b6e45a015 100644 (file)
@@ -419,7 +419,7 @@ PLyObject_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state, bool is_ele
            return PLyMapping_ToJsonbValue(obj, jsonb_state);
    }
 
-   out = palloc(sizeof(JsonbValue));
+   out = palloc_object(JsonbValue);
 
    if (obj == Py_None)
        out->type = jbvNull;
index 30d516e60bc214a54257db0e9e67b76bc7d5bfeb..ceb92a6304da283db267cf37ce97cccec962ecfa 100644 (file)
@@ -79,7 +79,7 @@ _ltree_compress(PG_FUNCTION_ARGS)
            item = NEXTVAL(item);
        }
 
-       retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        gistentryinit(*retval, PointerGetDatum(key),
                      entry->rel, entry->page,
                      entry->offset, false);
@@ -97,7 +97,7 @@ _ltree_compress(PG_FUNCTION_ARGS)
        }
 
        key = ltree_gist_alloc(true, sign, siglen, NULL, NULL);
-       retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        gistentryinit(*retval, PointerGetDatum(key),
                      entry->rel, entry->page,
                      entry->offset, false);
@@ -310,7 +310,7 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
 
    maxoff = OffsetNumberNext(maxoff);
    /* sort before ... */
-   costvector = (SPLITCOST *) palloc(sizeof(SPLITCOST) * maxoff);
+   costvector = palloc_array(SPLITCOST, maxoff);
    for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
    {
        costvector[j - 1].pos = j;
index b4a8097328d3a9141a9d246f3ea8ecb7d97b1b97..4d54ad34bb69f628532419ee548add7ed08987e3 100644 (file)
@@ -307,7 +307,7 @@ _lca(PG_FUNCTION_ARGS)
                (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
                 errmsg("array must not contain nulls")));
 
-   a = (ltree **) palloc(sizeof(ltree *) * num);
+   a = palloc_array(ltree *, num);
    while (num > 0)
    {
        num--;
index 932f69bff2d180a58239db80023c68ebeec6429f..bb7f46347221ed32912b7bba3782b65e650ab004 100644 (file)
@@ -101,7 +101,7 @@ ltree_compress(PG_FUNCTION_ARGS)
        ltree      *val = DatumGetLtreeP(entry->key);
        ltree_gist *key = ltree_gist_alloc(false, NULL, 0, val, 0);
 
-       retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        gistentryinit(*retval, PointerGetDatum(key),
                      entry->rel, entry->page,
                      entry->offset, false);
@@ -117,7 +117,7 @@ ltree_decompress(PG_FUNCTION_ARGS)
 
    if (PointerGetDatum(key) != entry->key)
    {
-       GISTENTRY  *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+       GISTENTRY  *retval = palloc_object(GISTENTRY);
 
        gistentryinit(*retval, PointerGetDatum(key),
                      entry->rel, entry->page,
@@ -318,7 +318,7 @@ ltree_picksplit(PG_FUNCTION_ARGS)
    v->spl_right = (OffsetNumber *) palloc(nbytes);
    v->spl_nleft = 0;
    v->spl_nright = 0;
-   array = (RIX *) palloc(sizeof(RIX) * (maxoff + 1));
+   array = palloc_array(RIX, maxoff + 1);
 
    /* copy the data into RIXes, and sort the RIXes */
    for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
index b54a15d6c685e6aacd11fe6670d60e8e8b1f17d3..59c4462df8061d63f2d0daa47b27321c3526e25c 100644 (file)
@@ -65,7 +65,7 @@ parse_ltree(const char *buf, struct Node *escontext)
                (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
                 errmsg("number of ltree labels (%d) exceeds the maximum allowed (%d)",
                        num + 1, LTREE_MAX_LEVELS)));
-   list = lptr = (nodeitem *) palloc(sizeof(nodeitem) * (num + 1));
+   list = lptr = palloc_array(nodeitem, num + 1);
    ptr = buf;
    while (*ptr)
    {
@@ -318,14 +318,14 @@ parse_lquery(const char *buf, struct Node *escontext)
            case LQPRS_WAITLEVEL:
                if (ISLABEL(ptr))
                {
-                   GETVAR(curqlevel) = lptr = (nodeitem *) palloc0(sizeof(nodeitem) * (numOR + 1));
+                   GETVAR(curqlevel) = lptr = palloc0_array(nodeitem, numOR + 1);
                    lptr->start = ptr;
                    state = LQPRS_WAITDELIM;
                    curqlevel->numvar = 1;
                }
                else if (t_iseq(ptr, '!'))
                {
-                   GETVAR(curqlevel) = lptr = (nodeitem *) palloc0(sizeof(nodeitem) * (numOR + 1));
+                   GETVAR(curqlevel) = lptr = palloc0_array(nodeitem, numOR + 1);
                    lptr->start = ptr + 1;
                    lptr->wlen = -1;    /* compensate for counting ! below */
                    state = LQPRS_WAITDELIM;
index e3a84db37ff8280841a6ba5dde474c45e32b14c6..c1fc77fc804c0df0df278c8da57a33dca2d6c8ab 100644 (file)
@@ -566,7 +566,7 @@ lca(PG_FUNCTION_ARGS)
    ltree     **a,
               *res;
 
-   a = (ltree **) palloc(sizeof(ltree *) * fcinfo->nargs);
+   a = palloc_array(ltree *, fcinfo->nargs);
    for (i = 0; i < fcinfo->nargs; i++)
        a[i] = PG_GETARG_LTREE_P(i);
    res = lca_inner(a, (int) fcinfo->nargs);
index ec331607793a7b287357fadf8ac3eb5831b1c000..3a2aa223c3ed5658c4e416b9603523a0f522e1a6 100644 (file)
@@ -154,7 +154,7 @@ gettoken_query(QPRS_STATE *state, int32 *val, int32 *lenval, char **strval, uint
 static bool
 pushquery(QPRS_STATE *state, int32 type, int32 val, int32 distance, int32 lenval, uint16 flag)
 {
-   NODE       *tmp = (NODE *) palloc(sizeof(NODE));
+   NODE       *tmp = palloc_object(NODE);
 
    tmp->type = type;
    tmp->val = val;
@@ -543,7 +543,7 @@ infix(INFIX *in, bool first)
        nrm.curpol = in->curpol;
        nrm.op = in->op;
        nrm.buflen = 16;
-       nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
+       nrm.cur = nrm.buf = palloc_array(char, nrm.buflen);
 
        /* get right operand */
        infix(&nrm, false);
@@ -582,7 +582,7 @@ ltxtq_out(PG_FUNCTION_ARGS)
 
    nrm.curpol = GETQUERY(query);
    nrm.buflen = 32;
-   nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
+   nrm.cur = nrm.buf = palloc_array(char, nrm.buflen);
    *(nrm.cur) = '\0';
    nrm.op = GETOPERAND(query);
    infix(&nrm, true);
@@ -615,7 +615,7 @@ ltxtq_send(PG_FUNCTION_ARGS)
 
    nrm.curpol = GETQUERY(query);
    nrm.buflen = 32;
-   nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
+   nrm.cur = nrm.buf = palloc_array(char, nrm.buflen);
    *(nrm.cur) = '\0';
    nrm.op = GETOPERAND(query);
    infix(&nrm, true);
index 990c965aa9241d21f296dd3d5a76efe27a2b534f..b7dcc8ac8a9676952ad50256d479586b4bc64f11 100644 (file)
@@ -186,7 +186,7 @@ brin_page_items(PG_FUNCTION_ARGS)
     * Initialize output functions for all indexed datatypes; simplifies
     * calling them later.
     */
-   columns = palloc(sizeof(brin_column_state *) * RelationGetDescr(indexRel)->natts);
+   columns = palloc_array(brin_column_state *, RelationGetDescr(indexRel)->natts);
    for (attno = 1; attno <= bdesc->bd_tupdesc->natts; attno++)
    {
        Oid         output;
index 2e67c9adf5aa7893e1888bf98455ad5f53f5a171..7ff6dc089342cfd018c5b9593596ec9badf80799 100644 (file)
@@ -379,7 +379,7 @@ bt_multi_page_stats(PG_FUNCTION_ARGS)
        /* Save arguments for reuse */
        mctx = MemoryContextSwitchTo(fctx->multi_call_memory_ctx);
 
-       uargs = palloc(sizeof(ua_page_stats));
+       uargs = palloc_object(ua_page_stats);
 
        uargs->relid = RelationGetRelid(rel);
        uargs->blkno = blkno;
@@ -660,7 +660,7 @@ bt_page_items_internal(PG_FUNCTION_ARGS, enum pageinspect_version ext_version)
         */
        mctx = MemoryContextSwitchTo(fctx->multi_call_memory_ctx);
 
-       uargs = palloc(sizeof(ua_page_items));
+       uargs = palloc_object(ua_page_items);
 
        uargs->page = palloc(BLCKSZ);
        memcpy(uargs->page, BufferGetPage(buffer), BLCKSZ);
@@ -752,7 +752,7 @@ bt_page_items_bytea(PG_FUNCTION_ARGS)
        fctx = SRF_FIRSTCALL_INIT();
        mctx = MemoryContextSwitchTo(fctx->multi_call_memory_ctx);
 
-       uargs = palloc(sizeof(ua_page_items));
+       uargs = palloc_object(ua_page_items);
 
        uargs->page = get_page_from_raw(raw_page);
 
index 09a90957081f1fffc2624d2f98fc1dfe4a33f7b0..f6168d8e8953c123eb105ef8042d32e804a8866c 100644 (file)
@@ -222,7 +222,7 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
                               opaq->flags,
                               (GIN_DATA | GIN_LEAF | GIN_COMPRESSED))));
 
-       inter_call_data = palloc(sizeof(gin_leafpage_items_state));
+       inter_call_data = palloc_object(gin_leafpage_items_state);
 
        /* Build a tuple descriptor for our result type */
        if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
index ca7f1f6e7410d14fb6a0be7a224de3d8df38cb6f..0e898889fa513ff817eb3b9642c80693a473b527 100644 (file)
@@ -325,7 +325,7 @@ hash_page_items(PG_FUNCTION_ARGS)
 
        page = verify_hash_page(raw_page, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
 
-       uargs = palloc(sizeof(struct user_args));
+       uargs = palloc_object(struct user_args);
 
        uargs->page = page;
 
index c13f07655c44169080c16c167c23a91015b67d5e..ca7bffdbea5fd46d4037f67faef0267438253435 100644 (file)
@@ -154,7 +154,7 @@ heap_page_items(PG_FUNCTION_ARGS)
        fctx = SRF_FIRSTCALL_INIT();
        mctx = MemoryContextSwitchTo(fctx->multi_call_memory_ctx);
 
-       inter_call_data = palloc(sizeof(heap_page_items_state));
+       inter_call_data = palloc_object(heap_page_items_state);
 
        /* Build a tuple descriptor for our result type */
        if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
@@ -553,7 +553,7 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
    }
 
    /* build set of raw flags */
-   flags = (Datum *) palloc0(sizeof(Datum) * bitcnt);
+   flags = palloc0_array(Datum, bitcnt);
 
    /* decode t_infomask */
    if ((t_infomask & HEAP_HASNULL) != 0)
index bd70b6d9d5ecc33c11f70b2e54bfaea106773460..fcdc17012da2ebce38e97915f5dcd78ad670885a 100644 (file)
@@ -95,7 +95,7 @@ overexplain_ensure_options(ExplainState *es)
 
    if (options == NULL)
    {
-       options = palloc0(sizeof(overexplain_options));
+       options = palloc0_object(overexplain_options);
        SetExplainExtensionState(es, es_extension_id, options);
    }
 
index 2e49f31c9d6a114ed04124eb2793757a0be84d53..66ff6adde9978dadf0dcbbe5a8366bca117c75f3 100644 (file)
@@ -51,7 +51,7 @@ gin_extract_value_trgm(PG_FUNCTION_ARGS)
        int32       i;
 
        *nentries = trglen;
-       entries = (Datum *) palloc(sizeof(Datum) * trglen);
+       entries = palloc_array(Datum, trglen);
 
        ptr = GETARR(trg);
        for (i = 0; i < trglen; i++)
@@ -123,7 +123,7 @@ gin_extract_query_trgm(PG_FUNCTION_ARGS)
                 * Pointers, but we just put the same value in each element.
                 */
                trglen = ARRNELEM(trg);
-               *extra_data = (Pointer *) palloc(sizeof(Pointer) * trglen);
+               *extra_data = palloc_array(Pointer, trglen);
                for (i = 0; i < trglen; i++)
                    (*extra_data)[i] = (Pointer) graph;
            }
@@ -146,7 +146,7 @@ gin_extract_query_trgm(PG_FUNCTION_ARGS)
 
    if (trglen > 0)
    {
-       entries = (Datum *) palloc(sizeof(Datum) * trglen);
+       entries = palloc_array(Datum, trglen);
        ptr = GETARR(trg);
        for (i = 0; i < trglen; i++)
        {
@@ -338,7 +338,7 @@ gin_trgm_triconsistent(PG_FUNCTION_ARGS)
                 * function, promoting all GIN_MAYBE keys to GIN_TRUE will
                 * give a conservative result.
                 */
-               boolcheck = (bool *) palloc(sizeof(bool) * nkeys);
+               boolcheck = palloc_array(bool, nkeys);
                for (i = 0; i < nkeys; i++)
                    boolcheck[i] = (check[i] != GIN_FALSE);
                if (!trigramsMatchGraph(extra_data[0], boolcheck))
index 5ba895217b0a914adc9ae2162f6bf8dac3189a4e..5c7deb103a6368cbb6ac40fe60585ab5449d908b 100644 (file)
@@ -124,7 +124,7 @@ gtrgm_compress(PG_FUNCTION_ARGS)
        text       *val = DatumGetTextPP(entry->key);
 
        res = generate_trgm(VARDATA_ANY(val), VARSIZE_ANY_EXHDR(val));
-       retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        gistentryinit(*retval, PointerGetDatum(res),
                      entry->rel, entry->page,
                      entry->offset, false);
@@ -143,7 +143,7 @@ gtrgm_compress(PG_FUNCTION_ARGS)
        }
 
        res = gtrgm_alloc(true, siglen, sign);
-       retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        gistentryinit(*retval, PointerGetDatum(res),
                      entry->rel, entry->page,
                      entry->offset, false);
@@ -163,7 +163,7 @@ gtrgm_decompress(PG_FUNCTION_ARGS)
    if (key != (text *) DatumGetPointer(entry->key))
    {
        /* need to pass back the decompressed item */
-       retval = palloc(sizeof(GISTENTRY));
+       retval = palloc_object(GISTENTRY);
        gistentryinit(*retval, PointerGetDatum(key),
                      entry->rel, entry->page, entry->offset, entry->leafkey);
        PG_RETURN_POINTER(retval);
@@ -820,7 +820,7 @@ gtrgm_picksplit(PG_FUNCTION_ARGS)
    SPLITCOST  *costvector;
 
    /* cache the sign data for each existing item */
-   cache = (CACHESIGN *) palloc(sizeof(CACHESIGN) * (maxoff + 1));
+   cache = palloc_array(CACHESIGN, maxoff + 1);
    cache_sign = palloc(siglen * (maxoff + 1));
 
    for (k = FirstOffsetNumber; k <= maxoff; k = OffsetNumberNext(k))
@@ -864,7 +864,7 @@ gtrgm_picksplit(PG_FUNCTION_ARGS)
    union_r = GETSIGN(datum_r);
 
    /* sort before ... */
-   costvector = (SPLITCOST *) palloc(sizeof(SPLITCOST) * maxoff);
+   costvector = palloc_array(SPLITCOST, maxoff);
    for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
    {
        costvector[j - 1].pos = j;
index 149f9eb259c01f62ec785720ceb08b1bc9439052..1a76794c42298d5f1711c7f0e435e68b0841a6c6 100644 (file)
@@ -791,12 +791,11 @@ getColorInfo(regex_t *regex, TrgmNFA *trgmNFA)
 
        colorInfo->expandable = true;
        colorInfo->containsNonWord = false;
-       colorInfo->wordChars = (trgm_mb_char *)
-           palloc(sizeof(trgm_mb_char) * charsCount);
+       colorInfo->wordChars = palloc_array(trgm_mb_char, charsCount);
        colorInfo->wordCharsCount = 0;
 
        /* Extract all the chars in this color */
-       chars = (pg_wchar *) palloc(sizeof(pg_wchar) * charsCount);
+       chars = palloc_array(pg_wchar, charsCount);
        pg_reg_getcharacters(regex, i, chars, charsCount);
 
        /*
@@ -1063,7 +1062,7 @@ addKey(TrgmNFA *trgmNFA, TrgmState *state, TrgmStateKey *key)
     * original NFA.
     */
    arcsCount = pg_reg_getnumoutarcs(trgmNFA->regex, key->nstate);
-   arcs = (regex_arc_t *) palloc(sizeof(regex_arc_t) * arcsCount);
+   arcs = palloc_array(regex_arc_t, arcsCount);
    pg_reg_getoutarcs(trgmNFA->regex, key->nstate, arcs, arcsCount);
 
    for (i = 0; i < arcsCount; i++)
@@ -1177,7 +1176,7 @@ addKey(TrgmNFA *trgmNFA, TrgmState *state, TrgmStateKey *key)
 static void
 addKeyToQueue(TrgmNFA *trgmNFA, TrgmStateKey *key)
 {
-   TrgmStateKey *keyCopy = (TrgmStateKey *) palloc(sizeof(TrgmStateKey));
+   TrgmStateKey *keyCopy = palloc_object(TrgmStateKey);
 
    memcpy(keyCopy, key, sizeof(TrgmStateKey));
    trgmNFA->keysQueue = lappend(trgmNFA->keysQueue, keyCopy);
@@ -1215,7 +1214,7 @@ addArcs(TrgmNFA *trgmNFA, TrgmState *state)
        TrgmStateKey *key = (TrgmStateKey *) lfirst(cell);
 
        arcsCount = pg_reg_getnumoutarcs(trgmNFA->regex, key->nstate);
-       arcs = (regex_arc_t *) palloc(sizeof(regex_arc_t) * arcsCount);
+       arcs = palloc_array(regex_arc_t, arcsCount);
        pg_reg_getoutarcs(trgmNFA->regex, key->nstate, arcs, arcsCount);
 
        for (i = 0; i < arcsCount; i++)
@@ -1311,7 +1310,7 @@ addArc(TrgmNFA *trgmNFA, TrgmState *state, TrgmStateKey *key,
    }
 
    /* Checks were successful, add new arc */
-   arc = (TrgmArc *) palloc(sizeof(TrgmArc));
+   arc = palloc_object(TrgmArc);
    arc->target = getState(trgmNFA, destKey);
    arc->ctrgm.colors[0] = key->prefix.colors[0];
    arc->ctrgm.colors[1] = key->prefix.colors[1];
@@ -1467,7 +1466,7 @@ selectColorTrigrams(TrgmNFA *trgmNFA)
    int         cnumber;
 
    /* Collect color trigrams from all arcs */
-   colorTrgms = (ColorTrgmInfo *) palloc0(sizeof(ColorTrgmInfo) * arcsCount);
+   colorTrgms = palloc0_array(ColorTrgmInfo, arcsCount);
    trgmNFA->colorTrgms = colorTrgms;
 
    i = 0;
@@ -1479,7 +1478,7 @@ selectColorTrigrams(TrgmNFA *trgmNFA)
        foreach(cell, state->arcs)
        {
            TrgmArc    *arc = (TrgmArc *) lfirst(cell);
-           TrgmArcInfo *arcInfo = (TrgmArcInfo *) palloc(sizeof(TrgmArcInfo));
+           TrgmArcInfo *arcInfo = palloc_object(TrgmArcInfo);
            ColorTrgmInfo *trgmInfo = &colorTrgms[i];
 
            arcInfo->source = state;
@@ -1964,8 +1963,7 @@ packGraph(TrgmNFA *trgmNFA, MemoryContext rcontext)
    }
 
    /* Collect array of all arcs */
-   arcs = (TrgmPackArcInfo *)
-       palloc(sizeof(TrgmPackArcInfo) * trgmNFA->arcsCount);
+   arcs = palloc_array(TrgmPackArcInfo, trgmNFA->arcsCount);
    arcIndex = 0;
    hash_seq_init(&scan_status, trgmNFA->states);
    while ((state = (TrgmState *) hash_seq_search(&scan_status)) != NULL)
@@ -2147,7 +2145,7 @@ printSourceNFA(regex_t *regex, TrgmColorInfo *colors, int ncolors)
        appendStringInfoString(&buf, ";\n");
 
        arcsCount = pg_reg_getnumoutarcs(regex, state);
-       arcs = (regex_arc_t *) palloc(sizeof(regex_arc_t) * arcsCount);
+       arcs = palloc_array(regex_arc_t, arcsCount);
        pg_reg_getoutarcs(regex, state, arcs, arcsCount);
 
        for (i = 0; i < arcsCount; i++)
index d79ef35006bfab6a4c98962715af1c3f97b576e7..7046c1b5f8e54a7b32c487702f6ea98820ad35ca 100644 (file)
@@ -741,7 +741,7 @@ collect_corrupt_items(Oid relid, bool all_visible, bool all_frozen)
     * number of entries allocated.  We'll repurpose these fields before
     * returning.
     */
-   items = palloc0(sizeof(corrupt_items));
+   items = palloc0_object(corrupt_items);
    items->next = 0;
    items->count = 64;
    items->tids = palloc(items->count * sizeof(ItemPointerData));
index 3c5e4a856a7ba9cfb7ac3b2b0c39c13f21e026b6..6945bac1306da6e471100b5cc02d7208b116b56e 100644 (file)
@@ -109,8 +109,7 @@ InitXLogReaderState(XLogRecPtr lsn)
                 errmsg("could not read WAL at LSN %X/%08X",
                        LSN_FORMAT_ARGS(lsn))));
 
-   private_data = (ReadLocalXLogPageNoWaitPrivate *)
-       palloc0(sizeof(ReadLocalXLogPageNoWaitPrivate));
+   private_data = palloc0_object(ReadLocalXLogPageNoWaitPrivate);
 
    xlogreader = XLogReaderAllocate(wal_segment_size, NULL,
                                    XL_ROUTINE(.page_read = &read_local_xlog_page_no_wait,
@@ -310,7 +309,7 @@ GetWALBlockInfo(FunctionCallInfo fcinfo, XLogReaderState *record,
            /* Construct and save block_fpi_info */
            bitcnt = pg_popcount((const char *) &blk->bimg_info,
                                 sizeof(uint8));
-           flags = (Datum *) palloc0(sizeof(Datum) * bitcnt);
+           flags = palloc0_array(Datum, bitcnt);
            if ((blk->bimg_info & BKPIMAGE_HAS_HOLE) != 0)
                flags[cnt++] = CStringGetTextDatum("HAS_HOLE");
            if (blk->apply_image)
index 8dfc1b39d48deb3bca33dcfe4bfb2f58332c14c2..6a23ad99706645af891c2b3482f4a3ef387469ee 100644 (file)
@@ -115,7 +115,7 @@ mbuf_create(int len)
    if (!len)
        len = 8192;
 
-   mbuf = palloc(sizeof *mbuf);
+   mbuf = palloc_object(MBuf);
    mbuf->data = palloc(len);
    mbuf->buf_end = mbuf->data + len;
    mbuf->data_end = mbuf->data;
@@ -132,7 +132,7 @@ mbuf_create_from_data(uint8 *data, int len)
 {
    MBuf       *mbuf;
 
-   mbuf = palloc(sizeof *mbuf);
+   mbuf = palloc_object(MBuf);
    mbuf->data = data;
    mbuf->buf_end = mbuf->data + len;
    mbuf->data_end = mbuf->data + len;
@@ -206,7 +206,7 @@ pullf_create(PullFilter **pf_p, const PullFilterOps *op, void *init_arg, PullFil
        res = 0;
    }
 
-   pf = palloc0(sizeof(*pf));
+   pf = palloc0_object(PullFilter);
    pf->buflen = res;
    pf->op = op;
    pf->priv = priv;
@@ -372,7 +372,7 @@ pushf_create(PushFilter **mp_p, const PushFilterOps *op, void *init_arg, PushFil
        res = 0;
    }
 
-   mp = palloc0(sizeof(*mp));
+   mp = palloc0_object(PushFilter);
    mp->block_size = res;
    mp->op = op;
    mp->priv = priv;
index f179e80c8429ec00bbbcd7feae298652f16f976a..d3c12e7fda36a28592154902637ab7b3b70e6df0 100644 (file)
@@ -197,7 +197,7 @@ px_find_digest(const char *name, PX_MD **res)
    ResourceOwnerRememberOSSLDigest(digest->owner, digest);
 
    /* The PX_MD object is allocated in the current memory context. */
-   h = palloc(sizeof(*h));
+   h = palloc_object(PX_MD);
    h->result_size = digest_result_size;
    h->block_size = digest_block_size;
    h->reset = digest_reset;
@@ -813,7 +813,7 @@ px_find_cipher(const char *name, PX_Cipher **res)
        od->evp_ciph = i->ciph->cipher_func();
 
    /* The PX_Cipher is allocated in current memory context */
-   c = palloc(sizeof(*c));
+   c = palloc_object(PX_Cipher);
    c->block_size = gen_ossl_block_size;
    c->key_size = gen_ossl_key_size;
    c->iv_size = gen_ossl_iv_size;
index de41e825b0ce85289b9de1763ca8900c3f1e182f..d8f1afc3aba42d98ad857708f26286495180d787 100644 (file)
@@ -67,7 +67,7 @@ pgp_cfb_create(PGP_CFB **ctx_p, int algo, const uint8 *key, int key_len,
        return res;
    }
 
-   ctx = palloc0(sizeof(*ctx));
+   ctx = palloc0_object(PGP_CFB);
    ctx->ciph = ciph;
    ctx->block_size = px_cipher_block_size(ciph);
    ctx->resync = resync;
index 961cf21e748913b66b9e35b3ecaddc39403f738c..caa80ecdb4596a79aa39436c0c7f9b4b0c686113 100644 (file)
@@ -80,7 +80,7 @@ compress_init(PushFilter *next, void *init_arg, void **priv_p)
    /*
     * init
     */
-   st = palloc0(sizeof(*st));
+   st = palloc0_object(struct ZipStat);
    st->buf_len = ZIP_OUT_BUF;
    st->stream.zalloc = z_alloc;
    st->stream.zfree = z_free;
@@ -211,7 +211,7 @@ decompress_init(void **priv_p, void *arg, PullFilter *src)
        && ctx->compress_algo != PGP_COMPR_ZIP)
        return PXE_PGP_UNSUPPORTED_COMPR;
 
-   dec = palloc0(sizeof(*dec));
+   dec = palloc0_object(struct DecomprData);
    dec->buf_len = ZIP_OUT_BUF;
    *priv_p = dec;
 
index e1ea5b3e58dcfba87cd44be7354364496ac0df2b..52ca7840c6d1e5ec276a485b1527db7841a85f4a 100644 (file)
@@ -224,7 +224,7 @@ pgp_create_pkt_reader(PullFilter **pf_p, PullFilter *src, int len,
                      int pkttype, PGP_Context *ctx)
 {
    int         res;
-   struct PktData *pkt = palloc(sizeof(*pkt));
+   struct PktData *pkt = palloc_object(struct PktData);
 
    pkt->type = pkttype;
    pkt->len = len;
@@ -448,7 +448,7 @@ mdcbuf_init(void **priv_p, void *arg, PullFilter *src)
    PGP_Context *ctx = arg;
    struct MDCBufData *st;
 
-   st = palloc0(sizeof(*st));
+   st = palloc0_object(struct MDCBufData);
    st->buflen = sizeof(st->buf);
    st->ctx = ctx;
    *priv_p = st;
index f7467c9b1cb1cd24d5abebdc142527e0d9d10d90..2c0598047062506aefeda1a835593a593f9471fd 100644 (file)
@@ -178,7 +178,7 @@ encrypt_init(PushFilter *next, void *init_arg, void **priv_p)
    if (res < 0)
        return res;
 
-   st = palloc0(sizeof(*st));
+   st = palloc0_object(struct EncStat);
    st->ciph = ciph;
 
    *priv_p = st;
@@ -240,7 +240,7 @@ pkt_stream_init(PushFilter *next, void *init_arg, void **priv_p)
 {
    struct PktStreamStat *st;
 
-   st = palloc(sizeof(*st));
+   st = palloc_object(struct PktStreamStat);
    st->final_done = 0;
    st->pkt_block = 1 << STREAM_BLOCK_SHIFT;
    *priv_p = st;
index 7c9f4c7b39b88ea812bc32331585513ee995b1ce..3e47b9364ab359f1e65b2221c2ac04b7b73abfbe 100644 (file)
@@ -782,8 +782,8 @@ parse_key_value_arrays(ArrayType *key_array, ArrayType *val_array,
                (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
                 errmsg("mismatched array dimensions")));
 
-   keys = (char **) palloc(sizeof(char *) * key_count);
-   values = (char **) palloc(sizeof(char *) * val_count);
+   keys = palloc_array(char *, key_count);
+   values = palloc_array(char *, val_count);
 
    for (i = 0; i < key_count; i++)
    {
@@ -937,7 +937,7 @@ pgp_armor_headers(PG_FUNCTION_ARGS)
        attinmeta = TupleDescGetAttInMetadata(tupdesc);
        funcctx->attinmeta = attinmeta;
 
-       state = (pgp_armor_headers_state *) palloc(sizeof(pgp_armor_headers_state));
+       state = palloc_object(pgp_armor_headers_state);
 
        res = pgp_extract_armor_headers((uint8 *) VARDATA_ANY(data),
                                        VARSIZE_ANY_EXHDR(data),
index 9a6561caf9ddedbb7cb7a22ffd18d4c26a03854a..6f1188659178bfa2cfdd9fe4028db15ce91d95d8 100644 (file)
@@ -39,7 +39,7 @@ pgp_key_alloc(PGP_PubKey **pk_p)
 {
    PGP_PubKey *pk;
 
-   pk = palloc0(sizeof(*pk));
+   pk = palloc0_object(PGP_PubKey);
    *pk_p = pk;
    return 0;
 }
index 99174d265517bebb267cbb5b9d4c5c1b2b3fbdfe..68e5cff6d6acd0096504286f321af9aaf6fe8528 100644 (file)
@@ -157,7 +157,7 @@ px_find_hmac(const char *name, PX_HMAC **res)
        return PXE_HASH_UNUSABLE_FOR_HMAC;
    }
 
-   h = palloc(sizeof(*h));
+   h = palloc_object(PX_HMAC);
    h->p.ipad = palloc(bs);
    h->p.opad = palloc(bs);
    h->md = md;
index d35ccca77746d8dba8ffc360ea8b90c90bba297c..4d668d4e4969ee592770814e16336b93fe11bb69 100644 (file)
@@ -291,7 +291,7 @@ px_find_combo(const char *name, PX_Combo **res)
 
    PX_Combo   *cx;
 
-   cx = palloc0(sizeof(*cx));
+   cx = palloc0_object(PX_Combo);
    buf = pstrdup(name);
 
    err = parse_cipher_name(buf, &s_cipher, &s_pad);
index b5de2a5e1be3fdadde32b83b66f44e1bd8df73f3..2d3a048c73ecb06f6c6854caf9425ef03d3a8e03 100644 (file)
@@ -107,7 +107,7 @@ Datum
 seg_in(PG_FUNCTION_ARGS)
 {
    char       *str = PG_GETARG_CSTRING(0);
-   SEG        *result = palloc(sizeof(SEG));
+   SEG        *result = palloc_object(SEG);
    yyscan_t    scanner;
 
    seg_scanner_init(str, &scanner);
@@ -370,7 +370,7 @@ gseg_picksplit(PG_FUNCTION_ARGS)
    /*
     * Emit segments to the left output page, and compute its bounding box.
     */
-   seg_l = (SEG *) palloc(sizeof(SEG));
+   seg_l = palloc_object(SEG);
    memcpy(seg_l, sort_items[0].data, sizeof(SEG));
    *left++ = sort_items[0].index;
    v->spl_nleft++;
@@ -388,7 +388,7 @@ gseg_picksplit(PG_FUNCTION_ARGS)
    /*
     * Likewise for the right page.
     */
-   seg_r = (SEG *) palloc(sizeof(SEG));
+   seg_r = palloc_object(SEG);
    memcpy(seg_r, sort_items[firstright].data, sizeof(SEG));
    *right++ = sort_items[firstright].index;
    v->spl_nright++;
@@ -632,7 +632,7 @@ seg_union(PG_FUNCTION_ARGS)
    SEG        *b = PG_GETARG_SEG_P(1);
    SEG        *n;
 
-   n = (SEG *) palloc(sizeof(*n));
+   n = palloc_object(SEG);
 
    /* take max of upper endpoints */
    if (a->upper > b->upper)
@@ -672,7 +672,7 @@ seg_inter(PG_FUNCTION_ARGS)
    SEG        *b = PG_GETARG_SEG_P(1);
    SEG        *n;
 
-   n = (SEG *) palloc(sizeof(*n));
+   n = palloc_object(SEG);
 
    /* take min of upper endpoints */
    if (a->upper < b->upper)
index a37d89a3f1cc0aa80be30bb66e64b1ca2531992b..978067e039147fd43a74120622bb04eb22f5b14b 100644 (file)
@@ -145,7 +145,7 @@ sepgsql_set_client_label(const char *new_label)
     */
    oldcxt = MemoryContextSwitchTo(CurTransactionContext);
 
-   plabel = palloc0(sizeof(pending_label));
+   plabel = palloc0_object(pending_label);
    plabel->subid = GetCurrentSubTransactionId();
    if (new_label)
        plabel->label = pstrdup(new_label);
index d9ccbc38bc538e9f73286ef42ba054a50f42afab..5e57971bb4dc8e44fee62404824f99a19aad19d3 100644 (file)
@@ -257,7 +257,7 @@ sepgsql_avc_compute(const char *scontext, const char *tcontext, uint16 tclass)
     */
    oldctx = MemoryContextSwitchTo(avc_mem_cxt);
 
-   cache = palloc0(sizeof(avc_cache));
+   cache = palloc0_object(avc_cache);
 
    cache->hash = hash;
    cache->scontext = pstrdup(scontext);
index 89898cad7b0d7701a225f3bbb310ccba5f583aa2..fbbd558ca1eb3942289a7421e99c304d08547de1 100644 (file)
@@ -651,7 +651,7 @@ find_plan(char *ident, EPlan **eplan, int *nplans)
    }
    else
    {
-       newp = *eplan = (EPlan *) palloc(sizeof(EPlan));
+       newp = *eplan = palloc_object(EPlan);
        (*nplans) = i = 0;
    }
 
index da702011193178b2eb5bb242141f7bf56e81c452..2b9eb90b09389f08fc100915319f215ac413c85e 100644 (file)
@@ -374,7 +374,7 @@ ssl_extension_info(PG_FUNCTION_ARGS)
        oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
 
        /* Create a user function context for cross-call persistence */
-       fctx = (SSLExtensionInfoContext *) palloc(sizeof(SSLExtensionInfoContext));
+       fctx = palloc_object(SSLExtensionInfoContext);
 
        /* Construct tuple descriptor */
        if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
index 74afdc0977f4781d50042bfaacaa698392c3031a..c40fd36dc96632d314959a75586c4a293abadc78 100644 (file)
@@ -207,7 +207,7 @@ normal_rand(PG_FUNCTION_ARGS)
        funcctx->max_calls = num_tuples;
 
        /* allocate memory for user context */
-       fctx = (normal_rand_fctx *) palloc(sizeof(normal_rand_fctx));
+       fctx = palloc_object(normal_rand_fctx);
 
        /*
         * Use fctx to keep track of upper and lower bounds from call to call.
@@ -766,7 +766,7 @@ load_categories_hash(char *cats_sql, MemoryContext per_query_ctx)
 
            SPIcontext = MemoryContextSwitchTo(per_query_ctx);
 
-           catdesc = (crosstab_cat_desc *) palloc(sizeof(crosstab_cat_desc));
+           catdesc = palloc_object(crosstab_cat_desc);
            catdesc->catname = catname;
            catdesc->attidx = i;
 
index 36e77c69e1c19471d42f3f61a054a67bda092cb4..47094f86f5fe90ddf15156eb140535a4142a37bf 100644 (file)
@@ -163,7 +163,7 @@ pg_decode_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
    TestDecodingData *data;
    bool        enable_streaming = false;
 
-   data = palloc0(sizeof(TestDecodingData));
+   data = palloc0_object(TestDecodingData);
    data->context = AllocSetContextCreate(ctx->context,
                                          "text conversion context",
                                          ALLOCSET_DEFAULT_SIZES);
index f401efa2131fc71596d839b72a94bdeef0840b57..ef145fa6747a775fece59aad09db6820281c6844 100644 (file)
@@ -163,7 +163,7 @@ system_rows_samplescangetsamplesize(PlannerInfo *root,
 static void
 system_rows_initsamplescan(SampleScanState *node, int eflags)
 {
-   node->tsm_state = palloc0(sizeof(SystemRowsSamplerData));
+   node->tsm_state = palloc0_object(SystemRowsSamplerData);
    /* Note the above leaves tsm_state->step equal to zero */
 }
 
index c9c71d8c3af39f55ec9da661a98fb60b15ad1b3a..1041258ea1a0899797efc61d2e1a1bac3f4807cc 100644 (file)
@@ -179,7 +179,7 @@ system_time_samplescangetsamplesize(PlannerInfo *root,
 static void
 system_time_initsamplescan(SampleScanState *node, int eflags)
 {
-   node->tsm_state = palloc0(sizeof(SystemTimeSamplerData));
+   node->tsm_state = palloc0_object(SystemTimeSamplerData);
    /* Note the above leaves tsm_state->step equal to zero */
 }
 
index 336ba31047a4ac83c1bde46dfc3599ec962d1860..68251660887cf50c01adab117a74a09ab019d062 100644 (file)
@@ -60,7 +60,7 @@ placeChar(TrieChar *node, const unsigned char *str, int lenstr,
    TrieChar   *curnode;
 
    if (!node)
-       node = (TrieChar *) palloc0(sizeof(TrieChar) * 256);
+       node = palloc0_array(TrieChar, 256);
 
    Assert(lenstr > 0);         /* else str[0] doesn't exist */
 
@@ -239,7 +239,7 @@ initTrie(const char *filename)
                if (trgquoted && state > 0)
                {
                    /* Ignore first and end quotes */
-                   trgstore = (char *) palloc(sizeof(char) * (trglen - 2));
+                   trgstore = palloc_array(char, trglen - 2);
                    trgstorelen = 0;
                    for (int i = 1; i < trglen - 1; i++)
                    {
@@ -252,7 +252,7 @@ initTrie(const char *filename)
                }
                else
                {
-                   trgstore = (char *) palloc(sizeof(char) * trglen);
+                   trgstore = palloc_array(char, trglen);
                    trgstorelen = trglen;
                    memcpy(trgstore, trg, trgstorelen);
                }
@@ -421,7 +421,7 @@ unaccent_lexize(PG_FUNCTION_ARGS)
    /* return a result only if we made at least one substitution */
    if (buf.data != NULL)
    {
-       res = (TSLexeme *) palloc0(sizeof(TSLexeme) * 2);
+       res = palloc0_array(TSLexeme, 2);
        res->lexeme = buf.data;
        res->flags = TSL_FILTER;
    }
index 4ac291c8251f7d0982f9f73a53a20d8672291e58..662d7d02f27b3b1d12d36756088a05bc198fb335 100644 (file)
@@ -485,8 +485,7 @@ pgxml_xpath(text *document, xmlChar *xpath, PgXmlErrorContext *xmlerrcxt)
 {
    int32       docsize = VARSIZE_ANY_EXHDR(document);
    xmlXPathCompExprPtr comppath;
-   xpath_workspace *workspace = (xpath_workspace *)
-       palloc0(sizeof(xpath_workspace));
+   xpath_workspace *workspace = palloc0_object(xpath_workspace);
 
    workspace->doctree = NULL;
    workspace->ctxt = NULL;
index 36578b82e4d2010ca6a4c88879932e0b63ee5240..2be87bec0cdf7f95d5c8bb1bfeea0764e3aad433 100644 (file)
@@ -69,7 +69,7 @@ xslt_process(PG_FUNCTION_ARGS)
    else
    {
        /* No parameters */
-       params = (const char **) palloc(sizeof(char *));
+       params = palloc_object(const char *);
        params[0] = NULL;
    }