pkgsrc/lang/vslisp/patches/patch-ad
jmc 3804345481 Port for powerpc (or any other arch which enforces alignment).
This code was assuming it could copy double's in/out of char *'s with just
casts and normal copies. This blows up on anything which enforces alignments.

Change the generic case for the ATOM to just have a special double field.

For the serialization routines memcpy the double in and provide a union to
memcpy it out to that also contains a single double value. This ensures
alignment is correct and it won't SIGBUS anymore.

Bump pkg to nb1
2002-03-15 00:22:42 +00:00

63 lines
1.7 KiB
Text

$NetBSD: patch-ad,v 1.1 2002/03/15 00:22:43 jmc Exp $
--- src/lc.c.orig Fri Mar 15 00:16:37 2002
+++ src/lc.c Fri Mar 15 00:16:49 2002
@@ -124,9 +124,11 @@
return y;
}
if(((l->f)>>1)==4) { /* DOUBLE */
+ double d;
pos= *l2;y=pos;
b[pos]=l->f;pos++;
- *(double *)(b+pos)=GetDouble((ATOM)l);
+ d=GetDouble((ATOM)l);
+ memcpy(b+pos, &d, sizeof(double));
pos+=sizeof(double);
*l2=pos;
ltab[ltabn].p=(uc *)l;ltab[ltabn].v=y;ltabn++;
@@ -155,10 +157,12 @@
if((l->f)&1) { /* LIST */
} else {
if(((l->f)>>1)==4) {
+ double d;
b[*l1]=3;(*l1)++;
a=strlen(global.Symbols[n]->nm);b[*l1]=a; (*l1)++;
memcpy(b+(*l1),global.Symbols[n]->nm,a);(*l1)+=a;
- *(double *)(b+(*l1))=GetDouble((ATOM)l);(*l1)+=sizeof(double);
+ d=GetDouble((ATOM)l);
+ memcpy(b+(*l1), &d, sizeof(double));(*l1)+=sizeof(double);
return 0;
} else
if(((l->f)>>1)==0) {
@@ -267,7 +271,12 @@
}
/* It's ATOM */
if(((*b)>>1)==4) { /*DOUBLE*/
- return (LIST)MakeDAtom(*((double *)(b+1)));
+ union dd {
+ char a[sizeof(double)];
+ double d;
+ } dd;
+ memcpy(&dd.a, b+1, sizeof(double));
+ return (LIST)MakeDAtom(dd.d);
} else
{ /*STRING*/
return (LIST)MakeAtom(b+1);
@@ -311,11 +320,16 @@
l1+=1+l1[1]+4+ *((ui *)(l1+1+l1[1]+1))+1;
} else
if(*l1==3) {
+ union dd {
+ char a[sizeof(double)];
+ double d;
+ } dd;
+ memcpy(&dd.a, (l1+1+l1[1]+1), sizeof(double));
memcpy(ss,l1+2,*(l1+1));
ss[(int)l1[1]]=0;
t1=mklist(NIL,mklist((LIST)MakeAtom(ss),
mklist(mklist((LIST)MakeAtom("quote"),
- mklist((LIST)MakeDAtom(*((double *)(l1+1+l1[1]+1))),
+ mklist((LIST)MakeDAtom(dd.d),
NIL)),NIL)));
t1->g=0;
L_Setq(&global,t1);