Thread: C function and enum types parameters

C function and enum types parameters

From
Edoardo Panfili
Date:
I use a C function in my database from 2002, all goes well also with
postgresql 8.3 but with 8.3.1 it no longer works, the problem is with
this line:

text *hibrid = (PG_ARGISNULL( 0) ||
VARSIZE(PG_GETARG_TEXT_P( 0))==VARHDRSZ ?NULL:PG_GETARG_TEXT_P(0));

the argument number 0 is an enum defined by

CREATE TYPE hibridationLevel AS ENUM('none','genus','specie');

the error is "ERROR:  invalid memory alloc request size 2298488997"

I can't figure by now how to correct my error, can anyone help me?

thank you
edoardo
--
Jabber: edoardopa@talk.google.com
tel: 075 9142766

Re: C function and enum types parameters

From
Edoardo Panfili
Date:
Edoardo Panfili ha scritto:
> I use a C function in my database from 2002, all goes well also with
> postgresql 8.3 but with 8.3.1 it no longer works, the problem is with
> this line:
>
> text *hibrid = (PG_ARGISNULL( 0) ||
> VARSIZE(PG_GETARG_TEXT_P( 0))==VARHDRSZ ?NULL:PG_GETARG_TEXT_P(0));
>
> the argument number 0 is an enum defined by
>
> CREATE TYPE hibridationLevel AS ENUM('none','genus','specie');
>
> the error is "ERROR:  invalid memory alloc request size 2298488997"
>
> I can't figure by now how to correct my error, can anyone help me?
>
I am still working on this after further investigation I can see that
the function is not correct also under postgres 8.3 (but it not raises
the error)

Is seems OK to retrieve the enum argument using
Oid oid = PG_GETARG_OID(0);
But using this way I can see only the Oid.

Can anyone confirm that this is the correct way to work with enum inside
a function?.

This is my little test case
-----------------------function--------------------------------
Datum prova1(PG_FUNCTION_ARGS){
     Oid oid = PG_GETARG_OID(0);
     ereport(WARNING, (errmsg_internal("(1) parametro1: %d", oid)));
}
-----------------------SQL definition--------------------------
CREATE FUNCTION prova1(hibridationLevel,text) RETURNS int
    AS 'funzioniGDB2.so' LANGUAGE C WITH (iscachable);"
---------------------------------------------------------------

thank you
Edoardo
--
Jabber: edoardopa@talk.google.com
tel: 075 9142766