StringInfo misc. issues

Lists: pgsql-hackers
From: NikhilS <nikkhils(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: StringInfo misc. issues
Date: 2007-08-29 14:40:47
Message-ID: d3c4af540708290740m2ac46220k608bd96b409f4c6c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

I palloc0'ed a variable of type StringInfo and without doing an
initStringInfo() (forgot to do it i.e.) tried to append some stuff to it
using appendStringInfo(). It went into a tight loop within the function
enlargeStringInfo() at:

while (needed > newlen)

Must be a common enough case for a palloc0'ed field right?

The attached patch should fix this.

*** 226,232 ****
! if (needed < 0 ||
((Size) needed) >= (MaxAllocSize - (Size) str->len))
elog(ERROR, "invalid string enlargement request size %d",
needed);
--- 226,232 ----
! if (needed <= 0 ||
((Size) needed) >= (MaxAllocSize - (Size) str->len))
elog(ERROR, "invalid string enlargement request size %d",
needed);

I also found the absence of a function like resetStringInfo() a bit
puzzling. A found a lot of places where the code was resetting the "len"
field to 0 and assigning '\0' to the data field to reset the variable. This
seems to be the only missing API which will be needed while working with the
StringInfo type.

Regards,
Nikhils

--
EnterpriseDB http://www.enterprisedb.com

Attachment Content-Type Size
StringInfomisc.patch text/x-patch 1.9 KB

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: StringInfo misc. issues
Date: 2007-08-29 14:56:59
Message-ID: 46D5893B.3000206@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

NikhilS wrote:
>
>
> I also found the absence of a function like resetStringInfo() a bit
> puzzling. A found a lot of places where the code was resetting the
> "len" field to 0 and assigning '\0' to the data field to reset the
> variable. This seems to be the only missing API which will be needed
> while working with the StringInfo type.

er, what? stringinfo.h has:

/*------------------------
* resetStringInfo
* Clears the current content of the StringInfo, if any. The
* StringInfo remains valid.
*/
extern void resetStringInfo(StringInfo str);

cheers

andrew

cheers

andrew


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: NikhilS <nikkhils(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: StringInfo misc. issues
Date: 2007-08-29 15:11:06
Message-ID: 20070829151106.GG7911@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan escribió:
>
>
> NikhilS wrote:
>>
>>
>> I also found the absence of a function like resetStringInfo() a bit
>> puzzling. A found a lot of places where the code was resetting the "len"
>> field to 0 and assigning '\0' to the data field to reset the variable.
>> This seems to be the only missing API which will be needed while working
>> with the StringInfo type.
>
>
> er, what? stringinfo.h has:
>
> /*------------------------
> * resetStringInfo
> * Clears the current content of the StringInfo, if any. The
> * StringInfo remains valid.
> */
> extern void resetStringInfo(StringInfo str);

I think Neil added this recently. Maybe NikhilS is looking at 8.2 or
something.

--
Alvaro Herrera Developer, http://www.PostgreSQL.org/
"The Gord often wonders why people threaten never to come back after they've
been told never to return" (www.actsofgord.com)


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: NikhilS <nikkhils(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: StringInfo misc. issues
Date: 2007-08-29 15:14:49
Message-ID: 784.1188400489@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

NikhilS <nikkhils(at)gmail(dot)com> writes:
> The attached patch should fix this.

And break other things, no doubt. needed = 0 is a perfectly valid
edge case and mustn't be rejected here. (In fact, I doubt you'd
even get through the regression tests with this patch ... how much
did you test it?)

The real problem with what you describe is that you should have used
makeStringInfo().

> I also found the absence of a function like resetStringInfo() a bit
> puzzling.

CVS HEAD is way ahead of you.

regards, tom lane


From: NikhilS <nikkhils(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: StringInfo misc. issues
Date: 2007-08-30 06:01:02
Message-ID: d3c4af540708292301p45027cand50aea3d29191dab@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Apologies! As Alvaro guessed it correctly I was working with 8.2 sources.
Sorry for the noise.

Regards,
Nikhils

On 8/29/07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> NikhilS <nikkhils(at)gmail(dot)com> writes:
> > The attached patch should fix this.
>
> And break other things, no doubt. needed = 0 is a perfectly valid
> edge case and mustn't be rejected here. (In fact, I doubt you'd
> even get through the regression tests with this patch ... how much
> did you test it?)
>
> The real problem with what you describe is that you should have used
> makeStringInfo().
>
> > I also found the absence of a function like resetStringInfo() a bit
> > puzzling.
>
> CVS HEAD is way ahead of you.
>
> regards, tom lane
>

--
EnterpriseDB http://www.enterprisedb.com