[libmath-prime-util-perl] 82/181: Stop checking return of New/Renew and its propagations
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:51:09 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.36
in repository libmath-prime-util-perl.
commit df94359b10ca8a24dcf62b300391e1330bdcad39
Author: Dana Jacobsen <dana at acm.org>
Date: Tue Dec 31 06:18:08 2013 -0800
Stop checking return of New/Renew and its propagations
---
XS.xs | 1 -
cache.c | 9 ++++-----
lehmer.c | 11 -----------
lmo.c | 4 ----
sieve.c | 15 ++-------------
util.c | 11 +----------
6 files changed, 7 insertions(+), 44 deletions(-)
diff --git a/XS.xs b/XS.xs
index d104adc..9efb552 100644
--- a/XS.xs
+++ b/XS.xs
@@ -260,7 +260,6 @@ sieve_primes(IN UV low, IN UV high)
}
} else if (ix == 2) { /* Erat */
unsigned char* sieve = sieve_erat30(high);
- if (sieve == 0) croak("Could not generate sieve for %"UVuf, high);
START_DO_FOR_EACH_SIEVE_PRIME( sieve, low, high ) {
av_push(av,newSVuv(p));
} END_DO_FOR_EACH_SIEVE_PRIME
diff --git a/cache.c b/cache.c
index 2aec994..10a1753 100644
--- a/cache.c
+++ b/cache.c
@@ -106,8 +106,8 @@ static void _erase_and_fill_prime_cache(UV n) {
if (n > 0) {
prime_cache_sieve = sieve_erat30(padded_n);
- if (prime_cache_sieve != 0)
- prime_cache_size = padded_n;
+ MPUassert(prime_cache_sieve != 0, "sieve returned null");
+ prime_cache_size = padded_n;
}
}
@@ -153,6 +153,7 @@ UV get_prime_cache(UV n, const unsigned char** sieve)
#else
if (prime_cache_size < n)
_erase_and_fill_prime_cache(n);
+ MPUassert(prime_cache_size >= n, "prime cache is too small!");
if (sieve != 0)
*sieve = prime_cache_sieve;
return prime_cache_size;
@@ -196,9 +197,7 @@ unsigned char* get_prime_segment(UV *size) {
New(0, mem, SECONDARY_SEGMENT_CHUNK_SIZE, unsigned char);
*size = SECONDARY_SEGMENT_CHUNK_SIZE;
}
-
- if (mem == 0)
- croak("Could not allocate %"UVuf" bytes for segment sieve", *size);
+ MPUassert(mem != 0, "get_prime_segment allocation failure");
return mem;
}
diff --git a/lehmer.c b/lehmer.c
index 9f4114f..6c0ee4a 100644
--- a/lehmer.c
+++ b/lehmer.c
@@ -145,8 +145,6 @@ static uint32_t* generate_small_primes(UV n)
{
uint32_t* primes;
New(0, primes, n+1, uint32_t);
- if (primes == 0)
- croak("Can not allocate small primes\n");
if (n < TINY_PRIME_SIZE) {
if (tiny_primes == 0)
tiny_primes = generate_small_primes(TINY_PRIME_SIZE+1);
@@ -192,8 +190,6 @@ static uint32_t* generate_small_primes(UV n)
if (n > 203280221)
croak("generate small primes with argument too large: %lu\n", (unsigned long)n);
New(0, primes, n+1, uint32_t);
- if (primes == 0)
- croak("Can not allocate small primes\n");
primes[0] = 0;
START_DO_FOR_EACH_PRIME(2, nth_prime) {
if (i >= n) break;
@@ -339,12 +335,10 @@ static void phi_cache_insert(uint32_t x, uint32_t a, IV sum, cache_t* cache) {
if (sum < SHRT_MIN || sum > SHRT_MAX) return;
if (cache->val[a] == 0) {
Newz(0, cache->val[a], cap, int16_t);
- if (cache->val[a] == 0) croak("phi cache allocation failure");
cache->max[a] = cap;
} else if (cache->max[a] < cap) {
uint32_t i;
Renew(cache->val[a], cap, int16_t);
- if (cache->val[a] == 0) croak("phi cache allocation failure");
for (i = cache->max[a]; i < cap; i++)
cache->val[a][i] = 0;
cache->max[a] = cap;
@@ -429,7 +423,6 @@ static void vcarray_insert(vcarray_t* l, UV val, IV count)
if (verbose>2) printf("REALLOCing list %p, new size %lu (%luk)\n",l->a,new_size, new_size*sizeof(vc_t)/1024);
Renew( l->a, new_size, vc_t );
}
- if (l->a == 0) croak("could not allocate list\n");
l->size = new_size;
}
/* printf(" inserting %lu %ld\n", val, count); */
@@ -550,8 +543,6 @@ static UV phi(UV x, UV a)
lastidx = a+1;
primes = generate_small_primes(lastidx);
- if (primes == 0)
- croak("Could not generate primes for phi(%lu,%lu)\n", x, a);
lastprime = primes[lastidx];
if (x < lastprime) { Safefree(primes); return (x > 0) ? 1 : 0; }
phicache_init(&pcache);
@@ -734,7 +725,6 @@ UV _XS_lehmer_pi(UV n)
if (verbose > 0) printf("lehmer %lu stage 3: %lu small primes\n", n, lastprime);
TIMING_START;
primes = generate_small_primes(lastprime);
- if (primes == 0) croak("Error generating primes.\n");
lastpc = primes[lastprime];
TIMING_END_PRINT("small primes")
@@ -796,7 +786,6 @@ UV _XS_LMOS_pi(UV n)
if (lastprime > 203280221) lastprime = 203280221;
if (lastprime < n13) lastprime = n13;
primes = generate_small_primes(lastprime);
- if (primes == 0) croak("Error generating primes.\n");
New(0, mu, n13+1, signed char);
memset(mu, 1, sizeof(signed char) * (n13+1));
diff --git a/lmo.c b/lmo.c
index 4c7ede2..a6024d1 100644
--- a/lmo.c
+++ b/lmo.c
@@ -124,7 +124,6 @@ static uint32_t* make_primelist(uint32 n, uint32* number_of_primes)
: (n/logn) * (1.0+1.0/logn+2.51/(logn*logn));
*number_of_primes = 0;
New(0, plist, max_index+1, uint32_t);
- if (plist == 0) croak("Can not allocate small primes\n");
plist[0] = 0;
/* We could do a simple SoE here. This is not time critical. */
START_DO_FOR_EACH_PRIME(2, n) {
@@ -211,7 +210,6 @@ static uint16* ft_create(uint32 max)
uint32 max_prime = (tableLimit - 1) / 3 + 1;
New(0, factor_table, tableSize, uint16);
- if (factor_table == 0) return 0;
/* Set all values to 65535 (a large prime), set 0 to 65534. */
factor_table[0] = 65534;
@@ -476,8 +474,6 @@ UV _XS_LMO_pi(UV n)
/* Create the array of small primes, and least-prime-factor/moebius table */
primes = make_primelist( M + 500, &nprimes );
factor_table = ft_create( M );
- if (primes == 0 || factor_table == 0)
- croak("Allocation failure in LMO Pi\n");
/* Create other arrays */
New(0, ss.sieve, PHI_SIEVE_WORDS + 2, sword_t);
diff --git a/sieve.c b/sieve.c
index 54a185f..d64615f 100644
--- a/sieve.c
+++ b/sieve.c
@@ -233,10 +233,6 @@ unsigned char* sieve_erat30(UV end)
/* Round up to a word */
max_buf = ((max_buf + sizeof(UV) - 1) / sizeof(UV)) * sizeof(UV);
New(0, mem, max_buf, unsigned char );
- if (mem == 0) {
- croak("allocation failure in sieve_erat30: could not alloc %"UVuf" bytes", max_buf);
- return 0;
- }
/* Fill buffer with marked 7, 11, and 13 */
sieve_prefill(mem, 0, max_buf-1);
@@ -305,10 +301,7 @@ int sieve_segment(unsigned char* mem, UV startd, UV endd)
slimit = limit;
if (slimit > BASE_SIEVE_LIMIT) slimit = BASE_SIEVE_LIMIT;
/* printf("segment sieve from %"UVuf" to %"UVuf" (aux sieve to %"UVuf")\n", startp, endp, slimit); */
- if (get_prime_cache(slimit, &sieve) < slimit) {
- release_prime_cache(sieve);
- return 0;
- }
+ get_prime_cache(slimit, &sieve);
START_DO_FOR_EACH_SIEVE_PRIME(sieve, 17, slimit)
{
@@ -426,8 +419,6 @@ void* start_segment_primes(UV low, UV high, unsigned char** segmentmem)
ctx->endp = (ctx->hid >= (UV_MAX/30)) ? UV_MAX-2 : 30*ctx->hid+29;
ctx->segment = get_prime_segment( &(ctx->segment_size) );
- if (ctx->segment == 0)
- croak("start_segment_primes: Could not get segment");
*segmentmem = ctx->segment;
ctx->base = 0;
@@ -457,9 +448,7 @@ int next_segment_primes(void* vctx, UV* base, UV* low, UV* high)
MPUassert( seghigh_d >= ctx->lod, "next_segment_primes: highd < lowd");
MPUassert( range_d <= ctx->segment_size, "next_segment_primes: range > segment size");
- if (sieve_segment(ctx->segment, ctx->lod, seghigh_d) == 0) {
- croak("Could not segment sieve from %"UVuf" to %"UVuf, *base+1, *high);
- }
+ sieve_segment(ctx->segment, ctx->lod, seghigh_d);
ctx->lod += range_d;
ctx->low = *high + 2;
diff --git a/util.c b/util.c
index ec25126..2e25b0b 100644
--- a/util.c
+++ b/util.c
@@ -747,8 +747,6 @@ UV _XS_nth_prime(UV n)
/* Start segment sieving. Get memory to sieve into. */
segbase = segment_size;
segment = get_prime_segment(&segment_size);
- if (segment == 0)
- croak("Could not get segment memory");
while (count < target) {
/* Limit the segment size if we know the answer comes earlier */
@@ -756,10 +754,7 @@ UV _XS_nth_prime(UV n)
segment_size = (upper_limit - segbase*30 + 30) / 30;
/* Do the actual sieving in the range */
- if (sieve_segment(segment, segbase, segbase + segment_size-1) == 0) {
- release_prime_segment(segment);
- croak("Could not segment sieve from %"UVuf" to %"UVuf, 30*segbase+1, 30*(segbase+segment_size)+29);
- }
+ sieve_segment(segment, segbase, segbase + segment_size-1);
/* Count up everything in this segment */
count += count_segment_maxcount(segment, 30*segbase, segment_size, target-count, &p);
@@ -791,8 +786,6 @@ signed char* _moebius_range(UV lo, UV hi)
UV nextlog;
Newz(0, mu, hi-lo+1, signed char);
- if (mu == 0)
- croak("Could not get memory for %"UVuf" moebius results\n", hi-lo+1);
A = (unsigned char*) mu;
if (sqrtn*sqrtn != hi) sqrtn++; /* ceil sqrtn */
@@ -830,8 +823,6 @@ UV* _totient_range(UV lo, UV hi) {
if (hi < lo) croak("_totient_range error hi %lu < lo %lu\n", hi, lo);
/* TODO: When is it faster to just do individual calls? */
New(0, totients, hi-lo+1, UV);
- if (totients == 0)
- croak("Could not get memory for %"UVuf" totients\n", hi);
for (i = lo; i <= hi; i++) {
UV v = i;
if (i % 2 == 0) v -= v/2;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git
More information about the Pkg-perl-cvs-commits
mailing list