[PATCH 1 of 4 lazy-manifest] manifest.c: new extension code to lazily parse manifests

Augie Fackler raf at durin42.com
Fri Jan 9 19:06:50 CST 2015


On Jan 9, 2015, at 8:02 PM, Martin von Zweigbergk <martinvonz at google.com> wrote:

> 
> 
> On Thu Jan 08 2015 at 12:35:42 PM Augie Fackler <raf at durin42.com> wrote:
> +static lazymanifest *lzm_copy(lazymanifest * self, PyObject * unused_args)
> +{
> +       lazymanifest *copy = NULL;
> +       if (compact(self) != 0) {
> +               goto nomem;
> +       }
> +       copy = PyObject_New(lazymanifest, &lazymanifestType);
> +       if (copy == NULL) {
> +               goto nomem;
> +       }
> +       copy->numlines = self->numlines;
> +       copy->livelines = self->livelines;
> +       copy->dirty = false;
> +       copy->lines = malloc(self->maxlines * sizeof(line));
> +       if (copy->lines == NULL) {
> +               goto nomem;
> +       }
> +       memcpy(copy->lines, self->lines, self->numlines * sizeof(line));
> 
> If some of the lines have from_malloc=true, and either the original or the copy gets GC'ed (so lzm_dealloc gets called), then the other copy will end up with pointers into free'd memory, no?

No, because we always call compact(self) before making the copy, so we know we don’t have any from_malloc lines. Does that make sense?

> 
> We could fix by allocating a separate copy for such lines. Probably simpler than replacing the boolean from_malloc by an integer for reference-counting.
> 
> +       copy->maxlines = self->maxlines;
> +       copy->pydata = self->pydata;
> +       Py_INCREF(copy->pydata);
> +       return copy;
> +nomem:
> +       PyErr_NoMemory();
> +       Py_XDECREF(copy);
> +       return NULL;
> +}
>  

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20150109/b027e30e/attachment.pgp>


More information about the Mercurial-devel mailing list