Update of /cvsroot/pure-data/externals/zexy/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10739
Modified Files:
lister.c
Log Message:
fixed bug with inline modification of buffer
Index: lister.c
===================================================================
RCS file: /cvsroot/pure-data/externals/zexy/src/lister.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** lister.c 14 Mar 2007 09:08:56 -0000 1.8
--- lister.c 1 Oct 2007 11:12:02 -0000 1.9
***************
*** 21,55 ****
#include <string.h>
/* ------------------------- list ------------------------------- */
/* this is for packages, what "float" is for floats */
static t_class *mypdlist_class;
static void mypdlist_secondlist(t_mypdlist *x, t_symbol *s, int argc, t_atom *argv)
{
! ZEXY_USEVAR(s);
! if (argc) {
! if (x->x_n != argc) {
! freebytes(x->x_list, x->x_n * sizeof(t_atom));
! x->x_n = argc;
! x->x_list = copybytes(argv, argc * sizeof(t_atom));
! } else memcpy(x->x_list, argv, argc * sizeof(t_atom));
! }
}
static void mypdlist_list(t_mypdlist *x, t_symbol *s, int argc, t_atom *argv)
{
! ZEXY_USEVAR(s);
! if (x->x_n != argc) {
! freebytes(x->x_list, x->x_n * sizeof(t_atom));
! x->x_n = argc;
! x->x_list = copybytes(argv, argc * sizeof(t_atom));
! } else memcpy(x->x_list, argv, argc * sizeof(t_atom));
!
! outlet_list(x->x_obj.ob_outlet, gensym("list"), x->x_n, x->x_list);
}
! static void mypdlist_bang(t_mypdlist *x)
! { outlet_list(x->x_obj.ob_outlet, gensym("list"), x->x_n, x->x_list);}
static void mypdlist_free(t_mypdlist *x)
--- 21,85 ----
#include <string.h>
+ #ifdef HAVE_ALLOCA_H
+ # include <alloca.h>
+ #endif
+
/* ------------------------- list ------------------------------- */
/* this is for packages, what "float" is for floats */
+ #define LIST_NGETBYTE 100 /* bigger that this we use alloc, not alloca */
+
+
static t_class *mypdlist_class;
+ #ifdef HAVE_ALLOCA_H
+ # define ATOMS_ALLOCA(x, n) ((x) = (t_atom *)((n) < LIST_NGETBYTE ? \
+ alloca((n) * sizeof(t_atom)) : getbytes((n) * sizeof(t_atom))))
+ # define ATOMS_FREEA(x, n) ( \
+ ((n) < LIST_NGETBYTE || (freebytes((x), (n) * sizeof(t_atom)), 0)))
+ #else
+ # define ATOMS_ALLOCA(x, n) ((x) = (t_atom *)getbytes((n) * sizeof(t_atom)))
+ # define ATOMS_FREEA(x, n) (freebytes((x), (n) * sizeof(t_atom)))
+ #endif
+
+ static void atoms_copy(int argc, t_atom *from, t_atom *to)
+ {
+ int i;
+ for (i = 0; i < argc; i++)
+ to[i] = from[i];
+ }
+
+
+ static void mypdlist_storelist(t_mypdlist *x, int argc, t_atom *argv)
+ {
+ if(x->x_list)freebytes(x->x_list, x->x_n*sizeof(t_atom));
+ x->x_n=argc;
+ x->x_list=(t_atom*)getbytes(x->x_n*sizeof(t_atom));
+
+ atoms_copy(argc, argv, x->x_list);
+ }
static void mypdlist_secondlist(t_mypdlist *x, t_symbol *s, int argc, t_atom *argv)
{
! mypdlist_storelist(x, argc, argv);
! }
!
! static void mypdlist_bang(t_mypdlist *x)
! {
! int outc=x->x_n;
! t_atom*outv;
! ATOMS_ALLOCA(outv, outc);
! atoms_copy(x->x_n, x->x_list, outv);
! outlet_list(x->x_obj.ob_outlet, gensym("list"), outc, outv);
! ATOMS_FREEA(outv, outc);
}
+
static void mypdlist_list(t_mypdlist *x, t_symbol *s, int argc, t_atom *argv)
{
! mypdlist_secondlist(x, s, argc, argv);
! mypdlist_bang(x);
}
!
static void mypdlist_free(t_mypdlist *x)
***************
*** 59,63 ****
{
t_mypdlist *x = (t_mypdlist *)pd_new(mypdlist_class);
- ZEXY_USEVAR(s);
outlet_new(&x->x_obj, 0);
--- 89,92 ----
***************
*** 67,71 ****
x->x_list = 0;
! mypdlist_secondlist(x, gensym("list"), argc, argv);
return (x);
--- 96,101 ----
x->x_list = 0;
! if(argc)
! mypdlist_secondlist(x, gensym("list"), argc, argv);
return (x);