* 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"
#include "fmgr.h"
#include "parser/scansup.h"
#include "mb/pg_wchar.h"
+#include "utils/builtins.h"
#include "mbuf.h"
#include "px.h"
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;
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;
}
{
text *tin = PG_GETARG_TEXT_P(0);
text *tout;
- int32 ressize;
xmlChar *ts,
*tt;
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);
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 */
xmlChar * plainsep)
{
xmlChar *xpresstr;
- int32 ressize;
text *xpres;
if (res == NULL)
/* 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();
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;
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);
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));
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/varchar.c,v 1.127 2008/03/25 22:42:44 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/varchar.c,v 1.128 2008/05/04 16:42:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
VarChar *source = PG_GETARG_VARCHAR_PP(0);
int32 typmod = PG_GETARG_INT32(1);
bool isExplicit = PG_GETARG_BOOL(2);
- VarChar *result;
int32 len,
maxlen;
size_t maxmblen;
maxlen)));
}
- result = palloc(maxmblen + VARHDRSZ);
- SET_VARSIZE(result, maxmblen + VARHDRSZ);
- memcpy(VARDATA(result), s_data, maxmblen);
-
- PG_RETURN_VARCHAR_P(result);
+ PG_RETURN_VARCHAR_P((VarChar *) cstring_to_text_with_len(s_data,
+ maxmblen));
}
Datum
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.72 2008/04/04 08:33:15 mha Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.73 2008/05/04 16:42:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
if (newstr != str)
{
pfree(result);
-
- nbytes = strlen(newstr);
-
- result = palloc(nbytes + VARHDRSZ);
- SET_VARSIZE(result, nbytes + VARHDRSZ);
- memcpy(VARDATA(result), newstr, nbytes);
-
+ result = (xmltype *) cstring_to_text(newstr);
pfree(newstr);
}
static xmltype *
stringinfo_to_xmltype(StringInfo buf)
{
- int32 len;
- xmltype *result;
-
- len = buf->len + VARHDRSZ;
- result = palloc(len);
- SET_VARSIZE(result, len);
- memcpy(VARDATA(result), buf->data, buf->len);
-
- return result;
+ return (xmltype *) cstring_to_text_with_len(buf->data, buf->len);
}
static xmltype *
cstring_to_xmltype(const char *string)
{
- int32 len;
- xmltype *result;
-
- len = strlen(string) + VARHDRSZ;
- result = palloc(len);
- SET_VARSIZE(result, len);
- memcpy(VARDATA(result), string, len - VARHDRSZ);
-
- return result;
+ return (xmltype *) cstring_to_text(string);
}
static xmltype *
xmlBuffer_to_xmltype(xmlBufferPtr buf)
{
- int32 len;
- xmltype *result;
-
- len = xmlBufferLength(buf) + VARHDRSZ;
- result = palloc(len);
- SET_VARSIZE(result, len);
- memcpy(VARDATA(result), xmlBufferContent(buf), len - VARHDRSZ);
-
- return result;
+ return (xmltype *) cstring_to_text_with_len((char *) xmlBufferContent(buf),
+ xmlBufferLength(buf));
}
#endif
char *str;
len = VARSIZE(x) - VARHDRSZ;
- str = palloc(len + 1);
- memcpy(str, VARDATA(x), len);
- str[len] = '\0';
+ str = text_to_cstring((text *) x);
parse_xml_decl((xmlChar *) str, &len, &version, NULL, &standalone);
StringInfoData buf;
len = VARSIZE(data) - VARHDRSZ;
- str = palloc(len + 1);
- memcpy(str, VARDATA(data), len);
- str[len] = '\0';
+ str = text_to_cstring((text *) data);
parse_xml_decl((xmlChar *) str, &len, &orig_version, NULL, &orig_standalone);
/*
- * xmlChar<->text convertions
+ * xmlChar<->text conversions
*/
static xmlChar *
xml_text2xmlChar(text *in)
{
- int32 len = VARSIZE(in) - VARHDRSZ;
- xmlChar *res;
-
- res = palloc(len + 1);
- memcpy(res, VARDATA(in), len);
- res[len] = '\0';
-
- return (res);
+ return (xmlChar *) text_to_cstring(in);
}
{
xmlChar *str;
xmltype *result;
- size_t len;
xmlBufferPtr buf;
if (cur->type == XML_ELEMENT_NODE)
else
{
str = xmlXPathCastNodeToString(cur);
- len = strlen((char *) str);
- result = (xmltype *) palloc(len + VARHDRSZ);
- SET_VARSIZE(result, len + VARHDRSZ);
- memcpy(VARDATA(result), str, len);
+ result = (xmltype *) cstring_to_text((char *) str);
}
return result;