version 1.1, 2003/03/30 08:10:57 |
version 1.2, 2003/06/05 21:12:07 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/ox_toolkit/gmp_fake.c,v 1.1 2003/03/30 08:10:57 ohara Exp $ */ |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
|
|
|
|
#define DEFAULT_LIMB_SIZE 1 |
#define DEFAULT_LIMB_SIZE 1 |
#define MALLOC(x) malloc((x)) |
#define MALLOC(x) malloc((x)) |
#define FREE(x) free((x)) |
#define MALLOC_ATOMIC(x) malloc((x)) |
|
#define REALLOC(p,x) realloc((p),(x)) |
|
#define ALLOCA(x) alloca((x)) |
|
|
#if !defined(CHAR_BIT) |
#if !defined(CHAR_BIT) |
#define CHAR_BIT 8 |
#define CHAR_BIT 8 |
Line 36 inline static void __mpz_clear(mpz_ptr z) |
|
Line 38 inline static void __mpz_clear(mpz_ptr z) |
|
|
|
void *_mpz_realloc(mpz_ptr z, size_t n) |
void *_mpz_realloc(mpz_ptr z, size_t n) |
{ |
{ |
FREE(z->_mp_d); |
mp_limb_t *p = REALLOC(z->_mp_d, n*sizeof(mp_limb_t)); |
z->_mp_size = n; |
if (p != NULL) { |
return z->_mp_d = MALLOC(n*sizeof(mp_limb_t)); |
z->_mp_d = p; |
|
} |
|
return p; |
} |
} |
|
|
void mpz_init(mpz_ptr z) |
void mpz_init(mpz_ptr z) |
{ |
{ |
z->_mp_size = DEFAULT_LIMB_SIZE; |
z->_mp_size = DEFAULT_LIMB_SIZE; |
z->_mp_d = MALLOC(DEFAULT_LIMB_SIZE); |
z->_mp_d = MALLOC_ATOMIC(DEFAULT_LIMB_SIZE); |
__mpz_clear(z); |
__mpz_clear(z); |
} |
} |
|
|
Line 109 char *mpz_get_str(char *s, int base, mpz_ptr src) |
|
Line 113 char *mpz_get_str(char *s, int base, mpz_ptr src) |
|
len = ((CHAR_BIT)*sizeof(mp_limb_t)*abs(src->_mp_size))/((base==16)? 4: 3)+4; |
len = ((CHAR_BIT)*sizeof(mp_limb_t)*abs(src->_mp_size))/((base==16)? 4: 3)+4; |
mpz_init(z); |
mpz_init(z); |
mpz_set(z, src); |
mpz_set(z, src); |
t = MALLOC(len+1); |
t = ALLOCA(len+1); |
t[len] = '\0'; |
t[len] = '\0'; |
for(i=len-1; i>=0; i--) { |
for(i=len-1; i>=0; i--) { |
res = 0; |
res = 0; |
Line 135 char *mpz_get_str(char *s, int base, mpz_ptr src) |
|
Line 139 char *mpz_get_str(char *s, int base, mpz_ptr src) |
|
} |
} |
len = strlen(t+i)+1; |
len = strlen(t+i)+1; |
if (s == NULL) { |
if (s == NULL) { |
s = MALLOC(len); |
s = MALLOC_ATOMIC(len); |
} |
} |
memcpy(s, t+i, len); |
memcpy(s, t+i, len); |
FREE(t); |
|
return s; |
return s; |
} |
} |
|
|