Обсуждение: Return value (instead of reference) for user defined type

Поиск
Список
Период
Сортировка

Return value (instead of reference) for user defined type

От
Don Y
Дата:
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
);


Re: Return value (instead of reference) for user defined type

От
Tom Lane
Дата:
Don Y <pgsql@DakotaCom.Net> writes:
> Nearest I can tell, the problem is related to my attempt to
> return an int "by value"

If that's what you intend, try cluing in CREATE TYPE (see
PASSEDBYVALUE).

            regards, tom lane

Re: Return value (instead of reference) for user defined

От
Don Y
Дата:
Tom Lane wrote:
> Don Y <pgsql@DakotaCom.Net> writes:
>> Nearest I can tell, the problem is related to my attempt to
>> return an int "by value"
>
> If that's what you intend, try cluing in CREATE TYPE (see
> PASSEDBYVALUE).

Thanks!  That did the trick!
--don