BUG #2574: C function: arg TEXT data corrupt

Поиск
Список
Период
Сортировка
От Michael Enke
Тема BUG #2574: C function: arg TEXT data corrupt
Дата
Msg-id 200608141353.k7EDrYPi038307@wwwmaster.postgresql.org
обсуждение исходный текст
Ответы Re: BUG #2574: C function: arg TEXT data corrupt  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
The following bug has been logged online:

Bug reference:      2574
Logged by:          Michael Enke
Email address:      michael.enke@wincor-nixdorf.com
PostgreSQL version: 8.1.4
Operating system:   Open Suse 10.1 and CentOS 4.3
Description:        C function: arg TEXT data corrupt
Details:

I created a C function:
extern Datum test_arg(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(test_arg);
Datum test_arg(PG_FUNCTION_ARGS) {
  elog(INFO, "arg: %s", VARDATA(PG_GETARG_TEXT_P(0)));
  PG_RETURN_INT16(0);
}
and used the
CREATE FUNCTION test_arg(TEXT) RETURNS INT4 AS 'path_to_lib.so' LANGUAGE
'C';

If I call this function "the first time"
after connecting with psql, the info output shows
corrupted data, the second and further call is ok:
me@noteme:~/uwx9/SVN/tpl/trunk/db/postgresql/src> psql -U tplinux
Welcome to psql 8.1.3, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

tplinux=> select test_arg('1');
INFO:  arg: 1s@3
 test_arg
----------
        0
(1 row)

tplinux=> select test_arg('1');
INFO:  arg: 1
 test_arg
----------
        0
(1 row)

The same problem is with input length of 2, 3, 4, 8 char (and may be more).
With input of 4 char I never get correct value.

No problem for first call with 5, 6 , 7 char,
but with 5 char problem if before called with 6 char.

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: distance operator dont work
Следующее
От: Nick Morrison
Дата:
Сообщение: no native spinlock support on os x 10.4.7