summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2016-07-14 23:07:49 +0900
committerTakashi Iwai <tiwai@suse.de>2016-07-14 16:33:52 +0200
commit499b0c04017d400654ec637dcf86c9092d7f3908 (patch)
treea199350384127acbe0baa7569a484a36644ec59c
parentf3562bea35dcd87d28d3f2609d6e2fab809d09ed (diff)
downloadalsa-lib-499b0c04017d400654ec637dcf86c9092d7f3908.tar.gz
alisp: remove alloca() from FA_hctl_elem_read()
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures. This commit obsolete usages of alloca() with automatic variables. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--src/alisp/alisp_snd.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/alisp/alisp_snd.c b/src/alisp/alisp_snd.c
index c63806be..6d5018af 100644
--- a/src/alisp/alisp_snd.c
+++ b/src/alisp/alisp_snd.c
@@ -622,8 +622,8 @@ static struct alisp_object * FA_hctl_elem_read(struct alisp_instance * instance,
{
snd_hctl_elem_t *handle;
struct alisp_object * lexpr, * p1 = NULL, * obj;
- snd_ctl_elem_info_t *info;
- snd_ctl_elem_value_t *value;
+ snd_ctl_elem_info_t info = {0};
+ snd_ctl_elem_value_t value = {0};
snd_ctl_elem_type_t type;
unsigned int idx, count;
int err;
@@ -634,16 +634,14 @@ static struct alisp_object * FA_hctl_elem_read(struct alisp_instance * instance,
handle = (snd_hctl_elem_t *)get_ptr(instance, p1, item->prefix);
if (handle == NULL)
return &alsa_lisp_nil;
- snd_ctl_elem_info_alloca(&info);
- snd_ctl_elem_value_alloca(&value);
- err = snd_hctl_elem_info(handle, info);
+ err = snd_hctl_elem_info(handle, &info);
if (err >= 0)
- err = snd_hctl_elem_read(handle, value);
+ err = snd_hctl_elem_read(handle, &value);
lexpr = new_lexpr(instance, err);
if (err < 0)
return lexpr;
- type = snd_ctl_elem_info_get_type(info);
- count = snd_ctl_elem_info_get_count(info);
+ type = snd_ctl_elem_info_get_type(&info);
+ count = snd_ctl_elem_info_get_count(&info);
if (type == SND_CTL_ELEM_TYPE_IEC958) {
count = sizeof(snd_aes_iec958_t);
type = SND_CTL_ELEM_TYPE_BYTES;
@@ -651,19 +649,19 @@ static struct alisp_object * FA_hctl_elem_read(struct alisp_instance * instance,
for (idx = 0; idx < count; idx++) {
switch (type) {
case SND_CTL_ELEM_TYPE_BOOLEAN:
- obj = new_integer(instance, snd_ctl_elem_value_get_boolean(value, idx));
+ obj = new_integer(instance, snd_ctl_elem_value_get_boolean(&value, idx));
break;
case SND_CTL_ELEM_TYPE_INTEGER:
- obj = new_integer(instance, snd_ctl_elem_value_get_integer(value, idx));
+ obj = new_integer(instance, snd_ctl_elem_value_get_integer(&value, idx));
break;
case SND_CTL_ELEM_TYPE_INTEGER64:
- obj = new_integer(instance, snd_ctl_elem_value_get_integer64(value, idx));
+ obj = new_integer(instance, snd_ctl_elem_value_get_integer64(&value, idx));
break;
case SND_CTL_ELEM_TYPE_ENUMERATED:
- obj = new_integer(instance, snd_ctl_elem_value_get_enumerated(value, idx));
+ obj = new_integer(instance, snd_ctl_elem_value_get_enumerated(&value, idx));
break;
case SND_CTL_ELEM_TYPE_BYTES:
- obj = new_integer(instance, snd_ctl_elem_value_get_byte(value, idx));
+ obj = new_integer(instance, snd_ctl_elem_value_get_byte(&value, idx));
break;
default:
obj = NULL;