Re: [PATCHES] Text <-> C string - Mailing list pgsql-hackers

From Brendan Jurd
Subject Re: [PATCHES] Text <-> C string
Date
Msg-id 37ed240d0803280912u530b6107xfdd14bcbd42a2338@mail.gmail.com
Whole thread Raw
In response to Re: [PATCHES] Text <-> C string  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [PATCHES] Text <-> C string  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On 26/03/2008, Tom Lane <tgl@sss.pgh.pa.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.

pgsql-hackers by date:

Previous
From: "Zubkovsky, Sergey"
Date:
Subject: Re: [DOCS] pg_total_relation_size() and CHECKPOINT
Next
From: Heikki Linnakangas
Date:
Subject: Re: advancing snapshot's xmin