OSDN Git Service

More alisp changes
authorJaroslav Kysela <perex@perex.cz>
Fri, 1 Aug 2003 18:21:19 +0000 (18:21 +0000)
committerJaroslav Kysela <perex@perex.cz>
Fri, 1 Aug 2003 18:21:19 +0000 (18:21 +0000)
alsalisp/hctl.lisp
src/alisp/alisp.c
src/alisp/alisp_snd.c

index 4d82ede..bcf4ec0 100644 (file)
        (princ "last     : " (acall 'hctl_last_elem hctl) "\n")
        (princ "next (first): " (acall 'hctl_elem_next (acall 'hctl_first_elem hctl)) "\n")
        (princ "prev (last) : " (acall 'hctl_elem_prev (acall 'hctl_last_elem hctl)) "\n")
-       (princ "first info  : " (acall 'hctl_elem_info (acall 'hctl_first_elem hctl)) "\n")
+       (setq elem (acall 'hctl_first_elem hctl))
+       (while elem
+         (progn
+           (setq info (acall 'hctl_elem_info elem))
+           (princ info "\n")
+           (setq elem (acall 'hctl_elem_next elem))
+         )
+        )
         (setq hctl (acall 'hctl_close hctl))
         (if (= hctl 0)
           (princ "hctl close success\n")
@@ -66,3 +73,5 @@
     (princ "ctl open failed: " ctl "\n")
   )
 )
+
+(&stat-memory)
index 6d3f15d..3c41f72 100644 (file)
@@ -683,6 +683,7 @@ static const char *obj_type_str(struct alisp_object * p)
        case ALISP_OBJ_FLOAT: return "float";
        case ALISP_OBJ_IDENTIFIER: return "identifier";
        case ALISP_OBJ_STRING: return "string";
+       case ALISP_OBJ_POINTER: return "pointer";
        case ALISP_OBJ_CONS: return "cons";
        default: assert(0);
        }
@@ -777,10 +778,14 @@ static void do_garbage_collect(struct alisp_instance *instance)
                        lisp_debug(instance, "** collecting cons %p", p);
                        free_object(p);
 
-                       p->next = instance->free_objs_list;
-                       instance->free_objs_list = p;
+                       if (instance->free_objs < 1000) {
+                               p->next = instance->free_objs_list;
+                               instance->free_objs_list = p;
+                               ++instance->free_objs;
+                       } else {
+                               free(p);
+                       }
 
-                       ++instance->free_objs;
                        --instance->used_objs;
                } else {
                        /* The object is referenced somewhere. */
@@ -1884,6 +1889,17 @@ static struct alisp_object * F_dump_memory(struct alisp_instance *instance, stru
        return &alsa_lisp_nil;
 }
 
+static struct alisp_object * F_stat_memory(struct alisp_instance *instance, struct alisp_object * args ATTRIBUTE_UNUSED)
+{
+       snd_output_printf(instance->out, "*** Memory stats\n");
+       snd_output_printf(instance->out, "  used_objs = %i, free_objs = %i, obj_size = %i (total = %i)\n",
+               instance->used_objs,
+               instance->free_objs,
+               sizeof(struct alisp_object),
+               (instance->used_objs + instance->free_objs) * sizeof(struct alisp_object));
+       return &alsa_lisp_nil;
+}
+
 static struct alisp_object * F_dump_objects(struct alisp_instance *instance, struct alisp_object * args)
 {
        struct alisp_object * p = car(args);
@@ -1909,6 +1925,7 @@ static struct intrinsic intrinsics[] = {
        { "%", F_mod },
        { "&dump-memory", F_dump_memory },
        { "&dump-objects", F_dump_objects },
+       { "&stat-memory", F_stat_memory },
        { "*", F_mul },
        { "+", F_add },
        { "-", F_sub },
index a3f8ef1..4383c0d 100644 (file)
@@ -137,6 +137,30 @@ static struct alisp_object * add_cons(struct alisp_instance * instance, struct a
        return lexpr;
 }
 
+static struct alisp_object * add_cons1(struct alisp_instance * instance, struct alisp_object *lexpr, int cdr, int id, struct alisp_object *obj)
+{
+       struct alisp_object * p1;
+
+       if (lexpr == NULL || obj == NULL)
+               return NULL;
+       if (cdr) {
+               p1 = lexpr->value.c.cdr = new_object(instance, ALISP_OBJ_CONS);
+       } else {
+               p1 = lexpr->value.c.car = new_object(instance, ALISP_OBJ_CONS);
+       }
+       lexpr = p1;
+       if (p1 == NULL)
+               return NULL;
+       p1->value.c.car = new_object(instance, ALISP_OBJ_CONS);
+       if ((p1 = p1->value.c.car) == NULL)
+               return NULL;
+       p1->value.c.car = new_integer(instance, id);
+       if (p1->value.c.car == NULL)
+               return NULL;
+       p1->value.c.cdr = obj;
+       return lexpr;
+}
+
 static inline struct alisp_object * new_result(struct alisp_instance * instance, int err)
 {
        return new_integer(instance, err);
@@ -361,7 +385,7 @@ static struct alisp_object * FA_card_info(struct alisp_instance * instance, stru
 static struct alisp_object * create_ctl_elem_id(struct alisp_instance * instance, snd_ctl_elem_id_t * id, struct alisp_object * cons)
 {
        cons = add_cons(instance, cons, 0, "numid", new_integer(instance, snd_ctl_elem_id_get_numid(id)));
-       cons = add_cons(instance, cons, 1, "iface", new_string(instance, snd_ctl_elem_iface_name(snd_ctl_elem_id_get_numid(id))));
+       cons = add_cons(instance, cons, 1, "iface", new_string(instance, snd_ctl_elem_iface_name(snd_ctl_elem_id_get_interface(id))));
        cons = add_cons(instance, cons, 1, "dev", new_integer(instance, snd_ctl_elem_id_get_device(id)));
        cons = add_cons(instance, cons, 1, "subdev", new_integer(instance, snd_ctl_elem_id_get_subdevice(id)));
        cons = add_cons(instance, cons, 1, "name", new_string(instance, snd_ctl_elem_id_get_name(id)));
@@ -402,8 +426,21 @@ static struct alisp_object * FA_hctl_elem_info(struct alisp_instance * instance,
        p1 = add_cons(instance, p1, 1, "isowner", new_integer(instance, snd_ctl_elem_info_is_owner(info)));
        p1 = add_cons(instance, p1, 1, "owner", new_integer(instance, snd_ctl_elem_info_get_owner(info)));
        p1 = add_cons(instance, p1, 1, "count", new_integer(instance, snd_ctl_elem_info_get_count(info)));
-       if (type == SND_CTL_ELEM_TYPE_ENUMERATED)
-               p1 = add_cons(instance, p1, 1, "items", new_integer(instance, snd_ctl_elem_info_get_items(info)));
+       if (type == SND_CTL_ELEM_TYPE_ENUMERATED) {
+               unsigned int items, item;
+               items = snd_ctl_elem_info_get_items(info);
+               p1 = add_cons(instance, p1, 1, "items", new_integer(instance, items));
+               p1 = add_cons(instance, p1, 1, "inames", p2 = new_object(instance, ALISP_OBJ_CONS));
+               for (item = 0; item < items; item++) {
+                       snd_ctl_elem_info_set_item(info, item);
+                       err = snd_hctl_elem_info(handle, info);
+                       if (err < 0) {
+                               p2 = add_cons1(instance, p2, item > 0, item, &alsa_lisp_nil);
+                       } else {
+                               p2 = add_cons1(instance, p2, item > 0, item, new_string(instance, snd_ctl_elem_info_get_item_name(info)));
+                       }
+               }
+       }
        if (p1 == NULL)
                return NULL;
        return lexpr;