Re: [HACKERS] What is nameout() for? - Mailing list pgsql-hackers

From Mike Mascari
Subject Re: [HACKERS] What is nameout() for?
Date
Msg-id 19991107203834.21729.rocketmail@web2105.mail.yahoo.com
Whole thread Raw
Responses Re: [HACKERS] What is nameout() for?  (Don Baccus <dhogaza@pacifier.com>)
Re: [HACKERS] What is nameout() for?  (Bruce Momjian <maillist@candle.pha.pa.us>)
Re: [HACKERS] What is nameout() for?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
--- Bruce Momjian <maillist@candle.pha.pa.us> wrote:
> I am confused by nameout().  There are a number of places where table
> names are output using nameout(), and many other cases where they are
> just output without calling nameout.  Can someone explain why the dash
> is important?  I can see the pstrdup as being important, but not in all
> of the cases where nameout is called.
> 
>
---------------------------------------------------------------------------
> 
> /*
>  *      nameout - converts internal reprsentation to "..."
>  */
> char *
> nameout(NameData *s)
> {  
>     if (s == NULL)
>         return "-";
>     else 
>         return pstrdup(s->data);
> }
> 

Actually, I have 'C' question regarding the above code. Where does the
"-" live in RAM? Does the compiler generated a data hunk such that this
string will be apart of the final executable and each invocation of this
routine would result in a pointer to that 'global' location being
returned? 
Or does it allocate the memory for, and initialize, the "-" on the stack? 
If so, isn't returning a "-" a dangerous act?

In fact, isn't returning a "-" dangerous either way without the 
protoype being:

const char *nameout(NameData *s);
^^^^^

Sorry to drift off topice, but I was just curious,

Mike Mascari
(mascarim@yahoo.com)





=====

__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com


pgsql-hackers by date:

Previous
From: Brian Hirt
Date:
Subject: Re: [HACKERS] IN clause and INTERSECT not behaving as expected
Next
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] What is nameout() for?