1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-03 07:10:10 +01:00
and a1dc8305f0

    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:
Leland Lucius
2019-12-15 22:57:40 -06:00
parent 9d61ee437a
commit 9b77109eff
7 changed files with 40 additions and 7 deletions

View File

@@ -12,6 +12,7 @@ HISTORY
*/
#include <string.h> /* for memcpy */
#include "switches.h"
#include "xlisp.h"
@@ -33,7 +34,7 @@ LVAL xstoprecordio(void);
#endif
/* the function table */
FUNDEF funtab[] = {
FUNDEF init_funtab[] = {
/* read macro functions */
{ NULL, S, rmhash }, /* 0 */
@@ -418,7 +419,32 @@ FUNDEF funtab[] = {
{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
* "no return value" warning