[PD-cvs] pd/src kernel.c,1.1.2.5,1.1.2.6

Mathieu Bouchard matju at users.sourceforge.net
Wed Dec 20 14:29:54 CET 2006


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7686

Modified Files:
      Tag: desiredata
	kernel.c 
Log Message:
just some more reformatting.


Index: kernel.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/kernel.c,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -C2 -d -r1.1.2.5 -r1.1.2.6
*** kernel.c	20 Dec 2006 08:25:53 -0000	1.1.2.5
--- kernel.c	20 Dec 2006 13:29:52 -0000	1.1.2.6
***************
*** 19,71 ****
  #endif
  
! void *getbytes(size_t nbytes)
! {
      void *ret;
      if (nbytes < 1) nbytes = 1;
      ret = (void *)calloc(nbytes, 1);
!     if (!ret)
!         post("pd: getbytes() failed -- out of memory");
!     return (ret);
  }
  
! void *copybytes(void *src, size_t nbytes)
! {
      void *ret;
      ret = getbytes(nbytes);
!     if (nbytes)
!         memcpy(ret, src, nbytes);
!     return (ret);
  }
  
! void *resizebytes(void *old, size_t oldsize, size_t newsize)
! {
      void *ret;
      if (newsize < 1) newsize = 1;
      if (oldsize < 1) oldsize = 1;
      ret = (void *)realloc((char *)old, newsize);
!     if (newsize > oldsize && ret)
!         memset(((char *)ret) + oldsize, 0, newsize - oldsize);
!     if (!ret)
!         post("pd: resizebytes() failed -- out of memory");
!     return (ret);
  }
  
! void freebytes(void *fatso, size_t nbytes)
! {
!     free(fatso);
! }
  
  /* in the following size_t is assumed to have the same size as a pointer type !!! */
  
  /* T.Grill - get aligned memory */
! void *getalignedbytes(size_t nbytes)
! {
  	/* to align the region we also need some extra memory to save the original pointer location
! 		it is saved immediately before the aligned vector memory
! 	*/
     	void *vec = getbytes(nbytes+ (VECTORALIGNMENT/8-1)+sizeof(void *));
! 
! 	if (vec != NULL)
! 	{
  		/* get alignment of first possible signal vector byte */
  		t_int alignment = ((t_int)vec+sizeof(void *))&(VECTORALIGNMENT/8-1);  
--- 19,57 ----
  #endif
  
! void *getbytes(size_t nbytes) {
      void *ret;
      if (nbytes < 1) nbytes = 1;
      ret = (void *)calloc(nbytes, 1);
!     if (!ret) post("pd: getbytes() failed -- out of memory");
!     return ret;
  }
  
! void *copybytes(void *src, size_t nbytes) {
      void *ret;
      ret = getbytes(nbytes);
!     if (nbytes) memcpy(ret, src, nbytes);
!     return ret;
  }
  
! void *resizebytes(void *old, size_t oldsize, size_t newsize) {
      void *ret;
      if (newsize < 1) newsize = 1;
      if (oldsize < 1) oldsize = 1;
      ret = (void *)realloc((char *)old, newsize);
!     if (newsize > oldsize && ret) memset(((char *)ret) + oldsize, 0, newsize - oldsize);
!     if (!ret) post("pd: resizebytes() failed -- out of memory");
!     return ret;
  }
  
! void freebytes(void *old, size_t nbytes) {free(old);}
  
  /* in the following size_t is assumed to have the same size as a pointer type !!! */
  
  /* T.Grill - get aligned memory */
! void *getalignedbytes(size_t nbytes) {
  	/* to align the region we also need some extra memory to save the original pointer location
! 		it is saved immediately before the aligned vector memory */
     	void *vec = getbytes(nbytes+ (VECTORALIGNMENT/8-1)+sizeof(void *));
! 	if (vec != NULL) {
  		/* get alignment of first possible signal vector byte */
  		t_int alignment = ((t_int)vec+sizeof(void *))&(VECTORALIGNMENT/8-1);  
***************
*** 76,118 ****
  		return ret;
  	}
! 	else
! 		return 0;
  	
  }
  
  /* T.Grill - free aligned vector memory */
! void freealignedbytes(void *ptr,size_t nbytes)
! {
  	/* get original memory location */
  	void *ori = *(void **)((unsigned char *)ptr-sizeof(void *)); 
- 
  	freebytes(ori,nbytes+(VECTORALIGNMENT/8-1)+sizeof(void *));
  }
  
  /* T.Grill - resize aligned vector memory */
! void *resizealignedbytes(void *ptr,size_t oldsize, size_t newsize)
! {
  	 /* get original memory location */
  	void *ori = *(void **)((unsigned char *)ptr-sizeof(void *));
!     void *vec = resizebytes(ori,oldsize+(VECTORALIGNMENT/8-1)+sizeof(void *),
! 							newsize+ (VECTORALIGNMENT/8-1)+sizeof(void *));
  	/* get alignment of first possible signal vector byte */
  	t_int alignment = ((t_int)vec+sizeof(void *))&(VECTORALIGNMENT/8-1);
  	/* calculate aligned pointer */
! 	void *ret = (unsigned char *)vec+sizeof(void *)+
! 		(alignment == 0?0:VECTORALIGNMENT/8-alignment);
  	/* save original memory location */
  	*(void **)((unsigned char *)ret-sizeof(void *)) = vec;
!     return ret;
  }
  
  /* TB: copy to aligned vector memory */
! void *copyalignedbytes(void *src, size_t nbytes)
! {
      void *ret;
      ret = getalignedbytes(nbytes);
!     if (nbytes)
!     	memcpy(ret, src, nbytes);
!     return (ret);
  }
  
--- 62,97 ----
  		return ret;
  	}
! 	return 0;
  	
  }
  
  /* T.Grill - free aligned vector memory */
! void freealignedbytes(void *ptr,size_t nbytes) {
  	/* get original memory location */
  	void *ori = *(void **)((unsigned char *)ptr-sizeof(void *)); 
  	freebytes(ori,nbytes+(VECTORALIGNMENT/8-1)+sizeof(void *));
  }
  
  /* T.Grill - resize aligned vector memory */
! void *resizealignedbytes(void *ptr,size_t oldsize, size_t newsize) {
  	 /* get original memory location */
  	void *ori = *(void **)((unsigned char *)ptr-sizeof(void *));
! 	void *vec = resizebytes(ori,oldsize+(VECTORALIGNMENT/8-1)+sizeof(void *),
! 		newsize+(VECTORALIGNMENT/8-1)+sizeof(void *));
  	/* get alignment of first possible signal vector byte */
  	t_int alignment = ((t_int)vec+sizeof(void *))&(VECTORALIGNMENT/8-1);
  	/* calculate aligned pointer */
! 	void *ret = (unsigned char *)vec+sizeof(void *)+(alignment == 0?0:VECTORALIGNMENT/8-alignment);
  	/* save original memory location */
  	*(void **)((unsigned char *)ret-sizeof(void *)) = vec;
! 	return ret;
  }
  
  /* TB: copy to aligned vector memory */
! void *copyalignedbytes(void *src, size_t nbytes) {
      void *ret;
      ret = getalignedbytes(nbytes);
!     if (nbytes) memcpy(ret, src, nbytes);
!     return ret;
  }
  
***************
*** 235,239 ****
  t_symbol *atom_gensym(t_atom *a) { /* this works  better for graph labels */
      char buf[30];
!     if (a->a_type == A_SYMBOL) return (a->a_w.w_symbol);
      else if (a->a_type == A_FLOAT) sprintf(buf, "%g", a->a_w.w_float);
      else strcpy(buf, "???");
--- 214,218 ----
  t_symbol *atom_gensym(t_atom *a) { /* this works  better for graph labels */
      char buf[30];
!     if (a->a_type == A_SYMBOL) return a->a_w.w_symbol;
      else if (a->a_type == A_FLOAT) sprintf(buf, "%g", a->a_w.w_float);
      else strcpy(buf, "???");
***************
*** 317,326 ****
      hash_set(object_table,x,(void*)0);
      if (c->c_gobj) ((t_gobj *)x)->g_adix = appendix_new((t_gobj *)x);
!     if (c->c_patchable)
!     {
          ((t_object *)x)->ob_inlet = 0;
          ((t_object *)x)->ob_outlet = 0;
      }
!     return (x);
  }
  
--- 296,304 ----
      hash_set(object_table,x,(void*)0);
      if (c->c_gobj) ((t_gobj *)x)->g_adix = appendix_new((t_gobj *)x);
!     if (c->c_patchable) {
          ((t_object *)x)->ob_inlet = 0;
          ((t_object *)x)->ob_outlet = 0;
      }
!     return x;
  }
  
