88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.70 2007/03/20 05:44:59 neilc Exp $
11+ * $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.71 2007/03/28 22:59:37 neilc Exp $
1212 *
1313 *Alistair Crooks added the code for the regex caching
1414 *agc - cached the regular expressions used - there's a good chance
3030#include "postgres.h"
3131
3232#include "access/heapam.h"
33+ #include "catalog/pg_type.h"
3334#include "funcapi.h"
3435#include "regex/regex.h"
3536#include "utils/builtins.h"
@@ -95,12 +96,6 @@ typedef struct regexp_matches_ctx
9596size_t offset ;
9697
9798re_comp_flags flags ;
98-
99- /* text type info */
100- Oid param_type ;
101- int16 typlen ;
102- bool typbyval ;
103- char typalign ;
10499}regexp_matches_ctx ;
105100
106101typedef struct regexp_split_ctx
@@ -119,8 +114,7 @@ typedef struct regexp_split_ctx
119114static int num_res = 0 ;/* # of cached re's */
120115static cached_re_str re_array [MAX_CACHED_RES ];/* cached re's */
121116
122- static regexp_matches_ctx * setup_regexp_matches (FunctionCallInfo fcinfo ,
123- text * orig_str ,text * pattern ,
117+ static regexp_matches_ctx * setup_regexp_matches (text * orig_str ,text * pattern ,
124118text * flags );
125119static ArrayType * perform_regexp_matches (regexp_matches_ctx * matchctx );
126120
@@ -760,8 +754,8 @@ regexp_matches(PG_FUNCTION_ARGS)
760754oldcontext = MemoryContextSwitchTo (funcctx -> multi_call_memory_ctx );
761755
762756/* be sure to copy the input string into the multi-call ctx */
763- matchctx = setup_regexp_matches (fcinfo , PG_GETARG_TEXT_P_COPY (0 ),
764- pattern , flags );
757+ matchctx = setup_regexp_matches (PG_GETARG_TEXT_P_COPY (0 ), pattern ,
758+ flags );
765759
766760MemoryContextSwitchTo (oldcontext );
767761funcctx -> user_fctx = (void * )matchctx ;
@@ -822,7 +816,7 @@ regexp_matches_no_flags(PG_FUNCTION_ARGS)
822816}
823817
824818static regexp_matches_ctx *
825- setup_regexp_matches (FunctionCallInfo fcinfo , text * orig_str ,text * pattern ,text * flags )
819+ setup_regexp_matches (text * orig_str ,text * pattern ,text * flags )
826820{
827821regexp_matches_ctx * matchctx = palloc (sizeof (regexp_matches_ctx ));
828822
@@ -835,11 +829,6 @@ setup_regexp_matches(FunctionCallInfo fcinfo, text *orig_str, text *pattern, tex
835829matchctx -> pmatch = palloc (sizeof (regmatch_t )* (matchctx -> cpattern -> re_nsub + 1 ));
836830matchctx -> offset = 0 ;
837831
838- /* get text type oid, too lazy to do it some other way */
839- matchctx -> param_type = get_fn_expr_argtype (fcinfo -> flinfo ,0 );
840- get_typlenbyvalalign (matchctx -> param_type ,& matchctx -> typlen ,
841- & matchctx -> typbyval ,& matchctx -> typalign );
842-
843832matchctx -> wide_str = palloc (sizeof (pg_wchar )* (matchctx -> orig_len + 1 ));
844833matchctx -> wide_len = pg_mb2wchar_with_len (VARDATA (matchctx -> orig_str ),
845834matchctx -> wide_str ,matchctx -> orig_len );
@@ -915,9 +904,9 @@ perform_regexp_matches(regexp_matches_ctx *matchctx)
915904dims [0 ]= 1 ;
916905}
917906
907+ /* XXX: this hardcodes assumptions about the text type */
918908return construct_md_array (elems ,nulls ,ndims ,dims ,lbs ,
919- matchctx -> param_type ,matchctx -> typlen ,
920- matchctx -> typbyval ,matchctx -> typalign );
909+ TEXTOID ,-1 , false,'i' );
921910}
922911
923912Datum
@@ -976,16 +965,12 @@ Datum regexp_split_to_array(PG_FUNCTION_ARGS)
976965{
977966ArrayBuildState * astate = NULL ;
978967regexp_split_ctx * splitctx ;
979- Oid param_type ;
980968int nitems ;
981969
982970splitctx = setup_regexp_split (PG_GETARG_TEXT_P (0 ),
983971PG_GETARG_TEXT_P (1 ),
984972PG_GETARG_TEXT_P_IF_EXISTS (2 ));
985973
986- /* get text type oid, too lazy to do it some other way */
987- param_type = get_fn_expr_argtype (fcinfo -> flinfo ,0 );
988-
989974for (nitems = 0 ;splitctx -> offset < splitctx -> wide_len ;nitems ++ )
990975{
991976if (nitems > splitctx -> wide_len )
@@ -995,7 +980,7 @@ Datum regexp_split_to_array(PG_FUNCTION_ARGS)
995980astate = accumArrayResult (astate ,
996981get_next_split (splitctx ),
997982 false,
998- param_type ,
983+ TEXTOID ,
999984CurrentMemoryContext );
1000985}
1001986