simon-git: spigot (master): Simon Tatham

Commits to Tartarus hosted VCS tartarus-commits at lists.tartarus.org
Sat Feb 11 15:09:17 GMT 2017


TL;DR:
  c1d5a58 Fill in a half-written comment in io.cpp.
  f3c31d7 Build spigot in a way that will accept C++14 features.
  a31b438 Turn SpigotPy into a real C++ class.
  b8dccb4 Make 'Spigot' a typedef for 'Coreable *', not 'Coreable'.
  d5181ad Make 'Spigot' a typedef for unique_ptr<Coreable>.
  d9a3f40 Use unique_ptr for MonotoneConstructor derivatives.
  5ef81e6 Use unique_ptr for all Generator subclasses in wrappers.
  14b2720 Use unique_ptr for all output generators.
  9a80503 Use unique_ptr for the Formatters in baseout.cpp.
  144770c Make bigint_{hex,dec}string return std::string.
  8d6a833 Make my error classes contain a std::string.
  256e3ac expr.cpp: use shared_ptr to store the AST and scopes.
  0256fbc gamma.cpp: keep Stirling numbers in a vector.
  2aed3cd io.cpp: keep FileBlocks in a std::list.
  62fa700 io.cpp: use shared_ptr for FileReaders.
  22792f9 sqrt.cpp: keep SqrtInteger's history list in a vector.
  c9fdccf Use a std::vector as the return type of Core::endpoints().
  1d65ce3 Remove the TODO item about memory leaks.

Repository:     https://git.tartarus.org/simon/spigot.git
On the web:     https://git.tartarus.org/?p=simon/spigot.git
Branch updated: master
Committer:      Simon Tatham <anakin at pobox.com>
Date:           2017-02-11 15:09:17

commit c1d5a58f28c98a9bd148b5a7613d07635f9c03b4
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=c1d5a58f28c98a9bd148b5a7613d07635f9c03b4;hp=7801f69298cde7e1ee53ac65c1058dd08efcd1d6
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:28 2017 +0000

    Fill in a half-written comment in io.cpp.
    
    Appparently I got distracted half way through explaining what the
    'simple cases' at the top of getch actually were :-)

 io.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

commit f3c31d771b8880c69526410785825696fa8da6f9
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=f3c31d771b8880c69526410785825696fa8da6f9;hp=c1d5a58f28c98a9bd148b5a7613d07635f9c03b4
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:28 2017 +0000

    Build spigot in a way that will accept C++14 features.
    
    Or a few of them, at least. I'm doing the autodetection in
    configure.ac my own way rather than using the AX_CXX_COMPILE_STDCXX
    macro in the Autoconf Archive, because I've found that the latter will
    reject Debian jessie's g++ (4.9.2) as not C++14-compliant, and yet it
    accepts -std=c++14 and compiles all the features I plan to use just
    fine in that mode. Presumably there's some other C++14 feature that it
    _doesn't_ get right, but whatever that is, I don't need it, and I
    don't want to rule out compiling on jessie due to its absence.
    
    I've also added -std=c++14 to the Python spigot module's build script,
    and switched the Windows build to Visual Studio 2015 (which supports
    C++14, unlike my previous archaic VS2003). In the process the Windows
    build has also become 64-bit, because I think that is the way of the
    future now for any program that doesn't have a large legacy problem;
    if anyone really needs it, I can always bring back a parallel 32-bit
    Windows spigot build on demand.

 Buildscr        |  2 +-
 configure.ac    | 42 ++++++++++++++++++++++++++++++++++++++++++
 python/setup.py |  1 +
 3 files changed, 44 insertions(+), 1 deletion(-)

commit a31b4382a4ba7dd2033981945dcd5bcdaec683e6
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=a31b4382a4ba7dd2033981945dcd5bcdaec683e6;hp=f3c31d771b8880c69526410785825696fa8da6f9
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:28 2017 +0000

    Turn SpigotPy into a real C++ class.
    
    It's now got a constructor and a destructor (but no vtable, meaning
    that the 'PyObject_HEAD' macro at the top of the class definition is
    still where it should be). This means we have to be a bit careful
    about how we create and destroy it: I've used the C++ 'placement new'
    feature in Spigot_new() which constructs a class instance at a
    specified address in already-allocated memory (and runs its
    constructor), and an explicit destructor call in Spigot_dealloc() to
    clean up anything dangling off it.
    
    There's no functional change expected here, and no particular extra
    convenience _now_ (in that I still have to do all my subsidiary
    deallocations by hand), but this opens the way to put more interesting
    kinds of auto-managed member variables into SpigotPy, such as C++14
    smart pointers.

 python/pyspig.cpp | 55 +++++++++++++++++++++++++++++++++----------------------
 1 file changed, 33 insertions(+), 22 deletions(-)

