8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
* Alistair Crooks added the code for the regex caching
14
14
* agc - cached the regular expressions used - there's a good chance
30
30
#include "postgres.h"
31
31
32
32
#include "access/heapam.h"
33
+ #include "catalog/pg_type.h"
33
34
#include "funcapi.h"
34
35
#include "regex/regex.h"
35
36
#include "utils/builtins.h"
@@ -95,12 +96,6 @@ typedef struct regexp_matches_ctx
95
96
size_t offset ;
96
97
97
98
re_comp_flags flags ;
98
-
99
- /* text type info */
100
- Oid param_type ;
101
- int16 typlen ;
102
- bool typbyval ;
103
- char typalign ;
104
99
} regexp_matches_ctx ;
105
100
106
101
typedef struct regexp_split_ctx
@@ -119,8 +114,7 @@ typedef struct regexp_split_ctx
119
114
static int num_res = 0 ; /* # of cached re's */
120
115
static cached_re_str re_array [MAX_CACHED_RES ]; /* cached re's */
121
116
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 ,
124
118
text * flags );
125
119
static ArrayType * perform_regexp_matches (regexp_matches_ctx * matchctx );
126
120
@@ -760,8 +754,8 @@ regexp_matches(PG_FUNCTION_ARGS)
760
754
oldcontext = MemoryContextSwitchTo (funcctx -> multi_call_memory_ctx );
761
755
762
756
/* 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 );
765
759
766
760
MemoryContextSwitchTo (oldcontext );
767
761
funcctx -> user_fctx = (void * ) matchctx ;
@@ -822,7 +816,7 @@ regexp_matches_no_flags(PG_FUNCTION_ARGS)
822
816
}
823
817
824
818
static 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 )
826
820
{
827
821
regexp_matches_ctx * matchctx = palloc (sizeof (regexp_matches_ctx ));
828
822
@@ -835,11 +829,6 @@ setup_regexp_matches(FunctionCallInfo fcinfo, text *orig_str, text *pattern, tex
835
829
matchctx -> pmatch = palloc (sizeof (regmatch_t ) * (matchctx -> cpattern -> re_nsub + 1 ));
836
830
matchctx -> offset = 0 ;
837
831
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
-
843
832
matchctx -> wide_str = palloc (sizeof (pg_wchar ) * (matchctx -> orig_len + 1 ));
844
833
matchctx -> wide_len = pg_mb2wchar_with_len (VARDATA (matchctx -> orig_str ),
845
834
matchctx -> wide_str , matchctx -> orig_len );
@@ -915,9 +904,9 @@ perform_regexp_matches(regexp_matches_ctx *matchctx)
915
904
dims [0 ] = 1 ;
916
905
}
917
906
907
+ /* XXX: this hardcodes assumptions about the text type */
918
908
return construct_md_array (elems , nulls , ndims , dims , lbs ,
919
- matchctx -> param_type , matchctx -> typlen ,
920
- matchctx -> typbyval , matchctx -> typalign );
909
+ TEXTOID , -1 , false, 'i' );
921
910
}
922
911
923
912
Datum
@@ -976,16 +965,12 @@ Datum regexp_split_to_array(PG_FUNCTION_ARGS)
976
965
{
977
966
ArrayBuildState * astate = NULL ;
978
967
regexp_split_ctx * splitctx ;
979
- Oid param_type ;
980
968
int nitems ;
981
969
982
970
splitctx = setup_regexp_split (PG_GETARG_TEXT_P (0 ),
983
971
PG_GETARG_TEXT_P (1 ),
984
972
PG_GETARG_TEXT_P_IF_EXISTS (2 ));
985
973
986
- /* get text type oid, too lazy to do it some other way */
987
- param_type = get_fn_expr_argtype (fcinfo -> flinfo , 0 );
988
-
989
974
for (nitems = 0 ; splitctx -> offset < splitctx -> wide_len ; nitems ++ )
990
975
{
991
976
if (nitems > splitctx -> wide_len )
@@ -995,7 +980,7 @@ Datum regexp_split_to_array(PG_FUNCTION_ARGS)
995
980
astate = accumArrayResult (astate ,
996
981
get_next_split (splitctx ),
997
982
false,
998
- param_type ,
983
+ TEXTOID ,
999
984
CurrentMemoryContext );
1000
985
}
1001
986
0 commit comments