From 438c72cef654e6efae83d16b31d685284a3b34e5 Mon Sep 17 00:00:00 2001 From: Jonathan Wilkes <jon.w.wilkes@gmail.com> Date: Mon, 14 Aug 2017 14:23:38 -0400 Subject: [PATCH] add hexmunger loading to the main loader. This is way simplified over the hexloader external (which will consequently be removed). The interface is: 1. If any characters that were illegal in a C function name were in the given object name, we get a "hexmunged" symbol where each illegal character is replaced with a "0x%c" where "%c" is the hex representation of that illegal character. 2. If we have a "hexmunged" symbol, we search for a file by the newly munged name. Currently this is search in addition to the normal paths-- it could probably be searched instead of it but I'm not completely sure if there are any edge cases that would be affected by that. 3. If the file is found, the loader searches for a setup routine named "setup_hexmungedSymbol". If it's a tilde object, it searches for "setup_hexmungedSymbol_tilde". (Note: normal external libs search for "normalLibname_setup".) Caveat: a lot of the obviously ad-hoc code for handling this cases in the external libraries just uses an "#include" directive for the entire C file of the original object. E.g., mtx_0x2a.c just does #include "../src/mtx_mul.c" with an extra setup routine that just calls the original one. So if a patch or running instance has both the [mtx_*] _and_ the [mtx_mul] objects, two separate libraries which essentially the same code and "setup" symbol will get loaded. The same is true for the original hexloader. I haven't had time to study the loaders on all Pd's platforms to figure out what the side-effects are of this approach --- pd/src/s_loader.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pd/src/s_loader.c b/pd/src/s_loader.c index fe1304c63..84924cbf8 100644 --- a/pd/src/s_loader.c +++ b/pd/src/s_loader.c @@ -165,6 +165,25 @@ static int sys_do_load_lib(t_canvas *canvas, const char *objectname, if ((fd = sys_trytoopenone(path, filename, sys_dllextent2, dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0) goto gotone; + /* for hexmunged binary external files, give it a shot + with the hexmunged name. This is a really ugly system + but we need it for all the legacy libraries that use + funky characters. (The only alternative is putting libdir + classes all in a single file and preloading, which is + even worse. + The hexmunger never worked for abstractions without recompiling, + so we don't and won't support hexmunged abstractions. + */ + if (hexmunge) + { + if ((fd = sys_trytoopenone(path, symname+6, sys_dllextent, + dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0) + goto gotone; + /* same, with the more generic sys_dllextent2 */ + if ((fd = sys_trytoopenone(path, symname+6, sys_dllextent2, + dirbuf, &nameptr, MAXPDSTRING, 1)) >= 0) + goto gotone; + } #ifdef ANDROID /* Android libs have a 'lib' prefix, '.so' suffix and don't allow ~ */ char libname[MAXPDSTRING] = "lib"; -- GitLab