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

Commit45173ae

Browse files
committed
Use new cstring/text conversion functions in some additional places.
These changes assume that the varchar and xml data types are representedthe same as text. (I did not, however, accept the portions of the proposedpatch that wanted to assume bytea is the same as text --- tgl.)Brendan Jurd
1 parent0ff74f0 commit45173ae

File tree

5 files changed

+24
-99
lines changed

5 files changed

+24
-99
lines changed

‎contrib/pgcrypto/pgp-pgsql.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pgsql.c,v 1.9 2007/02/27 23:48:06 tgl Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pgsql.c,v 1.10 2008/05/04 16:42:41 tgl Exp $
3030
*/
3131

3232
#include"postgres.h"
3333

3434
#include"fmgr.h"
3535
#include"parser/scansup.h"
3636
#include"mb/pg_wchar.h"
37+
#include"utils/builtins.h"
3738

3839
#include"mbuf.h"
3940
#include"px.h"
@@ -140,7 +141,6 @@ static text *
140141
convert_charset(text*src,intcset_from,intcset_to)
141142
{
142143
intsrc_len=VARSIZE(src)-VARHDRSZ;
143-
intdst_len;
144144
unsignedchar*dst;
145145
unsignedchar*csrc= (unsignedchar*)VARDATA(src);
146146
text*res;
@@ -149,10 +149,7 @@ convert_charset(text *src, int cset_from, int cset_to)
149149
if (dst==csrc)
150150
returnsrc;
151151

152-
dst_len=strlen((char*)dst);
153-
res=palloc(dst_len+VARHDRSZ);
154-
memcpy(VARDATA(res),dst,dst_len);
155-
SET_VARSIZE(res,dst_len+VARHDRSZ);
152+
res=cstring_to_text((char*)dst);
156153
pfree(dst);
157154
returnres;
158155
}

