I very much agree that in the future Pd (and externals) could be always compiled with PDINSTANCE.
I was thinking to a way for the transition: we could:
- change the t_pdinstance pd_s_* fields to pointers (and adapt the s_* replacement macros accordingly),
- export "hidden" globals s_*
- initialize pd_maininstance pd_s_* fields to the global versions.
CURRENT:
/* m_pd.h */
struct _pdinstance
{
t_symbol pd_s_float;
}
#define s_float (pd_this->pd_s_float)
/* m_class.c */
t_pdinstance *pdinstance_init(t_pdinstance *x)
{
dogensym("float", &x->pd_s_float, x);
}
PROPOSAL:
/* m_pd.h */
struct _pdinstance
{
t_symbol *pd_s_float;
}
#define s_float (*(pd_this->pd_s_float))
/* m_class.c */
#undef s_float
t_symbol s_float;
t_pdinstance *pdinstance_init(t_pdinstance *x)
{
if(x != &pd_maininstance) x->pd_s_float = gensym("float");
else {
dogensym("float", &s_float, x);
x->pd_s_float = &s_float;
}
What do you think?
I've tried this (in libpd context) almost successfully, but I've encountered a problem: the s_float as seen from an app linked to libpd seems to be uninitialized.
I've tried something simpler:
/* m_class.c */
float myfloat = 10.0;
t_pdinstance *pdinstance_init(t_pdinstance *x)
{
myfloat = 20.0;
printf("pdinstance_init::myfloat: %f\n", myfloat);
}
/* pdtest.c */
extern float myfloat;
int main()
{
libpd_init();
printf("myfloat: %f\n", myfloat);
}
cc -I../../../libpd_wrapper -I../../../pure-data/src -O3 -c -o pdtest.o pdtest.c
gcc -o pdtest pdtest.o ../../../libs/libpd.so
$ pdtest
pdinstance_init::myfloat: 20.00000
myfloat: 10.00000
Do you know why pdtest doesn't see the updated value?