commit b8dccb4871fbce47da709e6e46533a376cb3f2b9
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=b8dccb4871fbce47da709e6e46533a376cb3f2b9;hp=a31b4382a4ba7dd2033981945dcd5bcdaec683e6
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:28 2017 +0000

    Make 'Spigot' a typedef for 'Coreable *', not 'Coreable'.
    
    I never used the name without a trailing '*' in any case, so partly
    this is just going to save a bit of punctuation at more or less every
    call site. But also, it's groundwork for turning the C-style raw
    pointer into a more interesting auto-memory-managed smart pointer,
    because now I can flip that typedef without affecting existing
    declarations or prototypes (though other code changes will be needed).

 algebraic.cpp     |   8 +--
 arithmetic.cpp    |  26 +++----
 baseout.cpp       |   8 +--
 baseout.h         |   6 +-
 cfracout.cpp      |   6 +-
 cfracout.h        |   6 +-
 consts.cpp        |  10 +--
 enforce.cpp       |  10 +--
 erf.cpp           |  22 +++---
 error.h           |   4 +-
 exp.cpp           |  50 ++++++-------
 expint.cpp        |  62 ++++++++--------
 expr.cpp          |  42 +++++------
 expr.h            |   4 +-
 funcs.h           | 206 +++++++++++++++++++++++++++---------------------------
 gamma.cpp         |  46 ++++++------
 holefiller.h      |  18 ++---
 io.cpp            |   8 +--
 lambertw.cpp      |  14 ++--
 main.cpp          |   2 +-
 misc.cpp          |   4 +-
 monotone.cpp      |  16 ++---
 python/pyspig.cpp |  10 +--
 spigot.cpp        |   4 +-
 spigot.h          |  22 +++---
 sqrt.cpp          |  14 ++--
 trig.cpp          |  56 +++++++--------
 trigint.cpp       |  30 ++++----
 unary.cpp         |  32 ++++-----
 zeta.cpp          |  22 +++---
 30 files changed, 385 insertions(+), 383 deletions(-)

commit d5181addfebca096b900809b8507d3f31058b081
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=d5181addfebca096b900809b8507d3f31058b081;hp=b8dccb4871fbce47da709e6e46533a376cb3f2b9
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:28 2017 +0000

    Make 'Spigot' a typedef for unique_ptr<Coreable>.
    
    Following immediately on from one change to the definition of Spigot,
    here's another :-) This sweeping change throughout the code base
    converts every use of the Spigot pointer type to make it compatible
    with being a unique_ptr - allocations are done using make_unique
    rather than 'new', no calls to 'delete' are required any more, and
    passing the contents of a Spigot variable into any subfunction that
    will consume it now has a mandatory move() to make it clear that
    that's what's happening.
    
    The effect is that the memory management should become much more
    reliable (a lot of early exits from spigot_somefunc() setup functions
    would leak memory), with less effort on my part (I don't have to
    prevent those leaks by extensive manual 'delete' any more).

 algebraic.cpp     |   8 +--
 arithmetic.cpp    | 116 +++++++++++++-----------------
 baseout.cpp       |  29 ++++----
 cfracout.cpp      |  31 ++++----
 consts.cpp        |  12 ++--
 enforce.cpp       |  17 ++---
 erf.cpp           |  30 ++++----
 exp.cpp           | 108 ++++++++++++++--------------
 expint.cpp        |  70 +++++++++++-------
 expr.cpp          | 210 ++++++++++++++++++++++++++----------------------------
 funcs.h           |   4 +-
 gamma.cpp         |  76 ++++++++++----------
 holefiller.h      |  30 +++-----
 io.cpp            |  14 ++--
 lambertw.cpp      |   8 +--
 main.cpp          |  12 ++--
 misc.cpp          |   4 +-
 monotone.cpp      |  33 ++++-----
 python/pyspig.cpp |  24 +++----
 spigot.cpp        | 101 ++++++++++++--------------
 spigot.h          |  75 +++++++++++++------
 sqrt.cpp          |  42 +++++------
 trig.cpp          |  82 +++++++++++----------
 trigint.cpp       |  37 +++++-----
 unary.cpp         |  49 ++++++-------
 zeta.cpp          |  24 +++----
 26 files changed, 616 insertions(+), 630 deletions(-)

