summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-06-03 17:07:23 (GMT)
committerGuido van Rossum <guido@python.org>1992-06-03 17:07:23 (GMT)
commitab2490a6d52b0b5c22f7a6930d22d427d2a0cca0 (patch)
tree91adbbd0fe825892c04f7769e24d3033c7d3c636 /Python
parentf0476350b8565a2342b3a02f94f66fe976ad0a06 (diff)
downloadcpython-ab2490a6d52b0b5c22f7a6930d22d427d2a0cca0.zip
cpython-ab2490a6d52b0b5c22f7a6930d22d427d2a0cca0.tar.gz
cpython-ab2490a6d52b0b5c22f7a6930d22d427d2a0cca0.tar.bz2
Added new types to setattr() as well...
Diffstat (limited to 'Python')
-rw-r--r--Python/structmember.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/Python/structmember.c b/Python/structmember.c
index 173b3f0..e2658a6 100644
--- a/Python/structmember.c
+++ b/Python/structmember.c
@@ -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;