El sáb, 19-01-2008 a las 04:39 -0800, Albert Astals Cid escribió:
> commit e20f6a8e9ac3936b4bc03710a71fe390dfc4c094
> Author: Julien Rebetez <[EMAIL PROTECTED]>
> Date:   Sat Jan 19 12:52:02 2008 +0100
> 
>     Add deep copy constructor to Dict.
> 
> diff --git a/poppler/Dict.cc b/poppler/Dict.cc
> index 0c74566..be82890 100644
> --- a/poppler/Dict.cc
> +++ b/poppler/Dict.cc
> @@ -30,6 +30,18 @@ Dict::Dict(XRef *xrefA) {
>    ref = 1;
>  }
>  
> +Dict::Dict(Dict* dictA) {
> +  xref = dictA->xref;
> +  size = length = dictA->length;
> +  ref = 1;
> +
> +  entries = (DictEntry *)gmallocn(size, sizeof(DictEntry));
> +  for (int i=0; i<length; i++) {
> +    entries[i].key = strdup(dictA->entries[i].key);
> +    dictA->entries[i].val.copy(&entries[i].val);
> +  }
> +}
> +
>  Dict::~Dict() {
>    int i;
>  
> @@ -89,7 +101,7 @@ void Dict::set(char *key, Object *val) {
>    e = find (key);
>    if (e) {
>      e->val.free();
> -    e->val = *val;
> +    val->copy(&e->val);

I think this change is wrong. Dict::set should behave in the same way
whether the key already exists or not. With this change, if the key
already exists, the object will be copied (including dynamically
allocated memory) which means that the original object should be freed
after ->set. However, if the key doesn't exist Dict:add is called and
the object variable is copied (but not the dynamically allocated memory)
which means that the original object shouldn't be freed since it will be
freed by the Dict. Here is an example:

Object obj1;
obj1.initName ("bar");
dict->set ("foo", &obj1);
obj1.free (); -> should we call obj1.free () here? it depends . . . 

This it definitely not consistent. 

>    } else {
>      add (copyString(key), val);
>    }
-- 
Carlos Garcia Campos
   [EMAIL PROTECTED]
   [EMAIL PROTECTED]
   http://carlosgc.linups.org
PGP key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x523E6462

Attachment: signature.asc
Description: Esta parte del mensaje está firmada digitalmente

_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to