‎contrib/xml2/xpath.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ xml_encode_special_chars(PG_FUNCTION_ARGS)
194194
{
195195
text*tin=PG_GETARG_TEXT_P(0);
196196
text*tout;
197-
int32ressize;
198197
xmlChar*ts,
199198
*tt;
200199

@@ -204,10 +203,7 @@ xml_encode_special_chars(PG_FUNCTION_ARGS)
204203

205204
pfree(ts);
206205

207-
ressize=strlen((char*)tt);
208-
tout= (text*)palloc(ressize+VARHDRSZ);
209-
memcpy(VARDATA(tout),tt,ressize);
210-
SET_VARSIZE(tout,ressize+VARHDRSZ);
206+
tout=cstring_to_text((char*)tt);
211207

212208
xmlFree(tt);
213209

@@ -306,14 +302,7 @@ pgxmlNodeSetToText(xmlNodeSetPtr nodeset,
306302
xmlChar*
307303
pgxml_texttoxmlchar(text*textstring)
308304
{
309-
xmlChar*res;
310-
int32txsize;
311-
312-
txsize=VARSIZE(textstring)-VARHDRSZ;
313-
res= (xmlChar*)palloc(txsize+1);
314-
memcpy((char*)res,VARDATA(textstring),txsize);
315-
res[txsize]='\0';
316-
returnres;
305+
return (xmlChar*)text_to_cstring(textstring);
317306
}
318307

319308
/* Public visible XPath functions */
@@ -577,7 +566,6 @@ pgxml_result_to_text(xmlXPathObjectPtr res,
577566
xmlChar*plainsep)
578567
{
579568
xmlChar*xpresstr;
580-
int32ressize;
581569
text*xpres;
582570

583571
if (res==NULL)
@@ -604,10 +592,7 @@ pgxml_result_to_text(xmlXPathObjectPtr res,
604592

605593

606594
/* Now convert this result back to text */
607-
ressize=strlen((char*)xpresstr);
608-
xpres= (text*)palloc(ressize+VARHDRSZ);
609-
memcpy(VARDATA(xpres),xpresstr,ressize);
610-
SET_VARSIZE(xpres,ressize+VARHDRSZ);
595+
xpres=cstring_to_text((char*)xpresstr);
611596

612597
/* Free various storage */
613598
xmlCleanupParser();

‎contrib/xml2/xslt_proc.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ PG_FUNCTION_INFO_V1(xslt_process);
3939
Datum
4040
xslt_process(PG_FUNCTION_ARGS)
4141
{
42-
43-
42+
text*doct=PG_GETARG_TEXT_P(0);
43+
text*ssheet=PG_GETARG_TEXT_P(1);
44+
text*paramstr;
4445
constchar*params[MAXPARAMS+1];/* +1 for the terminator */
4546
xsltStylesheetPtrstylesheet=NULL;
4647
xmlDocPtrdoctree;
@@ -50,12 +51,6 @@ xslt_process(PG_FUNCTION_ARGS)
5051
intresstat;
5152
intreslen;
5253

53-
text*doct=PG_GETARG_TEXT_P(0);
54-
text*ssheet=PG_GETARG_TEXT_P(1);
55-
text*paramstr;
56-
text*tres;
57-
58-
5954
if (fcinfo->nargs==3)
6055
{
6156
paramstr=PG_GETARG_TEXT_P(2);
@@ -124,11 +119,7 @@ xslt_process(PG_FUNCTION_ARGS)
124119
if (resstat<0)
125120
PG_RETURN_NULL();
126121

127-
tres=palloc(reslen+VARHDRSZ);
128-
memcpy(VARDATA(tres),resstr,reslen);
129-
SET_VARSIZE(tres,reslen+VARHDRSZ);
130-
131-
PG_RETURN_TEXT_P(tres);
122+
PG_RETURN_TEXT_P(cstring_to_text_with_len(resstr,reslen));
132123
}
133124

134125

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/varchar.c,v 1.127 2008/03/25 22:42:44 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/varchar.c,v 1.128 2008/05/04 16:42:41 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -566,7 +566,6 @@ varchar(PG_FUNCTION_ARGS)
566566
VarChar*source=PG_GETARG_VARCHAR_PP(0);
567567
int32typmod=PG_GETARG_INT32(1);
568568
boolisExplicit=PG_GETARG_BOOL(2);
569-
VarChar*result;
570569
int32len,
571570
maxlen;
572571
size_tmaxmblen;
@@ -596,11 +595,8 @@ varchar(PG_FUNCTION_ARGS)
596595
maxlen)));
597596
}
598597

599-
result=palloc(maxmblen+VARHDRSZ);
600-
SET_VARSIZE(result,maxmblen+VARHDRSZ);
601-
memcpy(VARDATA(result),s_data,maxmblen);
602-
603-
PG_RETURN_VARCHAR_P(result);
598+
PG_RETURN_VARCHAR_P((VarChar*)cstring_to_text_with_len(s_data,
599+
maxmblen));
604600
}
605601

606602
Datum

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

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.72 2008/04/0408:33:15 mha Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.73 2008/05/0416:42:41 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -319,13 +319,7 @@ xml_recv(PG_FUNCTION_ARGS)
319319
if (newstr!=str)
320320
{
321321
pfree(result);
322-
323-
nbytes=strlen(newstr);
324-
325-
result=palloc(nbytes+VARHDRSZ);
326-
SET_VARSIZE(result,nbytes+VARHDRSZ);
327-
memcpy(VARDATA(result),newstr,nbytes);
328-
322+
result= (xmltype*)cstring_to_text(newstr);
329323
pfree(newstr);
330324
}
331325

@@ -369,46 +363,23 @@ appendStringInfoText(StringInfo str, const text *t)
369363
staticxmltype*
370364
stringinfo_to_xmltype(StringInfobuf)
371365
{
372-
int32len;
373-
xmltype*result;
374-
375-
len=buf->len+VARHDRSZ;
376-
result=palloc(len);
377-
SET_VARSIZE(result,len);
378-
memcpy(VARDATA(result),buf->data,buf->len);
379-
380-
returnresult;
366+
return (xmltype*)cstring_to_text_with_len(buf->data,buf->len);
381367
}
382368

