mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Use new cstring/text conversion functions in some additional places.
These changes assume that the varchar and xml data types are represented the same as text. (I did not, however, accept the portions of the proposed patch that wanted to assume bytea is the same as text --- tgl.) Brendan Jurd
This commit is contained in:
@ -26,7 +26,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pgsql.c,v 1.9 2007/02/27 23:48:06 tgl Exp $
|
||||
* $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pgsql.c,v 1.10 2008/05/04 16:42:41 tgl Exp $
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
@ -34,6 +34,7 @@
|
||||
#include "fmgr.h"
|
||||
#include "parser/scansup.h"
|
||||
#include "mb/pg_wchar.h"
|
||||
#include "utils/builtins.h"
|
||||
|
||||
#include "mbuf.h"
|
||||
#include "px.h"
|
||||
@ -140,7 +141,6 @@ static text *
|
||||
convert_charset(text *src, int cset_from, int cset_to)
|
||||
{
|
||||
int src_len = VARSIZE(src) - VARHDRSZ;
|
||||
int dst_len;
|
||||
unsigned char *dst;
|
||||
unsigned char *csrc = (unsigned char *) VARDATA(src);
|
||||
text *res;
|
||||
@ -149,10 +149,7 @@ convert_charset(text *src, int cset_from, int cset_to)
|
||||
if (dst == csrc)
|
||||
return src;
|
||||
|
||||
dst_len = strlen((char *) dst);
|
||||
res = palloc(dst_len + VARHDRSZ);
|
||||
memcpy(VARDATA(res), dst, dst_len);
|
||||
SET_VARSIZE(res, dst_len + VARHDRSZ);
|
||||
res = cstring_to_text((char *) dst);
|
||||
pfree(dst);
|
||||
return res;
|
||||
}
|
||||
|
@ -194,7 +194,6 @@ xml_encode_special_chars(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *tin = PG_GETARG_TEXT_P(0);
|
||||
text *tout;
|
||||
int32 ressize;
|
||||
xmlChar *ts,
|
||||
*tt;
|
||||
|
||||
@ -204,10 +203,7 @@ xml_encode_special_chars(PG_FUNCTION_ARGS)
|
||||
|
||||
pfree(ts);
|
||||
|
||||
ressize = strlen((char *) tt);
|
||||
tout = (text *) palloc(ressize + VARHDRSZ);
|
||||
memcpy(VARDATA(tout), tt, ressize);
|
||||
SET_VARSIZE(tout, ressize + VARHDRSZ);
|
||||
tout = cstring_to_text((char *) tt);
|
||||
|
||||
xmlFree(tt);
|
||||
|
||||
@ -306,14 +302,7 @@ pgxmlNodeSetToText(xmlNodeSetPtr nodeset,
|
||||
xmlChar *
|
||||
pgxml_texttoxmlchar(text *textstring)
|
||||
{
|
||||
xmlChar *res;
|
||||
int32 txsize;
|
||||
|
||||
txsize = VARSIZE(textstring) - VARHDRSZ;
|
||||
res = (xmlChar *) palloc(txsize + 1);
|
||||
memcpy((char *) res, VARDATA(textstring), txsize);
|
||||
res[txsize] = '\0';
|
||||
return res;
|
||||
return (xmlChar *) text_to_cstring(textstring);
|
||||
}
|
||||
|
||||
/* Public visible XPath functions */
|
||||
@ -577,7 +566,6 @@ pgxml_result_to_text(xmlXPathObjectPtr res,
|
||||
xmlChar * plainsep)
|
||||
{
|
||||
xmlChar *xpresstr;
|
||||
int32 ressize;
|
||||
text *xpres;
|
||||
|
||||
if (res == NULL)
|
||||
@ -604,10 +592,7 @@ pgxml_result_to_text(xmlXPathObjectPtr res,
|
||||
|
||||
|
||||
/* Now convert this result back to text */
|
||||
ressize = strlen((char *) xpresstr);
|
||||
xpres = (text *) palloc(ressize + VARHDRSZ);
|
||||
memcpy(VARDATA(xpres), xpresstr, ressize);
|
||||
SET_VARSIZE(xpres, ressize + VARHDRSZ);
|
||||
xpres = cstring_to_text((char *) xpresstr);
|
||||
|
||||
/* Free various storage */
|
||||
xmlCleanupParser();
|
||||
|
@ -39,8 +39,9 @@ PG_FUNCTION_INFO_V1(xslt_process);
|
||||
Datum
|
||||
xslt_process(PG_FUNCTION_ARGS)
|
||||
{
|
||||
|
||||
|
||||
text *doct = PG_GETARG_TEXT_P(0);
|
||||
text *ssheet = PG_GETARG_TEXT_P(1);
|
||||
text *paramstr;
|
||||
const char *params[MAXPARAMS + 1]; /* +1 for the terminator */
|
||||
xsltStylesheetPtr stylesheet = NULL;
|
||||
xmlDocPtr doctree;
|
||||
@ -50,12 +51,6 @@ xslt_process(PG_FUNCTION_ARGS)
|
||||
int resstat;
|
||||
int reslen;
|
||||
|
||||
text *doct = PG_GETARG_TEXT_P(0);
|
||||
text *ssheet = PG_GETARG_TEXT_P(1);
|
||||
text *paramstr;
|
||||
text *tres;
|
||||
|
||||
|
||||
if (fcinfo->nargs == 3)
|
||||
{
|
||||
paramstr = PG_GETARG_TEXT_P(2);
|
||||
@ -124,11 +119,7 @@ xslt_process(PG_FUNCTION_ARGS)
|
||||
if (resstat < 0)
|
||||
PG_RETURN_NULL();
|
||||
|
||||
tres = palloc(reslen + VARHDRSZ);
|
||||
memcpy(VARDATA(tres), resstr, reslen);
|
||||
SET_VARSIZE(tres, reslen + VARHDRSZ);
|
||||
|
||||
PG_RETURN_TEXT_P(tres);
|
||||
PG_RETURN_TEXT_P(cstring_to_text_with_len(resstr, reslen));
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user