mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
alisp update
- garbage collector is out (replaced with references and auto-free) - added serious test lisp code to detect memory leaks - fixme: alisp_snd.c code needs review (remove memory leaks)
This commit is contained in:
parent
f3da5548b3
commit
46ed2fc9e8
6 changed files with 1451 additions and 531 deletions
1504
src/alisp/alisp.c
1504
src/alisp/alisp.c
File diff suppressed because it is too large
Load diff
|
|
@ -21,6 +21,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "list.h"
|
||||
|
||||
enum alisp_tokens {
|
||||
ALISP_IDENTIFIER,
|
||||
ALISP_INTEGER,
|
||||
|
|
@ -30,21 +32,31 @@ enum alisp_tokens {
|
|||
};
|
||||
|
||||
enum alisp_objects {
|
||||
ALISP_OBJ_NIL,
|
||||
ALISP_OBJ_T,
|
||||
ALISP_OBJ_INTEGER,
|
||||
ALISP_OBJ_FLOAT,
|
||||
ALISP_OBJ_IDENTIFIER,
|
||||
ALISP_OBJ_STRING,
|
||||
ALISP_OBJ_POINTER,
|
||||
ALISP_OBJ_CONS
|
||||
ALISP_OBJ_CONS,
|
||||
ALISP_OBJ_LAST_SEARCH = ALISP_OBJ_CONS,
|
||||
ALISP_OBJ_NIL,
|
||||
ALISP_OBJ_T,
|
||||
};
|
||||
|
||||
struct alisp_object;
|
||||
|
||||
#define ALISP_MAX_REFS 0x0fffffff
|
||||
#define ALISP_MAX_REFS_LIMIT ((ALISP_MAX_REFS + 1) / 2)
|
||||
|
||||
#define ALISP_TYPE_MASK 0xf0000000
|
||||
#define ALISP_TYPE_SHIFT 28
|
||||
#define ALISP_REFS_MASK 0x0fffffff
|
||||
#define ALISP_REFS_SHIFT 0
|
||||
|
||||
struct alisp_object {
|
||||
unsigned char type;
|
||||
unsigned char gc;
|
||||
struct list_head list;
|
||||
unsigned int type_refs; /* type and count of references */
|
||||
union {
|
||||
char *id;
|
||||
char *s;
|
||||
long i;
|
||||
double f;
|
||||
|
|
@ -54,16 +66,61 @@ struct alisp_object {
|
|||
struct alisp_object *cdr;
|
||||
} c;
|
||||
} value;
|
||||
struct alisp_object *next;
|
||||
};
|
||||
|
||||
static inline enum alisp_objects alisp_get_type(struct alisp_object *p)
|
||||
{
|
||||
return (p->type_refs >> ALISP_TYPE_SHIFT);
|
||||
}
|
||||
|
||||
static inline void alisp_set_type(struct alisp_object *p, enum alisp_objects type)
|
||||
{
|
||||
p->type_refs &= ~ALISP_TYPE_MASK;
|
||||
p->type_refs |= (unsigned int)type << ALISP_TYPE_SHIFT;
|
||||
}
|
||||
|
||||
static inline int alisp_compare_type(struct alisp_object *p, enum alisp_objects type)
|
||||
{
|
||||
return ((unsigned int)type << ALISP_TYPE_SHIFT) ==
|
||||
(p->type_refs & ALISP_TYPE_MASK);
|
||||
}
|
||||
|
||||
static inline void alisp_set_refs(struct alisp_object *p, unsigned int refs)
|
||||
{
|
||||
p->type_refs &= ~ALISP_REFS_MASK;
|
||||
p->type_refs |= refs & ALISP_REFS_MASK;
|
||||
}
|
||||
|
||||
static inline unsigned int alisp_get_refs(struct alisp_object *p)
|
||||
{
|
||||
return p->type_refs & ALISP_REFS_MASK;
|
||||
}
|
||||
|
||||
static inline unsigned int alisp_inc_refs(struct alisp_object *p)
|
||||
{
|
||||
unsigned r = alisp_get_refs(p) + 1;
|
||||
alisp_set_refs(p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline unsigned int alisp_dec_refs(struct alisp_object *p)
|
||||
{
|
||||
unsigned r = alisp_get_refs(p) - 1;
|
||||
alisp_set_refs(p, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
struct alisp_object_pair {
|
||||
struct alisp_object *name;
|
||||
struct list_head list;
|
||||
const char *name;
|
||||
struct alisp_object *value;
|
||||
struct alisp_object_pair *next;
|
||||
};
|
||||
|
||||
#define ALISP_LEX_BUF_MAX 16
|
||||
#define ALISP_LEX_BUF_MAX 16
|
||||
#define ALISP_OBJ_PAIR_HASH_SHIFT 4
|
||||
#define ALISP_OBJ_PAIR_HASH_SIZE (1<<ALISP_OBJ_PAIR_HASH_SHIFT)
|
||||
#define ALISP_OBJ_PAIR_HASH_MASK (ALISP_OBJ_PAIR_HASH_SIZE-1)
|
||||
#define ALISP_FREE_OBJ_POOL 512 /* free objects above this pool */
|
||||
|
||||
struct alisp_instance {
|
||||
int verbose: 1,
|
||||
|
|
@ -84,15 +141,12 @@ struct alisp_instance {
|
|||
char *token_buffer;
|
||||
int token_buffer_max;
|
||||
int thistoken;
|
||||
/* object allocator */
|
||||
/* object allocator / storage */
|
||||
long free_objs;
|
||||
long used_objs;
|
||||
long max_objs;
|
||||
long gc_thr_objs;
|
||||
struct alisp_object *free_objs_list;
|
||||
struct alisp_object *used_objs_list;
|
||||
struct list_head free_objs_list;
|
||||
struct list_head used_objs_list[ALISP_OBJ_PAIR_HASH_SIZE][ALISP_OBJ_LAST_SEARCH + 1];
|
||||
/* set object */
|
||||
struct alisp_object_pair *setobjs_list;
|
||||
/* garbage collect */
|
||||
unsigned char gc_id;
|
||||
struct list_head setobjs_list[ALISP_OBJ_PAIR_HASH_SIZE];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,14 +32,14 @@ struct acall_table {
|
|||
|
||||
static inline int get_integer(struct alisp_object * obj)
|
||||
{
|
||||
if (obj->type == ALISP_OBJ_INTEGER)
|
||||
if (alisp_compare_type(obj, ALISP_OBJ_INTEGER))
|
||||
return obj->value.i;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline const void *get_pointer(struct alisp_object * obj)
|
||||
{
|
||||
if (obj->type == ALISP_OBJ_POINTER)
|
||||
if (alisp_compare_type(obj, ALISP_OBJ_POINTER))
|
||||
return obj->value.ptr;
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -48,10 +48,9 @@ static const char *get_string(struct alisp_object * obj, const char * deflt)
|
|||
{
|
||||
if (obj == &alsa_lisp_t)
|
||||
return "true";
|
||||
if (obj->type == ALISP_OBJ_STRING)
|
||||
if (alisp_compare_type(obj, ALISP_OBJ_STRING) ||
|
||||
alisp_compare_type(obj, ALISP_OBJ_IDENTIFIER))
|
||||
return obj->value.s;
|
||||
if (obj->type == ALISP_OBJ_IDENTIFIER)
|
||||
return obj->value.id;
|
||||
return deflt;
|
||||
}
|
||||
|
||||
|
|
@ -343,7 +342,7 @@ static struct alisp_object * FA_int_intp(struct alisp_instance * instance, struc
|
|||
int val, err;
|
||||
|
||||
args = eval(instance, car(args));
|
||||
if (args->type != ALISP_OBJ_INTEGER)
|
||||
if (!alisp_compare_type(args, ALISP_OBJ_INTEGER))
|
||||
return &alsa_lisp_nil;
|
||||
val = args->value.i;
|
||||
err = ((snd_int_intp_t)item->xfunc)(&val);
|
||||
|
|
@ -355,7 +354,8 @@ static struct alisp_object * FA_int_str(struct alisp_instance * instance, struct
|
|||
int err;
|
||||
|
||||
args = eval(instance, car(args));
|
||||
if (args->type != ALISP_OBJ_STRING && args->type != ALISP_OBJ_IDENTIFIER)
|
||||
if (!alisp_compare_type(args, ALISP_OBJ_STRING) &&
|
||||
!alisp_compare_type(args, ALISP_OBJ_IDENTIFIER))
|
||||
return &alsa_lisp_nil;
|
||||
err = ((snd_int_str_t)item->xfunc)(args->value.s);
|
||||
return new_integer(instance, err);
|
||||
|
|
@ -367,7 +367,7 @@ static struct alisp_object * FA_int_int_strp(struct alisp_instance * instance, s
|
|||
char *str;
|
||||
|
||||
args = eval(instance, car(args));
|
||||
if (args->type != ALISP_OBJ_INTEGER)
|
||||
if (!alisp_compare_type(args, ALISP_OBJ_INTEGER))
|
||||
return &alsa_lisp_nil;
|
||||
err = ((snd_int_int_strp_t)item->xfunc)(args->value.i, &str);
|
||||
return new_result3(instance, err, str);
|
||||
|
|
@ -422,9 +422,8 @@ static int parse_ctl_elem_id(struct alisp_object * cons, snd_ctl_elem_id_t * id)
|
|||
id->numid = 0;
|
||||
do {
|
||||
p1 = car(cons);
|
||||
if (p1->type == ALISP_OBJ_CONS) {
|
||||
if (alisp_compare_type(p1, ALISP_OBJ_CONS)) {
|
||||
xid = get_string(p1->value.c.car, NULL);
|
||||
printf("id = '%s'\n", xid);
|
||||
if (xid == NULL) {
|
||||
/* noop */
|
||||
} else if (!strcmp(xid, "numid")) {
|
||||
|
|
@ -723,7 +722,8 @@ static struct alisp_object * F_acall(struct alisp_instance *instance, struct ali
|
|||
struct acall_table key, *item;
|
||||
|
||||
p1 = eval(instance, car(args));
|
||||
if (p1->type != ALISP_OBJ_IDENTIFIER && p1->type != ALISP_OBJ_STRING)
|
||||
if (!alisp_compare_type(p1, ALISP_OBJ_IDENTIFIER) &&
|
||||
!alisp_compare_type(p1, ALISP_OBJ_STRING))
|
||||
return &alsa_lisp_nil;
|
||||
p2 = cdr(args);
|
||||
key.name = p1->value.s;
|
||||
|
|
@ -760,7 +760,7 @@ static int common_error(snd_output_t **rout, struct alisp_instance *instance, st
|
|||
|
||||
do {
|
||||
p1 = eval(instance, car(p));
|
||||
if (p1->type == ALISP_OBJ_STRING)
|
||||
if (alisp_compare_type(p1, ALISP_OBJ_STRING))
|
||||
snd_output_printf(out, "%s", p1->value.s);
|
||||
else
|
||||
princ_object(out, p1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue