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

Commit220db7c

Browse files
committed
Simplify and standardize conversions between TEXT datums and ordinary C
strings. This patch introduces four support functions cstring_to_text,cstring_to_text_with_len, text_to_cstring, and text_to_cstring_buffer, andtwo macros CStringGetTextDatum and TextDatumGetCString. A number ofexisting macros that provided variants on these themes were removed.Most of the places that need to make such conversions now require just onefunction or macro call, in place of the multiple notational layers that usedto be needed. There are no longer any direct calls of textout or textin,and we got most of the places that were using handmade conversions viamemcpy (there may be a few still lurking, though).This commit doesn't make any serious effort to eliminate transient memoryleaks caused by detoasting toasted text objects before they reachtext_to_cstring. We changed PG_GETARG_TEXT_P to PG_GETARG_TEXT_PP in a fewplaces where it was easy, but much more could be done.Brendan Jurd and Tom Lane
1 parentf948197 commit220db7c

File tree

94 files changed

+770
-1210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+770
-1210
lines changed

‎contrib/adminpack/adminpack.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Author: Andreas Pflug <pgadmin@pse-consulting.de>
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/contrib/adminpack/adminpack.c,v 1.10 2008/01/01 19:45:45 momjian Exp $
11+
* $PostgreSQL: pgsql/contrib/adminpack/adminpack.c,v 1.11 2008/03/25 22:42:41 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -23,6 +23,7 @@
2323
#include"miscadmin.h"
2424
#include"postmaster/syslogger.h"
2525
#include"storage/fd.h"
26+
#include"utils/builtins.h"
2627
#include"utils/datetime.h"
2728

2829

@@ -68,11 +69,7 @@ typedef struct
6869
staticchar*
6970
convert_and_check_filename(text*arg,boollogAllowed)
7071
{
71-
intinput_len=VARSIZE(arg)-VARHDRSZ;
72-
char*filename=palloc(input_len+1);
73-
74-
memcpy(filename,VARDATA(arg),input_len);
75-
filename[input_len]='\0';
72+
char*filename=text_to_cstring(arg);
7673

7774
canonicalize_path(filename);/* filename can change length here */
7875

‎contrib/chkpass/chkpass.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* darcy@druid.net
55
* http://www.druid.net/darcy/
66
*
7-
* $PostgreSQL: pgsql/contrib/chkpass/chkpass.c,v 1.19 2007/02/27 23:48:05 tgl Exp $
7+
* $PostgreSQL: pgsql/contrib/chkpass/chkpass.c,v 1.20 2008/03/25 22:42:41 tgl Exp $
88
* best viewed with tabs set to 4
99
*/
1010

@@ -17,6 +17,7 @@
1717
#endif
1818

1919
#include"fmgr.h"
20+
#include"utils/builtins.h"
2021

2122
PG_MODULE_MAGIC;
2223

@@ -124,15 +125,8 @@ Datum
124125
chkpass_rout(PG_FUNCTION_ARGS)
125126
{
126127
chkpass*password= (chkpass*)PG_GETARG_POINTER(0);
127-
text*result;
128-
intslen;
129128

130-
slen=strlen(password->password);
131-
result= (text*)palloc(VARHDRSZ+slen);
132-
SET_VARSIZE(result,VARHDRSZ+slen);
133-
memcpy(VARDATA(result),password->password,slen);
134-
135-
PG_RETURN_TEXT_P(result);
129+
PG_RETURN_TEXT_P(cstring_to_text(password->password));
136130
}
137131

138132

@@ -145,13 +139,10 @@ Datum
145139
chkpass_eq(PG_FUNCTION_ARGS)
146140
{
147141
chkpass*a1= (chkpass*)PG_GETARG_POINTER(0);
148-
text*a2= (text*)PG_GETARG_TEXT_P(1);
149-
charstr[10];
150-
intsz;
142+
text*a2=PG_GETARG_TEXT_PP(1);
143+
charstr[9];
151144

152-
sz=Min(VARSIZE(a2)-VARHDRSZ,8);
153-
memcpy(str,VARDATA(a2),sz);
154-
str[sz]='\0';
145+
text_to_cstring_buffer(a2,str,sizeof(str));
155146
PG_RETURN_BOOL(strcmp(a1->password,crypt(str,a1->password))==0);
156147
}
157148

@@ -160,12 +151,9 @@ Datum
160151
chkpass_ne(PG_FUNCTION_ARGS)
161152
{
162153
chkpass*a1= (chkpass*)PG_GETARG_POINTER(0);
163-
text*a2= (text*)PG_GETARG_TEXT_P(1);
164-
charstr[10];
165-
intsz;
154+
text*a2=PG_GETARG_TEXT_PP(1);
155+
charstr[9];
166156

167-
sz=Min(VARSIZE(a2)-VARHDRSZ,8);
168-
memcpy(str,VARDATA(a2),sz);
169-
str[sz]='\0';
157+
text_to_cstring_buffer(a2,str,sizeof(str));
170158
PG_RETURN_BOOL(strcmp(a1->password,crypt(str,a1->password))!=0);
171159
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp