So I am able to get objects with +, -, *, and ^ in the name to compile as individual files, I was not able to get objects with / in the name to work, plus they might cause problems with geiger namespaces (i.e. [libname/object]). But the only problem left is the setup functions.
AFAIK you are not allowed to have setup functions named mtx_+_setup(), mtx_-_setup() , etc. So if pd would translate the symbols to a word, like "mtx_plus_setup", like it does for ~, then this whole thing would work.
Currently, there is a little workaround for objects with aliases. If you load [mtx_sub], for example, then you can load [mtx_-] since [mtx_sub] will generate the symbol "mtx_-", etc.
.hc
________________________________________________________________________ ____
"[W]e have invented the technology to eliminate scarcity, but we are deliberately throwing it away to benefit those who profit from scarcity." -John Gilmore
Hans-Christoph Steiner wrote:
So I am able to get objects with +, -, *, and ^ in the name to compile as individual files, I was not able to get objects with / in the name to work, plus they might cause problems with geiger namespaces (i.e. [libname/object]). But the only problem left is the setup functions.
AFAIK you are not allowed to have setup functions named mtx_+_setup(), mtx_-_setup() , etc. So if pd would translate the symbols to a word, like "mtx_plus_setup", like it does for ~, then this whole thing would work.
Currently, there is a little workaround for objects with aliases. If you load [mtx_sub], for example, then you can load [mtx_-] since [mtx_sub] will generate the symbol "mtx_-", etc.
oh indeed!
so this is the 3rd mail on this topic. i really think it is a minor but important issue, that's why i didn't understand why everybody ignored my first 2 mails...(so that's why i am a bit sarcastic here)
anyhow i'll repeat what i have written: i think, that the "replacing '~' by 'tilde'" is a very clumsy approach. there is no real reason, why "mtx_plus_setup()" is better than "mtx_add_setup()" or anything else (both are human-readable; none is generic) the real problem i see is, that while we might find "good" replacements for +,-,*,^,,,. we will not find a replacement for "etc".
furthermore, there are certain character which cannot be used for filenames on certain filesystems (e.g. "||~.pd" as found in zexy is not a valid filename on w32)
i thus proposed (and propose again), to have additional (optional) setup functions (and filenames) which are encoded in a way, that is "safe".
simplest thing would be, to encode every character with in hexadecimal: e.g. the external [||~] would be in a file "7c7c7e.pd_linux" and would have a setup-function "setupHEX_7c7c7e()"
other things like [mtx_+] could be in a file "mtx_+.pd_linux" and still have a setup-function "setupHEX_6d74785f2b()"
i use a different scheme for the setup-function name, to avoid conflicts with normal setup-functions (just imagine, somebody made an object that is really called [7a7b]; additionally C-functions must not start with numbers)
i admit that the hex-encoding is inefficient (in terms of bits) and non-readable by humans. however, it is very simple and consistent.
what do you think?
mfg.a.dsr IOhannes
On Nov 15, 2005, at 3:26 PM, IOhannes m zmölnig wrote:
Hans-Christoph Steiner wrote:
So I am able to get objects with +, -, *, and ^ in the name to compile as individual files, I was not able to get objects with / in the name to work, plus they might cause problems with geiger namespaces (i.e. [libname/object]). But the only problem left is the setup functions. AFAIK you are not allowed to have setup functions named mtx_+_setup(), mtx_-_setup() , etc. So if pd would translate the symbols to a word, like "mtx_plus_setup", like it does for ~, then this whole thing would work. Currently, there is a little workaround for objects with aliases. If you load [mtx_sub], for example, then you can load [mtx_-] since [mtx_sub] will generate the symbol "mtx_-", etc.
oh indeed!
so this is the 3rd mail on this topic. i really think it is a minor but important issue, that's why i didn't understand why everybody ignored my first 2 mails...(so that's why i am a bit sarcastic here)
anyhow i'll repeat what i have written: i think, that the "replacing '~' by 'tilde'" is a very clumsy approach. there is no real reason, why "mtx_plus_setup()" is better than "mtx_add_setup()" or anything else (both are human-readable; none is generic) the real problem i see is, that while we might find "good" replacements for +,-,*,^,,,. we will not find a replacement for "etc".
furthermore, there are certain character which cannot be used for filenames on certain filesystems (e.g. "||~.pd" as found in zexy is not a valid filename on w32)
i thus proposed (and propose again), to have additional (optional) setup functions (and filenames) which are encoded in a way, that is "safe".
simplest thing would be, to encode every character with in hexadecimal: e.g. the external [||~] would be in a file "7c7c7e.pd_linux" and would have a setup-function "setupHEX_7c7c7e()"
other things like [mtx_+] could be in a file "mtx_+.pd_linux" and still have a setup-function "setupHEX_6d74785f2b()"
i use a different scheme for the setup-function name, to avoid conflicts with normal setup-functions (just imagine, somebody made an object that is really called [7a7b]; additionally C-functions must not start with numbers)
i admit that the hex-encoding is inefficient (in terms of bits) and non-readable by humans. however, it is very simple and consistent.
Well, I just ran into the problem while getting iemmatrix objects to compile as individual files, funny enough. So I guess you've been thru this already.
The overall idea sounds good, but why not just use HEX translation for just the characters that are not allowed on the filesystems and in C functions? This would keep the filenames and function names human readable. We could do something like HTML entities or C hex with a reserved combo of chars to define a special char, something like 0x then two digits. For example:
[mtx_+] == mtx_0x7e.pd_linux == setup_mtx_0x7e() [osc~] == osc0x7e.pd_linux == setup_osc0x7e
Then to type out "0x" you would just do the hex of "0" and "x" if we really wanted that.
.hc
________________________________________________________________________ ____
"The arc of history bends towards justice." - Dr. Martin Luther King, Jr.
Hans-Christoph Steiner wrote:
i admit that the hex-encoding is inefficient (in terms of bits) and non-readable by humans. however, it is very simple and consistent.
Well, I just ran into the problem while getting iemmatrix objects to compile as individual files, funny enough. So I guess you've been thru this already.
actually my problem was rather with zexy, since i have currently no plans to split iemmatrix into individual files (the plans are rather in the opposite direction: bundle functionality into "helper-files") (sorry about that...)
The overall idea sounds good, but why not just use HEX translation for just the characters that are not allowed on the filesystems and in C functions? This would keep the filenames and function names human readable. We could do something like HTML entities or C hex with a reserved combo of chars to define a special char, something like 0x then two digits. For example:
[mtx_+] == mtx_0x7e.pd_linux == setup_mtx_0x7e() [osc~] == osc0x7e.pd_linux == setup_osc0x7e
Then to type out "0x" you would just do the hex of "0" and "x" if we really wanted that.
this seems to be ok. so which characters should be escaped then? everything but [a-zA-Z0-9_] ? (i would suggest an implicit definition rather than an explicit one, since you never know...)
mfg.asd.f IOhannes
On Nov 16, 2005, at 4:31 AM, IOhannes m zmoelnig wrote:
Hans-Christoph Steiner wrote:
i admit that the hex-encoding is inefficient (in terms of bits) and non-readable by humans. however, it is very simple and consistent.
Well, I just ran into the problem while getting iemmatrix objects to compile as individual files, funny enough. So I guess you've been thru this already.
actually my problem was rather with zexy, since i have currently no plans to split iemmatrix into individual files (the plans are rather in the opposite direction: bundle functionality into "helper-files") (sorry about that...)
Too late, I already did. ;) Check externals/build/src. What do you mean by helper files?
The overall idea sounds good, but why not just use HEX translation for just the characters that are not allowed on the filesystems and in C functions? This would keep the filenames and function names human readable. We could do something like HTML entities or C hex with a reserved combo of chars to define a special char, something like 0x then two digits. For example: [mtx_+] == mtx_0x7e.pd_linux == setup_mtx_0x7e() [osc~] == osc0x7e.pd_linux == setup_osc0x7e Then to type out "0x" you would just do the hex of "0" and "x" if we really wanted that.
this seems to be ok. so which characters should be escaped then? everything but [a-zA-Z0-9_] ? (i would suggest an implicit definition rather than an explicit one, since you never know...)
I totally agree, keep it flexible and open. [a-zA-Z0-9_] sounds good to me.
It would be nice to have filenames and setup functions treated separately, so that filenames would remain human-readable. Filenames would only need to substitute:
["/*?<>|:]
Here's a little breakdown of the relevant filesystems:
http://www.comentum.com/File-Systems-HFS-FAT-UFS.html
.hc
________________________________________________________________________ ____
Hans-Christoph Steiner wrote:
actually my problem was rather with zexy, since i have currently no plans to split iemmatrix into individual files (the plans are rather in the opposite direction: bundle functionality into "helper-files") (sorry about that...)
Too late, I already did. ;) Check externals/build/src. What do you mean by helper files?
yes i noticed that and i am fine with it. however, please do not expect from me, that i will take care of not breaking this possibility.
i just noticed that a lot of shared functionality is spread over various files that are used by others, and obviously your approach with including c-files rather than doing proper linking works. most likely it will not get worse...
this seems to be ok. so which characters should be escaped then? everything but [a-zA-Z0-9_] ? (i would suggest an implicit definition rather than an explicit one, since you never know...)
I totally agree, keep it flexible and open. [a-zA-Z0-9_] sounds good to me.
It would be nice to have filenames and setup functions treated separately, so that filenames would remain human-readable. Filenames would only need to substitute:
["/*?<>|:]
for simplicities sake, i would suggest to not treat them totally different, but rather do it at 2 levels: example: creating an object [mtx_+] pd searches all it's paths for mtx_+.pd_linux (and mtx_+.pd, but we'll skip that part). if it finds a mtx_+.pd_linux then it will try to call the "mtx_+_setup()" function within this external. if that fails, it will try to call "setup_mtx_0x2b()" if it doesn't find a mtx_+.pd_linux it will search for a "mtx_0x2b.pd_linux"; if it finds that one, it will try to call "mtx_+_setup()" and afterwards "setup_mtx_0x2b()".
this should keep filenames as human-readable as possible while being most flexible.
as for abstractions, it would probably make most sense to 1. search for "mtx_+.pd_linux" 2. search for "mtx_0x2b.pd_linux" 3. search for "mtx_+.pd" 4. search for "mtx_0x2b.pd"
mfg.as.dr IOhannes
just for a start i hacked this together (doesn't do the conversion when trying to load the .pd-files though!)
mfg.asd.r IOhannes
--- s_loader.c.org 2005-11-16 19:45:32.550161296 +0100 +++ s_loader.c 2005-11-16 19:41:13.935476704 +0100 @@ -46,10 +46,45 @@
void class_set_extern_dir(t_symbol *s);
+/* 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; +} + int sys_load_lib(char *dirname, char *classname) { char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING], - classname2[MAXPDSTRING], *nameptr, *lastdot; + classname2[MAXPDSTRING], *nameptr, *lastdot, + altsymname[MAXPDSTRING], *altname=0; void *dlobj; t_xxx makeout = NULL; int fd; @@ -59,6 +94,7 @@ #if 0 fprintf(stderr, "lib %s %s\n", dirname, classname); #endif + altname=alternative_classname(classname); /* try looking in the path for (classname).(sys_dllextent) ... */ if ((fd = open_via_path(dirname, classname, sys_dllextent, dirbuf, &nameptr, MAXPDSTRING, 1)) < 0) @@ -72,6 +108,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 +148,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 +176,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 +188,7 @@ return (0); } makeout = (t_xxx)GetProcAddress(ntdll, symname); + if(!makeout)makeout = (t_xxx)GetProcAddress(ntdll, altsymname); #endif #ifdef MACOSX { @@ -147,6 +215,8 @@ } s = NSLookupSymbolInModule(ret, symname);
+ if(!s)s=NSLookupSymbolInModule(ret, altsymname); + if (s) makeout = (t_xxx)NSAddressOfSymbol( s); else makeout = 0; @@ -156,6 +226,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; }
Nice! I'll include it on the extended builds that I am working on right now.
.hc
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!)
mfg.asd.r IOhannes
--- s_loader.c.org 2005-11-16 19:45:32.550161296 +0100 +++ s_loader.c 2005-11-16 19:41:13.935476704 +0100 @@ -46,10 +46,45 @@
void class_set_extern_dir(t_symbol *s);
+/* 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;
+}
int sys_load_lib(char *dirname, char *classname) { char symname[MAXPDSTRING], filename[MAXPDSTRING], dirbuf[MAXPDSTRING],
classname2[MAXPDSTRING], *nameptr, *lastdot;
classname2[MAXPDSTRING], *nameptr, *lastdot,
void *dlobj; t_xxx makeout = NULL; int fd;altsymname[MAXPDSTRING], *altname=0;
@@ -59,6 +94,7 @@ #if 0 fprintf(stderr, "lib %s %s\n", dirname, classname); #endif
- altname=alternative_classname(classname); /* try looking in the path for (classname).(sys_dllextent) ... */ if ((fd = open_via_path(dirname, classname, sys_dllextent, dirbuf, &nameptr, MAXPDSTRING, 1)) < 0)
@@ -72,6 +108,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 +148,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 (symname[strlen(symname) - 1] == '~') strcpy(symname + (strlen(symname) - 1), "_tilde");/* if the last character is a tilde, replace with "_tilde" */
@@ -110,6 +176,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 +188,7 @@ return (0); } makeout = (t_xxx)GetProcAddress(ntdll, symname);
- if(!makeout)makeout = (t_xxx)GetProcAddress(ntdll, altsymname);
#endif #ifdef MACOSX { @@ -147,6 +215,8 @@ } s = NSLookupSymbolInModule(ret, symname);
if(!s)s=NSLookupSymbolInModule(ret, altsymname);
if (s) makeout = (t_xxx)NSAddressOfSymbol( s); else makeout = 0;
@@ -156,6 +226,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;
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)
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 */
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,
void *dlobj; t_xxx makeout = NULL; int fd;altsymname[MAXPDSTRING];
@@ -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 (symname[strlen(symname) - 1] == '~') strcpy(symname + (strlen(symname) - 1), "_tilde");/* if the last character is a tilde, replace with "_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.
On Nov 17, 2005, at 12:54 PM, IOhannes m zmoelnig wrote:
Hans-Christoph Steiner wrote:
Excellent! I am going to include this patch in some upcoming beta builds so that we can work out any possible problems.
one problem i can see so far is, that libraries that are loaded with "-lib" will not get expanded.
Do you mean that lib filenames can't have special characters? Or do you mean that setup functions in libs can't have special characters? The first hardly matters, and the second is easy enough to workaround, so its not a big deal for now.
.hc
________________________________________________________________________ ____
"Information wants to be free." -Stewart Brand
Hans-Christoph Steiner wrote:
On Nov 17, 2005, at 12:54 PM, IOhannes m zmoelnig wrote:
Hans-Christoph Steiner wrote:
Excellent! I am going to include this patch in some upcoming beta builds so that we can work out any possible problems.
one problem i can see so far is, that libraries that are loaded with "-lib" will not get expanded.
Do you mean that lib filenames can't have special characters? Or do you mean that setup functions in libs can't have special characters? The first hardly matters, and the second is easy enough to workaround, so its not a big deal for now.
the escaping mechanism as i have implemented right now just doesn't work forthe libraries (==externals!) that are loaded via the "-lib" flags.
you are right, that it is not a big deal: libraries should have a decent name, and externals will be initialized later (on demand).
mfga.dsr. IOhannes
IOhannes m zmoelnig wrote:
Hans-Christoph Steiner wrote:
actually my problem was rather with zexy, since i have currently no plans to split iemmatrix into individual files (the plans are rather in the opposite direction: bundle functionality into "helper-files") (sorry about that...)
Too late, I already did. ;) Check externals/build/src. What do you mean by helper files?
yes i noticed that and i am fine with it. however, please do not expect from me, that i will take care of not breaking this possibility.
Well, it would be nice if you took at least some care since this is what the extended builds are based on.
i just noticed that a lot of shared functionality is spread over various files that are used by others, and obviously your approach with including c-files rather than doing proper linking works. most likely it will not get worse...
Its kind of a hack, but so far I don't think there has been any problems with it.
this seems to be ok. so which characters should be escaped then? everything but [a-zA-Z0-9_] ? (i would suggest an implicit definition rather than an explicit one, since you never know...)
I totally agree, keep it flexible and open. [a-zA-Z0-9_] sounds good to me.
It would be nice to have filenames and setup functions treated separately, so that filenames would remain human-readable. Filenames would only need to substitute:
["/*?<>|:]
for simplicities sake, i would suggest to not treat them totally different, but rather do it at 2 levels: example: creating an object [mtx_+] pd searches all it's paths for mtx_+.pd_linux (and mtx_+.pd, but we'll skip that part). if it finds a mtx_+.pd_linux then it will try to call the "mtx_+_setup()" function within this external. if that fails, it will try to call "setup_mtx_0x2b()" if it doesn't find a mtx_+.pd_linux it will search for a "mtx_0x2b.pd_linux"; if it finds that one, it will try to call "mtx_+_setup()" and afterwards "setup_mtx_0x2b()".
this should keep filenames as human-readable as possible while being most flexible.
as for abstractions, it would probably make most sense to
- search for "mtx_+.pd_linux"
- search for "mtx_0x2b.pd_linux"
- search for "mtx_+.pd"
- search for "mtx_0x2b.pd"
Works for me.
.hc