2

I'm using a Postgresql 9.2 installation and I'm trying to get an extension (I have programmed) to run.

This code compiles, and I can load it into Postgresql; but every time I try to do an INSERT, the connection to the DB stops. I guess the reason for that is that my in-function is somehow broken.

First to the typedef:

typedef struct tphys {
   char   length[4];
   char   data[1];
} tphys;

As you see, I have a data-type that is meant to be unlimited in size. And now to the in-code:

PG_FUNCTION_INFO_V1(tphys_data_in);
Datum
tphys_data_in(PG_FUNCTION_ARGS)
{
   char *in  = PG_GETARG_CSTRING(0);
   tphys *dest = (tphys *) palloc(VARHDRSZ + VARSIZE(in));

   SET VARSIZE(dest, VARHDRSZ + VARSIZE(in));
   memcpy(VARDATA(dest), in, VARSIZE(in));

   PG_RETURN_POINTER(dest);
}

I've been trying with this code quite some time, and I really don't know where the error is. Do you maybe see it?

1 Answer 1

3

You cannot use VARSIZE macro for cstring type.

char *instr = PG_GETAR_CSTRING(0);
tphys *dest = (phhys *) palloc(VARHDRSZ + strlen(instr));

...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.