summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-05-25 09:38:27 (GMT)
committerGuido van Rossum <guido@python.org>1993-05-25 09:38:27 (GMT)
commiteb6b33a837a180221b635331e005f990024bdb30 (patch)
treeea03e645019d8494df1753da7ef42f86559ed5f6 /Objects
parent23301a9467024eb70b654924c3f0a54d76702e47 (diff)
downloadcpython-eb6b33a837a180221b635331e005f990024bdb30.zip
cpython-eb6b33a837a180221b635331e005f990024bdb30.tar.gz
cpython-eb6b33a837a180221b635331e005f990024bdb30.tar.bz2
* classobject.c: in instance_getattr, don't make a method out of a
function found as instance data. * socketmodule.c: added 'flags' argument sendto/recvfrom, rewrite argument parsing in send/recv. * More changes related to access (terminology change: owner instead of class; allow any object as owner; local/global variables are owned by their dictionary, only class/instance data is owned by the class; "from...import *" now only imports objects with public access; etc.)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/accessobject.c79
-rw-r--r--Objects/classobject.c15
-rw-r--r--Objects/frameobject.c13
-rw-r--r--Objects/moduleobject.c4
4 files changed, 60 insertions, 51 deletions
diff --git a/Objects/accessobject.c b/Objects/accessobject.c
index 6fd9bd5..1275eba 100644
--- a/Objects/accessobject.c
+++ b/Objects/accessobject.c
@@ -32,27 +32,23 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
typedef struct {
OB_HEAD
object *ac_value;
- object *ac_class;
+ object *ac_owner;
typeobject *ac_type;
int ac_mode;
} accessobject;
/* Forward */
static int typecheck PROTO((object *, typeobject *));
-static int classcheck PROTO((object *, object *, int, int));
+static int ownercheck PROTO((object *, object *, int, int));
object *
-newaccessobject(value, class, type, mode)
+newaccessobject(value, owner, type, mode)
object *value;
- object *class;
+ object *owner;
typeobject *type;
int mode;
{
accessobject *ap;
- if (class != NULL && !is_classobject(class)) {
- err_badcall();
- return NULL;
- }
if (!typecheck(value, type)) {
err_setstr(AccessError,
"access: initial value has inappropriate type");
@@ -63,8 +59,8 @@ newaccessobject(value, class, type, mode)
return NULL;
XINCREF(value);
ap->ac_value = value;
- XINCREF(class);
- ap->ac_class = class;
+ XINCREF(owner);
+ ap->ac_owner = owner;
XINCREF(type);
ap->ac_type = (typeobject *)type;
ap->ac_mode = mode;
@@ -81,22 +77,22 @@ cloneaccessobject(op)
return NULL;
}
ap = (accessobject *)op;
- return newaccessobject(ap->ac_value, ap->ac_class,
+ return newaccessobject(ap->ac_value, ap->ac_owner,
ap->ac_type, ap->ac_mode);
}
void
-setaccessowner(op, class)
+setaccessowner(op, owner)
object *op;
- object *class;
+ object *owner;
{
register accessobject *ap;
- if (!is_accessobject(op) || class != NULL && !is_classobject(class))
+ if (!is_accessobject(op))
return; /* XXX no error */
ap = (accessobject *)op;
- XDECREF(ap->ac_class);
- XINCREF(class);
- ap->ac_class = class;
+ XDECREF(ap->ac_owner);
+ XINCREF(owner);
+ ap->ac_owner = owner;
}
int
@@ -109,9 +105,9 @@ hasaccessvalue(op)
}
object *
-getaccessvalue(op, class)
+getaccessvalue(op, owner)
object *op;
- object *class;
+ object *owner;
{
register accessobject *ap;
if (!is_accessobject(op)) {
@@ -120,7 +116,7 @@ getaccessvalue(op, class)
}
ap = (accessobject *)op;
- if (!classcheck(class, ap->ac_class, AC_R, ap->ac_mode)) {
+ if (!ownercheck(owner, ap->ac_owner, AC_R, ap->ac_mode)) {
err_setstr(AccessError, "read access denied");
return NULL;
}
@@ -134,9 +130,9 @@ getaccessvalue(op, class)
}
int
-setaccessvalue(op, class, value)
+setaccessvalue(op, owner, value)
object *op;
- object *class;
+ object *owner;
object *value;
{
register accessobject *ap;
@@ -146,7 +142,7 @@ setaccessvalue(op, class, value)
}
ap = (accessobject *)op;
- if (!classcheck(class, ap->ac_class, AC_W, ap->ac_mode)) {
+ if (!ownercheck(owner, ap->ac_owner, AC_W, ap->ac_mode)) {
err_setstr(AccessError, "write access denied");
return -1;
}
@@ -227,17 +223,20 @@ typecheck(value, type)
}
static int
-classcheck(caller, owner, access, mode)
+ownercheck(caller, owner, access, mode)
object *caller;
object *owner;
int access;
int mode;
{
- if (caller == owner && owner != NULL)
- return access & mode & (AC_PRIVATE|AC_PROTECTED|AC_PUBLIC);
- if (caller != NULL && owner != NULL && issubclass(caller, owner))
- return access & mode & (AC_PROTECTED|AC_PUBLIC);
- return access & mode & AC_PUBLIC;
+ int mask = AC_PUBLIC;
+ if (owner != NULL) {
+ if (caller == owner)
+ mask |= AC_PRIVATE | AC_PROTECTED;
+ else if (is_classobject(owner) && issubclass(caller, owner))
+ mask |= AC_PROTECTED;
+ }
+ return access & mode & mask;
}
/* Access methods */
@@ -247,7 +246,7 @@ access_dealloc(ap)
accessobject *ap;
{
XDECREF(ap->ac_value);
- XDECREF(ap->ac_class);
+ XDECREF(ap->ac_owner);
XDECREF(ap->ac_type);
DEL(ap);
}
@@ -256,7 +255,7 @@ access_dealloc(ap)
static struct memberlist access_memberlist[] = {
{"ac_value", T_OBJECT, OFF(ac_value)},
- {"ac_class", T_OBJECT, OFF(ac_class)},
+ {"ac_owner", T_OBJECT, OFF(ac_owner)},
{"ac_type", T_OBJECT, OFF(ac_type)},
{"ac_mode", T_INT, OFF(ac_mode)},
{NULL} /* Sentinel */
@@ -275,12 +274,21 @@ access_repr(ap)
accessobject *ap;
{
char buf[300];
- classobject *class = (classobject *)ap->ac_class;
+ char buf2[20];
+ char *ownername;
typeobject *type = ap->ac_type;
+ if (is_classobject(ap->ac_owner)) {
+ ownername =
+ getstringvalue(((classobject *)ap->ac_owner)->cl_name);
+ }
+ else {
+ sprintf(buf2, "0x%lx", (long)ap->ac_owner);
+ ownername = buf2;
+ }
sprintf(buf,
- "<access object, value 0x%lx, class %.100s, type %.100s, mode %04o>",
+ "<access object, value 0x%lx, owner %.100s, type %.100s, mode %04o>",
(long)(ap->ac_value),
- class ? getstringvalue(class->cl_name) : "-",
+ ownername,
type ? type->tp_name : "-",
ap->ac_mode);
return newstringobject(buf);
@@ -305,7 +313,8 @@ typeobject Accesstype = {
0, /*tp_hash*/
};
-/* Dummy type objects to indicate classes of types */
+
+/* Pseudo type objects to indicate collections of types */
/* XXX This should be replaced by a more general "subclassing"
XXX mechanism for type objects... */
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 0a6fc7e..8836bb7 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -126,7 +126,7 @@ class_getattr(op, name)
return NULL;
}
if (is_accessobject(v)) {
- v = getaccessvalue(v, getclass());
+ v = getaccessvalue(v, getowner());
if (v == NULL)
return NULL;
}
@@ -157,7 +157,7 @@ class_setattr(op, name, v)
}
ac = dictlookup(op->cl_dict, name);
if (ac != NULL && is_accessobject(ac))
- return setaccessvalue(ac, getclass(), v);
+ return setaccessvalue(ac, getowner(), v);
if (v == NULL) {
int rv = dictremove(op->cl_dict, name);
if (rv < 0)
@@ -207,10 +207,10 @@ issubclass(class, base)
{
int i, n;
classobject *cp;
- if (class == NULL || !is_classobject(class))
- return 0;
if (class == base)
return 1;
+ if (class == NULL || !is_classobject(class))
+ return 0;
cp = (classobject *)class;
n = gettuplesize(cp->cl_bases);
for (i = 0; i < n; i++) {
@@ -363,6 +363,7 @@ instance_getattr(inst, name)
INCREF(inst->in_class);
return (object *)inst->in_class;
}
+ class = NULL;
v = dictlookup(inst->in_dict, name);
if (v == NULL) {
v = class_lookup(inst->in_class, name, &class);
@@ -372,13 +373,13 @@ instance_getattr(inst, name)
}
}
if (is_accessobject(v)) {
- v = getaccessvalue(v, getclass());
+ v = getaccessvalue(v, getowner());
if (v == NULL)
return NULL;
}
else
INCREF(v);
- if (is_funcobject(v)) {
+ if (is_funcobject(v) && class != NULL) {
object *w = newinstancemethodobject(v, (object *)inst,
(object *)class);
DECREF(v);
@@ -403,7 +404,7 @@ instance_setattr(inst, name, v)
}
ac = dictlookup(inst->in_dict, name);
if (ac != NULL && is_accessobject(ac))
- return setaccessvalue(ac, getclass(), v);
+ return setaccessvalue(ac, getowner(), v);
if (v == NULL) {
int rv = dictremove(inst->in_dict, name);
if (rv < 0)
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 7c2aeae..62a18e2 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -38,7 +38,7 @@ static struct memberlist frame_memberlist[] = {
{"f_code", T_OBJECT, OFF(f_code)},
{"f_globals", T_OBJECT, OFF(f_globals)},
{"f_locals", T_OBJECT, OFF(f_locals)},
- {"f_class", T_OBJECT, OFF(f_class)},
+ {"f_owner", T_OBJECT, OFF(f_owner)},
/* {"f_fastlocals",T_OBJECT, OFF(f_fastlocals)}, /* XXX Unsafe */
{"f_localmap", T_OBJECT, OFF(f_localmap)},
{"f_lasti", T_INT, OFF(f_lasti)},
@@ -85,7 +85,7 @@ frame_dealloc(f)
XDECREF(f->f_code);
XDECREF(f->f_globals);
XDECREF(f->f_locals);
- XDECREF(f->f_class);
+ XDECREF(f->f_owner);
XDECREF(f->f_fastlocals);
XDECREF(f->f_localmap);
f->f_back = free_list;
@@ -110,12 +110,12 @@ typeobject Frametype = {
};
frameobject *
-newframeobject(back, code, globals, locals, class, nvalues, nblocks)
+newframeobject(back, code, globals, locals, owner, nvalues, nblocks)
frameobject *back;
codeobject *code;
object *globals;
object *locals;
- object *class;
+ object *owner;
int nvalues;
int nblocks;
{
@@ -124,7 +124,6 @@ newframeobject(back, code, globals, locals, class, nvalues, nblocks)
code == NULL || !is_codeobject(code) ||
globals == NULL || !is_dictobject(globals) ||
locals == NULL || !is_dictobject(locals) ||
- (class != NULL && !is_classobject(class)) ||
nvalues < 0 || nblocks < 0) {
err_badcall();
return NULL;
@@ -150,8 +149,8 @@ newframeobject(back, code, globals, locals, class, nvalues, nblocks)
f->f_globals = globals;
INCREF(locals);
f->f_locals = locals;
- XINCREF(class);
- f->f_class = class;
+ XINCREF(owner);
+ f->f_owner = owner;
f->f_fastlocals = NULL;
f->f_localmap = NULL;
if (nvalues > f->f_nvalues || f->f_valuestack == NULL) {
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index 5c0db15..dca5543 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -112,7 +112,7 @@ module_getattr(m, name)
err_setstr(AttributeError, name);
else {
if (is_accessobject(res))
- res = getaccessvalue(res, getclass());
+ res = getaccessvalue(res, getglobals());
else
INCREF(res);
}
@@ -135,7 +135,7 @@ module_setattr(m, name, v)
}
ac = dictlookup(m->md_dict, name);
if (ac != NULL && is_accessobject(ac))
- return setaccessvalue(ac, getclass(), v);
+ return setaccessvalue(ac, getglobals(), v);
if (v == NULL) {
int rv = dictremove(m->md_dict, name);
if (rv < 0)