Changeset f9c314a5 in mainline for uspace/app/bithenge/transform.c
- Timestamp:
- 2012-08-07T04:06:14Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0191bd3
- Parents:
- 0ce0103
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bithenge/transform.c
r0ce0103 rf9c314a5 165 165 } 166 166 167 /** Initialize a transform scope. It must be destroyed with @a 168 * bithenge_scope_destroy after it is used. 169 * @param[out] scope The scope to initialize. */ 170 void bithenge_scope_init(bithenge_scope_t *scope) 171 { 172 scope->num_params = 0; 173 scope->params = NULL; 174 scope->current_node = NULL; 175 } 176 177 /** Destroy a transform scope. 178 * @param scope The scope to destroy. 167 /** Create a transform scope. It must be dereferenced with @a 168 * bithenge_scope_dec_ref after it is used. 169 * @param[out] out Holds the new scope. 179 170 * @return EOK on success or an error code from errno.h. */ 180 void bithenge_scope_destroy(bithenge_scope_t *scope) 181 { 182 bithenge_node_dec_ref(scope->current_node); 183 for (int i = 0; i < scope->num_params; i++) 184 bithenge_node_dec_ref(scope->params[i]); 185 free(scope->params); 171 int bithenge_scope_new(bithenge_scope_t **out) 172 { 173 bithenge_scope_t *self = malloc(sizeof(*self)); 174 if (!self) 175 return ENOMEM; 176 self->refs = 1; 177 self->num_params = 0; 178 self->params = NULL; 179 self->current_node = NULL; 180 *out = self; 181 return EOK; 182 } 183 184 /** Dereference a transform scope. 185 * @param self The scope to dereference. */ 186 void bithenge_scope_dec_ref(bithenge_scope_t *self) 187 { 188 if (!--self->refs) { 189 bithenge_node_dec_ref(self->current_node); 190 for (int i = 0; i < self->num_params; i++) 191 bithenge_node_dec_ref(self->params[i]); 192 free(self->params); 193 free(self); 194 } 186 195 } 187 196 … … 297 306 { 298 307 scope_transform_t *self = transform_as_param(base); 299 bithenge_scope_t inner_scope; 300 bithenge_scope_init(&inner_scope); 301 int rc = bithenge_scope_copy(&inner_scope, scope); 308 bithenge_scope_t *inner_scope; 309 int rc = bithenge_scope_new(&inner_scope); 310 if (rc != EOK) 311 return rc; 312 rc = bithenge_scope_copy(inner_scope, scope); 302 313 if (rc != EOK) 303 314 goto error; 304 bithenge_scope_set_current_node( &inner_scope, NULL);315 bithenge_scope_set_current_node(inner_scope, NULL); 305 316 rc = bithenge_transform_apply(self->transform, scope, in, out); 306 317 error: 307 bithenge_scope_de stroy(&inner_scope);318 bithenge_scope_dec_ref(inner_scope); 308 319 return rc; 309 320 }
Note:
See TracChangeset
for help on using the changeset viewer.