Skip to content

Commit 3ed2005

Browse files
committed
Introduce macros for typalign and typstorage constants.
Our usual practice for "poor man's enum" catalog columns is to define macros for the possible values and use those, not literal constants, in C code. But for some reason lost in the mists of time, this was never done for typalign/attalign or typstorage/attstorage. It's never too late to make it better though, so let's do that. The reason I got interested in this right now is the need to duplicate some uses of the TYPSTORAGE constants in an upcoming ALTER TYPE patch. But in general, this sort of change aids greppability and readability, so it's a good idea even without any specific motivation. I may have missed a few places that could be converted, and it's even more likely that pending patches will re-introduce some hard-coded references. But that's not fatal --- there's no expectation that we'd actually change any of these values. We can clean up stragglers over time. Discussion: https://postgr.es/m/16457.1583189537@sss.pgh.pa.us
1 parent 0ad6f84 commit 3ed2005

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+341
-309
lines changed

contrib/hstore/hstore_gin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ gin_extract_hstore_query(PG_FUNCTION_ARGS)
119119
text *item;
120120

121121
deconstruct_array(query,
122-
TEXTOID, -1, false, 'i',
122+
TEXTOID, -1, false, TYPALIGN_INT,
123123
&key_datums, &key_nulls, &key_count);
124124

125125
entries = (Datum *) palloc(sizeof(Datum) * key_count);

contrib/hstore/hstore_gist.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ ghstore_consistent(PG_FUNCTION_ARGS)
555555
int i;
556556

557557
deconstruct_array(query,
558-
TEXTOID, -1, false, 'i',
558+
TEXTOID, -1, false, TYPALIGN_INT,
559559
&key_datums, &key_nulls, &key_count);
560560

561561
for (i = 0; res && i < key_count; ++i)
@@ -578,7 +578,7 @@ ghstore_consistent(PG_FUNCTION_ARGS)
578578
int i;
579579

580580
deconstruct_array(query,
581-
TEXTOID, -1, false, 'i',
581+
TEXTOID, -1, false, TYPALIGN_INT,
582582
&key_datums, &key_nulls, &key_count);
583583

584584
res = false;

contrib/hstore/hstore_io.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ hstore_from_arrays(PG_FUNCTION_ARGS)
560560
errmsg("wrong number of array subscripts")));
561561

562562
deconstruct_array(key_array,
563-
TEXTOID, -1, false, 'i',
563+
TEXTOID, -1, false, TYPALIGN_INT,
564564
&key_datums, &key_nulls, &key_count);
565565

566566
/* see discussion in hstoreArrayToPairs() */
@@ -599,7 +599,7 @@ hstore_from_arrays(PG_FUNCTION_ARGS)
599599
errmsg("arrays must have same bounds")));
600600

601601
deconstruct_array(value_array,
602-
TEXTOID, -1, false, 'i',
602+
TEXTOID, -1, false, TYPALIGN_INT,
603603
&value_datums, &value_nulls, &value_count);
604604

605605
Assert(key_count == value_count);
@@ -689,7 +689,7 @@ hstore_from_array(PG_FUNCTION_ARGS)
689689
}
690690

691691
deconstruct_array(in_array,
692-
TEXTOID, -1, false, 'i',
692+
TEXTOID, -1, false, TYPALIGN_INT,
693693
&in_datums, &in_nulls, &in_count);
694694

695695
count = in_count / 2;

contrib/hstore/hstore_op.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ hstoreArrayToPairs(ArrayType *a, int *npairs)
8181
j;
8282

8383
deconstruct_array(a,
84-
TEXTOID, -1, false, 'i',
84+
TEXTOID, -1, false, TYPALIGN_INT,
8585
&key_datums, &key_nulls, &key_count);
8686

8787
if (key_count == 0)
@@ -583,7 +583,7 @@ hstore_slice_to_array(PG_FUNCTION_ARGS)
583583
int i;
584584

585585
deconstruct_array(key_array,
586-
TEXTOID, -1, false, 'i',
586+
TEXTOID, -1, false, TYPALIGN_INT,
587587
&key_datums, &key_nulls, &key_count);
588588

589589
if (key_count == 0)
@@ -623,7 +623,7 @@ hstore_slice_to_array(PG_FUNCTION_ARGS)
623623
ARR_NDIM(key_array),
624624
ARR_DIMS(key_array),
625625
ARR_LBOUND(key_array),
626-
TEXTOID, -1, false, 'i');
626+
TEXTOID, -1, false, TYPALIGN_INT);
627627

628628
PG_RETURN_POINTER(aout);
629629
}
@@ -720,7 +720,7 @@ hstore_akeys(PG_FUNCTION_ARGS)
720720
}
721721

722722
a = construct_array(d, count,
723-
TEXTOID, -1, false, 'i');
723+
TEXTOID, -1, false, TYPALIGN_INT);
724724

725725
PG_RETURN_POINTER(a);
726726
}
@@ -767,7 +767,7 @@ hstore_avals(PG_FUNCTION_ARGS)
767767
}
768768

769769
a = construct_md_array(d, nulls, 1, &count, &lb,
770-
TEXTOID, -1, false, 'i');
770+
TEXTOID, -1, false, TYPALIGN_INT);
771771

772772
PG_RETURN_POINTER(a);
773773
}
@@ -819,7 +819,7 @@ hstore_to_array_internal(HStore *hs, int ndims)
819819

820820
return construct_md_array(out_datums, out_nulls,
821821
ndims, out_size, lb,
822-
TEXTOID, -1, false, 'i');
822+
TEXTOID, -1, false, TYPALIGN_INT);
823823
}
824824

825825
PG_FUNCTION_INFO_V1(hstore_to_array);

contrib/pageinspect/btreefuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ bt_page_print_tuples(FuncCallContext *fctx, struct user_args *uargs)
385385
nposting,
386386
TIDOID,
387387
sizeof(ItemPointerData),
388-
false, 's'));
388+
false, TYPALIGN_SHORT));
389389
pfree(tids_datum);
390390
}
391391
else

contrib/pageinspect/ginfuncs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ gin_page_opaque_info(PG_FUNCTION_ARGS)
144144
values[0] = Int64GetDatum(opaq->rightlink);
145145
values[1] = Int32GetDatum(opaq->maxoff);
146146
values[2] = PointerGetDatum(construct_array(flags, nflags,
147-
TEXTOID, -1, false, 'i'));
147+
TEXTOID,
148+
-1, false, TYPALIGN_INT));
148149

149150
/* Build and return the result tuple. */
150151
resultTuple = heap_form_tuple(tupdesc, values, nulls);
@@ -247,7 +248,7 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
247248
ndecoded,
248249
TIDOID,
249250
sizeof(ItemPointerData),
250-
false, 's'));
251+
false, TYPALIGN_SHORT));
251252
pfree(tids_datum);
252253
pfree(tids);
253254

contrib/pageinspect/hashfuncs.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,14 +560,18 @@ hash_metapage_info(PG_FUNCTION_ARGS)
560560
values[j++] = PointerGetDatum(construct_array(spares,
561561
HASH_MAX_SPLITPOINTS,
562562
INT8OID,
563-
8, FLOAT8PASSBYVAL, 'd'));
563+
sizeof(int64),
564+
FLOAT8PASSBYVAL,
565+
TYPALIGN_DOUBLE));
564566

565567
for (i = 0; i < HASH_MAX_BITMAPS; i++)
566568
mapp[i] = Int64GetDatum((int64) metad->hashm_mapp[i]);
567569
values[j++] = PointerGetDatum(construct_array(mapp,
568570
HASH_MAX_BITMAPS,
569571
INT8OID,
570-
8, FLOAT8PASSBYVAL, 'd'));
572+
sizeof(int64),
573+
FLOAT8PASSBYVAL,
574+
TYPALIGN_DOUBLE));
571575

572576
tuple = heap_form_tuple(tupleDesc, values, nulls);
573577

contrib/pageinspect/heapfuncs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
589589

590590
/* build value */
591591
Assert(cnt <= bitcnt);
592-
a = construct_array(flags, cnt, TEXTOID, -1, false, 'i');
592+
a = construct_array(flags, cnt, TEXTOID, -1, false, TYPALIGN_INT);
593593
values[0] = PointerGetDatum(a);
594594

595595
/*
@@ -611,7 +611,7 @@ heap_tuple_infomask_flags(PG_FUNCTION_ARGS)
611611
if (cnt == 0)
612612
a = construct_empty_array(TEXTOID);
613613
else
614-
a = construct_array(flags, cnt, TEXTOID, -1, false, 'i');
614+
a = construct_array(flags, cnt, TEXTOID, -1, false, TYPALIGN_INT);
615615
pfree(flags);
616616
values[1] = PointerGetDatum(a);
617617

contrib/pg_trgm/trgm_op.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ show_trgm(PG_FUNCTION_ARGS)
980980
TEXTOID,
981981
-1,
982982
false,
983-
'i');
983+
TYPALIGN_INT);
984984

985985
for (i = 0; i < ARRNELEM(trg); i++)
986986
pfree(DatumGetPointer(d[i]));

contrib/pgcrypto/pgp-pgsql.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,11 +787,11 @@ parse_key_value_arrays(ArrayType *key_array, ArrayType *val_array,
787787
return 0;
788788

789789
deconstruct_array(key_array,
790-
TEXTOID, -1, false, 'i',
790+
TEXTOID, -1, false, TYPALIGN_INT,
791791
&key_datums, &key_nulls, &key_count);
792792

793793
deconstruct_array(val_array,
794-
TEXTOID, -1, false, 'i',
794+
TEXTOID, -1, false, TYPALIGN_INT,
795795
&val_datums, &val_nulls, &val_count);
796796

797797
if (key_count != val_count)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy