8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.157 2007/07/19 20:34:20 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.158 2007/09/22 00:36:38 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -689,15 +689,16 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
689
689
slice = (text * ) DatumGetPointer (str );
690
690
691
691
/* see if we got back an empty string */
692
- if (( VARSIZE ( slice ) - VARHDRSZ ) == 0 )
692
+ if (VARSIZE_ANY_EXHDR ( slice ) == 0 )
693
693
{
694
694
if (slice != (text * ) DatumGetPointer (str ))
695
695
pfree (slice );
696
696
return PG_STR_GET_TEXT ("" );
697
697
}
698
698
699
699
/* Now we can get the actual length of the slice in MB characters */
700
- slice_strlen = pg_mbstrlen_with_len (VARDATA (slice ), VARSIZE (slice ) - VARHDRSZ );
700
+ slice_strlen = pg_mbstrlen_with_len (VARDATA_ANY (slice ),
701
+ VARSIZE_ANY_EXHDR (slice ));
701
702
702
703
/*
703
704
* Check that the start position wasn't > slice_strlen. If so, SQL99
@@ -722,7 +723,7 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
722
723
/*
723
724
* Find the start position in the slice; remember S1 is not zero based
724
725
*/
725
- p = VARDATA (slice );
726
+ p = VARDATA_ANY (slice );
726
727
for (i = 0 ; i < S1 - 1 ; i ++ )
727
728
p += pg_mblen (p );
728
729
@@ -762,8 +763,8 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
762
763
Datum
763
764
textpos (PG_FUNCTION_ARGS )
764
765
{
765
- text * str = PG_GETARG_TEXT_P (0 );
766
- text * search_str = PG_GETARG_TEXT_P (1 );
766
+ text * str = PG_GETARG_TEXT_PP (0 );
767
+ text * search_str = PG_GETARG_TEXT_PP (1 );
767
768
768
769
PG_RETURN_INT32 ((int32 ) text_position (str , search_str ));
769
770
}
@@ -808,15 +809,15 @@ text_position(text *t1, text *t2)
808
809
static void
809
810
text_position_setup (text * t1 , text * t2 , TextPositionState * state )
810
811
{
811
- int len1 = VARSIZE (t1 ) - VARHDRSZ ;
812
- int len2 = VARSIZE (t2 ) - VARHDRSZ ;
812
+ int len1 = VARSIZE_ANY_EXHDR (t1 );
813
+ int len2 = VARSIZE_ANY_EXHDR (t2 );
813
814
814
815
if (pg_database_encoding_max_length () == 1 )
815
816
{
816
817
/* simple case - single byte encoding */
817
818
state -> use_wchar = false;
818
- state -> str1 = VARDATA (t1 );
819
- state -> str2 = VARDATA (t2 );
819
+ state -> str1 = VARDATA_ANY (t1 );
820
+ state -> str2 = VARDATA_ANY (t2 );
820
821
state -> len1 = len1 ;
821
822
state -> len2 = len2 ;
822
823
}
@@ -827,9 +828,9 @@ text_position_setup(text *t1, text *t2, TextPositionState *state)
827
828
* p2 ;
828
829
829
830
p1 = (pg_wchar * ) palloc ((len1 + 1 ) * sizeof (pg_wchar ));
830
- len1 = pg_mb2wchar_with_len (VARDATA (t1 ), p1 , len1 );
831
+ len1 = pg_mb2wchar_with_len (VARDATA_ANY (t1 ), p1 , len1 );
831
832
p2 = (pg_wchar * ) palloc ((len2 + 1 ) * sizeof (pg_wchar ));
832
- len2 = pg_mb2wchar_with_len (VARDATA (t2 ), p2 , len2 );
833
+ len2 = pg_mb2wchar_with_len (VARDATA_ANY (t2 ), p2 , len2 );
833
834
834
835
state -> use_wchar = true;
835
836
state -> wstr1 = p1 ;
@@ -2094,7 +2095,7 @@ byteacmp(PG_FUNCTION_ARGS)
2094
2095
static void
2095
2096
appendStringInfoText (StringInfo str , const text * t )
2096
2097
{
2097
- appendBinaryStringInfo (str , VARDATA (t ), VARSIZE (t ) - VARHDRSZ );
2098
+ appendBinaryStringInfo (str , VARDATA_ANY (t ), VARSIZE_ANY_EXHDR (t ));
2098
2099
}
2099
2100
2100
2101
/*
@@ -2108,9 +2109,9 @@ appendStringInfoText(StringInfo str, const text *t)
2108
2109
Datum
2109
2110
replace_text (PG_FUNCTION_ARGS )
2110
2111
{
2111
- text * src_text = PG_GETARG_TEXT_P (0 );
2112
- text * from_sub_text = PG_GETARG_TEXT_P (1 );
2113
- text * to_sub_text = PG_GETARG_TEXT_P (2 );
2112
+ text * src_text = PG_GETARG_TEXT_PP (0 );
2113
+ text * from_sub_text = PG_GETARG_TEXT_PP (1 );
2114
+ text * to_sub_text = PG_GETARG_TEXT_PP (2 );
2114
2115
int src_text_len ;
2115
2116
int from_sub_text_len ;
2116
2117
TextPositionState state ;
@@ -2148,7 +2149,7 @@ replace_text(PG_FUNCTION_ARGS)
2148
2149
}
2149
2150
2150
2151
/* start_ptr points to the start_posn'th character of src_text */
2151
- start_ptr = ( char * ) VARDATA (src_text );
2152
+ start_ptr = VARDATA_ANY (src_text );
2152
2153
2153
2154
initStringInfo (& str );
2154
2155
@@ -2172,7 +2173,7 @@ replace_text(PG_FUNCTION_ARGS)
2172
2173
while (curr_posn > 0 );
2173
2174
2174
2175
/* copy trailing data */
2175
- chunk_len = ((char * ) src_text + VARSIZE (src_text )) - start_ptr ;
2176
+ chunk_len = ((char * ) src_text + VARSIZE_ANY (src_text )) - start_ptr ;
2176
2177
appendBinaryStringInfo (& str , start_ptr , chunk_len );
2177
2178
2178
2179
text_position_cleanup (& state );
@@ -2191,8 +2192,8 @@ replace_text(PG_FUNCTION_ARGS)
2191
2192
static bool
2192
2193
check_replace_text_has_escape_char (const text * replace_text )
2193
2194
{
2194
- const char * p = VARDATA (replace_text );
2195
- const char * p_end = p + ( VARSIZE ( replace_text ) - VARHDRSZ );
2195
+ const char * p = VARDATA_ANY (replace_text );
2196
+ const char * p_end = p + VARSIZE_ANY_EXHDR ( replace_text );
2196
2197
2197
2198
if (pg_database_encoding_max_length () == 1 )
2198
2199
{
@@ -2226,8 +2227,8 @@ appendStringInfoRegexpSubstr(StringInfo str, text *replace_text,
2226
2227
regmatch_t * pmatch ,
2227
2228
char * start_ptr , int data_pos )
2228
2229
{
2229
- const char * p = VARDATA (replace_text );
2230
- const char * p_end = p + ( VARSIZE ( replace_text ) - VARHDRSZ );
2230
+ const char * p = VARDATA_ANY (replace_text );
2231
+ const char * p_end = p + VARSIZE_ANY_EXHDR ( replace_text );
2231
2232
int eml = pg_database_encoding_max_length ();
2232
2233
2233
2234
for (;;)
@@ -2332,7 +2333,7 @@ replace_text_regexp(text *src_text, void *regexp,
2332
2333
{
2333
2334
text * ret_text ;
2334
2335
regex_t * re = (regex_t * ) regexp ;
2335
- int src_text_len = VARSIZE (src_text ) - VARHDRSZ ;
2336
+ int src_text_len = VARSIZE_ANY_EXHDR (src_text );
2336
2337
StringInfoData buf ;
2337
2338
regmatch_t pmatch [REGEXP_REPLACE_BACKREF_CNT ];
2338
2339
pg_wchar * data ;
@@ -2346,13 +2347,13 @@ replace_text_regexp(text *src_text, void *regexp,
2346
2347
2347
2348
/* Convert data string to wide characters. */
2348
2349
data = (pg_wchar * ) palloc ((src_text_len + 1 ) * sizeof (pg_wchar ));
2349
- data_len = pg_mb2wchar_with_len (VARDATA (src_text ), data , src_text_len );
2350
+ data_len = pg_mb2wchar_with_len (VARDATA_ANY (src_text ), data , src_text_len );
2350
2351
2351
2352
/* Check whether replace_text has escape char. */
2352
2353
have_escape = check_replace_text_has_escape_char (replace_text );
2353
2354
2354
2355
/* start_ptr points to the data_pos'th character of src_text */
2355
- start_ptr = (char * ) VARDATA (src_text );
2356
+ start_ptr = (char * ) VARDATA_ANY (src_text );
2356
2357
data_pos = 0 ;
2357
2358
2358
2359
search_start = 0 ;
@@ -2439,7 +2440,7 @@ replace_text_regexp(text *src_text, void *regexp,
2439
2440
{
2440
2441
int chunk_len ;
2441
2442
2442
- chunk_len = ((char * ) src_text + VARSIZE (src_text )) - start_ptr ;
2443
+ chunk_len = ((char * ) src_text + VARSIZE_ANY (src_text )) - start_ptr ;
2443
2444
appendBinaryStringInfo (& buf , start_ptr , chunk_len );
2444
2445
}
2445
2446
@@ -2459,8 +2460,8 @@ replace_text_regexp(text *src_text, void *regexp,
2459
2460
Datum
2460
2461
split_text (PG_FUNCTION_ARGS )
2461
2462
{
2462
- text * inputstring = PG_GETARG_TEXT_P (0 );
2463
- text * fldsep = PG_GETARG_TEXT_P (1 );
2463
+ text * inputstring = PG_GETARG_TEXT_PP (0 );
2464
+ text * fldsep = PG_GETARG_TEXT_PP (1 );
2464
2465
int fldnum = PG_GETARG_INT32 (2 );
2465
2466
int inputstring_len ;
2466
2467
int fldsep_len ;
@@ -2559,8 +2560,8 @@ split_text(PG_FUNCTION_ARGS)
2559
2560
Datum
2560
2561
text_to_array (PG_FUNCTION_ARGS )
2561
2562
{
2562
- text * inputstring = PG_GETARG_TEXT_P (0 );
2563
- text * fldsep = PG_GETARG_TEXT_P (1 );
2563
+ text * inputstring = PG_GETARG_TEXT_PP (0 );
2564
+ text * fldsep = PG_GETARG_TEXT_PP (1 );
2564
2565
int inputstring_len ;
2565
2566
int fldsep_len ;
2566
2567
TextPositionState state ;
@@ -2601,7 +2602,7 @@ text_to_array(PG_FUNCTION_ARGS)
2601
2602
2602
2603
start_posn = 1 ;
2603
2604
/* start_ptr points to the start_posn'th character of inputstring */
2604
- start_ptr = ( char * ) VARDATA (inputstring );
2605
+ start_ptr = VARDATA_ANY (inputstring );
2605
2606
2606
2607
for (fldnum = 1 ;; fldnum ++ ) /* field number is 1 based */
2607
2608
{
@@ -2612,7 +2613,7 @@ text_to_array(PG_FUNCTION_ARGS)
2612
2613
if (end_posn == 0 )
2613
2614
{
2614
2615
/* fetch last field */
2615
- chunk_len = ((char * ) inputstring + VARSIZE (inputstring )) - start_ptr ;
2616
+ chunk_len = ((char * ) inputstring + VARSIZE_ANY (inputstring )) - start_ptr ;
2616
2617
}
2617
2618
else
2618
2619
{
0 commit comments