mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-15 15:49:36 +02:00
Reapply e6d069787bb0c010c7afb55841754fb85dd123e0
and a1dc8305f0a369b97b6a9f44d4e97197f1983872 Author: Paul Licameli <paul.licameli@audacityteam.org> Date: Thu Feb 22 01:02:15 2018 -0500 Fix mistake in commit a1dc830 and add a comment Author: Paul Licameli <paul.licameli@audacityteam.org> Date: Wed Feb 21 15:46:18 2018 -0500 A function to extend XLisp's table of function bindings dynamically
This commit is contained in:
parent
9d61ee437a
commit
9b77109eff
@ -12,6 +12,7 @@ HISTORY
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <string.h> /* for memcpy */
|
||||||
#include "switches.h"
|
#include "switches.h"
|
||||||
#include "xlisp.h"
|
#include "xlisp.h"
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ LVAL xstoprecordio(void);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* the function table */
|
/* the function table */
|
||||||
FUNDEF funtab[] = {
|
FUNDEF init_funtab[] = {
|
||||||
|
|
||||||
/* read macro functions */
|
/* read macro functions */
|
||||||
{ NULL, S, rmhash }, /* 0 */
|
{ NULL, S, rmhash }, /* 0 */
|
||||||
@ -418,7 +419,32 @@ FUNDEF funtab[] = {
|
|||||||
|
|
||||||
{0,0,0} /* end of table marker */
|
{0,0,0} /* end of table marker */
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FUNDEF *funtab = init_funtab;
|
||||||
|
static size_t szfuntab = sizeof(init_funtab) / sizeof(*init_funtab);
|
||||||
|
|
||||||
|
int xlbindfunctions(FUNDEF *functions, size_t nfunctions)
|
||||||
|
{
|
||||||
|
/* This is written very generally, imposing no fixed upper limit on the
|
||||||
|
growth of the table. But perhaps a lightweight alternative with such a
|
||||||
|
limit could be conditionally compiled.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* malloc, not realloc, to leave old table unchanged in case of failure */
|
||||||
|
FUNDEF *newfuntab = malloc((szfuntab + nfunctions) * sizeof(FUNDEF));
|
||||||
|
if (!newfuntab)
|
||||||
|
return FALSE;
|
||||||
|
memcpy(newfuntab, funtab, (szfuntab - 1) * sizeof(FUNDEF));
|
||||||
|
memcpy(newfuntab + szfuntab - 1, functions, nfunctions * sizeof(FUNDEF));
|
||||||
|
FUNDEF sentinel = { 0, 0, 0 };
|
||||||
|
newfuntab[szfuntab + nfunctions - 1] = sentinel;
|
||||||
|
funtab = newfuntab;
|
||||||
|
szfuntab += nfunctions;
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
/* To do: deallocate funtab when XLisp runtime shuts down */
|
||||||
|
}
|
||||||
|
|
||||||
/* xnotimp does not return anything on purpose, so disable
|
/* xnotimp does not return anything on purpose, so disable
|
||||||
* "no return value" warning
|
* "no return value" warning
|
||||||
|
@ -182,7 +182,7 @@ int xlisave(const char *fname)
|
|||||||
/* xlirestore - restore a saved memory image */
|
/* xlirestore - restore a saved memory image */
|
||||||
int xlirestore(const char *fname)
|
int xlirestore(const char *fname)
|
||||||
{
|
{
|
||||||
extern FUNDEF funtab[];
|
extern FUNDEF *funtab;
|
||||||
char fullname[STRMAX+1];
|
char fullname[STRMAX+1];
|
||||||
unsigned char *cp;
|
unsigned char *cp;
|
||||||
int n,i,max,type;
|
int n,i,max,type;
|
||||||
|
@ -41,7 +41,7 @@ extern LVAL a_fixnum,a_flonum,a_string,a_stream,a_object;
|
|||||||
extern LVAL a_vector,a_closure,a_char,a_ustream,a_extern;
|
extern LVAL a_vector,a_closure,a_char,a_ustream,a_extern;
|
||||||
extern LVAL s_gcflag,s_gchook;
|
extern LVAL s_gcflag,s_gchook;
|
||||||
extern LVAL s_search_path;
|
extern LVAL s_search_path;
|
||||||
extern FUNDEF funtab[];
|
extern FUNDEF *funtab;
|
||||||
|
|
||||||
/* forward declarations */
|
/* forward declarations */
|
||||||
FORWARD LOCAL void initwks(void);
|
FORWARD LOCAL void initwks(void);
|
||||||
|
@ -683,6 +683,13 @@ void xlinit(void);
|
|||||||
void xlsymbols(void);
|
void xlsymbols(void);
|
||||||
|
|
||||||
|
|
||||||
|
/* xlftab.c */
|
||||||
|
/* returns true on success,
|
||||||
|
false if table limits would be exceeded and the table remains unchanged
|
||||||
|
Call this, any number of times, before calling xlisp_main_init
|
||||||
|
*/
|
||||||
|
int xlbindfunctions(FUNDEF *functions, size_t nfunctions);
|
||||||
|
|
||||||
/* xlio.c */
|
/* xlio.c */
|
||||||
|
|
||||||
int xlgetc(LVAL fptr);
|
int xlgetc(LVAL fptr);
|
||||||
|
@ -88,7 +88,7 @@ void xladdivar(LVAL cls, const char *var)
|
|||||||
/* xladdmsg - add a message to a class */
|
/* xladdmsg - add a message to a class */
|
||||||
void xladdmsg(LVAL cls, const char *msg, int offset)
|
void xladdmsg(LVAL cls, const char *msg, int offset)
|
||||||
{
|
{
|
||||||
extern FUNDEF funtab[];
|
extern FUNDEF *funtab;
|
||||||
LVAL mptr;
|
LVAL mptr;
|
||||||
|
|
||||||
/* enter the message selector */
|
/* enter the message selector */
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
/* external variables */
|
/* external variables */
|
||||||
extern LVAL s_printcase,k_downcase,k_const,k_nmacro;
|
extern LVAL s_printcase,k_downcase,k_const,k_nmacro;
|
||||||
extern LVAL s_ifmt,s_ffmt;
|
extern LVAL s_ifmt,s_ffmt;
|
||||||
extern FUNDEF funtab[];
|
extern FUNDEF *funtab;
|
||||||
extern char buf[];
|
extern char buf[];
|
||||||
|
|
||||||
LOCAL void putsymbol(LVAL fptr, char *str, int escflag);
|
LOCAL void putsymbol(LVAL fptr, char *str, int escflag);
|
||||||
|
@ -932,7 +932,7 @@ int xlisnumber(char *str, LVAL *pval)
|
|||||||
/* defmacro - define a read macro */
|
/* defmacro - define a read macro */
|
||||||
void defmacro(int ch, LVAL type, int offset)
|
void defmacro(int ch, LVAL type, int offset)
|
||||||
{
|
{
|
||||||
extern FUNDEF funtab[];
|
extern FUNDEF *funtab;
|
||||||
LVAL subr;
|
LVAL subr;
|
||||||
subr = cvsubr(funtab[offset].fd_subr,funtab[offset].fd_type,offset);
|
subr = cvsubr(funtab[offset].fd_subr,funtab[offset].fd_type,offset);
|
||||||
setelement(getvalue(s_rtable),ch,cons(type,subr));
|
setelement(getvalue(s_rtable),ch,cons(type,subr));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user