Re: Text <-> C string

From: "Brendan Jurd" <direvus(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Gregory Stark" <stark(at)enterprisedb(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Text <-> C string
Date: 2007-09-22 21:55:59
Message-ID: 37ed240d0709221455o20b681ect9def043fd665cc9c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

On 9/22/07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "Brendan Jurd" <direvus(at)gmail(dot)com> writes:
> > I just noticed a couple of macros defined in src/include/tsearch/ts_utils.h:
>
> > #define TextPGetCString(t)
> > DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(t)))
> > #define CStringGetTextP(c) DatumGetTextP(DirectFunctionCall1(textin,
> > CStringGetDatum(c)))
>
> I think if you look around you'll find several similar things in various
> contrib modules. It would make some sense to try to unify all this.
> I'm not particularly for making it macros in postgres.h though ---
> that's no help if the macros require referencing stuff in builtins.h.
>
> On grounds of code-space savings I think it might be worth making
> these things be simple functions declared in builtins.h; that would
> also make it much easier to change their implementations.

You're right about finding similar things in various places. Even
varlena.c has a set of these macros (PG_TEXT_GET_STR etc), but it
doesn't look they've really been utilised.

I'm happy to take a swing at this. Declaring in builtins.h makes sense.

The thing that's got me confused at the moment is what naming
convention to use for the functions. Looking in builtins.h you might
get the impression that we use lower_underscore for functions that are
called via fmgr, UPPER_UNDERSCORE for macros and CamelCase for
ordinary internal C functions, but there are plenty of exceptions to
disprove that rule. I see camel cased macros and lowercased internal
functions. Camel cased identifiers sometimes start with uppercase,
sometimes lowercase.

So the name for the text -> cstring function could be any of:

text_cstr
text_to_cstr
textToCString
TextToCString

Is there any kind of authoritative naming convention I can refer to?

Thanks for your time,
BJ

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Brendan Jurd 2007-09-22 22:11:08 Re: [HACKERS] Add function for quote_qualified_identifier?
Previous Message Tom Lane 2007-09-22 21:41:19 Re: [HACKERS] Add function for quote_qualified_identifier?

Browse pgsql-patches by date

  From Date Subject
Next Message Brendan Jurd 2007-09-22 22:11:08 Re: [HACKERS] Add function for quote_qualified_identifier?
Previous Message Tom Lane 2007-09-22 21:41:19 Re: [HACKERS] Add function for quote_qualified_identifier?