***************
*** 340,348 ****
  }
  
! void gobj_save(t_gobj *x, t_binbuf *b)
! {
      t_class *c = x->g_pd;
!     if (c->c_savefn)
!         (c->c_savefn)(x, b);
  }
  
--- 318,324 ----
  }
  
! void gobj_save(t_gobj *x, t_binbuf *b) {
      t_class *c = x->g_pd;
!     if (c->c_savefn) c->c_savefn(x, b);
  }
  
***************
*** 353,358 ****
  static t_class *bindlist_class;
  
! typedef struct _bindelem
! {
      t_pd *e_who;
      struct _bindelem *e_next;
--- 329,333 ----
  static t_class *bindlist_class;
  
! typedef struct _bindelem {
      t_pd *e_who;
      struct _bindelem *e_next;
***************
*** 411,420 ****
  }
  
  void pd_unbind(t_pd *x, t_symbol *s) {
!     if (s->s_thing == x) s->s_thing = 0;
!     else if (s->s_thing && *s->s_thing == bindlist_class) {
!         /* bindlists always have at least two elements... if the number
!            goes down to one, get rid of the bindlist and bind the symbol
!            straight to the remaining element. */
          t_bindlist *b = (t_bindlist *)s->s_thing;
          t_bindelem *e, *e2;
--- 386,395 ----
  }
  
+ /* bindlists always have at least two elements... if the number
+    goes down to one, get rid of the bindlist and bind the symbol
+    straight to the remaining element. */
  void pd_unbind(t_pd *x, t_symbol *s) {
!     if (s->s_thing == x) {s->s_thing = 0; return;}
!     if (s->s_thing && *s->s_thing == bindlist_class) {
          t_bindlist *b = (t_bindlist *)s->s_thing;
          t_bindelem *e, *e2;
***************
*** 422,427 ****
              b->b_list = e->e_next;
              freebytes(e, sizeof(t_bindelem));
!         }
!         else for (e = b->b_list; (e2=e->e_next); e = e2) if (e2->e_who == x) {
              e->e_next = e2->e_next;
              freebytes(e2, sizeof(t_bindelem));
--- 397,401 ----
              b->b_list = e->e_next;
              freebytes(e, sizeof(t_bindelem));
!         } else for (e = b->b_list; (e2=e->e_next); e = e2) if (e2->e_who == x) {
              e->e_next = e2->e_next;
              freebytes(e2, sizeof(t_bindelem));
***************
*** 438,456 ****
  void zz(void) {}
  
! t_pd *pd_findbyclass(t_symbol *s, t_class *c)
! {
      t_pd *x = 0;
!     if (!s->s_thing) return (0);
!     if (*s->s_thing == c) return (s->s_thing);
!     if (*s->s_thing == bindlist_class)
!     {
          t_bindlist *b = (t_bindlist *)s->s_thing;
          t_bindelem *e;
          int warned = 0;
!         for (e = b->b_list; e; e = e->e_next)
!             if (*e->e_who == c)
!         {
!             if (x && !warned)
!             {
                  zz();
                  post("warning: %s: multiply defined", s->s_name);
--- 412,425 ----
  void zz(void) {}
  
! t_pd *pd_findbyclass(t_symbol *s, t_class *c) {
      t_pd *x = 0;
!     if (!s->s_thing) return 0;
!     if (*s->s_thing == c) return s->s_thing;
!     if (*s->s_thing == bindlist_class) {
          t_bindlist *b = (t_bindlist *)s->s_thing;
          t_bindelem *e;
          int warned = 0;
!         for (e = b->b_list; e; e = e->e_next) if (*e->e_who == c) {
!             if (x && !warned) {
                  zz();
                  post("warning: %s: multiply defined", s->s_name);
***************
*** 467,472 ****
  #undef g_next
  
! typedef struct _gstack
! {
      t_pd *g_what;
      t_symbol *g_loadingabstraction;
--- 436,440 ----
  #undef g_next
  
! typedef struct _gstack {
      t_pd *g_what;
      t_symbol *g_loadingabstraction;
***************
*** 478,493 ****
  static t_symbol *pd_loadingabstraction;
  
! int pd_setloadingabstraction(t_symbol *sym)
! {
      t_gstack *foo = gstack_head;
!     for (foo = gstack_head; foo; foo = foo->g_next)
!         if (foo->g_loadingabstraction == sym)
!             return (1);
      pd_loadingabstraction = sym;
!     return (0);
  }
  
! void pd_pushsym(t_pd *x)
! {
      t_gstack *y = (t_gstack *)t_getbytes(sizeof(*y));
      y->g_what = s__X.s_thing;
--- 446,457 ----
  static t_symbol *pd_loadingabstraction;
  
! int pd_setloadingabstraction(t_symbol *sym) {
      t_gstack *foo = gstack_head;
!     for (foo = gstack_head; foo; foo = foo->g_next) if (foo->g_loadingabstraction == sym) return 1;
      pd_loadingabstraction = sym;
!     return 0;
  }
  
! void pd_pushsym(t_pd *x) {
      t_gstack *y = (t_gstack *)t_getbytes(sizeof(*y));
      y->g_what = s__X.s_thing;
***************
*** 499,507 ****
  }
  
! void pd_popsym(t_pd *x)
! {
      if (!gstack_head || s__X.s_thing != x) bug("gstack_pop");
!     else
!     {
          t_gstack *headwas = gstack_head;
          s__X.s_thing = headwas->g_what;
--- 463,469 ----
  }
  
! void pd_popsym(t_pd *x) {
      if (!gstack_head || s__X.s_thing != x) bug("gstack_pop");
!     else {
          t_gstack *headwas = gstack_head;
          s__X.s_thing = headwas->g_what;
***************
*** 512,519 ****
  }
  
! void pd_doloadbang(void)
! {
!     if (lastpopped)
!         pd_vmess(lastpopped, gensym("loadbang"), "");
      lastpopped = 0;
  }
--- 474,479 ----
  }
  
! void pd_doloadbang(void) {
!     if (lastpopped) pd_vmess(lastpopped, gensym("loadbang"), "");
      lastpopped = 0;
  }
***************
*** 563,568 ****
  /* tb: } */
  
! union inletunion
! {
      t_symbol *iu_symto;
      t_gpointer *iu_pointerslot;
--- 523,527 ----
  /* tb: } */
  
! union inletunion {
      t_symbol *iu_symto;
      t_gpointer *iu_pointerslot;
***************
*** 574,579 ****
  int sys_tooltips = 1;
  
! struct _inlet
! {
      t_pd i_pd;
      struct _inlet *i_next;
--- 533,537 ----
  int sys_tooltips = 1;
  
! struct _inlet {
      t_pd i_pd;
      struct _inlet *i_next;
***************
*** 600,628 ****
  /* --------------------- generic inlets ala max ------------------ */
  
! t_inlet *inlet_new(t_object *owner, t_pd *dest, t_symbol *s1, t_symbol *s2)
! {
      t_inlet *x = (t_inlet *)pd_new(inlet_class), *y, *y2;
      x->i_owner = owner;
      x->i_dest = dest;
!     if (s1 == &s_signal)
!         x->i_un.iu_floatsignalvalue = 0;
      else x->i_symto = s2;
      x->i_symfrom = s1;
      x->i_next = 0;
      x->i_tip = gensym("?");
!     if (y = owner->ob_inlet)
!     {
          while ((y2=y->i_next)) y = y2;
          y->i_next = x;
      }
      else owner->ob_inlet = x;
!     return (x);
  }
  
! t_inlet *signalinlet_new(t_object *owner, t_float f)
! {
      t_inlet *x = inlet_new(owner, &owner->ob_pd, &s_signal, &s_signal);
      x->i_un.iu_floatsignalvalue = f;
!     return (x);
  }
  
--- 558,582 ----
  /* --------------------- generic inlets ala max ------------------ */
  
! t_inlet *inlet_new(t_object *owner, t_pd *dest, t_symbol *s1, t_symbol *s2) {
      t_inlet *x = (t_inlet *)pd_new(inlet_class), *y, *y2;
      x->i_owner = owner;
      x->i_dest = dest;
!     if (s1 == &s_signal) x->i_un.iu_floatsignalvalue = 0;
      else x->i_symto = s2;
      x->i_symfrom = s1;
      x->i_next = 0;
      x->i_tip = gensym("?");
!     if (y = owner->ob_inlet) {
          while ((y2=y->i_next)) y = y2;
          y->i_next = x;
      }
      else owner->ob_inlet = x;
!     return x;
  }
  
! t_inlet *signalinlet_new(t_object *owner, t_float f) {
      t_inlet *x = inlet_new(owner, &owner->ob_pd, &s_signal, &s_signal);
      x->i_un.iu_floatsignalvalue = f;
!     return x;
  }
  
***************
*** 679,684 ****
  }
  
! void inlet_free(t_inlet *x)
! {
      t_object *y = x->i_owner;
      t_inlet *x2;
--- 633,637 ----
  }
  
! void inlet_free(t_inlet *x) {
      t_object *y = x->i_owner;
      t_inlet *x2;
***************
*** 734,739 ****
      Before you call this check that the object doesn't have a more
      specific way to handle lists. */
! void obj_list(t_object *x, t_symbol *s, int argc, t_atom *argv)
! {
      t_atom *ap;
      int count;
--- 687,691 ----
      Before you call this check that the object doesn't have a more
      specific way to handle lists. */
! void obj_list(t_object *x, t_symbol *s, int argc, t_atom *argv) {
      t_atom *ap;
      int count;
***************
*** 787,792 ****
  } t_wire;
  
! struct _outlet
! {
      t_object *o_owner;
      struct _outlet *o_next;
--- 739,743 ----
  } t_wire;
  
! struct _outlet {
      t_object *o_owner;
      struct _outlet *o_next;
***************
*** 816,833 ****
  }
  
! t_outlet *outlet_new(t_object *owner, t_symbol *s)
! {
      t_outlet *x = (t_outlet *)getbytes(sizeof(*x)), *y, *y2;
      x->o_owner = owner;
      x->o_next = 0;
!     if (y = owner->ob_outlet)
!     {
          while (y2 = y->o_next) y = y2;
          y->o_next = x;
!     }
!     else owner->ob_outlet = x;
      x->o_connections = 0;
      x->o_sym = s;
!     return (x);
  }
  
--- 767,781 ----
  }
  
! t_outlet *outlet_new(t_object *owner, t_symbol *s) {
      t_outlet *x = (t_outlet *)getbytes(sizeof(*x)), *y, *y2;
      x->o_owner = owner;
      x->o_next = 0;
!     if (y = owner->ob_outlet) {
          while (y2 = y->o_next) y = y2;
          y->o_next = x;
!     } else owner->ob_outlet = x;
      x->o_connections = 0;
      x->o_sym = s;
!     return x;
  }
  
***************
*** 1061,1071 ****
      if (x->ob_pd->c_firstin && x->ob_pd->c_floatsignalin) {
          if (!m--)
!             return x->ob_pd->c_floatsignalin > 0 ?
!                 (t_sample *)(((char *)x) + x->ob_pd->c_floatsignalin) : 0;
          n++;
      }
      for (i = x->ob_inlet; i; i = i->i_next, m--) if (i->i_symfrom == &s_signal) {
!         if (m == 0)
!             return (&i->i_un.iu_floatsignalvalue);
          n++;
      }
--- 1009,1017 ----
      if (x->ob_pd->c_firstin && x->ob_pd->c_floatsignalin) {
          if (!m--)
!             return x->ob_pd->c_floatsignalin > 0 ? (t_sample *)(((char *)x) + x->ob_pd->c_floatsignalin) : 0;
          n++;
      }
      for (i = x->ob_inlet; i; i = i->i_next, m--) if (i->i_symfrom == &s_signal) {
!         if (m == 0) return &i->i_un.iu_floatsignalvalue;
          n++;
      }





More information about the Pd-cvs mailing list