# HG changeset patch # User Paul Boddie # Date 1235846415 -3600 # Node ID 55c8334f8ef15e24049a3a03a6aa8490fbb8bab5 # Parent ae20cd4d0679a04b593dd1a0126921cd421c5144 Attempt to enforce proper checks on attribute access with context overriding. Attempt to make _CheckInstance work correctly. diff -r ae20cd4d0679 -r 55c8334f8ef1 docs/assignment.txt --- a/docs/assignment.txt Sat Feb 28 01:49:33 2009 +0100 +++ b/docs/assignment.txt Sat Feb 28 19:40:15 2009 +0100 @@ -61,7 +61,8 @@ null context preserved other context (instance) preserved - LoadAttrIndex must therefore check whether the context must be overridden + LoadAddressContext and LoadAttrIndex must therefore check whether the + context must be overridden Since the object table encodes sufficient information (an instance must be compatible to access the class attribute, and compatibility information is diff -r ae20cd4d0679 -r 55c8334f8ef1 rsvp.py --- a/rsvp.py Sat Feb 28 01:49:33 2009 +0100 +++ b/rsvp.py Sat Feb 28 19:40:15 2009 +0100 @@ -320,9 +320,9 @@ self.value = self.load(self.operand) def LoadAddressContext(self): - value = self.load(self.operand) - # Replace the context with the current value. - self.value = self.value[1], value[1] + context, ref = self.load(self.operand) + inst_context, inst_ref = self.value + self.value = self._LoadAddressContext(context, ref, inst_context, inst_ref) def StoreAddress(self): # Preserve context. @@ -356,10 +356,7 @@ if attr_index == self.operand: if class_attr: loaded_context, loaded_ref = self.load(offset) # offset is address of class attribute - if replace_context: - self.value = ref, loaded_ref # classes can also replace the context if compatible - return - self.value = loaded_context, loaded_ref + self.value = self._LoadAddressContext(loaded_context, loaded_ref, context, ref) else: self.value = self.load(ref + offset) else: @@ -549,6 +546,11 @@ data = self.load(ref) target_data = self.load(cls) + # Insist on a class. + + if target_data.instance: + return 0 + # Find the table entry for the descendant. element = self.objlist[target_data.classcode + data.attrcode] @@ -562,6 +564,16 @@ self.save(addr, data) return addr + def _LoadAddressContext(self, context, ref, inst_context, inst_ref): + + # Check the instance context against the target's context. + + if self._CheckInstance(inst_ref, context): + # Replace the context with the instance. + return inst_ref, ref + else: + return context, ref + # Native function implementations. def builtins_object_init(self):