88 *
99 *
1010 * 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 $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -689,15 +689,16 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
689689slice = (text * )DatumGetPointer (str );
690690
691691/* see if we got back an empty string */
692- if (( VARSIZE ( slice ) - VARHDRSZ )== 0 )
692+ if (VARSIZE_ANY_EXHDR ( slice )== 0 )
693693{
694694if (slice != (text * )DatumGetPointer (str ))
695695pfree (slice );
696696return PG_STR_GET_TEXT ("" );
697697}
698698
699699/* 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 ));
701702
702703/*
703704 * 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)
722723/*
723724 * Find the start position in the slice; remember S1 is not zero based
724725 */
725- p = VARDATA (slice );
726+ p = VARDATA_ANY (slice );
726727for (i = 0 ;i < S1 - 1 ;i ++ )
727728p += pg_mblen (p );
728729
@@ -762,8 +763,8 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
762763Datum
763764textpos (PG_FUNCTION_ARGS )
764765{
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 );
767768
768769PG_RETURN_INT32 ((int32 )text_position (str ,search_str ));
769770}
@@ -808,15 +809,15 @@ text_position(text *t1, text *t2)
808809static void
809810text_position_setup (text * t1 ,text * t2 ,TextPositionState * state )
810811{
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 );
813814
814815if (pg_database_encoding_max_length ()== 1 )
815816{
816817/* simple case - single byte encoding */
817818state -> 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 );
820821state -> len1 = len1 ;
821822state -> len2 = len2 ;
822823}
@@ -827,9 +828,9 @@ text_position_setup(text *t1, text *t2, TextPositionState *state)
827828* p2 ;
828829
829830p1 = (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 );
831832p2 = (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 );
833834
834835state -> use_wchar = true;
835836state -> wstr1 = p1 ;
@@ -2094,7 +2095,7 @@ byteacmp(PG_FUNCTION_ARGS)
20942095static void
20952096appendStringInfoText (StringInfo str ,const text * t )
20962097{
2097- appendBinaryStringInfo (str ,VARDATA (t ),VARSIZE (t )- VARHDRSZ );
2098+ appendBinaryStringInfo (str ,VARDATA_ANY (t ),VARSIZE_ANY_EXHDR (t ));
20982099}
20992100
21002101/*
@@ -2108,9 +2109,9 @@ appendStringInfoText(StringInfo str, const text *t)
21082109Datum
21092110replace_text (PG_FUNCTION_ARGS )
21102111{
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 );
21142115int src_text_len ;
21152116int from_sub_text_len ;
21162117TextPositionState state ;
@@ -2148,7 +2149,7 @@ replace_text(PG_FUNCTION_ARGS)
21482149}
21492150
21502151/* 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 );
21522153
21532154initStringInfo (& str );
21542155
@@ -2172,7 +2173,7 @@ replace_text(PG_FUNCTION_ARGS)
21722173while (curr_posn > 0 );
21732174
21742175/* 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 ;
21762177appendBinaryStringInfo (& str ,start_ptr ,chunk_len );
21772178
21782179text_position_cleanup (& state );
@@ -2191,8 +2192,8 @@ replace_text(PG_FUNCTION_ARGS)
21912192static bool
21922193check_replace_text_has_escape_char (const text * replace_text )
21932194{
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 );
21962197
21972198if (pg_database_encoding_max_length ()== 1 )
21982199{
@@ -2226,8 +2227,8 @@ appendStringInfoRegexpSubstr(StringInfo str, text *replace_text,
22262227regmatch_t * pmatch ,
22272228char * start_ptr ,int data_pos )
22282229{
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 );
22312232int eml = pg_database_encoding_max_length ();
22322233
22332234for (;;)
@@ -2332,7 +2333,7 @@ replace_text_regexp(text *src_text, void *regexp,
23322333{
23332334text * ret_text ;
23342335regex_t * re = (regex_t * )regexp ;
2335- int src_text_len = VARSIZE (src_text )- VARHDRSZ ;
2336+ int src_text_len = VARSIZE_ANY_EXHDR (src_text );
23362337StringInfoData buf ;
23372338regmatch_t pmatch [REGEXP_REPLACE_BACKREF_CNT ];
23382339pg_wchar * data ;
@@ -2346,13 +2347,13 @@ replace_text_regexp(text *src_text, void *regexp,
23462347
23472348/* Convert data string to wide characters. */
23482349data = (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 );
23502351
23512352/* Check whether replace_text has escape char. */
23522353have_escape = check_replace_text_has_escape_char (replace_text );
23532354
23542355/* 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 );
23562357data_pos = 0 ;
23572358
23582359search_start = 0 ;
@@ -2439,7 +2440,7 @@ replace_text_regexp(text *src_text, void *regexp,
24392440{
24402441int chunk_len ;
24412442
2442- chunk_len = ((char * )src_text + VARSIZE (src_text ))- start_ptr ;
2443+ chunk_len = ((char * )src_text + VARSIZE_ANY (src_text ))- start_ptr ;
24432444appendBinaryStringInfo (& buf ,start_ptr ,chunk_len );
24442445}
24452446
@@ -2459,8 +2460,8 @@ replace_text_regexp(text *src_text, void *regexp,
24592460Datum
24602461split_text (PG_FUNCTION_ARGS )
24612462{
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 );
24642465int fldnum = PG_GETARG_INT32 (2 );
24652466int inputstring_len ;
24662467int fldsep_len ;
@@ -2559,8 +2560,8 @@ split_text(PG_FUNCTION_ARGS)
25592560Datum
25602561text_to_array (PG_FUNCTION_ARGS )
25612562{
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 );
25642565int inputstring_len ;
25652566int fldsep_len ;
25662567TextPositionState state ;
@@ -2601,7 +2602,7 @@ text_to_array(PG_FUNCTION_ARGS)
26012602
26022603start_posn = 1 ;
26032604/* start_ptr points to the start_posn'th character of inputstring */
2604- start_ptr = ( char * ) VARDATA (inputstring );
2605+ start_ptr = VARDATA_ANY (inputstring );
26052606
26062607for (fldnum = 1 ;;fldnum ++ )/* field number is 1 based */
26072608{
@@ -2612,7 +2613,7 @@ text_to_array(PG_FUNCTION_ARGS)
26122613if (end_posn == 0 )
26132614{
26142615/* fetch last field */
2615- chunk_len = ((char * )inputstring + VARSIZE (inputstring ))- start_ptr ;
2616+ chunk_len = ((char * )inputstring + VARSIZE_ANY (inputstring ))- start_ptr ;
26162617}
26172618else
26182619{