From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Nick Raj <nickrajjain(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Defining input function for new datatype |
Date: | 2011-04-21 14:47:20 |
Message-ID: | 9759.1303397240@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
Nick Raj <nickrajjain(at)gmail(dot)com> writes:
> 1 Datum mpoint_in(PG_FUNCTION_ARGS)
> 2 {
> 3
> 4 mpoint *result;
> 5 char *pnt=(char *)malloc (sizeof (20));
> 6 char *ts=(char *)malloc (sizeof (20));
(1) You should *not* use malloc here. There is seldom any reason to use
malloc directly at all in functions coded for Postgres. Use palloc,
or expect memory leaks.
(2) sizeof(20) almost certainly doesn't mean what you want. It's most
likely 4 ...
> 11 result->p = point_in(PointerGetDatum(pnt)); //
> point_in (input function for point that assigns x, y into point)
You need to use DirectFunctionCallN when trying to call a function that
obeys the PG_FUNCTION_ARGS convention, as point_in does. And the result
is a Datum, which means you're going to need to apply a DatumGetWhatever
macro to get a bare Point or Timestamp from these functions.
Look around in the PG sources for examples.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Greg Smith | 2011-04-21 14:49:28 | Re: SSDs with Postgresql? |
Previous Message | Chris Greenhill | 2011-04-21 14:38:05 | Re: Trouble loading Perl modules from postgresql.conf |
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2011-04-21 15:04:01 | Re: Formatting Curmudgeons WAS: MMAP Buffers |
Previous Message | Andres Freund | 2011-04-21 14:31:15 | Re: hot backups: am I doing it wrong, or do we have a problem with pg_clog? |