UDFs

From: jf <jf(at)danglingpointers(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: UDFs
Date: 2007-08-13 15:17:36
Message-ID: Pine.LNX.4.64.0708131512500.4503@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi.

Trying to implement some simple digest routines via UDFs and for whatever
reason I get: ERROR: invalid memory alloc request size 4294967293 on
PG_RETURN_TEXT_P(); any ideas what the issue is exactly?

The code is verified as working when pulled out of a UDF and put into a
normal C program. Thanks.

dp_blag=# CREATE OR REPLACE FUNCTION sha512(text) RETURNS text AS
'dp_sha512.so','dp_sha512' LANGUAGE C STRICT;
CREATE FUNCTION
dp_blag=# SELECT sha512('jf');
ERROR: invalid memory alloc request size 4294967293

PG_FUNCTION_INFO_V1(dp_sha512);

Datum
dp_sha512(PG_FUNCTION_ARGS)
{
text * hash;
text * plain;
int32 hlen;

plain = (text *)PG_GETARG_TEXT_P(0);

if (NULL == plain) {
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("invalid argument to function"))
);
PG_RETURN_NULL();
}

hlen = SHA512_DIGEST_LENGTH;

hash = (text *)palloc(hlen+1);

if (NULL == hash) {
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("palloc() failed"))
);
PG_RETURN_NULL();
}

memset(VARDATA(hash), 0, hlen);
SHA512(VARDATA(plain), hlen, VARDATA(hash));
PG_RETURN_TEXT_P(hash);
}

Responses

  • Re: UDFs at 2007-08-13 08:39:17 from Pavel Stehule
  • Re: UDFs at 2007-08-13 08:42:52 from Martijn van Oosterhout
  • Re: UDFs at 2007-08-13 09:29:58 from hubert depesz lubaczewski

Browse pgsql-general by date

  From Date Subject
Next Message Lim Berger 2007-08-13 15:18:03 Re: "Out of memory" errors..
Previous Message Lim Berger 2007-08-13 15:12:59 Re: "Out of memory" errors..