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); } } }
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
Never mind, I was looking at old code. I see these type-puns were already removed and replaced with unions.
-JOnathan
On Monday, October 6, 2014 10:23 PM, Jonathan Wilkes <jancsika@yahoo.com> wrote:
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
Well, Pd-extended 0.43-4 will crash when trying to create [iem_sqrt4~]. (I'm not sure how to tell whether it's using the latest code or not.) -Jonathan
On Monday, October 6, 2014 10:23 PM, Jonathan Wilkes <jancsika@yahoo.com> wrote:
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
Am 07. Oktober 2014 06:58:25 MESZ, schrieb Jonathan Wilkes via Pd-list pd-list@lists.iem.at:
Well, Pd-extended 0.43-4 will crash when trying to create [iem_sqrt4~]. (I'm not sure how to tell whether it's using the latest code or not.)
The last Pd-extended release has been a while and is not using the latest code. The latest and greatest code can usually be found in the svn repository at sourceforge.
mfg.ugd.fhj IOhannes
-- Sent from my pdp-11