Return value (instead of reference) for user defined type

From: Don Y <pgsql(at)DakotaCom(dot)Net>
To: pgsql-general(at)postgresql(dot)org
Subject: Return value (instead of reference) for user defined type
Date: 2006-05-02 07:00:04
Message-ID: 44570374.4060206@DakotaCom.Net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
);

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Noel Faux 2006-05-02 07:03:09 Re: How to join to delete
Previous Message Chris Velevitch 2006-05-02 06:53:58 How to join to delete