Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 84e8a70 in mainline


Ignore:
Timestamp:
2012-07-28T23:43:23Z (9 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master
Children:
d7c8e39f
Parents:
f85ca3f
Message:

Bithenge: fix struct_transform and add parameter test script

Location:
uspace
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bithenge/transform.c

    rf85ca3f r84e8a70  
    387387        bithenge_scope_t scope;
    388388        bithenge_blob_t *blob;
     389        bool prefix;
    389390} struct_node_t;
    390391
     
    497498        }
    498499
    499         aoff64_t remaining;
    500         rc = bithenge_blob_size(blob, &remaining);
    501         if (rc != EOK)
    502                 goto error;
    503         if (remaining != 0) {
    504                 rc = EINVAL;
    505                 goto error;
     500        if (!struct_node->prefix) {
     501                aoff64_t remaining;
     502                rc = bithenge_blob_size(blob, &remaining);
     503                if (rc != EOK)
     504                        goto error;
     505                if (remaining != 0) {
     506                        rc = EINVAL;
     507                        goto error;
     508                }
    506509        }
    507510
     
    514517{
    515518        struct_node_t *node = node_as_struct(base);
     519
     520        /* We didn't inc_ref for the scope in struct_transform_make_node, so
     521         * make sure it doesn't try to dec_ref. */
     522        node->scope.current_node = NULL;
     523        bithenge_scope_destroy(&node->scope);
     524
    516525        bithenge_transform_dec_ref(struct_as_transform(node->transform));
    517526        bithenge_blob_dec_ref(node->blob);
    518         bithenge_scope_destroy(&node->scope);
    519527        free(node);
    520528}
     
    525533};
    526534
    527 static int struct_transform_apply(bithenge_transform_t *base,
    528     bithenge_scope_t *scope, bithenge_node_t *in, bithenge_node_t **out)
    529 {
    530         struct_transform_t *self = transform_as_struct(base);
    531         if (bithenge_node_type(in) != BITHENGE_NODE_BLOB)
    532                 return EINVAL;
     535static int struct_transform_make_node(struct_transform_t *self,
     536    bithenge_node_t **out, bithenge_scope_t *scope, bithenge_blob_t *blob,
     537    bool prefix)
     538{
    533539        struct_node_t *node = malloc(sizeof(*node));
    534540        if (!node)
     
    547553                return rc;
    548554        }
    549         bithenge_transform_inc_ref(base);
     555        bithenge_transform_inc_ref(struct_as_transform(self));
     556        bithenge_blob_inc_ref(blob);
    550557        node->transform = self;
    551         bithenge_node_inc_ref(in);
    552         node->blob = bithenge_node_as_blob(in);
     558        node->blob = blob;
     559        node->prefix = prefix;
    553560        *out = struct_as_node(node);
    554         bithenge_node_inc_ref(*out);
     561
     562        /* We should inc_ref(*out) here, but that would make a cycle. Instead,
     563         * we leave it 1 too low, so that when the only remaining use of *out
     564         * is the scope, *out will be destroyed. Also see the comment in
     565         * struct_node_destroy. */
    555566        bithenge_scope_set_current_node(&node->scope, *out);
    556         return EOK;
     567
     568        return EOK;
     569}
     570
     571static int struct_transform_apply(bithenge_transform_t *base,
     572    bithenge_scope_t *scope, bithenge_node_t *in, bithenge_node_t **out)
     573{
     574        struct_transform_t *self = transform_as_struct(base);
     575        if (bithenge_node_type(in) != BITHENGE_NODE_BLOB)
     576                return EINVAL;
     577        return struct_transform_make_node(self, out, scope,
     578            bithenge_node_as_blob(in), false);
    557579}
    558580
     
    561583{
    562584        struct_transform_t *self = transform_as_struct(base);
    563         int rc = EOK;
     585        bithenge_node_t *struct_node;
     586        int rc = struct_transform_make_node(self, &struct_node, scope, blob,
     587            true);
     588        if (rc != EOK)
     589                return rc;
     590        bithenge_scope_t *inner = &node_as_struct(struct_node)->scope;
     591
    564592        bithenge_node_t *node;
    565593        bithenge_blob_inc_ref(blob);
     
    574602                    self->subtransforms[i].transform;
    575603                aoff64_t sub_size;
    576                 rc = bithenge_transform_prefix_length(subxform, scope, blob,
     604                rc = bithenge_transform_prefix_length(subxform, inner, blob,
    577605                    &sub_size);
    578606                if (rc != EOK)
     
    585613                blob = bithenge_node_as_blob(node);
    586614        }
     615
    587616error:
     617        bithenge_node_dec_ref(struct_node);
    588618        bithenge_blob_dec_ref(blob);
    589         return EOK;
     619        return rc;
    590620}
    591621
Note: See TracChangeset for help on using the changeset viewer.