Commit Graph

18 Commits

Author SHA1 Message Date
Augie Fackler
9084d6d473 lazymanifest: check error return in filter 2015-12-31 13:45:48 -05:00
Augie Fackler
3e532379e3 lazymanifest: add missing closing parenthesis in comment 2015-12-31 13:44:59 -05:00
Bryan O'Sullivan
0302ab4676 manifest: fix formatting
One poor unfortunate line was hanging way off the right hand side
of the universe.  Rescued it.
2015-12-12 20:10:33 -08:00
Martin von Zweigbergk
e81582fa94 lazymanifest: drop SP before some labels
These seem to be the only occurrences in our code base, so let's make
it consistent.
2015-04-12 07:14:53 -07:00
Martin von Zweigbergk
d15b0c7277 lazymanifest: avoid 'bail' label when used on success path
e3b881ea6832 (lazymanifest: extract function for iterating to next
line, 2015-03-11) introduced a large memory leak because I stopped
running the 'bail' block in the successful case. Let's rename 'bail'
to 'done', since it has to run not only in the error case.
2015-04-12 07:12:39 -07:00
Augie Fackler
5e2ccad13e lazymanifest: prevent leak when updating an entry more than once
__setitem__ on the lazymanifest C type wasn't checking to see if a
line had previously been malloced before replacing it, leading to
leaks if files got updated multiple times in the course of a task.

I was able to reproduce the leak with this change to test-manifest.py:

diff --git a/tests/test-manifest.py b/tests/test-manifest.py
--- a/tests/test-manifest.py
+++ b/tests/test-manifest.py
@@ -456,6 +456,16 @@ class basemanifesttests(object):
                 ['a/b/c/bar.txt', 'a/b/c/foo.txt', 'a/b/d/ten.txt'],
                 m2.keys())

+    def testManifestSetItem(self):
+        m = self.parsemanifest('')
+        for x in range(3):
+            m['file%d' % x] = BIN_HASH_1
+        for x in range(3):
+            m['file%d' % x] = BIN_HASH_2
+        import time
+        time.sleep(4)
+
+

along with the commands:

 $ make local
 $ PYTHONPATH=. SILENT_BE_NOISY=1 python tests/test-manifest.py testmanifestdict.testManifestSetItem &
 $ sleep 4
 $ leaks $(jobs -p | tee /dev/stderr | awk '{print $3}')
 $ wait

in an interactive shell on OS X. As far as I can tell, it had to be an
interactive shell so that I could get the pid of the test run using
the jobs builtin. Prior to this change, I was leaking several strings,
and after this change leaks reports no leaks.

I thought there was a bug filed for this in bugzilla, but I can't find
it either in bugzilla or by searching my email.
2015-04-11 11:56:21 -04:00
Mike Hommey
50ad077324 lazymanifest: fix memory leak in lmiter_iterentriesnext() after e3b881ea6832 2015-04-12 06:51:13 -07:00
Matt Mackall
99e9f5ee02 manifest: move C bool polyfill into util.h 2015-03-25 14:16:10 -05:00
Matt Mackall
2f9bd7da07 manifest: use util.h to get Py_ssize_t 2015-03-25 14:13:11 -05:00
Drew Gottlieb
5daf7be6fb manifest: include Python.h before standard headers
Python.h should be included before any standard headers according to the
python docs: https://docs.python.org/2/c-api/intro.html#include-files
2015-03-18 11:41:36 -07:00
Matt Harbison
eecb718435 manifest.c: ensure realloc_if_full() returns 1 or 0
This fixes an MSVC 2008 warning that I don't see with gcc 4.6.3-2:

    warning C4047: 'return' :
            'bool' differs in levels of indirection from 'line *'

More importantly, the truncation from pointer to 'unsigned char' would have
returned 0 if self->lines pointed to an address divisible by 0xFF, which causes
find_lines() to return MANIFEST_OOM.  I was able to cause this to happen in a
trivial program with the gcc compiler.
2015-03-13 22:50:40 -04:00
Martin von Zweigbergk
ce0723ee16 lazymanifest: make __iter__ generate filenames, not 3-tuples
The _lazymanifest type(s) behave very much like a sorted dict with
filenames as keys and (nodeid, flags) as values. It therefore seems
surprising that its __iter__ generates 3-tuples of (path, nodeid,
flags). Let's make it match dict's behavior of generating the keys
instead, and add a new iterentries method for the 3-tuples. With this
change, the "x" in "if x in lm" and "for x in lm" now have the same
type (a filename string).
2015-03-12 18:18:29 -07:00
Martin von Zweigbergk
2421174b13 lazymanifest: add iterkeys() method
So we don't have to iteratate over (path, node, flags) tuples only to
throw away the node and flags.
2015-03-11 13:46:15 -07:00
Martin von Zweigbergk
59c86845ac lazymanifest: extract function for iterating to next line
This will soon be reused by keys iterator.
2015-03-11 13:15:26 -07:00
Martin von Zweigbergk
58ba8d255c lazymanifest: fail if path or hash strings cannot be created
While generating (path, hash, flags), we fail if flags cannot be
created. We should also fail if path or hash cannot be created.
2015-03-11 13:35:34 -07:00
Martin von Zweigbergk
2f636305e8 lazymanifest: don't depend on printf's 'hh' format to work
Where we convert a 20-byte binary to a 40-byte hex string in
lazymanifest_setitem(), we use sprintf("%02hhx", hash[i]). As Matt
Harbison found out, 'hh' seems to be ignored on some platforms (Visual
Studio?). If char is signed on such platforms, the value gets
sign-extended as it gets promoted into an int when passed into the
variadic sprintf(). The resulting integer value will then be printed
with leading f's (14 of them on 64-bit systems), since the '2' in the
format string indicates only minimum number of characters. This is
both incorrect and runs the risk of writing outside of allocated
memory (as Matt reported).

To fix, let's cast the value to unsigned char before passing it to
sprintf(). Also drop the poorly supported 'hh' formatting that now
becomes unnecessary.
2015-03-12 09:06:45 -07:00
Augie Fackler
608c4b91f7 lazymanifest: use a binary search to do an insertion
This makes insertions log(n) plus some memmove() overhead, rather than
doing an append followed by an n*log(n) sort. There's probably a lot
of performance to be gained by adding a batch-add method, which could
be smarter about the memmove()s performed.

Includes a couple of extra tests that should help prevent bugs.

Thanks to Martin for some significant pre-mail cleanup of this change.
2015-01-30 21:30:40 -08:00
Augie Fackler
b619fe8004 manifest.c: new extension code to lazily parse manifests
This lets us iterate manifests in order, but do a _lot_ less work in
the common case when we only care about a few manifest entries.

Many thanks to Mike Edgar for reviewing this in advance of it going
out to the list, which caught many things I missed.

This version of the patch includes C89 fixes from Sean Farley and
many correctness/efficiency cleanups from Martin von
Zweigbergk. Thanks to both!
2015-01-13 14:31:38 -08:00