Exemple #1
0
void *
tests_allocate (size_t size)
{
  struct header  *h;
  void *rptr, *ptr;
  mp_limb_t PATTERN2_var;

  if (size == 0)
    {
      fprintf (stderr, "tests_allocate(): attempt to allocate 0 bytes\n");
      abort ();
    }

  h = (struct header *) __gmp_default_allocate (sizeof (*h));
  h->next = tests_memory_list;
  tests_memory_list = h;

  rptr = __gmp_default_allocate (size + 2 * sizeof (mp_limb_t));
  ptr = (void *) ((gmp_intptr_t) rptr + sizeof (mp_limb_t));

  *((mp_limb_t *) ((gmp_intptr_t) ptr - sizeof (mp_limb_t)))
    = PATTERN1 - PTRLIMB (ptr);
  PATTERN2_var = PATTERN2 - PTRLIMB (ptr);
  memcpy ((void *) ((gmp_intptr_t) ptr + size), &PATTERN2_var, sizeof (mp_limb_t));

  h->size = size;
  h->ptr = ptr;
  return h->ptr;
}
Exemple #2
0
void *
tests_allocate (size_t size)
{
    struct header  *h;

    if (size == 0)
    {
        printf ("tests_allocate(): attempt to allocate 0 bytes\n");
        abort ();
    }

    h = (struct header *) __gmp_default_allocate (sizeof (*h));
    h->next = tests_memory_list;
    tests_memory_list = h;

    h->size = size;
    h->ptr = __gmp_default_allocate (size);
    return h->ptr;
}