On 02/03/2015 08:29 PM, IOhannes m zmölnig wrote:
On 02/03/2015 08:16 PM, IOhannes m zmölnig wrote:
EXTERN t_class *class_new32(...) EXTERN t_class *class_new64(...)
this btw, would also allow to write externals that provide both single- and double-prevision versions of an objectclass, without the need to change the extension.
they key to this is to provide dummy registration classes for the unsupported precisions, so an external compiled for the "wrong" architecture can be loaded by dlopen() but cannot actually *do* anything (wrong).
it's probably possible to all this in a single wrapper file, but i hope it's easier to understand without preprocessor magic.
a probably more readable example is the following: suppose we have a implementation of a given external (whose author used t_float/t_sample throughout, but has not done anything yet to port it to a singe/double "phat" binary. the objectclass is "mycobject" and lives in mycobject.c
then the following should be enough to make a phat binary: <mycobject_phat.c> void mycobject_setup32(); void mycobject_setup64(); void mycobject_setup() { mycobject_setup64(); mycobject_setup32(); } <mycobject_phat.c>
and compile the original code with the above glue as follows: $ cc -c -o mycobject-single.o mycobject.c -DPD_FLOATSIZE=32 \ -Dmycobject_setup=mycobject_setup32 $ cc -c -o mycobject-double.o mycobject.c -DPD_FLOATSIZE=64 \ -Dmycobject_setup=mycobject_setup64 $ cc -c -o mycobject-phat.o mycobject-phat.c $ cc -o mycobject.pd_linux \ mycobject-single.o mycobject-double.o mycobject-phat.o -lc
so the changes required to build such phat binaries are mainly (only¹) in the build-system, and no (properly written) code needs be touched.
gfmadsr IOhannes
¹ the glue-code given above is trivial and it should be easy to write a reuseable wrapper that is part of the build-system. something like embedding the following file in the build-system <phat.c> #define CONCAT_EXPAND(s1, s2) s1 ## s2 #define CONCAT(s1,s2) CONCAT_EXPAND(s1,s2) void CONCAT(SETUP, 32); void CONCAT(SETUP, 64); void SETUP () { CONCAT(SETUP, 32); CONCAT(SETUP, 64); return 0; } </phat.c> and compiling it as (3rd line in the above example): $ cc -c -o mycobject-phat.o phat.c -DSETUP=mycobject_setup