[PD-dev] proposed fix for objects named with +,-,*,^, etc.

Hans-Christoph Steiner hans at eds.org
Thu Nov 17 18:32:55 CET 2005


On Nov 17, 2005, at 7:22 AM, IOhannes m zmoelnig wrote:

> IOhannes m zmoelnig wrote:
>> just for a start i hacked this together (doesn't do the conversion  
>> when trying to load the .pd-files though!)
>
> so this is a version that also loads .pd files with alternative names.
> however, now 3 files are affected (m_class.c, s_loader.c, s_stuff.h)

Excellent!  I am going to include this patch in some upcoming beta  
builds so that we can work out any possible problems.

.hc


> i'll file the patches into the tracker.
>
> mfg.asd.r
> IOhannes
> diff -Naur src.org/m_class.c src/m_class.c
> --- src.org/m_class.c	2005-11-17 13:05:44.244141632 +0100
> +++ src/m_class.c	2005-11-17 13:17:55.620955456 +0100
> @@ -16,6 +16,7 @@
>
>  #include <stdarg.h>
>  #include <string.h>
> +#include <stdio.h>
>
>  static t_symbol *class_loadsym;     /* name under which an extern is  
> invoked */
>  static void pd_defaultfloat(t_pd *x, t_float f);
> @@ -513,6 +514,42 @@
>  t_symbol* pathsearch(t_symbol *s,char* ext);
>  int pd_setloadingabstraction(t_symbol *sym);
>
> +
> +/* replace everything but [a-zA-Z0-9_] by "0x%x" */
> +static char*alternative_classname(char*classname)
> +{
> +  char *altname=(char*)getbytes(sizeof(char)*MAXPDSTRING);
> +  int count=0;
> +  int i=0;
> +  for(i=0; i<MAXPDSTRING; i++)
> +    altname[i]=0;
> +  i=0;
> +  while(*classname)
> +    {
> +      char c=*classname;
> +      if((c>=48 && c<=57)|| /* [0-9] */
> +         (c>=65 && c<=90)|| /* [A-Z] */
> +         (c>=97 && c<=122)||/* [a-z] */
> +         (c==95)) /* [_] */
> +        {
> +          altname[i]=c;
> +          i++;
> +        }
> +      else /* a "bad" character */
> +        {
> +          sprintf(altname+i, "0x%02x", c);
> +          i+=4;
> +          count++;
> +        }
> +      classname++;
> +    }
> +  if(count>0)return altname;
> +  /* seems like the given classname is fine as can be */
> +  freebytes(altname, sizeof(char)*MAXPDSTRING);
> +  return 0;
> +}
> +
> +
>      /* this routine is called when a new "object" is requested whose  
> class Pd
>      doesn't know.  Pd tries to load it as an extern, then as an  
> abstraction. */
>  void new_anything(void *dummy, t_symbol *s, int argc, t_atom *argv)
> @@ -521,10 +558,11 @@
>      t_symbol *dir = canvas_getcurrentdir();
>      int fd;
>      char dirbuf[MAXPDSTRING], *nameptr;
> +    char *altname=alternative_classname(s->s_name);
>      if (tryingalready) return;
>      newest = 0;
>      class_loadsym = s;
> -    if (sys_load_lib(dir->s_name, s->s_name))
> +    if (sys_load_lib_alt(dir->s_name, s->s_name,altname))
>      {
>          tryingalready = 1;
>          typedmess(dummy, s, argc, argv);
> @@ -535,6 +573,8 @@
>      current = s__X.s_thing;
>      if ((fd = open_via_path(dir->s_name, s->s_name, ".pd",
>          dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0 ||
> +        (altname && (fd = open_via_path(dir->s_name, altname, ".pd",
> +              dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0) ||
>              (fd = open_via_path(dir->s_name, s->s_name, ".pat",
>                  dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0)
>      {
> diff -Naur src.org/s_loader.c src/s_loader.c
> --- src.org/s_loader.c	2005-11-17 13:05:44.288134944 +0100
> +++ src/s_loader.c	2005-11-17 13:17:55.651950744 +0100
> @@ -46,10 +46,11 @@
>
>  void class_set_extern_dir(t_symbol *s);
>
> -int sys_load_lib(char *dirname, char *classname)
> +int sys_load_lib_alt(char *dirname, char *classname, char*altname)
>  {
>      char symname[MAXPDSTRING], filename[MAXPDSTRING],  
> dirbuf[MAXPDSTRING],
> -        classname2[MAXPDSTRING], *nameptr, *lastdot;
> +      classname2[MAXPDSTRING], *nameptr, *lastdot,
> +      altsymname[MAXPDSTRING];
>      void *dlobj;
>      t_xxx makeout = NULL;
>      int fd;
> @@ -72,6 +73,25 @@
>          if ((fd = open_via_path(dirname, classname2, sys_dllextent,
>              dirbuf, &nameptr, MAXPDSTRING, 1)) < 0)
>          {
> +          /* next try (alternative_classname).(sys_dllextent) */
> +          if(altname)
> +            {
> +              if ((fd = open_via_path(dirname, altname, sys_dllextent,
> +                                      dirbuf, &nameptr, MAXPDSTRING,  
> 1)) < 0)
> +
> +                /* next try  
> (alternative_classname)/(alternative_classname).(sys_dllextent) ... */
> +                strncpy(classname2, altname, MAXPDSTRING);
> +              filename[MAXPDSTRING-2] = 0;
> +              strcat(classname2, "/");
> +              strncat(classname2, altname,  
> MAXPDSTRING-strlen(classname2));
> +              filename[MAXPDSTRING-1] = 0;
> +              if ((fd = open_via_path(dirname, classname2,  
> sys_dllextent,
> +                                      dirbuf, &nameptr, MAXPDSTRING,  
> 1)) < 0)
> +                {
> +                  return 0;
> +                }
> +            }
> +          else
>              return (0);
>          }
>      }
> @@ -93,9 +113,20 @@
>  #ifdef MACOSX
>      strcpy(symname, "_");
>      strcat(symname, nameptr);
> +    if(altname)
> +      {
> +        strcpy(altsymname, "_setup_");
> +        strcat(symname, altname);
> +      }
>  #else
>      strcpy(symname, nameptr);
> +    if(altname)
> +      {
> +        strcpy(altsymname, "setup_");
> +        strcat(altsymname, altname);
> +      }
>  #endif
> +
>          /* if the last character is a tilde, replace with "_tilde" */
>      if (symname[strlen(symname) - 1] == '~')
>          strcpy(symname + (strlen(symname) - 1), "_tilde");
> @@ -110,6 +141,7 @@
>          return (0);
>      }
>      makeout = (t_xxx)dlsym(dlobj,  symname);
> +    if(!makeout)makeout = (t_xxx)dlsym(dlobj,  altsymname);
>  #endif
>  #ifdef MSW
>      sys_bashfilename(filename, filename);
> @@ -121,6 +153,7 @@
>          return (0);
>      }
>      makeout = (t_xxx)GetProcAddress(ntdll, symname);
> +    if(!makeout)makeout = (t_xxx)GetProcAddress(ntdll, altsymname);
>  #endif
>  #ifdef MACOSX
>      {
> @@ -147,6 +180,8 @@
>          }
>          s = NSLookupSymbolInModule(ret, symname);
>
> +        if(!s)s=NSLookupSymbolInModule(ret, altsymname);
> +
>          if (s)
>              makeout = (t_xxx)NSAddressOfSymbol( s);
>          else makeout = 0;
> @@ -156,6 +191,8 @@
>      if (!makeout)
>      {
>          post("load_object: Symbol \"%s\" not found", symname);
> +        if(altname)
> +          post("load_object: Symbol \"%s\" not found", altsymname);
>          class_set_extern_dir(&s_);
>          return 0;
>      }
> @@ -164,6 +201,10 @@
>      return (1);
>  }
>
> +int sys_load_lib(char *dirname, char *filename)
> +{
> +  return sys_load_lib_alt(dirname, filename, 0);
> +}
>
>
>
> diff -Naur src.org/s_stuff.h src/s_stuff.h
> --- src.org/s_stuff.h	2005-11-17 13:05:44.301132968 +0100
> +++ src/s_stuff.h	2005-11-17 13:17:55.656949984 +0100
> @@ -47,6 +47,7 @@
>
>  /* s_loader.c */
>  int sys_load_lib(char *dirname, char *filename);
> +int sys_load_lib_alt(char *dirname, char *filename, char* altname);
>
>  /* s_audio.c */
>
>

________________________________________________________________________ 
____

"I have the audacity to believe that peoples everywhere can have three  
meals a day for their bodies, education and culture for their minds,  
and dignity, equality and freedom for their spirits."
                                             - Martin Luther King, Jr.





More information about the Pd-dev mailing list