Exemplo n.º 1
0
void *xmalloc(size_t size)
{
  void *ret = try_malloc(size);

  if (!ret) {
    OUT_STR("Vim: Error: Out of memory.\n");
    preserve_exit();
  }
  return ret;
}
Exemplo n.º 2
0
void *xmallocz(size_t size)
{
  size_t total_size = size + 1;
  void *ret;

  if (total_size < size) {
    OUT_STR("Vim: Data too large to fit into virtual memory space\n");
    preserve_exit();
  }

  ret = xmalloc(total_size);
  ((char*)ret)[size] = 0;

  return ret;
}
Exemplo n.º 3
0
char * xstrdup(const char *str)
{
  char *ret = strdup(str);

  if (!ret) {
    try_to_free_memory();
    ret = strdup(str);
    if (!ret) {
      OUT_STR("Vim: Error: Out of memory.\n");
      preserve_exit();
    }
  }

  return ret;
}
Exemplo n.º 4
0
void *xrealloc(void *ptr, size_t size)
{
  void *ret = realloc(ptr, size);

  if (!ret && !size)
    ret = realloc(ptr, 1);

  if (!ret) {
    try_to_free_memory();
    ret = realloc(ptr, size);
    if (!ret && !size)
      ret = realloc(ptr, 1);
    if (!ret) {
      OUT_STR("Vim: Error: Out of memory.\n");
      preserve_exit();
    }
  }

  return ret;
}
Exemplo n.º 5
0
void *xcalloc(size_t count, size_t size)
{
  void *ret = calloc(count, size);

  if (!ret && (!count || !size))
    ret = calloc(1, 1);

  if (!ret) {
    try_to_free_memory();
    ret = calloc(count, size);
    if (!ret && (!count || !size))
      ret = calloc(1, 1);
    if (!ret) {
      OUT_STR("Vim: Error: Out of memory.\n");
      preserve_exit();
    }
  }

  return ret;
}