# HG changeset patch # User Paul Boddie # Date 1484953285 -3600 # Node ID 6ab1b9e4be06e6a137a97c05d0653aee6fedbf21 # Parent 1bd646f3d906f73b31494ca361e2129f45bf2a50 Make getattr update the context when a method is obtained via an instance. diff -r 1bd646f3d906 -r 6ab1b9e4be06 templates/native/introspection.c --- a/templates/native/introspection.c Fri Jan 20 23:59:15 2017 +0100 +++ b/templates/native/introspection.c Sat Jan 21 00:01:25 2017 +0100 @@ -33,11 +33,28 @@ __attr * const _default = &__args[3]; /* name.__data__ interpreted as string */ __attr key = __load_via_object(name->value, __pos___key__); + __attr out; if ((key.code == 0) && (key.pos == 0)) return *_default; - else - return __check_and_load_via_any(obj->value, key.pos, key.code); + + /* Attempt to get the attribute from the object. */ + + out = __check_and_load_via_object_null(obj->value, key.pos, key.code); + if (out.value == 0) + { + /* Inspect the object's class if this failed. */ + + out = __check_and_load_via_class(obj->value, key.pos, key.code); + if (out.value == 0) + return *_default; + + /* Update the context to the object if it is a method. */ + + return __replace_context(obj->value, out); + } + + return out; } static int __issubclass(__ref obj, __attr cls) diff -r 1bd646f3d906 -r 6ab1b9e4be06 templates/ops.c --- a/templates/ops.c Fri Jan 20 23:59:15 2017 +0100 +++ b/templates/ops.c Sat Jan 21 00:01:25 2017 +0100 @@ -122,7 +122,7 @@ /* Attribute testing and retrieval operations. */ -static __attr __check_and_load_via_object_null(__ref obj, int pos, int code) +__attr __check_and_load_via_object_null(__ref obj, int pos, int code) { if (__HASATTR(obj, pos, code)) return __load_via_object(obj, pos); diff -r 1bd646f3d906 -r 6ab1b9e4be06 templates/ops.h --- a/templates/ops.h Fri Jan 20 23:59:15 2017 +0100 +++ b/templates/ops.h Sat Jan 21 00:01:25 2017 +0100 @@ -57,6 +57,7 @@ __attr __check_and_load_via_class(__ref obj, int pos, int code); __attr __check_and_load_via_object(__ref obj, int pos, int code); +__attr __check_and_load_via_object_null(__ref obj, int pos, int code); __attr __check_and_load_via_any(__ref obj, int pos, int code); /* Attribute testing and storage operations. */