Changeset 0191bd3 in mainline for uspace/app/bithenge/transform.c
- Timestamp:
- 2012-08-07T04:30:04Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a8be91a
- Parents:
- f9c314a5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bithenge/transform.c
rf9c314a5 r0191bd3 166 166 167 167 /** Create a transform scope. It must be dereferenced with @a 168 * bithenge_scope_dec_ref after it is used. 168 * bithenge_scope_dec_ref after it is used. Takes ownership of nothing. 169 169 * @param[out] out Holds the new scope. 170 * @param outer The outer scope, or NULL. 170 171 * @return EOK on success or an error code from errno.h. */ 171 int bithenge_scope_new(bithenge_scope_t **out )172 int bithenge_scope_new(bithenge_scope_t **out, bithenge_scope_t *outer) 172 173 { 173 174 bithenge_scope_t *self = malloc(sizeof(*self)); … … 175 176 return ENOMEM; 176 177 self->refs = 1; 178 if (outer) 179 bithenge_scope_inc_ref(outer); 180 self->outer = outer; 177 181 self->num_params = 0; 178 182 self->params = NULL; … … 186 190 void bithenge_scope_dec_ref(bithenge_scope_t *self) 187 191 { 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 } 192 if (!self) 193 return; 194 if (--self->refs) 195 return; 196 bithenge_node_dec_ref(self->current_node); 197 for (int i = 0; i < self->num_params; i++) 198 bithenge_node_dec_ref(self->params[i]); 199 bithenge_scope_dec_ref(self->outer); 200 free(self->params); 201 free(self); 195 202 } 196 203 … … 279 286 { 280 287 assert(scope); 281 assert(i >= 0 && i < scope->num_params); 282 *out = scope->params[i]; 283 bithenge_node_inc_ref(*out); 284 return EOK; 288 if (scope->num_params) { 289 assert(i >= 0 && i < scope->num_params); 290 *out = scope->params[i]; 291 bithenge_node_inc_ref(*out); 292 return EOK; 293 } else { 294 return bithenge_scope_get_param(scope->outer, i, out); 295 } 285 296 } 286 297 … … 307 318 scope_transform_t *self = transform_as_param(base); 308 319 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); 313 if (rc != EOK) 314 goto error; 315 bithenge_scope_set_current_node(inner_scope, NULL); 320 int rc = bithenge_scope_new(&inner_scope, scope); 321 if (rc != EOK) 322 return rc; 316 323 rc = bithenge_transform_apply(self->transform, scope, in, out); 317 error:318 324 bithenge_scope_dec_ref(inner_scope); 319 325 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.