I'm experiencing much trouble making use of the V1 custom c function
definition framework built into postgres, probably by virtue of my lack of
experience with C.

In a nutshell, I've paid close attention to the documentation, have had some
success getting useful code out of the version 0 naming convention for
simple return types, but need to do some variable-length text processing (to
write a crc hash function). My basic question is how to usefully get through
the header architecture into some actual data so that I can do an some
calculations and return a useful result.

The simplest possible example I could come up with was a slight modification
one of the documentation's "variable length, by reference" examples:

PG_FUNCTION_INFO_V1(par);
Datum par(PG_FUNCTION_ARGS) // pete and repeat! takes text struct pointer
{
  text *t = PG_GETARG_TEXT_P(0);
  text *new_t = (text*) palloc(VARSIZE(t));
  VARATT_SIZEP(new_t) = VARSIZE(t);
  memcpy((void*) VARDATA(new_t),(void*)VARDATA(t),VARSIZE(t) - VARHDRSZ);
  char *ptr = (char*) VARDATA(new_t);
  *ptr = 'Q'; // NO EFFECT
  PG_RETURN_TEXT(new_t);
}

The "no effect" comment applies to trying to rewrite to the same memory,
write from some static type I define, etc, etc. I'm guessing there's a const
declaration hiding somewhere that I'm missing. I'd really love to look at
some documentation for what a text struct actually IS so that I can use an
indirection operator to get its internals. But I'm guessing that's not the
appropriate way to do it...

--
========================================================
Jason Nerothin
Programmer/Analyst IV - Database Administration
UCLA-DOE Institute for Genomics & Proteomics
Howard Hughes Medical Institute
========================================================
611 C.E. Young Drive East   | Tel: (310) 206-3907
105 Boyer Hall, Box 951570  | Fax: (310) 206-3914
Los Angeles, CA 90095. USA | Mail: [EMAIL PROTECTED]
========================================================
http://www.mbi.ucla.edu/~jason
========================================================

Reply via email to