Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: libedit trouble



On Fri, Feb 20, 2009 at 06:29:25PM +0000, Christos Zoulas wrote:
> In article <20090219200933.GB29459%shaak.vert-toit.net@localhost>,
> Quentin Garnier  <cube%cubidou.net@localhost> wrote:
> >-=-=-=-=-=-
> >
> >On Thu, Feb 19, 2009 at 06:56:27PM +0000, Patrick Welche wrote:
> >> Using "bc" as the libedit using test programme,
> >> 
> >> Core was generated by `bc'.
> >> Program terminated with signal 11, Segmentation fault.
> >> #0  0xbb934070 in ?? ()
> >> (gdb) bt
> >> #0  0xbb934070 in ?? ()
> >> #1  0xbbbd58e7 in prompt_print (el=0xbb90cc00, op=0)
> >>     at /usr/src/lib/libedit/prompt.c:95
> >> #2  0xbbbd6aed in re_refresh (el=0xbb90cc00)
> >>     at /usr/src/lib/libedit/refresh.c:220
> >> #3  0xbbbd609b in read_prepare (el=0xbb90cc00)
> >>     at /usr/src/lib/libedit/read.c:394
> >> #4  0xbbbd624a in el_gets (el=0xbb90cc00, nread=0x80584a0)
> >>     at /usr/src/lib/libedit/read.c:466
> >> #5  0x0804fd59 in yy_get_next_buffer ()
> >> #6  0x08050207 in yylex ()
> >> #7  0x08049512 in yyparse ()
> >> #8  0x0804cbcb in main ()
> >> 
> >> frame 1 el contains
> >> 
> >> el_prompt = {
> >>     p_func = 0xbb934070, p_pos = {h = 0, v = 0}, p_arg = 0x804f570}, 
> >>   el_rprompt = {p_func = 0xbbbd58a0 <prompt_default_r>, p_pos = {h = 0, 
> >>       v = 0}, p_arg = 0x0}
> >> 
> >> Not obvious what's up...
> >
> >If I make bc call el_set (edit, EL_PROMPT, null_prompt, NULL) like I
> >think it should now, it doesn't dump core anymore, but it displays the
> >'?' prompt...
> 
> Crap, I thought that the last argument was guaranteed to be null varyadic
> functions.

Christos and I briefly talked about the variadic function, and I
thought the same as him, but obviously not. What I'd propose is a
different approach to the problem of getting at a private data pointer
from within the user-supplied prompt function, when all you have
available is a pointer to an EditLine struct (which is itself opaque).

1. Modify the EditLine struct to have a void * private data pointer.

2. provide an el_set(edit, EL_PRIVATE_DATA, void *vp) function

3. provide a corresponding el_get(edit, EL_PRIVATE_DATA, void *vp) function
to return the same value

4. Keep the EL_PROMPT signature as it was previously (we have no way of
ensuring that third-party code is not in the same boat as bc was)

That way we can access a pointer to a private structure anywhere, and
retrieve the pointer from within the prompting function.

Regards,
Alistair


Home | Main Index | Thread Index | Old Index