Example #1
0
def _init_mpq_cache():
    global mpq_cache, in_mpq_cache
    mpq_cache = []
    in_mpq_cache = cache_size
    for _ in xrange(cache_size):
        mpq = ffi.new("mpq_t")
        gmp.mpq_init(mpq)
        mpq_cache.append(mpq)
Example #2
0
def _new_mpq():
    """Return an initialized mpq_t."""
    global in_mpq_cache

    if in_mpq_cache:
        in_mpq_cache -= 1
        return mpq_cache[in_mpq_cache]
    else:
        mpq = ffi.new("mpq_t")
        gmp.mpq_init(mpq)
        return mpq