I'm still a little shaky on type-punning, but here goes:I'm guessing that the author of iemlib_sqrt4~ assumed that sizeof(long) == sizeof(float) == 4. Then when one sets the value of the type-pun'd variable that new value would be guaranteed to lie within the float's 4-byte boundary. But since sizeof(long) == 8 on a 64-bit OS, Pd writes another 4 bytes past what's been allocated for that float. Then... glibc gets angry, and Linux puts Pd to bed. Is this about right? If so, what's the solution? I guess one could use sizeof and have a branch for 32-bit and one for 64, but that seems even worse. -Jonathan
On Monday, October 6, 2014 6:09 PM, Jonathan Wilkes via Pd-list <pd-list@lists.iem.at> wrote:
Hi list,[iem_sqrt4~] crashes when trying to create on amd_64. It creates fine on 32 bit linux. This leads me to believe there is something in the setup routine that makes an assumption that only holds true for a 32bit OS. The only thing that stands out to me is a function called in the setup routine, posted below. This looks particularly suspicious to my untrained eye: *(long *)(&f) = l;Even if that's not causing the crash, what does it do?
And does that or anything stand out to anyone else? Thanks,Jonathan
static void iem_sqrt4_tilde_maketable(void) { int i; t_float f; long l; if(!iem_sqrt4_tilde_exptab) { iem_sqrt4_tilde_exptab = (t_float *)getbytes(sizeof(t_float) * IEMSQRT4TAB1SIZE); for(i=0; i<IEMSQRT4TAB1SIZE; i++) { l = (i ? (i == IEMSQRT4TAB1SIZE-1 ? IEMSQRT4TAB1SIZE-2 : i) : 1)<< 23; *(long *)(&f) = l; iem_sqrt4_tilde_exptab[i] = 1.0f/sqrt(f); } } if(!iem_sqrt4_tilde_mantissatab) { iem_sqrt4_tilde_mantissatab = (t_float *)getbytes(sizeof(t_float) * IEMSQRT4TAB2SIZE); for(i=0; i<IEMSQRT4TAB2SIZE; i++) { f = 1.0f + (1.0f/(t_float)IEMSQRT4TAB2SIZE) * (t_float)i; iem_sqrt4_tilde_mantissatab[i] = 1.0f/sqrt(f); } } }
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list