Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(730)

Side by Side Diff: base/mac/objc_property_releaser.mm

Issue 1961013002: DCHECK when an ObjCPropertyReleaser has no properties to release. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698