| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "base/mac/objc_property_releaser.h" | 5 #import "base/mac/objc_property_releaser.h" |
| 6 | 6 |
| 7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 class_ = classy; | 97 class_ = classy; |
| 98 } | 98 } |
| 99 | 99 |
| 100 void ObjCPropertyReleaser::ReleaseProperties() { | 100 void ObjCPropertyReleaser::ReleaseProperties() { |
| 101 DCHECK(object_); | 101 DCHECK(object_); |
| 102 DCHECK(class_); | 102 DCHECK(class_); |
| 103 | 103 |
| 104 unsigned int property_count = 0; | 104 unsigned int property_count = 0; |
| 105 objc_property_t* properties = class_copyPropertyList(class_, &property_count); | 105 objc_property_t* properties = class_copyPropertyList(class_, &property_count); |
| 106 | 106 |
| 107 bool released_something = false; |
| 107 for (unsigned int property_index = 0; | 108 for (unsigned int property_index = 0; |
| 108 property_index < property_count; | 109 property_index < property_count; |
| 109 ++property_index) { | 110 ++property_index) { |
| 110 objc_property_t property = properties[property_index]; | 111 objc_property_t property = properties[property_index]; |
| 111 std::string instance_name = ReleasableInstanceName(property); | 112 std::string instance_name = ReleasableInstanceName(property); |
| 112 if (!instance_name.empty()) { | 113 if (!instance_name.empty()) { |
| 113 id instance_value = nil; | 114 id instance_value = nil; |
| 114 Ivar instance_variable = | 115 Ivar instance_variable = |
| 115 object_getInstanceVariable(object_, instance_name.c_str(), | 116 object_getInstanceVariable(object_, instance_name.c_str(), |
| 116 (void**)&instance_value); | 117 (void**)&instance_value); |
| 117 DCHECK(instance_variable); | 118 DCHECK(instance_variable); |
| 118 [instance_value release]; | 119 [instance_value release]; |
| 120 released_something = true; |
| 119 } | 121 } |
| 120 } | 122 } |
| 121 | 123 |
| 124 // Check that this property releaser was of some use. |
| 125 DCHECK(released_something); |
| 126 |
| 122 free(properties); | 127 free(properties); |
| 123 | 128 |
| 124 // Clear object_ and class_ in case this ObjCPropertyReleaser will live on. | 129 // Clear object_ and class_ in case this ObjCPropertyReleaser will live on. |
| 125 // It's only expected to release the properties it supervises once per Init. | 130 // It's only expected to release the properties it supervises once per Init. |
| 126 object_ = nil; | 131 object_ = nil; |
| 127 class_ = nil; | 132 class_ = nil; |
| 128 } | 133 } |
| 129 | 134 |
| 130 } // namespace mac | 135 } // namespace mac |
| 131 } // namespace base | 136 } // namespace base |
| OLD | NEW |