Nick Raj <nickrajjain@gmail.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