Intenta con:
Datum
ej2(PG_FUNCTION_ARGS)
{
int32 x = PG_GETARG_INT32(0);
text *t = PG_GETARG_TEXT_P(1);
int32 z;
int32 new_size = VARSIZE(t) - VARHDRSZ;
char *new = (char *) palloc(new_size + 1);
memcpy(new, VARDATA(t), new_size);
*(new + new_size) = '\0';
z = x*8;
elog(INFO, "Cadena: %s", new);
PG_RETURN_INT32(z);
}
También podrías usar algo como:
char *new = DatumGetCString(DirectFunctionCall1(textout,PointerGetDatum(t)));
y evitar toda la danza de copiar, etc.
Saludos,
Manuel.