mirror of
https://github.com/postgres/postgres.git
synced 2025-12-13 14:22:43 +03:00
Use palloc_object() and palloc_array() in more areas of the tree
The idea is to encourage more the use of these new routines across the
tree, as these offer stronger type safety guarantees than palloc().
The following paths are included in this batch, treating all the areas
proposed by the author for the most trivial changes, except src/backend
(by far the largest batch):
src/bin/
src/common/
src/fe_utils/
src/include/
src/pl/
src/test/
src/tutorial/
Similar work has been done in 31d3847a37.
The code compiles the same before and after this commit, with the
following exceptions due to changes in line numbers because some of the
new allocation formulas are shorter:
blkreftable.c
pgfnames.c
pl_exec.c
Author: David Geier <geidav.pg@gmail.com>
Discussion: https://postgr.es/m/ad0748d4-3080-436e-b0bc-ac8f86a3466a@gmail.com
This commit is contained in:
@@ -1082,8 +1082,8 @@ plperl_build_tuple_result(HV *perlhash, TupleDesc td)
|
||||
HE *he;
|
||||
HeapTuple tup;
|
||||
|
||||
values = palloc0(sizeof(Datum) * td->natts);
|
||||
nulls = palloc(sizeof(bool) * td->natts);
|
||||
values = palloc0_array(Datum, td->natts);
|
||||
nulls = palloc_array(bool, td->natts);
|
||||
memset(nulls, true, sizeof(bool) * td->natts);
|
||||
|
||||
hv_iterinit(perlhash);
|
||||
@@ -1502,7 +1502,7 @@ plperl_ref_from_pg_array(Datum arg, Oid typid)
|
||||
* Currently we make no effort to cache any of the stuff we look up here,
|
||||
* which is bad.
|
||||
*/
|
||||
info = palloc0(sizeof(plperl_array_info));
|
||||
info = palloc0_object(plperl_array_info);
|
||||
|
||||
/* get element type information, including output conversion function */
|
||||
get_type_io_data(elementtype, IOFunc_output,
|
||||
@@ -1538,7 +1538,7 @@ plperl_ref_from_pg_array(Datum arg, Oid typid)
|
||||
&nitems);
|
||||
|
||||
/* Get total number of elements in each dimension */
|
||||
info->nelems = palloc(sizeof(int) * info->ndims);
|
||||
info->nelems = palloc_array(int, info->ndims);
|
||||
info->nelems[0] = nitems;
|
||||
for (i = 1; i < info->ndims; i++)
|
||||
info->nelems[i] = info->nelems[i - 1] / dims[i - 1];
|
||||
@@ -2797,7 +2797,7 @@ compile_plperl_function(Oid fn_oid, bool is_trigger, bool is_event_trigger)
|
||||
* struct prodesc and subsidiary data must all live in proc_cxt.
|
||||
************************************************************/
|
||||
oldcontext = MemoryContextSwitchTo(proc_cxt);
|
||||
prodesc = (plperl_proc_desc *) palloc0(sizeof(plperl_proc_desc));
|
||||
prodesc = palloc0_object(plperl_proc_desc);
|
||||
prodesc->proname = pstrdup(NameStr(procStruct->proname));
|
||||
MemoryContextSetIdentifier(proc_cxt, prodesc->proname);
|
||||
prodesc->fn_cxt = proc_cxt;
|
||||
@@ -3596,7 +3596,7 @@ plperl_spi_prepare(char *query, int argc, SV **argv)
|
||||
"PL/Perl spi_prepare query",
|
||||
ALLOCSET_SMALL_SIZES);
|
||||
MemoryContextSwitchTo(plan_cxt);
|
||||
qdesc = (plperl_query_desc *) palloc0(sizeof(plperl_query_desc));
|
||||
qdesc = palloc0_object(plperl_query_desc);
|
||||
snprintf(qdesc->qname, sizeof(qdesc->qname), "%p", qdesc);
|
||||
qdesc->plan_cxt = plan_cxt;
|
||||
qdesc->nargs = argc;
|
||||
|
||||
Reference in New Issue
Block a user