[PD-cvs] externals/miXed/shared/toxy plusbob.c, 1.3, 1.4 plusbob.h, 1.1, 1.2

Krzysztof Czaja krzyszcz at users.sourceforge.net
Mon May 30 11:29:28 CEST 2005


Update of /cvsroot/pure-data/externals/miXed/shared/toxy
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23253/shared/toxy

Modified Files:
	plusbob.c plusbob.h 
Log Message:
toxy alpha18 and pddp alpha2 (see notes.txt for toxy, pddp and shared)

Index: plusbob.c
===================================================================
RCS file: /cvsroot/pure-data/externals/miXed/shared/toxy/plusbob.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** plusbob.c	11 Jan 2005 10:33:21 -0000	1.3
--- plusbob.c	30 May 2005 09:29:26 -0000	1.4
***************
*** 1,3 ****
! /* Copyright (c) 2003 krzYszcz and others.
   * For information on usage and redistribution, and for a DISCLAIMER OF ALL
   * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */
--- 1,3 ----
! /* Copyright (c) 2003-2005 krzYszcz and others.
   * For information on usage and redistribution, and for a DISCLAIMER OF ALL
   * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */
***************
*** 12,21 ****
  #endif
  
! /* LATER let there be a choice of using either fake-symbols, or gpointers.
     The gpointer layout would be such:  gs_un points to a plusbob-like
!    structure (without the bob_tag field), a unique integer code has to be
     reserved for gs_which, the fields gp_un and gp_valid are ignored.
     Using bob_refcount instead of gs_refcount is likely to simplify code. */
  
  /* Currently, objects of all +bob types are tagged with the same name: */
  static char plustag_name[] = "+bob";
--- 12,39 ----
  #endif
  
! /* The main failure of the current implementation is when a foreign object
!    stores a faked symbol beyond lifetime of a wrappee.  There is no obvious
!    way of protecting against stale pointers, other than leaking small
!    portions of memory (four words) with every new faked symbol.  In case of
!    plustot, this is not a very big deal, since for each [+tot] object the
!    number of wrapped tcl objects is small and constant.
! 
!    Another failure is when a foreign object binds something to a faked
!    symbol (for example, when a faked symbol is passed to an array's rename
!    method).  This should not happen in usual contexts, and even if it does,
!    it will unlikely cause any real harm.
! 
!    LATER let there be a choice of using either fake-symbols, or gpointers.
     The gpointer layout would be such:  gs_un points to a plusbob-like
!    structure (without the bob_stub field), a unique integer code has to be
     reserved for gs_which, the fields gp_un and gp_valid are ignored.
     Using bob_refcount instead of gs_refcount is likely to simplify code. */
  
+ typedef struct _plusstub
+ {
+     t_symbol    sb_tag;  /* common value for all bob types */
+     t_plusbob  *sb_bob;
+ } t_plusstub;
+ 
  /* Currently, objects of all +bob types are tagged with the same name: */
  static char plustag_name[] = "+bob";
***************
*** 28,36 ****
  }
  