commit d9a3f40f6ad4a664509dd22325916e32d8f11f6d
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=d9a3f40f6ad4a664509dd22325916e32d8f11f6d;hp=d5181addfebca096b900809b8507d3f31058b081
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:28 2017 +0000

    Use unique_ptr for MonotoneConstructor derivatives.
    
    The setup functions spigot_monotone and spigot_monotone_invert now
    take a unique_ptr<MonotoneConstructor> instead of a plain pointer, and
    MonotoneConstructor's clone method returns a unique_ptr too. Knock-on
    effects at every call site and subclass, of course.

 erf.cpp      | 25 ++++++++++++++++---------
 exp.cpp      | 12 ++++++++----
 expint.cpp   | 14 +++++++++-----
 funcs.h      |  7 ++++---
 gamma.cpp    | 20 ++++++++++++++------
 lambertw.cpp | 13 ++++++++-----
 monotone.cpp | 24 ++++++++++++------------
 trig.cpp     | 30 ++++++++++++++++++++----------
 trigint.cpp  | 15 +++++++++------
 9 files changed, 100 insertions(+), 60 deletions(-)

commit 5ef81e695b195984fe95f4b46412ffb43eb7497d
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=5ef81e695b195984fe95f4b46412ffb43eb7497d;hp=d9a3f40f6ad4a664509dd22325916e32d8f11f6d
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:28 2017 +0000

    Use unique_ptr for all Generator subclasses in wrappers.
    
    This affects nearly all the classes that wrap one or more input
    Spigot, use BracketingGenerator to extract data from them, and
    re-enter the results (appropriately tweaked or checked) into a
    BinaryIntervalSource.
    
    Affected classes are MonotoneHelper, HoleFiller (and therefore its
    derivatives), PowPrefixWrapper in exp.cpp, and GammaWrapper in
    gamma.cpp.
    
    (One similar wrapper class *not* affected is Enforcer, which is simple
    enough that its BracketingGenerators were just class member variables
    with no indirection, so they didn't need separate freeing anyway.)

 exp.cpp      | 17 ++++-------------
 gamma.cpp    | 15 ++++-----------
 holefiller.h | 35 ++++++++++++-----------------------
 monotone.cpp | 20 +++++---------------
 4 files changed, 25 insertions(+), 62 deletions(-)

commit 14b2720618bf093c1b500b46dd83af32e5c496eb
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=14b2720618bf093c1b500b46dd83af32e5c496eb;hp=5ef81e695b195984fe95f4b46412ffb43eb7497d
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:29 2017 +0000

    Use unique_ptr for all output generators.
    
    All the functions in baseout.cpp and cfracout.cpp that are called from
    main() now return a unique_ptr<OutputGenerator> in place of a raw
    pointer.
    
    While I'm at it, I've also made the same change in the direct use of
    the old-style CfracGenerator in the Python module, which has allowed
    me to remove all the actual code from the SpigotPy destructor - now
    everything stored in that class is automatically freed as a side
    effect of my explicit destructor call in Spigot_dealloc.

 baseout.cpp       | 25 ++++++++++++-------------
 baseout.h         | 22 ++++++++++++----------
 cfracout.cpp      | 21 +++++++++++----------
 cfracout.h        | 14 +++++++++-----
 main.cpp          |  6 +++---
 python/pyspig.cpp | 21 ++++++---------------
 6 files changed, 53 insertions(+), 56 deletions(-)

commit 9a8050364cb4bb0f5442c36676c85f6b319c3cc7
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=9a8050364cb4bb0f5442c36676c85f6b319c3cc7;hp=14b2720618bf093c1b500b46dd83af32e5c496eb
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:29 2017 +0000

    Use unique_ptr for the Formatters in baseout.cpp.
    
    These pointers were previously copied back and forth between two
    arrays in the course of deciding which subset of the formatters from
    one digit position were still live in the next one. Fortunately, all
    those copies were conceptually moves (just not actually marked as
    such), so it didn't turn out to be too difficult to translate them
    into valid unique_ptr language.

 baseout.cpp | 72 ++++++++++++++++++++++++++-----------------------------------
 1 file changed, 31 insertions(+), 41 deletions(-)

commit 144770c5d9c9b7026aa7350677f7bebf3c3b0683
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=144770c5d9c9b7026aa7350677f7bebf3c3b0683;hp=9a8050364cb4bb0f5442c36676c85f6b319c3cc7
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:29 2017 +0000

    Make bigint_{hex,dec}string return std::string.
    
    Aside from removing the risk of memory management goofs, this is just
    _obviously_ a more sensible return type for these functions,
    especially when you look at the client code in cfracout.cpp!

 bi_gmp.h          | 15 ++++++++++----
 bi_internal.h     | 61 +++++++++++++++++++------------------------------------
 cfracout.cpp      | 34 ++++++-------------------------
 python/pyspig.cpp |  8 +++++---
 4 files changed, 43 insertions(+), 75 deletions(-)

commit 8d6a833788e786e73dfa836d97dde101ee845622
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=8d6a833788e786e73dfa836d97dde101ee845622;hp=144770c5d9c9b7026aa7350677f7bebf3c3b0683
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:29 2017 +0000

    Make my error classes contain a std::string.
    
    This is another case where I wonder how I ever thought the previous
    code was a good idea!

 error.h           | 40 ++++++++++++++++++++--------------------
 main.cpp          |  6 +++---
 python/pyspig.cpp |  2 +-
 3 files changed, 24 insertions(+), 24 deletions(-)

commit 256e3ac93ca6e62feb7c78b70ba02fc87abfbe91
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=256e3ac93ca6e62feb7c78b70ba02fc87abfbe91;hp=8d6a833788e786e73dfa836d97dde101ee845622
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:29 2017 +0000

    expr.cpp: use shared_ptr to store the AST and scopes.
    
    These have to be shared_ptr rather than unique_ptr because pieces of
    AST cross-refer. In particular, I used to have a special class
    'ASTRef' whose job was to cross-refer to another piece of AST
    _without_ causing it to be double-freed when the whole lot got cleaned
    up; that's now completely gone, because I just replace each ASTRef
    with a copy of the shared_ptr to the node it really wanted to refer
    to, and the reference counting sorts everything out for me.
    
    (Of course, this relies on the fact that ASTs are acyclic!)

 expr.cpp | 175 +++++++++++++++++++++++++++------------------------------------
 1 file changed, 76 insertions(+), 99 deletions(-)

commit 0256fbcd7f5d781dfbffb95ff9ec5b05f4790839
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=0256fbcd7f5d781dfbffb95ff9ec5b05f4790839;hp=256e3ac93ca6e62feb7c78b70ba02fc87abfbe91
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:29 2017 +0000

    gamma.cpp: keep Stirling numbers in a vector.
    
    This replaces a lot of ad-hoc manual linked-list code with a
    straightforward use of vector, with std::move used to replace the
    vector with the new version every time it gets updated on the way
    round the loop.
    
    I only use Stirling numbers with indices 1,...,n in each trip round
    the loop, so just to avoid confusion I started by inserting a 0 at the
    front of the vector so that the indices wouldn't be off by one. That
    turned out to be a good idea in any case, because it removes a special
    case during the update loop. (The 'if (node->next)' check is gone,
    because the missing node->next in the old code was the analogue of
    element 0 of the vector, so now it _does_ exist.)

 gamma.cpp | 57 +++++++++++++++++++++------------------------------------
 1 file changed, 21 insertions(+), 36 deletions(-)

commit 2aed3cdc760559c9852bc3b0187c4c0e1054f2a6
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=2aed3cdc760559c9852bc3b0187c4c0e1054f2a6;hp=0256fbcd7f5d781dfbffb95ff9ec5b05f4790839
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:29 2017 +0000

    io.cpp: keep FileBlocks in a std::list.
    
    This saves me doing the linked-list management by hand when I append a
    new block to the end of the list. (But it would probably have been
    more unpleasant without the C++11 emplace_back method.)

 io.cpp | 76 ++++++++++++++++++++++++++++++++++++------------------------------
 1 file changed, 41 insertions(+), 35 deletions(-)

commit 62fa70022e3d03d3255c57c9e6954586c97a655e
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=62fa70022e3d03d3255c57c9e6954586c97a655e;hp=2aed3cdc760559c9852bc3b0187c4c0e1054f2a6
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:29 2017 +0000

    io.cpp: use shared_ptr for FileReaders.
    
    FileReader is the class that's shared between all the uses of a number
    read from the same file, so that there's exactly one FileReader per
    input file (or input fd), and each client of it keeps a separate
    FileReaderPos. Each FileReaderPos is owned and freed by its client
    Source, but the FileReaders themselves still need managing, and given
    that structure, shared_ptr is a natural fit for them.

 io.cpp | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

commit 22792f942f7b2eeaaa87741599367e69177b2b6d
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=22792f942f7b2eeaaa87741599367e69177b2b6d;hp=62fa70022e3d03d3255c57c9e6954586c97a655e
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:29 2017 +0000

    sqrt.cpp: keep SqrtInteger's history list in a vector.
    
    This was another piece of painful manual memory management which I've
    replaced with a smaller and simpler use of the STL that will guarantee
    no leaks.

 sqrt.cpp | 47 +++++++++++++++++------------------------------
 1 file changed, 17 insertions(+), 30 deletions(-)

commit c9fdccf1daf5a16b8e9dfa98f8e208e5dba65310
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=c9fdccf1daf5a16b8e9dfa98f8e208e5dba65310;hp=22792f942f7b2eeaaa87741599367e69177b2b6d
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:29 2017 +0000

    Use a std::vector as the return type of Core::endpoints().
    
    This is a great deal simpler than the previous code in which each Core
    would pre-commit to the largest number of endpoints it might ever need
    to return, permitting clients to allocate an ordinary C array, and
    then each call to endpoints() would write into that array and return a
    count of how many elements it put there. Now endpoints() just returns
    an actual vector<endpoint>, so no pre-commitment to a maximum size is
    needed.
    
    Also, this clarifies the code because previously the output array was
    an array of _bigints_, but each endpoint is actually composed of two
    bigints (numerator and denominator, more or less), which led to a lot
    of faffing about with odd and even indices and expressions like
    endpoints[2*i+1]. Now I've made a little class that has members 'n'
    and 'd', so that those multipurpose array indices are more sensibly
    divided into which endpoint you're addressing and which half of it you
    want.

 arithmetic.cpp | 136 ++++++++++++++++++++++++---------------------------------
 spigot.cpp     |  98 ++++++++++++++++++-----------------------
 spigot.h       |  18 +++++---
 3 files changed, 110 insertions(+), 142 deletions(-)

commit 1d65ce37254543148c913374ba4ecf9ae13451c0
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=1d65ce37254543148c913374ba4ecf9ae13451c0;hp=c9fdccf1daf5a16b8e9dfa98f8e208e5dba65310
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Feb 11 15:01:29 2017 +0000

    Remove the TODO item about memory leaks.
    
    After this splurge of memory management fixes, there are _no_
    remaining cases where I call any explicit allocate or free function,
    except where external APIs make it unavoidable - e.g. the GMP API does
    allocation (but I arrange that every mpz_t I create is cleaned up
    again by the bigint class destructor), other GMP functions like
    mpz_get_str, and interactions with the CPython internal API.
    
    valgrind reports no leaked memory blocks at all for a typical spigot
    invocation, unless you ask it for the still-reachable ones too with
    --show-leak-kinds=all, in which case it reports some blocks that were
    allocated in the course of calling the terminfo functions like
    tigetstr, which I presume libtinfo keeps around so as to reuse them to
    answer any further queries, and which are not worrying for any real
    reason (in particular, there won't be a gradually increasing number of
    them as spigot continues to run).

 TODO.txt | 15 ---------------
 1 file changed, 15 deletions(-)



More information about the tartarus-commits mailing list