[poppler] 11 commits - poppler/Annot.cc poppler/Annot.h poppler/Decrypt.cc poppler/Decrypt.h poppler/Dict.cc poppler/Dict.h poppler/Form.cc poppler/PDFDoc.cc poppler/PDFDoc.h poppler/Stream.cc poppler/Stream.h poppler/XRef.cc poppler/XRef.h test/Makefile.am test/pdf-fullrewrite.cc

Carlos Garcia Campos carlosgc at gnome.org
Wed Jan 23 05:29:45 PST 2008


El sáb, 19-01-2008 a las 04:39 -0800, Albert Astals Cid escribió:
> commit e20f6a8e9ac3936b4bc03710a71fe390dfc4c094
> Author: Julien Rebetez <julien at fhtagn.net>
> 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
   elkalmail at yahoo.es
   carlosgc at gnome.org
   http://carlosgc.linups.org
PGP key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x523E6462
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada
	digitalmente
Url : http://lists.freedesktop.org/archives/poppler/attachments/20080123/841564b6/attachment.pgp 


More information about the poppler mailing list