Return value (instead of reference) for user defined type

Поиск
Список
Период
Сортировка
От Don Y
Тема Return value (instead of reference) for user defined type
Дата
Msg-id 44570374.4060206@DakotaCom.Net
обсуждение исходный текст
Ответы Re: Return value (instead of reference) for user defined type  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Hi,

I've successfully built several user types.  But, I'm having
problems with the one I am working on currently.  The server
SIGSEGV's at the end of the _in routine.

Nearest I can tell, the problem is related to my attempt to
return an int "by value" (all of my other types return
references but this type fits in an int4 so value seems
more economical).

I don't see anything in the documentation that suggests that
I can NOT do this... :-/

Below, snippets of the implementation and associated SQL.

Thanks for any pointers!
--don

================
typedef int4 foo;

PG_FUNCTION_INFO_VI(foo_in);

Datum
foo_in(PG_FUNCTION_ARGS)
{
   char *string;
   foo value;

   string = PG_GETARG_CSTRING(0);

   ...

   value = 0;
   PG_RETURN_INT32(value);
}

===================
DROP TYPE foo;

CREATE TYPE foo;

CREATE FUNCTION foo_in(cstring)
RETURNS foo
AS '$libdir/foo'
LANGUAGE C IMMUTABLE STRICT;

CREATE FUNCTION foo_out(foo)
RETURNS cstring
AS '$libdir/foo'
LANGUAGE C IMMUTABLE STRICT;

CREATE TYPE foo (
         INTERNALLENGTH = 4,
         ALIGNMENT = int4,
         STORAGE = plain,
         INPUT = foo_in,
         OUTPUT = foo_out
);


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

Предыдущее
От: "Chris Velevitch"
Дата:
Сообщение: How to join to delete
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Return value (instead of reference) for user defined type