> Jeremy Drake wrote:
> > On Thu, 22 Mar 2007, Tom Lane wrote:
> >
> > > I'd vote for making this new code look like the rest of it, to wit
> > > hardwire the values.
> >
> > Attached please find a patch which does this.

I just realized that the last patch removed all usage of fcinfo in the
setup_regexp_matches function, so this version of the patch also removes
it as a parameter to that function.

-- 
Think of it!  With VLSI we can pack 100 ENIACs in 1 sq. cm.!
Index: src/backend/utils/adt/regexp.c
===================================================================
RCS file: 
/home/jeremyd/local/postgres/cvsuproot/pgsql/src/backend/utils/adt/regexp.c,v
retrieving revision 1.70
diff -c -r1.70 regexp.c
*** src/backend/utils/adt/regexp.c      20 Mar 2007 05:44:59 -0000      1.70
--- src/backend/utils/adt/regexp.c      28 Mar 2007 18:57:28 -0000
***************
*** 30,35 ****
--- 30,36 ----
  #include "postgres.h"
  
  #include "access/heapam.h"
+ #include "catalog/pg_type.h"
  #include "funcapi.h"
  #include "regex/regex.h"
  #include "utils/builtins.h"
***************
*** 95,106 ****
        size_t            offset;
  
        re_comp_flags flags;
- 
-       /* text type info */
-       Oid                       param_type;
-       int16             typlen;
-       bool              typbyval;
-       char              typalign;
  } regexp_matches_ctx;
  
  typedef struct regexp_split_ctx
--- 96,101 ----
***************
*** 119,126 ****
  static int    num_res = 0;            /* # of cached re's */
  static cached_re_str re_array[MAX_CACHED_RES];        /* cached re's */
  
! static regexp_matches_ctx *setup_regexp_matches(FunctionCallInfo fcinfo,
!                                                                               
                text *orig_str, text *pattern,
                                                                                
                text *flags);
  static ArrayType *perform_regexp_matches(regexp_matches_ctx *matchctx);
  
--- 114,120 ----
  static int    num_res = 0;            /* # of cached re's */
  static cached_re_str re_array[MAX_CACHED_RES];        /* cached re's */
  
! static regexp_matches_ctx *setup_regexp_matches(text *orig_str, text *pattern,
                                                                                
                text *flags);
  static ArrayType *perform_regexp_matches(regexp_matches_ctx *matchctx);
  
***************
*** 760,767 ****
                oldcontext = 
MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
  
                /* be sure to copy the input string into the multi-call ctx */
!               matchctx = setup_regexp_matches(fcinfo, 
PG_GETARG_TEXT_P_COPY(0),
!                                                                               
pattern, flags);
  
                MemoryContextSwitchTo(oldcontext);
                funcctx->user_fctx = (void *) matchctx;
--- 754,761 ----
                oldcontext = 
MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
  
                /* be sure to copy the input string into the multi-call ctx */
!               matchctx = setup_regexp_matches(PG_GETARG_TEXT_P_COPY(0), 
pattern,
!                                                                               
flags);
  
                MemoryContextSwitchTo(oldcontext);
                funcctx->user_fctx = (void *) matchctx;
***************
*** 822,828 ****
  }
  
  static regexp_matches_ctx *
! setup_regexp_matches(FunctionCallInfo fcinfo, text *orig_str, text *pattern, 
text *flags)
  {
        regexp_matches_ctx      *matchctx = palloc(sizeof(regexp_matches_ctx));
  
--- 816,822 ----
  }
  
  static regexp_matches_ctx *
! setup_regexp_matches(text *orig_str, text *pattern, text *flags)
  {
        regexp_matches_ctx      *matchctx = palloc(sizeof(regexp_matches_ctx));
  
***************
*** 835,845 ****
        matchctx->pmatch = palloc(sizeof(regmatch_t) * 
(matchctx->cpattern->re_nsub + 1));
        matchctx->offset = 0;
  
-       /* get text type oid, too lazy to do it some other way */
-       matchctx->param_type = get_fn_expr_argtype(fcinfo->flinfo, 0);
-       get_typlenbyvalalign(matchctx->param_type, &matchctx->typlen,
-                                                &matchctx->typbyval, 
&matchctx->typalign);
- 
        matchctx->wide_str = palloc(sizeof(pg_wchar) * (matchctx->orig_len + 
1));
        matchctx->wide_len = pg_mb2wchar_with_len(VARDATA(matchctx->orig_str),
                                                                                
          matchctx->wide_str, matchctx->orig_len);
--- 829,834 ----
***************
*** 915,923 ****
                dims[0] = 1;
        }
  
        return construct_md_array(elems, nulls, ndims, dims, lbs,
!                                                         matchctx->param_type, 
matchctx->typlen,
!                                                         matchctx->typbyval, 
matchctx->typalign);
  }
  
  Datum
--- 904,912 ----
                dims[0] = 1;
        }
  
+       /* XXX: this hardcodes assumptions about the text type */
        return construct_md_array(elems, nulls, ndims, dims, lbs,
!                                                         TEXTOID, -1, false, 
'i');
  }
  
  Datum
***************
*** 976,991 ****
  {
        ArrayBuildState         *astate = NULL;
        regexp_split_ctx        *splitctx;
-       Oid                              param_type;
        int                              nitems;
  
        splitctx = setup_regexp_split(PG_GETARG_TEXT_P(0),
                                                                  
PG_GETARG_TEXT_P(1),
                                                                  
PG_GETARG_TEXT_P_IF_EXISTS(2));
  
-       /* get text type oid, too lazy to do it some other way */
-       param_type = get_fn_expr_argtype(fcinfo->flinfo, 0);
- 
        for (nitems = 0; splitctx->offset < splitctx->wide_len; nitems++)
        {
                if (nitems > splitctx->wide_len)
--- 965,976 ----
***************
*** 995,1001 ****
                astate = accumArrayResult(astate,
                                                                  
get_next_split(splitctx),
                                                                  false,
!                                                                 param_type,
                                                                  
CurrentMemoryContext);
        }
  
--- 980,986 ----
                astate = accumArrayResult(astate,
                                                                  
get_next_split(splitctx),
                                                                  false,
!                                                                 TEXTOID,
                                                                  
CurrentMemoryContext);
        }
  
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to [EMAIL PROTECTED] so that your
       message can get through to the mailing list cleanly

Reply via email to