Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8ecac94

Browse files
committed
Functions on 'text' type updated to new fmgr style. 'text' is
now TOAST-able.
1 parent40f6406 commit8ecac94

File tree

20 files changed

+750
-687
lines changed

20 files changed

+750
-687
lines changed

‎src/backend/utils/adt/cash.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* workings can be found in the book "Software Solutions in C" by
1010
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
1111
*
12-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.41 2000/07/03 23:09:50 wieck Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.42 2000/07/06 05:48:11 tgl Exp $
1313
*/
1414

1515
#include<limits.h>
@@ -41,7 +41,7 @@ static struct lconv *lconvert = NULL;
4141
* Cash is a pass-by-ref SQL type, so we must pass and return pointers.
4242
* These macros and support routine hide the pass-by-refness.
4343
*/
44-
#definePG_GETARG_CASH(n) (* ((Cash *)DatumGetPointer(fcinfo->arg[n])))
44+
#definePG_GETARG_CASH(n) (* ((Cash *)PG_GETARG_POINTER(n)))
4545
#definePG_RETURN_CASH(x) return CashGetDatum(x)
4646

4747
staticDatum
@@ -677,10 +677,11 @@ cashsmaller(Cash *c1, Cash *c2)
677677
* This converts a int4 as well but to a representation using words
678678
* Obviously way North American centric - sorry
679679
*/
680-
text*
681-
cash_words_out(Cash*value)
680+
Datum
681+
cash_words_out(PG_FUNCTION_ARGS)
682682
{
683-
staticcharbuf[128];
683+
Cashvalue=PG_GETARG_CASH(0);
684+
charbuf[128];
684685
char*p=buf;
685686
Cashm0;
686687
Cashm1;
@@ -689,19 +690,19 @@ cash_words_out(Cash *value)
689690
text*result;
690691

691692
/* work with positive numbers */
692-
if (*value<0)
693+
if (value<0)
693694
{
694-
*value*=-1;
695+
value=-value;
695696
strcpy(buf,"minus ");
696697
p+=6;
697698
}
698699
else
699-
*buf=0;
700+
buf[0]='\0';
700701

701-
m0=*value %100;/* cents */
702-
m1= (*value /100) %1000;/* hundreds */
703-
m2= (*value /100000) %1000;/* thousands */
704-
m3=*value /100000000 %1000;/* millions */
702+
m0=value %100;/* cents */
703+
m1= (value /100) %1000;/* hundreds */
704+
m2= (value /100000) %1000;/* thousands */
705+
m3=value /100000000 %1000;/* millions */
705706

706707
if (m3)
707708
{
@@ -721,20 +722,20 @@ cash_words_out(Cash *value)
721722
if (!*p)
722723
strcat(buf,"zero");
723724

724-
strcat(buf, (int) (*value /100)==1 ?" dollar and " :" dollars and ");
725+
strcat(buf, (int) (value /100)==1 ?" dollar and " :" dollars and ");
725726
strcat(buf,num_word(m0));
726727
strcat(buf,m0==1 ?" cent" :" cents");
727728

728729
/* capitalize output */
729-
*buf=toupper(*buf);
730+
buf[0]=toupper(buf[0]);
730731

731732
/* make a text type for output */
732733
result= (text*)palloc(strlen(buf)+VARHDRSZ);
733734
VARATT_SIZEP(result)=strlen(buf)+VARHDRSZ;
734735
memcpy(VARDATA(result),buf,strlen(buf));
735736

736-
returnresult;
737-
}/* cash_words_out() */
737+
PG_RETURN_TEXT_P(result);
738+
}
738739

739740

740741
/*************************************************************************

‎src/backend/utils/adt/float.c

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.62 2000/07/03 23:09:50 wieck Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.63 2000/07/06 05:48:11 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -941,91 +941,99 @@ i2tof(PG_FUNCTION_ARGS)
941941
/*
942942
*float8_text- converts a float8 number to a text string
943943
*/
944-
text*
945-
float8_text(float64num)
944+
Datum
945+
float8_text(PG_FUNCTION_ARGS)
946946
{
947+
float8num=PG_GETARG_FLOAT8(0);
947948
text*result;
948949
intlen;
949950
char*str;
950951

951-
str=float8out(num);
952-
len=(strlen(str)+VARHDRSZ);
952+
str=float8out(&num);/* XXX temporary hack */
953+
len=strlen(str)+VARHDRSZ;
953954

954-
result=palloc(len);
955+
result=(text*)palloc(len);
955956

956957
VARATT_SIZEP(result)=len;
957-
memmove(VARDATA(result),str, (len-VARHDRSZ));
958+
memcpy(VARDATA(result),str, (len-VARHDRSZ));
958959

959960
pfree(str);
960-
returnresult;
961-
}/* float8_text() */
961+
962+
PG_RETURN_TEXT_P(result);
963+
}
962964

