Re: [PATCHES] Text <-> C string

From: "Brendan Jurd" <direvus(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org, pgsql-patches(at)postgresql(dot)org
Subject: Re: [PATCHES] Text <-> C string
Date: 2008-03-28 16:12:51
Message-ID: 37ed240d0803280912u530b6107xfdd14bcbd42a2338@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

On 26/03/2008, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> There are no textout/textin calls left, but I may have missed some
> places that were doing it the hard way with direct palloc/memcpy
> manipulations. It might be worth trolling all the VARDATA() references
> to see if any more are easily replaceable.
>

I think there are perhaps a dozen such sites, and I hope to submit a
cleanup patch that gets rid of these soon.

I did come across one site I'm not sure about in utils/adt/xml.c:291

/*
* We need a null-terminated string to pass to parse_xml_decl(). Rather
* than make a separate copy, make the temporary result one byte bigger
* than it needs to be.
*/
result = palloc(nbytes + 1 + VARHDRSZ);
SET_VARSIZE(result, nbytes + VARHDRSZ);
memcpy(VARDATA(result), str, nbytes);
str = VARDATA(result);
str[nbytes] = '\0';

The author seemed pretty sure he didn't want to make a separate copy
of the string, so I'm thinking there's not a whole lot I can do to
improve this site.

> I notice in particular that xfunc.sgml contains sample C functions to
> copy and concatenate text. While these aren't directly replaceable
> with the new functions, I wonder whether we ought to change the examples
> to make them less certain to break if we ever change text's
> representation.
>

Yes, these sample C functions are shown in tutorial/funcs.c and
funcs_new.c as well. I agree that the examples could do with
changing, but don't have any keen insight on what to change them to.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2008-03-28 16:14:58 Re: advancing snapshot's xmin
Previous Message Zubkovsky, Sergey 2008-03-28 16:07:31 Re: [DOCS] pg_total_relation_size() and CHECKPOINT

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2008-03-28 17:23:09 Re: [PATCHES] Implemented current_query
Previous Message Zubkovsky, Sergey 2008-03-28 16:07:31 Re: [DOCS] pg_total_relation_size() and CHECKPOINT