[PD-cvs] pd/src kernel.c,1.1.2.11,1.1.2.12
Mathieu Bouchard
matju at users.sourceforge.net
Thu Dec 28 07:49:23 CET 2006
Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19653
Modified Files:
Tag: desiredata
kernel.c
Log Message:
cleanup and introducing binbuf_capa()
Index: kernel.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/kernel.c,v
retrieving revision 1.1.2.11
retrieving revision 1.1.2.12
diff -C2 -d -r1.1.2.11 -r1.1.2.12
*** kernel.c 28 Dec 2006 00:46:45 -0000 1.1.2.11
--- kernel.c 28 Dec 2006 06:49:20 -0000 1.1.2.12
***************
*** 1,13 ****
! /* Copyright (c) 2006 Mathieu Bouchard */
! /* Copyright (c) 1997-1999 Miller Puckette except the hashtable.
! * For information on usage and redistribution, and for a DISCLAIMER OF ALL
! * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
#include "desire.h"
#include <stdlib.h>
#include <string.h>
! /* T.Grill - include SIMD functionality */
! #include "m_simd.h"
#include <stdio.h>
/* T.Grill - bit alignment for signal vectors (must be a multiple of 8!) */
--- 1,30 ----
! /* Copyright 2006-2007 Mathieu Bouchard.
! * Copyright (c) 1997-2006 Miller Puckette.
! * For information on usage and redistribution, and for a DISCLAIMER OF ALL
! * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
!
! /* IOhannes :
! * changed the canvas_restore in "g_canvas.c", so that it might accept $args as well (like "pd $0_test")
! * so you can make multiple & distinguishable templates
! * 1511:forum::für::umläute:2001
! * change marked with IOhannes
! */
#include "desire.h"
+ #include "m_simd.h"
#include <stdlib.h>
+ #include <stdarg.h>
#include <string.h>
! #include <fcntl.h>
#include <stdio.h>
+ #include <ctype.h>
+ #include <errno.h>
+ #include <pthread.h>
+ #ifdef UNISTD
+ #include <unistd.h>
+ #endif
+ #ifdef MSW
+ #include <io.h>
+ #endif
/* T.Grill - bit alignment for signal vectors (must be a multiple of 8!) */
***************
*** 246,260 ****
void atom_string(t_atom *a, char *buf, unsigned int bufsize) {
- char tbuf[30];
switch(a->a_type) {
case A_SEMI: strcpy(buf, ";"); break;
case A_COMMA: strcpy(buf, ","); break;
case A_POINTER: strcpy(buf, "(pointer)"); break;
! case A_FLOAT:
sprintf(tbuf, "%g", a->a_w.w_float);
if (strlen(tbuf) < bufsize-1) strcpy(buf, tbuf);
else if (a->a_w.w_float < 0) strcpy(buf, "-");
else strcat(buf, "+");
! break;
case A_SYMBOL: {
char *sp;
--- 263,277 ----
void atom_string(t_atom *a, char *buf, unsigned int bufsize) {
switch(a->a_type) {
case A_SEMI: strcpy(buf, ";"); break;
case A_COMMA: strcpy(buf, ","); break;
case A_POINTER: strcpy(buf, "(pointer)"); break;
! case A_FLOAT: {
! char tbuf[30];
sprintf(tbuf, "%g", a->a_w.w_float);
if (strlen(tbuf) < bufsize-1) strcpy(buf, tbuf);
else if (a->a_w.w_float < 0) strcpy(buf, "-");
else strcat(buf, "+");
! } break;
case A_SYMBOL: {
char *sp;
***************
*** 1001,1024 ****
}
- /* Copyright (c) 1997-1999 Miller Puckette.
- * For information on usage and redistribution, and for a DISCLAIMER OF ALL
- * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
- #define PD_CLASS_DEF
- #include "desire.h"
- #include "s_stuff.h"
- #include <stdlib.h>
- #ifdef UNISTD
- #include <unistd.h>
- #endif
- #ifdef MSW
- #include <io.h>
- #endif
-
- #include <stdio.h> /* grrrr: for sprintf */
- #include <stdarg.h>
- #include <string.h>
- #include <pthread.h> /* tb: for hashtable locking */
-
#ifdef QUALIFIED_NAME
static char *pd_library_name = 0;
--- 1018,1021 ----
***************
*** 1061,1065 ****
}
-
void obj_list(t_object *x, t_symbol *s, int argc, t_atom *argv);
static void class_nosavefn(t_gobj *z, t_binbuf *b);
--- 1058,1061 ----
***************
*** 1394,1398 ****
{
pthread_mutex_unlock(&hash_lock);
! return(sym2);
}
sym1 = &sym2->s_next;
--- 1390,1394 ----
{
pthread_mutex_unlock(&hash_lock);
! return sym2;
}
sym1 = &sym2->s_next;
***************
*** 1686,1690 ****
for (i = c->nmethod, m = c->methods; i--; m++) if (m->me_name == s) return m->me_fun;
pd_error(x, "%s: no method for message '%s'", c->name->s_name, s->s_name);
! return((t_gotfn)nullfn);
}
--- 1682,1686 ----
for (i = c->nmethod, m = c->methods; i--; m++) if (m->me_name == s) return m->me_fun;
pd_error(x, "%s: no method for message '%s'", c->name->s_name, s->s_name);
! return (t_gotfn)nullfn;
}
***************
*** 1749,1807 ****
}
- /* Copyright 2006-2007 Mathieu Bouchard.
- * Copyright 1997-2006 Miller Puckette.
- * For information on usage and redistribution, and for a DISCLAIMER OF ALL
- * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-
- /* IOhannes :
- * changed the canvas_restore in "g_canvas.c", so that it might accept $args as well (like "pd $0_test")
- * so you can make multiple & distinguishable templates
- * 1511:forum::für::umläute:2001
- * change marked with IOhannes
- */
-
- #include <stdlib.h>
- #include "m_pd.h"
- #include "s_stuff.h"
- #include <stdio.h>
- #ifdef UNISTD
- #include <unistd.h>
- #endif
- #ifdef MSW
- #include <io.h>
- #endif
- #include <fcntl.h>
- #include <string.h>
- #include <stdarg.h>
- #include <errno.h>
-
struct _binbuf {
! int b_n;
! t_atom *b_vec;
};
t_binbuf *binbuf_new(void) {
t_binbuf *x = (t_binbuf *)t_getbytes(sizeof(*x));
! x->b_n = 0;
! x->b_vec = (t_atom *)t_getbytes(0);
return x;
}
void binbuf_free(t_binbuf *x) {
! t_freebytes(x->b_vec, x->b_n * sizeof(*x->b_vec));
! t_freebytes(x, sizeof(*x));
}
t_binbuf *binbuf_duplicate(t_binbuf *y) {
t_binbuf *x = (t_binbuf *)t_getbytes(sizeof(*x));
! x->b_n = y->b_n;
! x->b_vec = (t_atom *)t_getbytes(x->b_n * sizeof(*x->b_vec));
! memcpy(x->b_vec, y->b_vec, x->b_n * sizeof(*x->b_vec));
return x;
}
void binbuf_clear(t_binbuf *x) {
! x->b_vec = (t_atom *)t_resizebytes(x->b_vec, x->b_n * sizeof(*x->b_vec), 0);
! x->b_n = 0;
}
--- 1745,1785 ----
}
struct _binbuf {
! int n;
! int capa; /* capacity: how much n may grow without reallocating */
! t_atom *vec;
};
t_binbuf *binbuf_new(void) {
t_binbuf *x = (t_binbuf *)t_getbytes(sizeof(*x));
! x->n = 0;
! x->capa = 0;
! x->vec = (t_atom *)t_getbytes(0);
return x;
}
+ /* caution: capa >= x->n */
+ static void binbuf_capa(t_binbuf *x, int capa) {
+ x->vec = (t_atom *)t_resizebytes(x->vec, x->capa*sizeof(*x->vec), capa*sizeof(*x->vec));
+ x->capa = capa;
+ }
+
void binbuf_free(t_binbuf *x) {
! t_freebytes(x->vec, x->n * sizeof(*x->vec));
! t_freebytes(x, sizeof(*x));
}
t_binbuf *binbuf_duplicate(t_binbuf *y) {
t_binbuf *x = (t_binbuf *)t_getbytes(sizeof(*x));
! x->capa = x->n = y->n;
! x->vec = (t_atom *)t_getbytes(x->n * sizeof(*x->vec));
! memcpy(x->vec, y->vec, x->n * sizeof(*x->vec));
return x;
}
void binbuf_clear(t_binbuf *x) {
! x->n = 0;
! x->vec = (t_atom *)t_resizebytes(x->vec, x->n * sizeof(*x->vec), 0);
! x->capa = 0;
}
***************
*** 1810,1825 ****
char buf[MAXPDSTRING+1], *bufp, *ebuf = buf+MAXPDSTRING;
const char *textp = text, *etext = text+size;
! t_atom *ap;
! int nalloc = 16, natom = 0;
! t_freebytes(x->b_vec, x->b_n * sizeof(*x->b_vec));
! x->b_vec = (t_atom *)t_getbytes(nalloc * sizeof(*x->b_vec));
! ap = x->b_vec;
! x->b_n = 0;
while (1) {
/* skip leading space */
while ((textp != etext) && (*textp == ' ' || *textp == '\n' || *textp == '\r' || *textp == '\t')) textp++;
if (textp == etext) break;
! if (*textp == ';') SETSEMI(ap), textp++;
! else if (*textp == ',') SETCOMMA(ap), textp++;
else {
/* it's an atom other than a comma or semi */
--- 1788,1800 ----
char buf[MAXPDSTRING+1], *bufp, *ebuf = buf+MAXPDSTRING;
const char *textp = text, *etext = text+size;
! binbuf_clear(x);
! binbuf_capa(x,16);
! x->n = 0;
while (1) {
/* skip leading space */
while ((textp != etext) && (*textp == ' ' || *textp == '\n' || *textp == '\r' || *textp == '\t')) textp++;
if (textp == etext) break;
! if (*textp == ';') {binbuf_addv(x,";"); textp++;}
! else if (*textp == ',') {binbuf_addv(x,","); textp++;}
else {
/* it's an atom other than a comma or semi */
***************
*** 1832,1896 ****
slash = (c == '\\');
if (q >= 0) {
! int digit = (c >= '0' && c <= '9'), dot = (c == '.'), minus = (c == '-'),
! plusminus = (minus || (c == '+')), expon = (c == 'e' || c == 'E');
! if (q == 0) { /* beginning */
if (minus) q = 1; else if (digit) q = 2; else if (dot) q = 3; else q = -1;
! } else if (q == 1) { /* got minus */
if (digit) q = 2; else if (dot) q = 3; else q = -1;
! } else if (q == 2) { /* got digits */
if (dot) q = 4; else if (expon) q = 6; else if (!digit) q = -1;
! } else if (q == 3) { /* got '.' without digits */
if (digit) q = 5; else q = -1;
! } else if (q == 4) { /* got '.' after digits */
if (digit) q = 5; else if (expon) q = 6; else q = -1;
! } else if (q == 5) { /* got digits after . */
if (expon) q = 6; else if (!digit) q = -1;
! } else if (q == 6) { /* got 'e' */
if (plusminus) q = 7; else if (digit) q = 8; else q = -1;
! } else if (q == 7) { /* got plus or minus */
if (digit) q = 8; else q = -1;
! } else if (q == 8) { /* got digits */
if (!digit) q = -1;
}
}
! if (!lastslash && c == '$' && (textp != etext &&
! textp[0] >= '0' && textp[0] <= '9'))
! dollar = 1;
if (!slash) bufp++;
! }
! while (textp != etext && bufp != ebuf &&
! (slash || (*textp != ' ' && *textp != '\n' && *textp != '\r'
! && *textp != '\t' &&*textp != ',' && *textp != ';')));
*bufp = 0;
! if (q == 2 || q == 4 || q == 5 || q == 8) SETFLOAT(ap, atof(buf));
! /* LATER try to figure out how to mix "$" and "\$" correctly;
! here, the backslashes were already stripped so we assume all
! "$" chars are real dollars. In fact, we only know at least one
! was. */
else if (dollar) {
! if (buf[0] != '$')
! dollar = 0;
! for (bufp = buf+1; *bufp; bufp++)
! if (*bufp < '0' || *bufp > '9')
! dollar = 0;
! if (dollar) SETDOLLAR(ap, atoi(buf+1));
! else SETDOLLSYM(ap, gensym(buf));
! }
! else SETSYMBOL(ap, gensym(buf));
! }
! ap++;
! natom++;
! if (natom == nalloc) {
! x->b_vec = (t_atom *)t_resizebytes(x->b_vec, nalloc * sizeof(*x->b_vec),
! nalloc * (2*sizeof(*x->b_vec)));
! nalloc = nalloc * 2;
! ap = x->b_vec + natom;
}
if (textp == etext) break;
}
! /* reallocate the vector to exactly the right size */
! x->b_vec = (t_atom *)t_resizebytes(x->b_vec, nalloc * sizeof(*x->b_vec),
! natom * sizeof(*x->b_vec));
! x->b_n = natom;
}
--- 1807,1848 ----
slash = (c == '\\');
if (q >= 0) {
! int digit = isdigit(c), dot=c=='.', minus=c=='-', plusminus=minus||c=='+', expon=c=='e'||c=='E';
! if (q==0) { /* beginning */
if (minus) q = 1; else if (digit) q = 2; else if (dot) q = 3; else q = -1;
! } else if (q==1) { /* got minus */
if (digit) q = 2; else if (dot) q = 3; else q = -1;
! } else if (q==2) { /* got digits */
if (dot) q = 4; else if (expon) q = 6; else if (!digit) q = -1;
! } else if (q==3) { /* got '.' without digits */
if (digit) q = 5; else q = -1;
! } else if (q==4) { /* got '.' after digits */
if (digit) q = 5; else if (expon) q = 6; else q = -1;
! } else if (q==5) { /* got digits after . */
if (expon) q = 6; else if (!digit) q = -1;
! } else if (q==6) { /* got 'e' */
if (plusminus) q = 7; else if (digit) q = 8; else q = -1;
! } else if (q==7) { /* got plus or minus */
if (digit) q = 8; else q = -1;
! } else if (q==8) { /* got digits */
if (!digit) q = -1;
}
}
! if (!lastslash && c == '$' && textp!=etext && isdigit(textp[0])) dollar = 1;
if (!slash) bufp++;
! } while (textp != etext && bufp != ebuf && (slash || !strchr(" \n\r\t,;",*textp)));
*bufp = 0;
! if (q == 2 || q == 4 || q == 5 || q == 8) binbuf_addv(x,"f",atof(buf));
! /* LATER try to figure out how to mix "$" and "\$" correctly; here, the backslashes were already
! stripped so we assume all "$" chars are real dollars. In fact, we only know at least one was. */
else if (dollar) {
! if (buf[0] != '$') dollar = 0;
! for (bufp = buf+1; *bufp; bufp++) if (*bufp < '0' || *bufp > '9') dollar = 0;
! if (dollar) binbuf_addv(x,"$",atoi(buf+1));
! else binbuf_addv(x,"&",gensym(buf));
! } else binbuf_addv(x,"s",gensym(buf));
}
if (textp == etext) break;
}
! binbuf_capa(x,x->n);
}
***************
*** 1902,1906 ****
t_atom *ap;
int indx;
! for (ap = x->b_vec, indx = x->b_n; indx--; ap++) {
int newlength;
if ((ap->a_type == A_SEMI || ap->a_type == A_COMMA) && length && buf[length-1] == ' ') length--;
--- 1854,1858 ----
t_atom *ap;
int indx;
! for (ap = x->vec, indx = x->n; indx--; ap++) {
int newlength;
if ((ap->a_type == A_SEMI || ap->a_type == A_COMMA) && length && buf[length-1] == ' ') length--;
***************
*** 1924,1946 ****
}
! /* LATER improve the out-of-space behavior below. Also fix this so that
! writing to file doesn't buffer everything together. */
!
void binbuf_add(t_binbuf *x, int argc, t_atom *argv) {
! int newsize = x->b_n + argc, i;
! t_atom *ap;
! if (ap = (t_atom *)t_resizebytes(x->b_vec, x->b_n * sizeof(*x->b_vec), newsize * sizeof(*x->b_vec))) {
! x->b_vec = ap;
! } else {
! error("binbuf_addmessage: out of space");
! return;
! }
! #if 0
! startpost("binbuf_add: ");
! postatom(argc, argv);
! endpost();
! #endif
! for (ap = x->b_vec + x->b_n, i = argc; i--; ap++) *ap = *(argv++);
! x->b_n = newsize;
}
--- 1876,1887 ----
}
! /* Miller said: fix this so that writing to file doesn't buffer everything together. */
! /* matju said: make this use vector size doubling as it used to be in binbuf_text */
void binbuf_add(t_binbuf *x, int argc, t_atom *argv) {
! int newsize = x->n + argc, i;
! t_atom *ap = (t_atom *)t_resizebytes(x->vec, x->n * sizeof(*x->vec), newsize * sizeof(*x->vec));
! x->vec = ap;
! for (ap = x->vec + x->n, i = argc; i--; ap++) *ap = *(argv++);
! x->capa = x->n = newsize;
}
***************
*** 1963,1966 ****
--- 1904,1909 ----
case ';': SETSEMI(at); break;
case ',': SETCOMMA(at); break;
+ case '$': SETDOLLAR(at, va_arg(ap, int)); break;
+ case '&': SETDOLLSYM(at, va_arg(ap, t_symbol *)); break;
default: goto done;
}
***************
*** 1980,1985 ****
int i;
t_atom *ap;
! binbuf_add(z, y->b_n, y->b_vec);
! for (i = 0, ap = z->b_vec; i < z->b_n; i++, ap++) {
char tbuf[MAXPDSTRING];
switch (ap->a_type) {
--- 1923,1928 ----
int i;
t_atom *ap;
! binbuf_add(z, y->n, y->vec);
! for (i = 0, ap = z->vec; i < z->n; i++, ap++) {
char tbuf[MAXPDSTRING];
switch (ap->a_type) {
***************
*** 1998,2002 ****
}
}
! binbuf_add(x, z->b_n, z->b_vec);
}
--- 1941,1945 ----
}
}
! binbuf_add(x, z->n, z->vec);
}
***************
*** 2011,2023 ****
void binbuf_restore(t_binbuf *x, int argc, t_atom *argv) {
! int newsize = x->b_n + argc, i;
t_atom *ap;
! if (ap = (t_atom *)t_resizebytes(x->b_vec, x->b_n * sizeof(*x->b_vec), newsize * sizeof(*x->b_vec))) {
! x->b_vec = ap;
} else {
error("binbuf_addmessage: out of space");
return;
}
! for (ap = x->b_vec + x->b_n, i = argc; i--; ap++) {
if (argv->a_type == A_SYMBOL) {
char *str = argv->a_w.w_symbol->s_name, *str2;
--- 1954,1966 ----
void binbuf_restore(t_binbuf *x, int argc, t_atom *argv) {
! int newsize = x->n + argc, i;
t_atom *ap;
! if (ap = (t_atom *)t_resizebytes(x->vec, x->n * sizeof(*x->vec), newsize * sizeof(*x->vec))) {
! x->vec = ap;
} else {
error("binbuf_addmessage: out of space");
return;
}
! for (ap = x->vec + x->n, i = argc; i--; ap++) {
if (argv->a_type == A_SYMBOL) {
char *str = argv->a_w.w_symbol->s_name, *str2;
***************
*** 2041,2045 ****
} else *ap = *(argv++);
}
! x->b_n = newsize;
}
--- 1984,1988 ----
} else *ap = *(argv++);
}
! x->n = newsize;
}
***************
*** 2049,2053 ****
void binbuf_print(t_binbuf *x) {
int i, startedpost = 0, newline = 1;
! for (i = 0; i < x->b_n; i++) {
if (newline) {
if (startedpost) endpost();
--- 1992,1996 ----
void binbuf_print(t_binbuf *x) {
int i, startedpost = 0, newline = 1;
! for (i = 0; i < x->n; i++) {
if (newline) {
if (startedpost) endpost();
***************
*** 2055,2066 ****
startedpost = 1;
}
! postatom(1, x->b_vec + i);
! newline = !! x->b_vec[i].a_type == A_SEMI;
}
if (startedpost) endpost();
}
! int binbuf_getnatom(t_binbuf *x) {return x->b_n;}
! t_atom *binbuf_getvec(t_binbuf *x) {return x->b_vec;}
int canvas_getdollarzero(void);
--- 1998,2009 ----
startedpost = 1;
}
! postatom(1, x->vec + i);
! newline = !! x->vec[i].a_type == A_SEMI;
}
if (startedpost) endpost();
}
! int binbuf_getnatom(t_binbuf *x) {return x->n;}
! t_atom *binbuf_getvec(t_binbuf *x) {return x->vec;}
int canvas_getdollarzero(void);
***************
*** 2156,2161 ****
static t_atom mstack[MSTACKSIZE], *msp = mstack, *ems = mstack+MSTACKSIZE;
t_atom *stackwas = msp;
! t_atom *at = x->b_vec;
! int ac = x->b_n;
int nargs;
while (1) {
--- 2099,2104 ----
static t_atom mstack[MSTACKSIZE], *msp = mstack, *ems = mstack+MSTACKSIZE;
t_atom *stackwas = msp;
! t_atom *at = x->vec;
! int ac = x->n;
int nargs;
while (1) {
***************
*** 2374,2378 ****
goto fail;
}
! for (ap = x->b_vec, indx = x->b_n; indx--; ap++) {
int length;
/* estimate how many characters will be needed. Printing out
--- 2317,2321 ----
goto fail;
}
! for (ap = x->vec, indx = x->n; indx--; ap++) {
int length;
/* estimate how many characters will be needed. Printing out
***************
*** 2428,2433 ****
static t_binbuf *binbuf_convert(t_binbuf *oldb, int maxtopd) {
t_binbuf *newb = binbuf_new();
! t_atom *vec = oldb->b_vec;
! t_int n = oldb->b_n, nextindex, stackdepth = 0, stack[MAXSTACK], nobj = 0, i;
t_atom outmess[MAXSTACK], *nextmess;
if (!maxtopd) binbuf_addv(newb, "ss;", gensym("max"), gensym("v2"));
--- 2371,2376 ----
static t_binbuf *binbuf_convert(t_binbuf *oldb, int maxtopd) {
t_binbuf *newb = binbuf_new();
! t_atom *vec = oldb->vec;
! t_int n = oldb->n, nextindex, stackdepth = 0, stack[MAXSTACK], nobj = 0, i;
t_atom outmess[MAXSTACK], *nextmess;
if (!maxtopd) binbuf_addv(newb, "ss;", gensym("max"), gensym("v2"));
***************
*** 2692,2698 ****
int binbuf_match(t_binbuf *inbuf, t_binbuf *searchbuf) {
int indexin, nmatched;
! for (indexin = 0; indexin <= inbuf->b_n - searchbuf->b_n; indexin++) {
! for (nmatched = 0; nmatched < searchbuf->b_n; nmatched++) {
! t_atom *a1 = &inbuf->b_vec[indexin + nmatched], *a2 = &searchbuf->b_vec[nmatched];
if (a1->a_type != a2->a_type ||
a1->a_type == A_SYMBOL && a1->a_w.w_symbol != a2->a_w.w_symbol ||
--- 2635,2641 ----
int binbuf_match(t_binbuf *inbuf, t_binbuf *searchbuf) {
int indexin, nmatched;
! for (indexin = 0; indexin <= inbuf->n - searchbuf->n; indexin++) {
! for (nmatched = 0; nmatched < searchbuf->n; nmatched++) {
! t_atom *a1 = &inbuf->vec[indexin + nmatched], *a2 = &searchbuf->vec[nmatched];
if (a1->a_type != a2->a_type ||
a1->a_type == A_SYMBOL && a1->a_w.w_symbol != a2->a_w.w_symbol ||
More information about the Pd-cvs
mailing list