pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
More long-string woes
3+ messages / 2 participants
[nested] [flat]

* More long-string woes
@ 2002-05-04 20:57  Joseph Barillari <jbarilla@princeton.edu>
  0 siblings, 1 reply; 3+ messages in thread

From: Joseph Barillari @ 2002-05-04 20:57 UTC (permalink / raw)
  To: pgsql-sql

My apologies in advance if this is redundant -- I've managed to get
the backend to cough up an error message which may provide some clue
as to why some of the other errors happened:


cal=> drop function foo();
ERROR:  pg_func_ownercheck: function 'foo()' does not exist
cal=> \i tf3
CREATE
cal=> select foo();
NOTICE:  [bnlah bnlah <repeats for ~1024 chars, snipped>
 foo 
-----
   1
(1 row)

cal=> \i tf3
CREATE
cal=> select foo();
NOTICE:  [bnlah bnlah <repeats for ~1024 chars, snipped>
NOTICE:  Error occurred while executing PL/pgSQL function foo
NOTICE:  while casting return value to functions return type
ERROR:  AllocSetFree: cannot find block containing chunk 0x8247780
cal=> 

Pl/pgsql hackers -- does this indicate some problems with my
installation? I recompiled using gcc3, and the errors persist. Here's
the function I used to produce them:


CREATE OR REPLACE FUNCTION foo()
    RETURNS INTEGER
    AS '
DECLARE
	querystr TEXT;

BEGIN

querystr := ''bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah bnlah '';

raise notice ''[%]'', querystr;

return 1;
end;
'
language 'plpgsql';

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: More long-string woes
@ 2002-05-05 06:01  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Joseph Barillari <jbarilla@princeton.edu>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2002-05-05 06:01 UTC (permalink / raw)
  To: Joseph Barillari <jbarilla@princeton.edu>; +Cc: pgsql-sql

Joseph Barillari <jbarilla@princeton.edu> writes:
> [ problems with long literals in plpgsql ]

I'm amazed no one has noticed this before.  plpgsql_dstring_append
is broken: it assumes it never needs to more than double the size
of the string.

Too tired to commit a fix tonight, but that's where the problem
lies...

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: More long-string woes
@ 2002-05-05 17:47  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2002-05-05 17:47 UTC (permalink / raw)
  To: Joseph Barillari <jbarilla@princeton.edu>; +Cc: pgsql-sql

Tom Lane <tgl@sss.pgh.pa.us> writes:
> Joseph Barillari <jbarilla@princeton.edu> writes:
>> [ problems with long literals in plpgsql ]

> I'm amazed no one has noticed this before.  plpgsql_dstring_append
> is broken: it assumes it never needs to more than double the size
> of the string.

I've applied the attached patch to current CVS and the 7.2 branch
(it also works against 7.1 sources).  Seems to fix the cases you report.

			regards, tom lane

inline patch 1: src/pl/plpgsql/src/pl_funcs.c (+7/-2 lines) download inline-1.patch*** src/pl/plpgsql/src/pl_funcs.c.orig Thu Nov 15 18:31:09 2001 --- src/pl/plpgsql/src/pl_funcs.c Sun May 5 13:38:26 2002 *************** *** 64,69 **** --- 64,70 ---- { ds->value = palloc(ds->alloc = 512); ds->used = 0; + ds->value[0] = '\0'; } *************** *** 86,95 **** plpgsql_dstring_append(PLpgSQL_dstring * ds, char *str) { int len = strlen(str); ! if (ds->used + len + 1 > ds->alloc) { ! ds->alloc *= 2; ds->value = repalloc(ds->value, ds->alloc); } --- 87,100 ---- plpgsql_dstring_append(PLpgSQL_dstring * ds, char *str) { int len = strlen(str); + int needed = ds->used + len + 1; ! if (needed > ds->alloc) { ! /* might have to double more than once, if len is large */ ! do { ! ds->alloc *= 2; ! } while (needed > ds->alloc); ds->value = repalloc(ds->value, ds->alloc); }
^ permalink raw reply [nested|flat] 3+ messages in thread


end of thread, other threads:[~2002-05-05 17:47 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-05-04 20:57 More long-string woes Joseph Barillari <jbarilla@princeton.edu>
2002-05-05 06:01 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-05-05 17:47   ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox