Return value (instead of reference) for user defined type - Mailing list pgsql-general

From Don Y
Subject Return value (instead of reference) for user defined type
Date
Msg-id 44570374.4060206@DakotaCom.Net
Whole thread Raw
Responses Re: Return value (instead of reference) for user defined type
List 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 by date:

Previous
From: "Chris Velevitch"
Date:
Subject: How to join to delete
Next
From: Tom Lane
Date:
Subject: Re: Return value (instead of reference) for user defined type