From: John Darrington Date: Sun, 19 Jul 2009 11:04:39 +0000 (+0200) Subject: Respect the constness of caseproto. X-Git-Tag: build37~50^2~6 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=commitdiff_plain;h=ed0dda01c61c6b086e47f64302b75da5df97db87 Respect the constness of caseproto. New function caseproto_clone. This means we can clone a proto, then mutate it as we want. --- diff --git a/src/data/caseproto.c b/src/data/caseproto.c index 1a40213a..68df141b 100644 --- a/src/data/caseproto.c +++ b/src/data/caseproto.c @@ -59,6 +59,26 @@ caseproto_create (void) return proto; } + +struct caseproto * +caseproto_clone (const struct caseproto *in) +{ + struct caseproto *proto = xmalloc (caseproto_size (in->n_widths)); + proto->ref_cnt = 1; + + proto->n_widths = in->n_widths; + proto->allocated_widths = in->allocated_widths; + + memcpy (proto->widths, in->widths, proto->n_widths * sizeof *proto->widths); + + proto->n_long_strings = in->n_long_strings; + proto->long_strings = NULL; + if ( proto->n_long_strings > 0) + caseproto_refresh_long_string_cache__ (proto); + + return proto; +} + static void do_unref (void *proto_) { diff --git a/src/data/caseproto.h b/src/data/caseproto.h index b85a9f32..3fc8c2c0 100644 --- a/src/data/caseproto.h +++ b/src/data/caseproto.h @@ -78,6 +78,7 @@ struct pool; /* Creation and destruction. */ struct caseproto *caseproto_create (void) MALLOC_LIKE; +struct caseproto *caseproto_clone (const struct caseproto *) ; static inline struct caseproto *caseproto_ref (const struct caseproto *); struct caseproto *caseproto_ref_pool (const struct caseproto *, struct pool *); static inline void caseproto_unref (struct caseproto *); diff --git a/src/data/casereader-translator.c b/src/data/casereader-translator.c index a2963980..c193d404 100644 --- a/src/data/casereader-translator.c +++ b/src/data/casereader-translator.c @@ -417,12 +417,16 @@ consolodate_weight (struct ccase *input, void *aux) struct consolidator *cdr = aux; struct ccase *c; - c = case_unshare_and_resize (input, cdr->proto); - if (cdr->weight) - case_data_rw (c, cdr->weight)->f = cdr->prev_cc; + { + c = case_unshare (input); + case_data_rw (c, cdr->weight)->f = cdr->prev_cc; + } else - case_data_rw_idx (c, caseproto_get_n_widths (cdr->proto) - 1)->f = cdr->prev_cc; + { + c = case_unshare_and_resize (input, cdr->proto); + case_data_rw_idx (c, caseproto_get_n_widths (cdr->proto) - 1)->f = cdr->prev_cc; + } return c; } @@ -457,7 +461,7 @@ casereader_create_distinct (struct casereader *input, { struct casereader *u ; struct casereader *ud ; - const struct caseproto *output_proto = casereader_get_proto (input); + struct caseproto *output_proto = caseproto_clone (casereader_get_proto (input)); struct consolidator *cdr = xmalloc (sizeof (*cdr)); cdr->n = 0; @@ -480,5 +484,7 @@ casereader_create_distinct (struct casereader *input, consolodate_weight, uniquify_destroy, cdr); + + return ud; }