Skip to content

Commit

Permalink
Merge pull request #103 from mcmtroffaes/feature/fix-memory-leak
Browse files Browse the repository at this point in the history
Fix memory leak (see issue #102).
  • Loading branch information
mcmtroffaes committed Sep 20, 2016
2 parents 55e518b + 2e9055f commit a0a53a8
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sphinxcontrib/bibtex/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,13 @@ def _get_bibliography_entries(self, docname, id_, warn):
# entries are modified in an unpickable way
# when formatting, so fetch a deep copy
# and return this copy with prefixed key
# we do not deep copy entry.collection because that
# consumes enormous amounts of memory
entry.collection = None
entry2 = copy.deepcopy(entry)
entry2.key = bibcache.keyprefix + entry.key
entry2.collection = data
entry.collection = data
yield entry2

def get_bibliography_entries(self, docname, id_, warn):
Expand Down
2 changes: 2 additions & 0 deletions test/crossref/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extensions = ['sphinxcontrib.bibtex']
exclude_patterns = ['_build']
3 changes: 3 additions & 0 deletions test/crossref/contents.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:cite:`2001:zaffalon`

.. bibliography:: test.bib
21 changes: 21 additions & 0 deletions test/crossref/test.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@INCOLLECTION{2001:zaffalon,
AUTHOR = {Zaffalon, Marco},
TITLE = {Statistical inference of the naive credal
classifier},
PAGES = {384--393},
CROSSREF = {2001:ISIPTA}
}

% need booktitle for crossrefs
@PROCEEDINGS{2001:ISIPTA,
TITLE = {{ISIPTA} '01 -- Proceedings of the Second
International Symposium on Imprecise Probabilities
and Their Applications},
BOOKTITLE = {{ISIPTA} '01 -- Proceedings of the Second
International Symposium on Imprecise Probabilities
and Their Applications},
YEAR = {2001},
PUBLISHER = {Shaker Publishing},
EDITOR = {{de} Cooman, G. and Fine, T. L. and Seidenfeld, T.},
ADDRESS = {Maastricht}
}
31 changes: 31 additions & 0 deletions test/test_crossref.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
test_crossref
~~~~~~~~~~~~~
Test that cross references work.
"""

import os.path
import re

from sphinx_testing.util import path, with_app

srcdir = path(__file__).dirname().joinpath('crossref').abspath()


def teardown_module():
(srcdir / '_build').rmtree(True)


@with_app(srcdir=srcdir, warningiserror=True)
def test_crossref(app, status, warning):
app.builder.build_all()
# default style is plain; check output
with open(os.path.join(app.outdir, "contents.html")) as stream:
output = stream.read()
# ensure Zaf is cited
assert len(re.findall('\\[Zaf\\]', output)) == 2
# ensure proceedings only mentioned for Zaf
assert len(re.findall(
'Proceedings of the Second International Symposium '
'on Imprecise Probabilities and Their Applications', output)) == 1

0 comments on commit a0a53a8

Please sign in to comment.