963965

964966
/*
965967
*text_float8- converts a text string to a float8 number
966968
*/
967-
float64
968-
text_float8(text*string)
969+
Datum
970+
text_float8(PG_FUNCTION_ARGS)
969971
{
972+
text*string=PG_GETARG_TEXT_P(0);
970973
float64result;
971974
intlen;
972975
char*str;
973976

974977
len= (VARSIZE(string)-VARHDRSZ);
975978
str=palloc(len+1);
976-
memmove(str,VARDATA(string),len);
979+
memcpy(str,VARDATA(string),len);
977980
*(str+len)='\0';
978981

979982
result=float8in(str);
983+
980984
pfree(str);
981985

982-
returnresult;
983-
}/* text_float8() */
986+
returnPointerGetDatum(result);
987+
}
984988

985989

986990
/*
987991
*float4_text- converts a float4 number to a text string
988992
*/
989-
text*
990-
float4_text(float32num)
993+
Datum
994+
float4_text(PG_FUNCTION_ARGS)
991995
{
996+
float4num=PG_GETARG_FLOAT4(0);
992997
text*result;
993998
intlen;
994999
char*str;
9951000

996-
str=float4out(num);
997-
len=(strlen(str)+VARHDRSZ);
1001+
str=float4out(&num);/* XXX temporary hack */
1002+
len=strlen(str)+VARHDRSZ;
9981003

999-
result=palloc(len);
1004+
result=(text*)palloc(len);
10001005

10011006
VARATT_SIZEP(result)=len;
1002-
memmove(VARDATA(result),str, (len-VARHDRSZ));
1007+
memcpy(VARDATA(result),str, (len-VARHDRSZ));
10031008

10041009
pfree(str);
1005-
returnresult;
1006-
}/* float4_text() */
1010+
1011+
PG_RETURN_TEXT_P(result);
1012+
}
10071013

10081014

10091015
/*
10101016
*text_float4- converts a text string to a float4 number
10111017
*/
1012-
float32
1013-
text_float4(text*string)
1018+
Datum
1019+
text_float4(PG_FUNCTION_ARGS)
10141020
{
1021+
text*string=PG_GETARG_TEXT_P(0);
10151022
float32result;
10161023
intlen;
10171024
char*str;
10181025

10191026
len= (VARSIZE(string)-VARHDRSZ);
10201027
str=palloc(len+1);
1021-
memmove(str,VARDATA(string),len);
1028+
memcpy(str,VARDATA(string),len);
10221029
*(str+len)='\0';
10231030

10241031
result=float4in(str);
1032+
10251033
pfree(str);
10261034

1027-
returnresult;
1028-
}/* text_float4() */
1035+
returnPointerGetDatum(result);
1036+
}
10291037

10301038

10311039
/*

‎src/backend/utils/adt/like.c

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
1313
* IDENTIFICATION
14-
*$Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.35 2000/06/14 18:59:42 momjian Exp $
14+
*$Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.36 2000/07/06 05:48:11 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
1818
#include"postgres.h"
19+
1920
#include"mb/pg_wchar.h"
2021
#include"utils/builtins.h"
2122

22-
staticintlike(pg_wchar*text,pg_wchar*p);
23+
staticboollike(pg_wchar*text,pg_wchar*p);
2324

2425
/*
2526
*interface routines called by the function manager
@@ -30,20 +31,17 @@ static intlike(pg_wchar * text, pg_wchar * p);
3031
3132
a generic fixed length like routine
3233
s- the string to match against (not necessarily null-terminated)
33-
p - the pattern
34+
p - the pattern (as text*)
3435
charlen - the length of the string
3536
*/
3637
staticbool
37-
fixedlen_like(char*s,structvarlena*p,intcharlen)
38+
fixedlen_like(char*s,text*p,intcharlen)
3839
{
3940
pg_wchar*sterm,
4041
*pterm;
41-
intresult;
42+
boolresult;
4243
intlen;
4344

44-
if (!s|| !p)
45-
return FALSE;
46-
4745
/* be sure sterm is null-terminated */
4846
#ifdefMULTIBYTE
4947
sterm= (pg_wchar*)palloc((charlen+1)*sizeof(pg_wchar));
@@ -54,7 +52,7 @@ fixedlen_like(char *s, struct varlena * p, int charlen)
5452
#endif
5553

5654
/*
57-
* p is a text = varlena, not a string so we have to make a string
55+
* p is a text, not a string so we have to make a string
5856
* from the vl_data field of the struct.
5957
*/
6058

@@ -65,8 +63,8 @@ fixedlen_like(char *s, struct varlena * p, int charlen)
6563
(void)pg_mb2wchar_with_len((unsignedchar*)VARDATA(p),pterm,len);
6664
#else
6765
pterm= (char*)palloc(len+1);
68-
memmove(pterm,VARDATA(p),len);
69-
*(pterm+len)=(char)NULL;
66+
memcpy(pterm,VARDATA(p),len);
67+
*(pterm+len)='\0';
7068
#endif
7169

7270
/* do the regexp matching */
@@ -75,35 +73,43 @@ fixedlen_like(char *s, struct varlena * p, int charlen)
7573
pfree(sterm);
7674
pfree(pterm);
7775

78-
return(bool)result;
76+
returnresult;
7977
}
8078

