libzahl

big integer library
git clone git://git.suckless.org/libzahl
Log | Files | Refs | README | LICENSE

zfree.c (622B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include "internals.h"
      3 
      4 
      5 void
      6 zfree(z_t a)
      7 {
      8 	size_t i, x, j;
      9 	zahl_char_t **new;
     10 
     11 	if (unlikely(!a->chars))
     12 		return;
     13 
     14 	i = libzahl_msb_nz_zu(a->alloced);
     15 	j = libzahl_pool_n[i]++;
     16 
     17 	if (j == libzahl_pool_alloc[i]) {
     18 		x = j ? ((j * 3) >> 1) : 128;
     19 		new = realloc(libzahl_pool[i], x * sizeof(zahl_char_t *));
     20 		if (check(!new)) {
     21 			free(a->chars);
     22 			free(libzahl_pool[i]);
     23 			libzahl_pool_n[i] = 0;
     24 			libzahl_pool[i] = 0;
     25 			libzahl_pool_alloc[i] = 0;
     26 			return;
     27 		}
     28 		libzahl_pool[i] = new;
     29 		libzahl_pool_alloc[i] = x;
     30 	}
     31 
     32 	libzahl_pool[i][j] = a->chars;
     33 }