bug-bash
[Top][All Lists]
Advanced

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

Changes coming in Readline-4.2


From: Chet Ramey
Subject: Changes coming in Readline-4.2
Date: Tue, 31 Oct 2000 13:14:39 -0500

I've been getting questions and bug reports from people attempting to link
their C++ code with readline.  They're running into two problems: `const'
and function pointers.  I've fixed both, but this message is about the
second topic.  (Readline-4.2 does use `const' arguments where appropriate,
but that's not very interesting.)

Readline-4.1 uses four typedefs for function pointers:

        typedef int Function ();
        typedef void VFunction ();
        typedef char *CPFunction ();
        typedef char **CPPFunction ();

This is good enough for C code, but C++ really wants to check that
function prototypes match exactly.  These definitions are shared
between readline, the tilde library, and bash, and each must avoid
redefining them.  They also contribute to namespace pollution -- no
code that links against readline can use these typedefs for anything
else.

I have just finished modifying the readline source to use a new set
of typedefs for function pointers, all fully prototyped, and all using
the `rl_' prefix.  The readline and history libraries no longer use
any of the four typedefs above internally.  I also modified the tilde 
library, and it now uses a single new typedef, with a `tilde_' prefix
(typedef char *tilde_hook_func_t __P((char *)); for the curious),
replacing the previous use of `CPFunction *'.

Here's the guts of the new `rltypedefs.h' header file, containing the
new typedef declarations.

#if !defined (_RL_FUNCTION_TYPEDEF)
#  define _RL_FUNCTION_TYPEDEF

/* Bindable functions */
typedef int rl_command_func_t __P((int, int));

/* Typedefs for the completion system */
typedef char *rl_compentry_func_t __P((const char *, int));
typedef char **rl_completion_func_t __P((char *, int, int));

typedef char *rl_quote_func_t __P((char *, int, char *));
typedef char *rl_dequote_func_t __P((char *, int));

typedef int rl_compignore_func_t __P((char **));

typedef void rl_compdisp_func_t __P((char **, int, int));

/* Type for input and pre-read hook functions like rl_event_hook */
typedef int rl_hook_func_t __P((void));

/* Input function type */
typedef int rl_getc_func_t __P((FILE *));

/* Generic function that takes a character buffer (which could be the readline
   line buffer) and an index into it (which could be rl_point) and returns
   an int. */
typedef int rl_linebuf_func_t __P((char *, int));

/* `Generic' function pointer typedefs */
typedef int rl_intfunc_t __P((int));
#define rl_ivoidfunc_t rl_hook_func_t
typedef int rl_icpfunc_t __P((char *));
typedef int rl_icppfunc_t __P((char **));

typedef void rl_voidfunc_t __P((void));
typedef void rl_vintfunc_t __P((int));
typedef void rl_vcpfunc_t __P((char *));
typedef void rl_vcppfunc_t __P((char **));

#endif /* _RL_FUNCTION_TYPEDEF */

There are so many because I was very careful not to change the return value
or parameters of any of the existing functions.  This should ensure that
old code continues to work -- in fact, before I changed bash to use the
new prototypes, I rebuilt the parts of bash that use readline, and they
compiled correctly.

The intent is that the old typedefs will continue to work for one more
release, and then will be removed from the public header files.  This
should give everyone enough time to update his or her code.

I did change the type of one readline variable:

        rl_completion_entry_function

The code that called through this pointer always expected it to return a
char *, which required a lot of messy casting, and which did not work on
all architectures.  rl_completion_entry_function is now a pointer to an
rl_compentry_func_t, which, as above, is a function returning a char *.
I should have done this a while ago.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet)

Chet Ramey, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]