From: | Ben <bench(at)silentmedia(dot)com> |
---|---|
To: | Teodor Sigaev <teodor(at)sigaev(dot)ru> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: making tsearch2 dictionaries |
Date: | 2004-02-16 16:29:39 |
Message-ID: | 1076948978.20248.28.camel@purple |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thanks for the replies. Just to clarify what I was doing, quaicode
looked something like:
phrase = palloc(8);
phrase = "foo\0bar\0";
res = palloc(3);
res[0] = phrase[0];
res[1] = phrase[5];
res[2] = 0;
That crashed. Once I changed it to:
res = palloc(3);
res[0] = palloc(4);
res[0] = "foo\0";
res[1] = palloc(4);
res[2] = "bar\0";
res[3] = 0;
it worked.
Anyway, I'm happy to forget my pain with this if only I could figure out
how to pipe the lexemes from one dictionary into another dictionary. :)
On Mon, 2004-02-16 at 08:09, Teodor Sigaev wrote:
> Excuse me, but I was too brief.
> I mean your lexize method of dictionary should return pointer to array with 3
> elements:
> first should points to "one" C-string, second - to "hundred" C-string and 3rd is
> NULL.
> Array and C-strings should be palloc'ed in short-lived context, because it's
> lives during parse text only.
>
>
>
>
> Tom Lane wrote:
> > Ben <bench(at)silentmedia(dot)com> writes:
> >
> >>Okay, so I was actually able to answer this question on my own, in a
> >>manner of speaking. It seems the way to do this is to merely return a
> >>larger char** array, with one element for each word. But I was having
> >>trouble with postgres crashing, because (I think) it tries to free each
> >>element independently before using all of them. I had set each element
> >>to a different null-terminated chunk of the same palloc'd memory
> >>segment. Having never written C stored procs before, I take it that's
> >>bad practice?
> >
> >
> > Given Teodor's response, I think the issue is probably that you were
> > palloc'ing in too short-lived a context. But whatever the problem is,
> > you'll narrow it down a lot faster if you build with --enable-cassert.
> > I wouldn't ever recommend trying to debug C functions without that.
> >
> > regards, tom lane
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 5: Have you checked our extensive FAQ?
> >
> > http://www.postgresql.org/docs/faqs/FAQ.html
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2004-02-16 16:40:39 | Re: PGSQL C API() |
Previous Message | Wei Wang | 2004-02-16 16:26:46 | How do I call multiple functions in one trigger? |