On Fri, 30 Aug 2002, Christopher Kings-Lynne wrote:
>
> --------------------------------
>
> struct varlena *data;
> char *word = "john";
> char *cur_pos = NULL;
> int cur_pos_length = 0;
>
> data = (struct varlena *) palloc(VARHDRSZ + column_length + 1);
> word_length = strlen(word);
> cur_pos = &word[word_length - 2];
>
> while(cur_pos > word)
> {
> cur_pos_length = strlen(cur_pos);
> /* Line below causes seg fault on SECOND iteration */
> data->vl_len = cur_pos_length + sizeof(int32);
> memcpy(VARDATA(data), cur_pos, cur_pos_length);
> values[0] = PointerGetDatum(data);
> values[1] = 0;
> values[2] = oid;
>
> ret = SPI_execp(*(plan->splan), values, NULL, 0);
> if(ret != SPI_OK_INSERT)
> elog(ERROR, "Full Text Indexing: error executing plan in insert\n");
>
> cur_pos--;
> }
>
That would imply the SPI_execp call is trashing the value of data. Have you
confirmed that? (Sometimes it helps to confirm exactly where a pointer is
getting hammered.)
column_length is something sensible like word_length I presume.
That sizeof(int32) should really be VARHDRSZ imo, but I can't see how that's
breaking it.
Disclaimer: I have no idea what I'm doing here.
--
Nigel J. Andrews