81-
bool
82-
namelike(NameData*n,structvarlena*p)
79+
Datum
80+
namelike(PG_FUNCTION_ARGS)
8381
{
84-
if (!n)
85-
return FALSE;
86-
returnfixedlen_like(NameStr(*n),p,NAMEDATALEN);
82+
Namen=PG_GETARG_NAME(0);
83+
text*p=PG_GETARG_TEXT_P(1);
84+
85+
PG_RETURN_BOOL(fixedlen_like(NameStr(*n),p,strlen(NameStr(*n))));
8786
}
8887

89-
bool
90-
namenlike(NameData*s,structvarlena*p)
88+
Datum
89+
namenlike(PG_FUNCTION_ARGS)
9190
{
92-
return !namelike(s,p);
91+
Namen=PG_GETARG_NAME(0);
92+
text*p=PG_GETARG_TEXT_P(1);
93+
94+
PG_RETURN_BOOL(!fixedlen_like(NameStr(*n),p,strlen(NameStr(*n))));
9395
}
9496

95-
bool
96-
textlike(structvarlena*s,structvarlena*p)
97+
Datum
98+
textlike(PG_FUNCTION_ARGS)
9799
{
98-
if (!s)
99-
return FALSE;
100-
returnfixedlen_like(VARDATA(s),p,VARSIZE(s)-VARHDRSZ);
100+
text*s=PG_GETARG_TEXT_P(0);
101+
text*p=PG_GETARG_TEXT_P(1);
102+
103+
PG_RETURN_BOOL(fixedlen_like(VARDATA(s),p,VARSIZE(s)-VARHDRSZ));
101104
}
102105

103-
bool
104-
textnlike(structvarlena*s,structvarlena*p)
106+
Datum
107+
textnlike(PG_FUNCTION_ARGS)
105108
{
106-
return !textlike(s,p);
109+
text*s=PG_GETARG_TEXT_P(0);
110+
text*p=PG_GETARG_TEXT_P(1);
111+
112+
PG_RETURN_BOOL(!fixedlen_like(VARDATA(s),p,VARSIZE(s)-VARHDRSZ));
107113
}
108114

109115

@@ -221,11 +227,11 @@ DoMatch(pg_wchar * text, pg_wchar * p)
221227
/*
222228
**User-level routine. Returns TRUE or FALSE.
223229
*/
224-
staticint
230+
staticbool
225231
like(pg_wchar*text,pg_wchar*p)
226232
{
227233
/* Fast path for match-everything pattern */
228234
if (p[0]=='%'&&p[1]=='\0')
229-
returnTRUE;
235+
returntrue;
230236
returnDoMatch(text,p)==LIKE_TRUE;
231237
}

‎src/backend/utils/adt/lztext.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* ----------
22
* lztext.c -
33
*
4-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/lztext.c,v 1.9 2000/07/05 10:09:53 wieck Exp $
4+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/lztext.c,v 1.10 2000/07/06 05:48:11 tgl Exp $
55
*
66
*Text type with internal LZ compressed representation. Uses the
77
*standard PostgreSQL compression method.
@@ -174,19 +174,13 @@ lztextoctetlen(lztext *lz)
174174
*Convert text to lztext
175175
* ----------
176176
*/
177-
lztext*
178-
text_lztext(text*txt)
177+
Datum
178+
text_lztext(PG_FUNCTION_ARGS)
179179
{
180+
text*txt=PG_GETARG_TEXT_P(0);
180181
lztext*result;
181182
int32rawsize;
182183

183-
/* ----------
184-
* Handle NULL
185-
* ----------
186-
*/
187-
if (txt==NULL)
188-
returnNULL;
189-
190184
/* ----------
191185
* Copy the entire attribute
192186
* ----------
@@ -196,7 +190,7 @@ text_lztext(text *txt)
196190
VARATT_SIZEP(result)=rawsize+VARHDRSZ;
197191
memcpy(VARATT_DATA(result),VARATT_DATA(txt),rawsize);
198192

199-
returnresult;
193+
PG_RETURN_POINTER(result);
200194
}
201195

202196

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp