Changeset 0191bd3 in mainline
- Timestamp:
- 2012-08-07T04:30:04Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a8be91a
- Parents:
- f9c314a5
- Location:
- uspace/app/bithenge
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bithenge/expression.c
rf9c314a5 r0191bd3 425 425 param_wrapper_t *self = transform_as_param_wrapper(base); 426 426 bithenge_scope_t *inner; 427 int rc = bithenge_scope_new(&inner );427 int rc = bithenge_scope_new(&inner, outer); 428 428 if (rc != EOK) 429 429 return rc; … … 445 445 param_wrapper_t *self = transform_as_param_wrapper(base); 446 446 bithenge_scope_t *inner; 447 int rc = bithenge_scope_new(&inner );447 int rc = bithenge_scope_new(&inner, outer); 448 448 if (rc != EOK) 449 449 return rc; … … 454 454 rc = bithenge_transform_prefix_length(self->transform, inner, in, out); 455 455 in = NULL; 456 457 error: 458 bithenge_scope_dec_ref(inner); 459 return rc; 460 } 461 462 static int param_wrapper_prefix_apply(bithenge_transform_t *base, 463 bithenge_scope_t *outer, bithenge_blob_t *in, bithenge_node_t **out_node, 464 aoff64_t *out_length) 465 { 466 param_wrapper_t *self = transform_as_param_wrapper(base); 467 bithenge_scope_t *inner; 468 int rc = bithenge_scope_new(&inner, outer); 469 if (rc != EOK) 470 return rc; 471 rc = param_wrapper_fill_scope(self, inner, outer); 472 if (rc != EOK) 473 goto error; 474 475 rc = bithenge_transform_prefix_apply(self->transform, inner, in, 476 out_node, out_length); 456 477 457 478 error: … … 474 495 .apply = param_wrapper_apply, 475 496 .prefix_length = param_wrapper_prefix_length, 497 .prefix_apply = param_wrapper_prefix_apply, 476 498 .destroy = param_wrapper_destroy, 477 499 }; -
uspace/app/bithenge/sequence.c
rf9c314a5 r0191bd3 267 267 self->num_ends = 0; 268 268 self->end_on_empty = end_on_empty; 269 int rc = bithenge_scope_new(&self->scope); 270 if (rc != EOK) { 271 free(self->ends); 272 return rc; 273 } 274 rc = bithenge_scope_copy(self->scope, scope); 275 if (rc != EOK) { 276 bithenge_scope_dec_ref(self->scope); 277 free(self->ends); 278 return rc; 279 } 269 self->scope = scope; 270 if (self->scope) 271 bithenge_scope_inc_ref(self->scope); 280 272 return EOK; 281 273 } … … 468 460 return rc; 469 461 } 470 471 rc = seq_node_init(struct_as_seq(node), &struct_node_seq_ops, scope, 462 bithenge_scope_t *inner; 463 rc = bithenge_scope_new(&inner, scope); 464 if (rc != EOK) { 465 free(node); 466 return rc; 467 } 468 /* We should inc_ref(node) here, but that would make a cycle. Instead, 469 * we leave it 1 too low, so that when the only remaining use of node 470 * is the scope, node will be destroyed. Also see the comment in 471 * struct_node_destroy. */ 472 bithenge_scope_set_current_node(inner, struct_as_node(node)); 473 474 rc = seq_node_init(struct_as_seq(node), &struct_node_seq_ops, inner, 472 475 blob, self->num_subtransforms, false); 476 bithenge_scope_dec_ref(inner); 473 477 if (rc != EOK) { 474 478 free(node); … … 480 484 node->prefix = prefix; 481 485 *out = struct_as_node(node); 482 483 /* We should inc_ref(*out) here, but that would make a cycle. Instead,484 * we leave it 1 too low, so that when the only remaining use of *out485 * is the scope, *out will be destroyed. Also see the comment in486 * struct_node_destroy. */487 bithenge_scope_set_current_node(seq_node_scope(struct_as_seq(node)),488 *out);489 486 490 487 return EOK; … … 942 939 943 940 bithenge_scope_t *scope; 944 rc = bithenge_scope_new(&scope); 941 rc = bithenge_scope_new(&scope, 942 seq_node_scope(do_while_as_seq(self))); 945 943 if (rc != EOK) { 946 944 bithenge_node_dec_ref(subxform_result); 947 945 return rc; 948 946 } 949 rc = bithenge_scope_copy(scope,950 seq_node_scope(do_while_as_seq(self)));951 947 bithenge_scope_set_current_node(scope, subxform_result); 952 if (rc != EOK) {953 bithenge_scope_dec_ref(scope);954 return rc;955 }956 948 bithenge_node_t *expr_result; 957 949 rc = bithenge_expression_evaluate(self->expr, scope, -
uspace/app/bithenge/test.c
rf9c314a5 r0191bd3 73 73 bithenge_node_t *node = NULL, *node2 = NULL; 74 74 75 rc = bithenge_scope_new(&scope );75 rc = bithenge_scope_new(&scope, NULL); 76 76 if (rc != EOK) { 77 77 printf("Error creating scope: %s\n", str_error(rc)); -
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; -
uspace/app/bithenge/transform.h
rf9c314a5 r0191bd3 50 50 51 51 /** Context and parameters used when applying transforms. */ 52 typedef struct {52 typedef struct bithenge_scope { 53 53 /** @privatesection */ 54 54 unsigned int refs; 55 struct bithenge_scope *outer; 55 56 int num_params; 56 57 bithenge_node_t **params; … … 148 149 bithenge_transform_t **, size_t); 149 150 150 int bithenge_scope_new(bithenge_scope_t ** );151 int bithenge_scope_new(bithenge_scope_t **, bithenge_scope_t *); 151 152 void bithenge_scope_dec_ref(bithenge_scope_t *); 152 153 int bithenge_scope_copy(bithenge_scope_t *, bithenge_scope_t *);
Note:
See TracChangeset
for help on using the changeset viewer.