! /* silent if caller is empty */
! int plustag_isvalid(t_symbol *tag, t_pd *caller)
  {
      if (tag->s_name == plustag_name)
! 	return (1);
      else if (caller)
      {
--- 46,54 ----
  }
  
! /* returns tagged +bob if valid, null otherwise (silent if caller is empty) */
! t_plusbob *plustag_isvalid(t_symbol *tag, t_pd *caller)
  {
      if (tag->s_name == plustag_name)
! 	return (((t_plusstub *)tag)->sb_bob);
      else if (caller)
      {
***************
*** 44,47 ****
--- 62,73 ----
  }
  
+ static t_plusstub *plusstub_create(t_plusbob *bob)
+ {
+     t_plusstub *stub = getbytes(sizeof(*stub));
+     plustag_init(&stub->sb_tag);
+     stub->sb_bob = bob;
+     return (stub);
+ }
+ 
  /* +bob is an object tossed around, a bobbing object.  Currently, this is
     a wrapping for Tcl_Interp, Tcl_Obj, or a tcl variable, but the +bob
***************
*** 129,133 ****
      if (bob = getbytes(tp->tp_size))
      {
! 	plustag_init(&bob->bob_tag);
  	bob->bob_type = tp;
  	while (tp->tp_base) tp = tp->tp_base;
--- 155,159 ----
      if (bob = getbytes(tp->tp_size))
      {
! 	bob->bob_stub = (t_symbol *)plusstub_create(bob);
  	bob->bob_type = tp;
  	while (tp->tp_base) tp = tp->tp_base;
***************
*** 155,158 ****
--- 181,185 ----
  	if (tp->tp_deletefn) (*tp->tp_deletefn)(bob);
      freebytes(bob, (bob->bob_type ? bob->bob_type->tp_size : sizeof(*bob)));
+     /* the stub remains... */
  }
  
***************
*** 252,270 ****
  void outlet_plusbob(t_outlet *o, t_plusbob *bob)
  {
!     outlet_symbol(o, (t_symbol *)bob);
  }
  
! /* silent if caller is empty */
! int plustag_validtype(t_symbol *tag, t_symbol *tname, t_pd *caller)
  {
      if (tag->s_name == plustag_name)
      {
! 	if (((t_plusbob *)tag)->bob_type->tp_name == tname)
! 	    return (1);
  	else if (caller)
  	{
! 	    t_symbol *s = ((t_plusbob *)tag)->bob_type->tp_name;
! 	    loud_error((caller == PLUSBOB_OWNER ?
! 			((t_plusbob *)tag)->bob_owner : caller),
  		       "invalid type '%s' ('%s' expected)",
  		       (s ? s->s_name : "<unknown>"),
--- 279,297 ----
  void outlet_plusbob(t_outlet *o, t_plusbob *bob)
  {
!     outlet_symbol(o, bob->bob_stub);
  }
  
! /* returns tagged +bob if valid, null otherwise (silent if caller is empty) */
! t_plusbob *plustag_validtype(t_symbol *tag, t_symbol *tname, t_pd *caller)
  {
      if (tag->s_name == plustag_name)
      {
! 	t_plusbob *bob = ((t_plusstub *)tag)->sb_bob;
! 	if (bob->bob_type->tp_name == tname)
! 	    return (bob);
  	else if (caller)
  	{
! 	    t_symbol *s = bob->bob_type->tp_name;
! 	    loud_error((caller == PLUSBOB_OWNER ? bob->bob_owner : caller),
  		       "invalid type '%s' ('%s' expected)",
  		       (s ? s->s_name : "<unknown>"),
***************
*** 277,292 ****
  }
  
! /* silent if caller is empty */
! int plustag_validroot(t_symbol *tag, t_symbol *rname, t_pd *caller)
  {
      if (tag->s_name == plustag_name)
      {
! 	if (((t_plusbob *)tag)->bob_root->tp_name == rname)
! 	    return (1);
  	else if (caller)
  	{
! 	    t_symbol *s = ((t_plusbob *)tag)->bob_root->tp_name;
! 	    loud_error((caller == PLUSBOB_OWNER ?
! 			((t_plusbob *)tag)->bob_owner : caller),
  		       "invalid base type '%s' ('%s' expected)",
  		       (s ? s->s_name : "<unknown>"),
--- 304,319 ----
  }
  
! /* returns tagged +bob if valid, null otherwise (silent if caller is empty) */
! t_plusbob *plustag_validroot(t_symbol *tag, t_symbol *rname, t_pd *caller)
  {
      if (tag->s_name == plustag_name)
      {
! 	t_plusbob *bob = ((t_plusstub *)tag)->sb_bob;
! 	if (bob->bob_root->tp_name == rname)
! 	    return (bob);
  	else if (caller)
  	{
! 	    t_symbol *s = bob->bob_root->tp_name;
! 	    loud_error((caller == PLUSBOB_OWNER ? bob->bob_owner : caller),
  		       "invalid base type '%s' ('%s' expected)",
  		       (s ? s->s_name : "<unknown>"),
***************
*** 302,306 ****
  {
      if (!validate || tag->s_name == plustag_name)
! 	return (((t_plusbob *)tag)->bob_type->tp_name);
      else if (plustag_isvalid(tag, caller))  /* print the error there */
  	loudbug_bug("plustag_typename");
--- 329,333 ----
  {
      if (!validate || tag->s_name == plustag_name)
! 	return (((t_plusstub *)tag)->sb_bob->bob_type->tp_name);
      else if (plustag_isvalid(tag, caller))  /* print the error there */
  	loudbug_bug("plustag_typename");
***************
*** 311,315 ****
  {
      if (!validate || tag->s_name == plustag_name)
! 	return (((t_plusbob *)tag)->bob_root->tp_name);
      else if (plustag_isvalid(tag, caller))  /* print the error there */
  	loudbug_bug("plustag_rootname");
--- 338,342 ----
  {
      if (!validate || tag->s_name == plustag_name)
! 	return (((t_plusstub *)tag)->sb_bob->bob_root->tp_name);
      else if (plustag_isvalid(tag, caller))  /* print the error there */
  	loudbug_bug("plustag_rootname");

Index: plusbob.h
===================================================================
RCS file: /cvsroot/pure-data/externals/miXed/shared/toxy/plusbob.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** plusbob.h	19 Feb 2004 22:23:17 -0000	1.1
--- plusbob.h	30 May 2005 09:29:26 -0000	1.2
***************
*** 1,3 ****
! /* Copyright (c) 2003 krzYszcz and others.
   * For information on usage and redistribution, and for a DISCLAIMER OF ALL
   * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */
--- 1,3 ----
! /* Copyright (c) 2003-2005 krzYszcz and others.
   * For information on usage and redistribution, and for a DISCLAIMER OF ALL
   * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */
***************
*** 13,19 ****
  #define t_plusenv  struct _plusenv
  
  struct _plusbob
  {
!     t_symbol     bob_tag;   /* common value for all bob types */
      t_plustype  *bob_type;  /* our type */
      t_plustype  *bob_root;  /* our base type directly derived from t_plusbob */
--- 13,20 ----
  #define t_plusenv  struct _plusenv
  
+ /* LATER move to plusbob.c */
  struct _plusbob
  {
!     t_symbol    *bob_stub;  /* points back to stub = symbol, pointer-to-here */
      t_plustype  *bob_type;  /* our type */
      t_plustype  *bob_root;  /* our base type directly derived from t_plusbob */
***************
*** 38,42 ****
  typedef void (*t_plustypefn)(void *);
  
! int plustag_isvalid(t_symbol *s, t_pd *caller);
  
  t_plustype *plustype_new(t_plustype *base, t_symbol *name, size_t sz,
--- 39,47 ----
  typedef void (*t_plustypefn)(void *);
  
! t_plusbob *plustag_isvalid(t_symbol *tag, t_pd *caller);
! t_plusbob *plustag_validtype(t_symbol *tag, t_symbol *tname, t_pd *caller);
! t_plusbob *plustag_validroot(t_symbol *tag, t_symbol *rname, t_pd *caller);
! t_symbol *plustag_typename(t_symbol *tag, int validate, t_pd *caller);
! t_symbol *plustag_rootname(t_symbol *tag, int validate, t_pd *caller);
  
  t_plustype *plustype_new(t_plustype *base, t_symbol *name, size_t sz,
***************
*** 58,65 ****
  t_pd *plusbob_getowner(t_plusbob *bob);
  void outlet_plusbob(t_outlet *o, t_plusbob *bob);
- int plustag_validtype(t_symbol *tag, t_symbol *tname, t_pd *caller);
- int plustag_validroot(t_symbol *tag, t_symbol *rname, t_pd *caller);
- t_symbol *plustag_typename(t_symbol *tag, int validate, t_pd *caller);
- t_symbol *plustag_rootname(t_symbol *tag, int validate, t_pd *caller);
  
  t_plusenv *plusenv_create(t_plustype *tp, t_plusbob *parent, t_symbol *id);
--- 63,66 ----





More information about the Pd-cvs mailing list