Added new types to setattr() as well...

This commit is contained in:
Guido van Rossum 1992-06-03 17:07:23 +00:00
parent f0476350b8
commit ab2490a6d5
1 changed files with 52 additions and 0 deletions

View File

@ -66,15 +66,34 @@ getmember(addr, mlist, name)
object *v;
addr += l->offset;
switch (l->type) {
case T_BYTE:
v = newintobject((long)
(((*(char*)addr & 0xff)
^ 0x80) - 0x80));
break;
case T_UBYTE:
v = newintobject((long) *(char*)addr & 0xff);
break;
case T_SHORT:
v = newintobject((long) *(short*)addr);
break;
case T_USHORT:
v = newintobject((long)
*(unsigned short*)addr);
break;
case T_INT:
v = newintobject((long) *(int*)addr);
break;
case T_UINT:
v = newintobject((long) *(unsigned int*)addr);
break;
case T_LONG:
v = newintobject(*(long*)addr);
break;
case T_ULONG:
v = dnewlongobject((double)
*(unsigned long*)addr);
break;
case T_FLOAT:
v = newfloatobject((double)*(float*)addr);
break;
@ -89,6 +108,9 @@ getmember(addr, mlist, name)
else
v = newstringobject(*(char**)addr);
break;
case T_CHAR:
v = newsizedstringobject((char*)addr, 1);
break;
case T_OBJECT:
v = *(object **)addr;
if (v == NULL)
@ -124,13 +146,23 @@ setmember(addr, mlist, name, v)
}
addr += l->offset;
switch (l->type) {
case T_BYTE:
case T_UBYTE:
if (!is_intobject(v)) {
err_badarg();
return -1;
}
*(char*)addr = getintvalue(v);
break;
case T_SHORT:
case T_USHORT:
if (!is_intobject(v)) {
err_badarg();
return -1;
}
*(short*)addr = getintvalue(v);
break;
case T_UINT:
case T_INT:
if (!is_intobject(v)) {
err_badarg();
@ -145,6 +177,16 @@ setmember(addr, mlist, name, v)
}
*(long*)addr = getintvalue(v);
break;
case T_ULONG:
if (is_intobject(v))
*(long*)addr = getintvalue(v);
else if (is_longobject(v))
*(long*)addr = getlongvalue(v);
else {
err_badarg();
return -1;
}
break;
case T_FLOAT:
if (is_intobject(v))
*(float*)addr = getintvalue(v);
@ -170,6 +212,16 @@ setmember(addr, mlist, name, v)
XINCREF(v);
*(object **)addr = v;
break;
case T_CHAR:
if (is_stringobject(v) &&
getstringsize(v) == 1) {
*(char*)addr =
getstringvalue(v)[0];
}
else {
err_badarg();
return -1;
}
default:
err_setstr(SystemError, "bad memberlist type");
return -1;