383369

384370
staticxmltype*
385371
cstring_to_xmltype(constchar*string)
386372
{
387-
int32len;
388-
xmltype*result;
389-
390-
len=strlen(string)+VARHDRSZ;
391-
result=palloc(len);
392-
SET_VARSIZE(result,len);
393-
memcpy(VARDATA(result),string,len-VARHDRSZ);
394-
395-
returnresult;
373+
return (xmltype*)cstring_to_text(string);
396374
}
397375

398376

399377
#ifdefUSE_LIBXML
400378
staticxmltype*
401379
xmlBuffer_to_xmltype(xmlBufferPtrbuf)
402380
{
403-
int32len;
404-
xmltype*result;
405-
406-
len=xmlBufferLength(buf)+VARHDRSZ;
407-
result=palloc(len);
408-
SET_VARSIZE(result,len);
409-
memcpy(VARDATA(result),xmlBufferContent(buf),len-VARHDRSZ);
410-
411-
returnresult;
381+
return (xmltype*)cstring_to_text_with_len((char*)xmlBufferContent(buf),
382+
xmlBufferLength(buf));
412383
}
413384
#endif
414385

@@ -474,9 +445,7 @@ xmlconcat(List *args)
474445
char*str;
475446

476447
len=VARSIZE(x)-VARHDRSZ;
477-
str=palloc(len+1);
478-
memcpy(str,VARDATA(x),len);
479-
str[len]='\0';
448+
str=text_to_cstring((text*)x);
480449

481450
parse_xml_decl((xmlChar*)str,&len,&version,NULL,&standalone);
482451

@@ -751,9 +720,7 @@ xmlroot(xmltype *data, text *version, int standalone)
751720
StringInfoDatabuf;
752721

753722
len=VARSIZE(data)-VARHDRSZ;
754-
str=palloc(len+1);
755-
memcpy(str,VARDATA(data),len);
756-
str[len]='\0';
723+
str=text_to_cstring((text*)data);
757724

758725
parse_xml_decl((xmlChar*)str,&len,&orig_version,NULL,&orig_standalone);
759726

@@ -1237,19 +1204,12 @@ xml_parse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace,
12371204

12381205

12391206
/*
1240-
* xmlChar<->textconvertions
1207+
* xmlChar<->textconversions
12411208
*/
12421209
staticxmlChar*
12431210
xml_text2xmlChar(text*in)
12441211
{
1245-
int32len=VARSIZE(in)-VARHDRSZ;
1246-
xmlChar*res;
1247-
1248-
res=palloc(len+1);
1249-
memcpy(res,VARDATA(in),len);
1250-
res[len]='\0';
1251-
1252-
return (res);
1212+
return (xmlChar*)text_to_cstring(in);
12531213
}
12541214

12551215

@@ -3188,7 +3148,6 @@ xml_xmlnodetoxmltype(xmlNodePtr cur)
31883148
{
31893149
xmlChar*str;
31903150
xmltype*result;
3191-
size_tlen;
31923151
xmlBufferPtrbuf;
31933152

31943153
if (cur->type==XML_ELEMENT_NODE)
@@ -3201,10 +3160,7 @@ xml_xmlnodetoxmltype(xmlNodePtr cur)
32013160
else
32023161
{
32033162
str=xmlXPathCastNodeToString(cur);
3204-
len=strlen((char*)str);
3205-
result= (xmltype*)palloc(len+VARHDRSZ);
3206-
SET_VARSIZE(result,len+VARHDRSZ);
3207-
memcpy(VARDATA(result),str,len);
3163+
result= (xmltype*)cstring_to_text((char*)str);
32083164
}
32093165

32103166
returnresult;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp